Repository navigation
Fix STM32 boards crashing instead of running out of memory - #11610
Merged
Merged
Conversation
Since 1cc4e6f (adafruit#9962) port_heap_get_top() returns _ld_heap_end, the top of RAM. That is right for common_tcm.ld, where the stack lives in DTCM, but common_default.ld and common_nvm.ld put the stack at the top of RAM too. On those boards (Feather STM32F405 and 17 others) the TLSF pool covered the whole stack, 25 KB on the F405, so a large heap block could be handed out on top of it. A list growing to 32 KB in a fragmented heap then hard-faulted, or overwrote the stack canary and reset into safe mode with STACK_OVERFLOW, instead of raising MemoryError. Stop the heap at port_stack_get_limit() when the stack top falls inside the heap's RAM, as atmel-samd, nordic and raspberrypi do. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
tannewt
requested changes
Oct 15, 2026
tannewt
left a comment
Member
There was a problem hiding this comment.
Why not change the linker script?
Move the fix from port_heap_get_top() into common_default.ld and common_nvm.ld, as suggested in review. _ld_heap_end now stops at the same address port_stack_get_limit() returns. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
What
Keep the heap out of the stack's RAM on 18 STM32 boards.
Why
A big allocation could land on the stack and crash the board instead of raising MemoryError.
The largest free block on the Feather STM32F405 shrinks by about 24 KB.
Code that fit only by overlapping the stack now raises MemoryError.
Probe code and output
AI assistance: written with Claude Code. I reviewed the change and the trial results.
🤖 Generated with Claude Code