Skip to content

Speaker: enlarge the spk_task stack for builds without optimization - #425

Merged
lovyan03 merged 1 commit into
m5stack:developfrom
ainyan03:spk_task_stack
Oct 29, 2026
Merged

lovyan03 merged 1 commit into
m5stack:developfrom
ainyan03:spk_task_stack

Conversation

@ainyan03

Copy link
Copy Markdown
Contributor

Fixes #424

spk_task overflowed its stack right after the first tone() when M5Unified was compiled without optimization. The official PlatformIO espressif32 8.0.0 platform passes no -O flag for Arduino projects, so sketches built there (and the libraries they pull in) are compiled at -O0; pioarduino passes -Os. The sdkconfig of both platforms is identical for ESP32-S3.

This raises the fixed part of the spk_task stack from 1280 to 1536 bytes (the dma_buf_len-dependent part is unchanged).

Measurement

ESP32-S3 (Cardputer ADV), Arduino core 3.3.12, toolchain 14.2.0+20260121, default dma_buf_len (256), stack high water mark of spk_task while playing tones:

build used before (2304 B) after (2560 B)
-Os (pioarduino 55.03.312, or official 8.0.0 + build_flags = -Os) 2076 B 228 B left 484 B left
-O0 (official 8.0.0, no build_flags) 2376 B overflow (canary watchpoint) 172 B left

The reporter's minimal sketch (M5Cardputer.begin(cfg, true); M5Cardputer.Speaker.tone(1000, 100);) on official 8.0.0 boot-loops with the same register dump as in #424 before this change, and runs normally after it. M5.begin() alone reproduces it as well.

Built with the upstream CI environments locally and with the CI on the fork.

…36 bytes

When the library is compiled without optimization (-O0), spk_task needs
about 2376 bytes with the default dma_buf_len (256), which exceeded the
2304-byte stack and triggered the stack canary watchpoint right after
the first tone() on ESP32-S3. The official PlatformIO espressif32 8.0.0
platform passes no optimization flag for Arduino projects, so sketches
built there are compiled at -O0.

Measured on ESP32-S3 (Arduino core 3.3.12), high water mark of spk_task:
  -O0: 2376 bytes used (now 172 bytes left of 2560)
  -Os: 2076 bytes used

Fixes m5stack#424
@lovyan03
lovyan03 merged commit 180021a into m5stack:develop Oct 29, 2026
31 checks passed
@ainyan03
ainyan03 deleted the spk_task_stack branch October 29, 2026 09:43
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