Search code examples
stm32interruptresetfreertosstm32f7

NVIC System Reset fails


I’m using STM32f767zi with FreeRTOS kernel. I have two task:

1- one is triggered by a task notification from an interrupt every 100ms and receives some data through TCP.

2- the other task is handling some requests from user.

Now, if task-2 request for a system reset using NVIC_SystemReset API, system reset fails and every things hangs. When I run debugger, it seems it hangs in vPortRaiseBASEPRI. In disassembly, that is a few lines after vTaskNotifyFromISR which is the notification function I used for task-1.

When I remove that task notification and use just a flag in the interrupt, the system reset works fine. However, I think this way consumes the processor cycles and will not be efficient.

I tried to disable interrupts portDISABLE_INTERRUPT, tasks vTaskSuspendAll or enter critical taskENTER_CRITICAL but nothing work.

I did a way around method by requesting to portDISABLE_INTERRUPT in an independent request (so that any pended interrupt or “notification” can finish), then sending system reset in another request. This one works, however, it is not safe because the user can (by mistake) do the system reset before disabling interrupts.

Note that when I do hardware reset (push button on board) it works fine?!

So, any idea how to solve this problem? how to reset the board by software without that issue?


Solution

  • The problem solved by simply adding some delay after disabling task-1 interrupt:

    NVIC_DisableIRQ(IRQn);
    vTaskDelay(xTicksToDelay);
    NVIC_SystemReset();
    

    I still don't know if this solved the root cause.