Softreset from Hardfault in NIL

Discussions and support about ChibiOS/NIL, the almost nil RTOS.
kdums
Posts: 13
Joined: Tue Oct 17, 2017 4:06 pm
Has thanked: 1 time

Softreset from Hardfault in NIL

Postby kdums » Wed Dec 04, 2019 7:43 am

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

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: Softreset from Hardfault in NIL

Postby Giovanni » Wed Dec 04, 2019 8:28 am

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

kdums
Posts: 13
Joined: Tue Oct 17, 2017 4:06 pm
Has thanked: 1 time

Re: Softreset from Hardfault in NIL

Postby kdums » Fri Dec 06, 2019 8:16 am

Thanks for your advice.


Return to “ChibiOS/NIL”

Who is online

Users browsing this forum: No registered users and 8 guests