2016-01-06 10:06 AM
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-problem2016-01-06 10:36 AM
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.2016-01-06 11:23 AM
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.2016-01-06 11:41 AM
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.