cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Hangs when program too big, stack and heap increase not help

pawburdzy
Associate
Posted on January 06, 2016 at 19:06

Hello anyone who want to help me.

Got problem with my code, just do weird things when code become too big (not sure it is code size depend). I though it could be a problem with stack or heap but increasing them doesn't help at all. Written many codes and same happen, no mother it is compiled with Eclipse+GCC or Keil. Used: STM32F103C8T6 or STM32F105RBT6.

Maybe it is problem with code alignment. I observed I could help to work code fine when use asm(''nop'') (2 or 4 times) in place where code behave weirldy. Then code works perfectly. Changing the code in other place and same happen so then I need to remove asm directives (2 or 4) and again everything is fine. Could anyone explain me this thing?

Big thanks guys!

Pawel

#stm32-weird-begave-hangs-problem
3 REPLIES 3
Posted on January 06, 2016 at 19:36

You'd do better looking at the generated code, and have a hard fault handler, than twiddling knobs until the problem apparently goes away.

That Keil and GNU/GCC fails is more suggestive that your code is trashing the stack through pointers, or exceeding the bounds of the variables/arrays you are using.

A good opportunity to polish your debugging skills.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pawburdzy
Associate
Posted on January 06, 2016 at 20:23

Just implemented:

void HardFault_Handler (void) {

if (CoreDebug->DHCSR & 1) { // check C_DEBUGEN == 1 -> Debugger Connected

__breakpoint (0); // halt program execution here

}

while (1);

}

void MemManage_Handler(void) {

while (1);

}

void BusFault_Handler(void) {

while(1);

}

void UsageFault_Handler(void) {

while(1);

}

None of them has been thrown.

Moreover, the code works fine in Debug mode!  What's going on, any further sugestions? Thanks.

Posted on January 06, 2016 at 20:41

So when it hangs, and you hit the STOP button in the debugger, where exactly is it hanging?

Understand what your code does, use static analysis.

Understand what is happening, and how it gets there, instrument your code so you can see real time the flow of things. Take that knowledge and apply it to the aforementioned static analysis.

As you confine the failure add more instrumentation to confine it further.

Use a Hard Fault handler that outputs actual diagnostics about the state of the machine.

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