cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 MCU stack analysis

MRedd.3
Associate II

STM32F469NI controller and IDE System workbench version 4.5.2 MCU with 2MB flash and 320kb RAM are used. for LCD ST emWin graphic library with GUI interface we using.

The problem is that we are updated new touch driver code. The touch is detected, but if we go to another screen, the structure does not change, and the controller code is running touch irq pin detecting when we touch. So we assumed it was a stack issue, so we removed two variables and everything was fine.

Could you please tell me how to resolve the problem and if there is a tool for memory optimization?

how to find how much memory stack and heap size?

THe code details:

section         size     addr

.isr_vector       436   134217728

.text         257092   134218176

.rodata        192716   134475268

.init_array         4   134667984

.fini_array         4   134667988

.data          3296   536870912

.ccmram          0   268435456

.bss         197008   536874208

._user_heap_stack   1536   537071216

.ARM.attributes     46       0

.debug_info      863228       0

.debug_abbrev      46865       0

.debug_aranges     9832       0

.debug_ranges      8944       0

.debug_macro      117622       0

.debug_line      283470       0

.debug_str       769386       0

.comment         257       0

.debug_frame      43260       0

.stabstr         223       0

Total        2795225

2 REPLIES 2
KnarfB
Principal III

few points:

  • In STM32CubeIDE there is a static stack analyzer view which shows the static stack use of inidividual functions and entire call chains. Consider additional overhead for irq handlers...
  • in the Device Configuration view Project Mananger, you specify two values Min. Heap Size and Min. Stack Size. If you increase those to realistic values, the linker can check at build time that the configured amount of memory will be available at run time.
  • I'm not aware of STM specific tools for dynamic stack usage analysis except some support in FreeRTOS. You can fill the entire stack with some specific byte pattern and regularily check that there is some bottom stack space not overwritten (= unused).
  • You may try complier specific support https://gcc.gnu.org/onlinedocs/gccint/Stack-Checking.html but I haven't used that yet.

hth

KnarfB

Variables from interrupts, make sure they are volatile.

Sure basic methods like filling the stack space with a pattern to find the low water mark could be employed.

Basic understanding of MCU operation, stacks and heaps, would also be helpful.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..