memory protection detecting stack overwriting heap
Posted: Sun Jan 10, 2021 8:36 am
i've occasionally seen my sketches/firmware crash and i think it is caused by the stack overwriting heap memory. there is only 20k sram on bluepill (stm32f103) style mcus after all. i'd guess sometimes with various functionalities integrated together, it is quite possible to run out of memory.
there doesn't seem to be an 'easy' way to detect this, i'm not sure if the memory protection features on the mcu could be used to detect this condition.
is there a way to use the memory protection features (say on stm32f103) to detect this?
edit:
i did a little google search and stumbled into these
https://www.st.com/resource/en/applicat ... ronics.pdf
https://www.iotality.com/armcm-access-levels/
it seemed an implementation can require rather significant stack redesign as it may imply that writing to the heap always requires a 'privileged' mode.
And that 'privileged' mode can only be accessed from an exception or service call
there doesn't seem to be an 'easy' way to detect this, i'm not sure if the memory protection features on the mcu could be used to detect this condition.
is there a way to use the memory protection features (say on stm32f103) to detect this?
edit:
i did a little google search and stumbled into these
https://www.st.com/resource/en/applicat ... ronics.pdf
https://www.iotality.com/armcm-access-levels/
it seemed an implementation can require rather significant stack redesign as it may imply that writing to the heap always requires a 'privileged' mode.
And that 'privileged' mode can only be accessed from an exception or service call