Hi!
In case of a fault I need to reset the CPU (ARM Cortex M3), but I must not do a hard reset.
What do I have to do to make a clean restart using the Reset_Handler when I am in a fault handler e.g. HardFault?
Kind regards,
Klaus Dums
Softreset from Hardfault in NIL
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Softreset from Hardfault in NIL
Hi,
If you are in an exception state then you cannot simply jump to Reset_Handler, you need to empty the stack of exceptions inside NVIC.
Assuming that your exception happened while running in process mode (the stack contains just one exception) then you can modify the return address into the exception return structure then return from exception. This will pop the exception from the NVIC and jump to the reset vector.
You can see an example of this in the IRQ epilogue code (Cortex-M port), it is used to return from an IRQ into a specific point, you need to do pretty much the same.
If you need to handle multiple level exceptions then it is more complex, I don't have an example for this but you need to return on code that checks if there are more exceptions and return again again etc. On the last one you return on the reset vector (all while keeping interrupts disabled or you could be preempted).
Giovanni
If you are in an exception state then you cannot simply jump to Reset_Handler, you need to empty the stack of exceptions inside NVIC.
Assuming that your exception happened while running in process mode (the stack contains just one exception) then you can modify the return address into the exception return structure then return from exception. This will pop the exception from the NVIC and jump to the reset vector.
You can see an example of this in the IRQ epilogue code (Cortex-M port), it is used to return from an IRQ into a specific point, you need to do pretty much the same.
If you need to handle multiple level exceptions then it is more complex, I don't have an example for this but you need to return on code that checks if there are more exceptions and return again again etc. On the last one you return on the reset vector (all while keeping interrupts disabled or you could be preempted).
Giovanni
Who is online
Users browsing this forum: No registered users and 29 guests