cancel
Showing results for 
Search instead for 
Did you mean: 

What happens when an Exception occurs in Exception Handler I'm working with the STM32H755ZI and gcc.

MBos.1
Associate II

Dear people,

I do not understand the following behavior of the STM32H755ZI:

I implemented a stack test by configuring a safety zone with MPU. When the stack overflows, the MemManage Handler is called. So far so good.

In this MemManage Handler I only save the exception info in a "noinit" section and then trigger a NVIC SystemReset.. The MCU does not reset, it directly falls into HardFault Handler.

The saving of the exception info needs another access to the stack which actually again is a MemManage Fault., so the command NVIC_SystemReset never gets reached.

Could this second Memory Fault in MemManage Handler leads to the HardFault?

  • When I leave out the part with saving the exception info, the HardFault Handler is not called
  • When I have another MemManage fault (no stack overflow), the HardFault Handler is not called.
  • The behavior is 100 % reproducable

Thanks a lot .

Kind regards

Michael

3 REPLIES 3
TDK
Guru

If your error handlers causes errors and calls itself, you're screwed. You could implement a valid memory check in MemManage handler to ensure data you're accessing is in a valid range.

If you feel a post has answered your question, please click "Accept as Solution".
berendi
Principal

AFAIK if the stack overflows into the protected area, then the values written there are lost, don't try to recover them.

You can set up separate stack pointers (PSP and MSP) for the application and the interrupt handlers, right in the Reset_Handler(). See the Programming manuals for details on each core. It won't solve the problem if there is a stack overflow in an interrupt handler, so you might still have to rewrite the MemManage_Handler() with a stack pointer check in assembly to be more robust.

MBos.1
Associate II

Thanks a lot for your answers. :)

I'm going to check the stack pointer in MemManage_Handler() and try to catch it if necessary.

Have a nice weekend