Skip to main content
Associate
Mar 4, 2026 1:59 PM UTC
Solved

calling NVIC_SystemReset() in the os task will trigger hard fault

When I calling NVIC_SystemReset() in the os task, the system will enter into hard fault handler error, so I have to call NVIC_SystemReset() again in the HardFault_Handler() to reset the system, so what is the proper way to call NVIC_SystemReset() in the os task?

st_code.png

 

 

Pavel A.
Pavel A.Best answer
Mar 4, 2026 7:39 PM UTC

Do your RTOS tasks run in non-privileged mode? Then of course NVIC_SystemReset() will cause a fault.

>  so what is the proper way to call NVIC_SystemReset() in the os task?

Maybe, do this in SVC handler and make the task execute SVC. Or just leave it as is.

 

5 replies

TDK
Mar 4, 2026 2:14 PM UTC

NVIC_SystemReset() is one correct way to reset the chip.  Calling this from a task as opposed to the main thread should not cause issues.

If a hardfault occurs, I recommend finding the root cause and solving that. STM32CubeIDE has a hard fault analyzer that could be used.

"If you feel a post has answered your question, please click ""Accept as Solution""."
xyxiao82Author
Associate
Mar 9, 2026 4:26 AM UTC

The root cause of hardfault is "Precise Data Bus Error", and the BFAR register is 0xE000ED0C which is SCB->AIRCR register (the reset register). 

The root cause of my problem is that I run NVIC_SystemReset() under non-privileged mode, so I change the task mode to privileged mode to solve this problem.

Thank you for your support.

Andrew Neil
Super User
Mar 4, 2026 2:25 PM UTC

As @TDK said, you should find out what's causing the Hard Fault:

Debugging Cortex-M Hard Faults

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Pavel A.
Pavel A.Best answer
Mar 4, 2026 7:39 PM UTC

Do your RTOS tasks run in non-privileged mode? Then of course NVIC_SystemReset() will cause a fault.

>  so what is the proper way to call NVIC_SystemReset() in the os task?

Maybe, do this in SVC handler and make the task execute SVC. Or just leave it as is.

 

xyxiao82Author
Associate
Mar 9, 2026 4:19 AM UTC

Yes, you are right. The os task is running in the non-privileged mode. As the OS has taken over the SVC_Handler, I configured the OS task to run in Privileged Mode instead.

Thank you for the help.