Repository navigation
Conversation
opus_codec has a 24 KB stack, the largest on the robot; xiaozhi already runs its AFE and wake-word tasks on PSRAM stacks. lan_server only lives until Wi-Fi is up, when internal RAM is at its lowest. Neither touches flash. Adds a StackChan Memory Kconfig menu. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Xju5qGrWGLo7EfBXNe5Gy2
When AI Agent starts and BLE was never started this boot, release the BT controller, NimBLE and BLE ROM static RAM to the heap. Leaving AI Agent reboots, so BLE comes back on the next boot. Also run the BLE controller from flash, which frees about 25 KB of IRAM. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Xju5qGrWGLo7EfBXNe5Gy2
The buffer lives in internal DMA RAM; 10 lines is 6.25 KB instead of 12.5 KB. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Xju5qGrWGLo7EfBXNe5Gy2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Alan · project thread
Stacked on #4 (
fix-mcp-xiaozhi-2.5, what runs on the robot). Goal: more internal SRAM headroom in AI Agent mode with the LAN MCP server and mDNS on (about 16 KB free now, dips to 1.7 KB at boot).Not compiled and not run on hardware. The cloud session couldn't build because the Espressif component registry is blocked there. Each change uses IDF 6.1 APIs I checked against the IDF source (
xTaskCreateWithCaps/vTaskDeleteWithCapsself-delete,esp_bt_mem_release,BT_CTRL_RUN_IN_FLASH_ONLYon S3).Changes (estimated internal RAM saved)
opus_codectask stack (24 KB) moved to PSRAM. xiaozhi already runs AFE and wake-word tasks on PSRAM stacks. The task never touches flash.STACKCHAN_OPUS_TASK_STACK_IN_PSRAMCONFIG_BT_CTRL_RUN_IN_FLASH_ONLY=y. Measured from the IDF libs:libbtdm_app.ahas 26.5 KB of IRAM, the flash variant has 1.6 KB. On the S3, IRAM comes out of the same SRAM as the heap.esp_bt_mem_release(BLE)when AI Agent starts and BLE was never started this boot. Frees BT/NimBLE .bss/.data and the BLE ROM's reserved RAM. Leaving AI Agent already reboots (home indicator, thenrequestWarmReboot).ble_initrefuses to start after a release. Logs before/after free.released BT memory)STACKCHAN_RELEASE_BT_MEMORY_FOR_AI_AGENTSTACKCHAN_LVGL_BUFFER_LINESlan_serverstart task (4 KB) moved to a PSRAM stack. It only lives until Wi-Fi is up, which is when the boot dip happens.Estimated total: about 55-75 KB more free internal RAM in AI Agent mode.
Options not in this PR
tcp_receive/ssl_receive, 4 KB internal each, one per open connection, in78/esp-ml307). This is a likely cause of the camerahttp->Openfailure: opening the explain URL needs a new 4 KB internal stack. Moving them to PSRAM means vendoring and patching esp-ml307 (it's a managed component). Medium effort, about 4 KB per connection.CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL512 → 0/64. This moves small mallocs (cJSON nodes for MCP, std::string) to PSRAM, which could save tens of KB at peaks. lwIP uses plainmallochere, so small pbufs would move to PSRAM too. That's close to theTRY_ALLOCATE_WIFI_LWIPchange that broke Wi-Fi. Medium-high risk; try it separately.port_cfg.task_stack_caps, ~7 KB). Unsafe if any LVGL callback writes NVS (IDF asserts on flash ops from a PSRAM stack). Needs an audit.Testing (on the robot)
sdkconfig. Runidf.py fullcleanor deletesdkconfig, or setBT_CTRL_RUN_IN_FLASH_ONLYin menuconfig. The new Kconfig options get their defaults automatically.HAL-BLE: BLE unused this boot, released BT memory: internal free X -> Yand the periodic heap stats; compare with ~16 KB before.Generated by Claude Code