Skip to main content
Associate
March 4, 2026
Solved

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

  • March 4, 2026
  • 3 replies
  • 263 views

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

 

 

Best answer by Pavel A.

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.

 

3 replies

TDK
Super User
March 4, 2026

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
March 9, 2026

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
March 4, 2026

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
Super User
March 4, 2026

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
March 9, 2026

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.