Skip to content

Feat/mp3 internal ram pool - #674

Open
KOKO-cyco wants to merge 13 commits into
tuya:masterfrom
KOKO-cyco:feat/mp3-internal-ram-pool
Open

Feat/mp3 internal ram pool#674
KOKO-cyco wants to merge 13 commits into
tuya:masterfrom
KOKO-cyco:feat/mp3-internal-ram-pool

Conversation

@KOKO-cyco

Copy link
Copy Markdown
Contributor

PR 描述/PR description

[在此详细描述 PR 的内容]/[Describe the PR content in detail here]

代码质量/Code Quality:

在本次拉取请求中,我已考虑以下事项 As part of this pull request, I've considered the following:

  • 确保代码注释和文档清晰,并使用英文注释以保证代码可读性。Ensure that the code comments and documentation are clear, and use English for comments to ensure code readability.
  • 确保文件头遵循文件头格式。Ensure that the file header follows the File Header Format.
  • 确保函数头遵循 Doxygen 格式。Ensure that function headers follow the Doxygen format as specified in Comments.
  • 已查阅 编码风格指南,并核查代码风格合规性,包括缩进、空格、命名规范及其他风格要求。 Reviewed the Coding Style Guide and verified code style compliance, including indentation, spacing, naming conventions, and other style guidelines.
  • 已使用代码格式化工具确保符合 TuyaOpen 编码规范。Have used the code-formatting source code formatting tool to ensure compliance with TuyaOpen coding standards.

guanshan.xu and others added 7 commits August 12, 2026 14:53
新增 boards/SiWx917/,覆盖两块板:
- SIWX917_AI_DEV_KIT:涂鸦 AI 开发板,含 ST7789 显示注册
- BRD2605A:芯科官方开发套件 SiWx917-DK2605A,含麦克风使能

两块板同为 SiWG917M111MGTBA,共用 common/ 下的无 codec 音频驱动。

boards/Kconfig 注册 BOARD_ENABLE_SIWX917 与板型选择。
platform_config.yaml 将 SiWx917 平台层固定到 TuyaOpen-SiliconLabs
master @ 123524c1。

新增 your_chat_bot 的 SIWX917_AI_DEV_KIT.config:保留较大的
AI 收发环形缓冲(最新默认的 20KB 在本平台上会卡顿),启用
ENABLE_EXT_RAM + CONFIG_SPIRAM,AI 协议固定 v1(v2 的 TTS
音频路径在本平台尚未验证)。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
audio_player:新增 MP3_DECODER_STATIC_BUF,把 minimp3 的 scratch、
解码上下文和 L12_scale_info 放到 TUYA_MEM_SECTION_RAM 的静态缓冲里。
开了 ENABLE_EXT_RAM 之后 MP3_MALLOC 从 PSRAM 分配,而 mp3dec_scratch_t
(grbuf/syn 约 16KB)每帧都要反复读写,PSRAM 的访问延迟跟不上,在
SiWx917 上会听得出卡顿。代价是常驻约 24KB 内部 RAM 且解码不可重入,
只适合单路播放,所以默认关闭。

liblwip:新增 ENABLE_LWIP_DHCPD,按需编入 dhcpserver.c。

libtls:AES-GCM 在 ENABLE_PLATFORM_AES 下走 tal_aes_gcm_* 硬件路径。
平台实现只作为加速器,任何错误都回落到软件 mbedtls,不让它成为单点故障。

cli_build.py:build_setup 的参数改为逐个 shlex.quote,并追加
$BUILD_PATH。没有 CONFIG_CHIP_CHOICE 的板子 chip 为空串,未加引号时
会被 shell 丢弃,导致 $BUILD_PATH 挪到 $CHIP 的位置;加引号同时也让
含空格的路径不被拆开。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
ENABLE_LWIP_DHCPD 和 MP3_DECODER_STATIC_BUF 全仓只有 SiWx917 两块板
select,却声明在 src/liblwip 和 src/audio_player 的通用层里。Kconfig 是
扁平命名空间,声明放哪个文件不影响 select 和 #if defined() 的解析,所以
把两个声明搬到 boards/SiWx917/TKL_Kconfig,通用层回到未被改动的状态。

ENABLE_LWIP_DHCPD 另有一处实际问题:dhcpserver.c 的编译决策原本在
src/liblwip/CMakeLists.txt,而引用 dhcps_* 的是平台层的 tkl_wifi.c,两边
不同步——关掉这个开关不是关掉功能,而是断链。编译决策一并交给平台层
(见 TuyaOpen-SiliconLabs 的 feat/lwip-dhcpd-guard)。

顺带删掉 minimp3.h 里那段冗余的 TUYA_MEM_SECTION_RAM 探测:唯一的调用方
decoder_mp3.c 在 include minimp3.h 之前已经引好了这个头,那段 __has_include
回退分支从未生效,且其中硬编码的 tuyaopen_bss_to_ram 段名只有 SiWx917 的
链接脚本认识,留在通用第三方代码里会让别的平台静默错放缓冲。

行为不变:SIWX917_AI_DEV_KIT 重新 config + 编译通过,两个开关取值与改动前
一致,静态缓冲仍落在内部 RAM(.bss)。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
cipher_wrapper.c 里那段 ENABLE_PLATFORM_AES 分支是死代码:平台适配层
GCM_NONCE_LEN_REQUIRED 写死 16,而走这条路的调用方(tuya_protocol 的
PV23/LPV35、tuya_lan、atop_base)nonce 全是 12,每次必然返回
OPRT_NOT_SUPPORTED 回落软件 mbedtls,硬件一次都没命中过。回落逻辑对
NOT_SUPPORTED 刻意不打日志,所以跑起来毫无痕迹。

删除后实测:全工程再无任何 .obj 引用 tal_aes_gcm_*,即它本就没有活的
调用方;编译通过,行为零变化。

官方 ENABLE_PLATFORM_AES 机制本身不受影响——它靠 mbedtls_symmetry.c 的
#if 让位、由平台层提供 8 个 tkl_aes_*,这条链路不经过 cipher_wrapper,
本来就不需要改通用层。

同时把 SiWx917 平台钉子更到 4564c81(已合入上游的 DHCPD 条件编译)。
钉在旧的 123524c 会断链:src/liblwip 已不再编 dhcpserver.c,而那个版本的
tkl_wifi.c 仍无条件引用 dhcps_*。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
上次给 build_setup 加的 shlex.quote + 第 5 个参数(BUILD_PATH),起因是
SiWx917 的 build_setup.py 需要 app 的构建目录。现在那个生成步骤改由
platform_config.cmake 触发(见 TuyaOpen-SiliconLabs 的
feat/slc-generate-via-cmake),CMake 在 configure 阶段本来就知道
CMAKE_CURRENT_BINARY_DIR,不需要 tos.py 传参数,SiWx917 也不再提供
build_setup.py,cli_build.py 的 build_setup() 会直接跳过它。

顺带把当初要修的那个 bug(chip 为空时 shell 丢弃空参数,$BUILD_PATH 挪
到 $CHIP 位置)从根上消除了:新流程不再依赖位置参数传路径。

src/ 通用层不需要为一个平台的构建细节留特例。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Add a generic, platform-overridable allocator hook to decoder_mp3.c/
minimp3.h: platforms whose general-purpose heap can't sustain the
per-frame scratch buffer's access pattern (e.g. because it's routed to
PSRAM) can point MP3_MALLOC/MP3_FREE at their own implementation via a
compile-time -D, with the official ENABLE_EXT_RAM-based allocator as the
unchanged default when no override is defined.

Pin SiWx917 to the platform commit that implements this via a dedicated
23KB internal-RAM pool (mp3_internal_pool.c), replacing the previous
raw static-struct-in-a-linker-section approach with normal malloc/free
semantics while keeping the same memory footprint. Update the Kconfig
help text to match. Verified on hardware: TTS playback smooth across
multiple sessions.
@KOKO-cyco KOKO-cyco closed this Aug 14, 2026
@KOKO-cyco KOKO-cyco reopened this Aug 14, 2026
guanshan.xu and others added 6 commits August 17, 2026 09:49
Picks up the bootstrap fix: platform_prepare.py invokes ./script/bootstrap
with no arguments, which began with `sudo apt-get update` and aborted under
`set -e` on any runner without passwordless sudo -- which is why the
SiWx917.config build fails in CI today.
Carries the three bootstrap fixes needed for SiWx917.config to build on
the CI runner:
 - skip the apt install when sudo needs a password (it aborted bootstrap)
 - extract zips via python when unzip is absent, preserving mode bits
 - verify the tools the rest of the bootstrap needs and name any missing
   one up front rather than failing deep inside slc later
Carries everything needed for SiWx917.config to get through the CI
runner, which has neither passwordless sudo nor java:

 - skip the apt install when sudo needs a password, instead of letting
   it abort the whole bootstrap
 - extract zips through python when unzip is absent, mode bits included
 - fetch a Temurin JRE when the host has no java, since slc needs one
 - verify the remaining tools up front and name any that are missing,
   rather than failing deep inside slc twenty minutes later

Also brings the Mac/Windows build work and the flash bridge; both are
inert on Linux.
Picks up the three prebuilt slc payloads, so the three configurations this
repository's CI builds for SiWx917 -- switch_demo and weather_get_demo through
the boards/ fallback list, your_chat_bot through its own config -- restore
generator output instead of invoking slc. A CI run no longer downloads slc or
a JRE, and the "An error has occurred. See the log file" that took a job 51
minutes to report cannot happen. Verified against this exact commit: all three
build clean with slc invoked zero times.

Also carries the Windows host fixes, which are what made those payloads
necessary: junction instead of ln -s for the SDK extension links, forward
slashes on paths handed to bash, the .exe suffix on the toolchain binaries,
and probing for slc's bundled Python rather than naming one path.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
platform_config.yaml conflicted because both sides changed the tail of the
file: master bumped GD32 to c8943cf on what was the last line, and this branch
appends the SiWx917 entry directly after it. Neither edit contradicts the
other, so the resolution keeps both -- master's GD32 and ESP32 bumps, plus the
SiWx917 entry at 84c23b3.

Rebuilt the three configurations CI covers for SiWx917 against the merged
tree; all three restore their prebuilt slc payload and link clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Picks up the CLI-only Simplicity Commander install. The full Commander build
links Qt5Gui/Qt5Widgets and therefore needs libGL from the host, which the CI
container does not have -- the build reached the post-link image conversion and
died there with "libGL.so.1: cannot open shared object file", about 17 minutes
into the job. The CLI build ships in the same archive, links no graphics
libraries at all, and produces byte-identical rps/hex/s37/isp.bin.

Verified locally on switch_demo with boards/SiWx917/config/SiWx917.config, the
configuration this failed on: dependency closure has zero libGL/libX11/libxcb
entries and the full build succeeds.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants