I built a STemwin Project with Cubemx and run this project on STM32F429ii based PCB. Every time when it reached the GUI_INIT() which was related to the memory allocation, it ran into HardFault_Handler(). I debugged this issue and found it was caused by the Timer while the only timer in this project is TIM1 for Timebase source. I can't understand how can Timer cause the HardFault? Can someone give me a clue about this issue? Thank you.

Here is some debugging information:

->SP value when HardFault occur

enter image description here

->LR value in Stack

enter image description here

->Assembly code position

enter image description here

->C code position

enter image description here

Edit: Problem is solved. When the SDRAM clock frequency drops from 72Mhz to 36Mhz, the emwin runs well. The SDRAM controller needs to be check and reconfigured later but the emwin is ok.

  • \$\begingroup\$ That's a classic symptom of stack corruption. The HAL_TIM_PeriodElapsedCallback function is trying to return, but the return address on the stack has been overwritten by something else. Have you made your stack(s) large enough? Have you added any additional code to HAL_IncTick? \$\endgroup\$
    – brhans
    Sep 10, 2019 at 1:17
  • \$\begingroup\$ @brhans The stack&heap size was both 0x2000. I just enlarged them to 0x10000, but still the same. The HAL_IncTick is generated by Cubemx which I haven't made any change. \$\endgroup\$
    – Ross
    Sep 10, 2019 at 2:02
  • \$\begingroup\$ I do not think you are even close. What kind if HF is it? Precise or imprecise? What is at the stack (but the stack contains the values of the registers stacked there when the HF was invoked. IMO install atollic studio which has a very handy plugin showing all the necessary information needed \$\endgroup\$ Sep 11, 2019 at 15:05


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.