While working on the Huangshan branch, I found that during Bluetooth audio playback, connecting to the Xiaozhi server via WebClient causes a system crash due to malloc failure. When I checked memory usage via the msh script’s ‘free’ command, I found that total memory was around 300 KB. With Bluetooth audio playback enabled, the memory status showed: total memory: 310652, used memory: 178084, maximum allocated memory: 272984. If connecting to the Xiaozhi server at this point, the system crashes immediately due to insufficient memory.
This means enabling the Bluetooth sink in the Huangshanpai program. The code modifications for bt_sink in the SDK are shown above. When playing audio via Bluetooth, connecting to the Xiao Zhi server triggers a system crash, and the log shows a malloc failure. On my side, due to uncertainty about whether the PAN disconnection and reconnection are handled correctly, I used a 5-second timer to periodically send Xiao Zhi’s webclient event to check PAN connectivity, and this issue was discovered during that process.
The device won’t crash if not connected to Xiao Zhi. It seems that the memory allocated by the audio_open function is in the internal SRAM. The issue could be resolved by switching malloc to allocate memory from external PSRAM instead. I haven’t examined your SDK’s network component in detail, but it likely also uses malloc to directly allocate internal SRAM. My suggestion is to add a configuration switch in menuconfig to allow choosing between internal and external RAM.