AnsweredAssumed Answered

NVIC_SystemReset stuck

Question asked by remis.florent on Nov 24, 2015
Latest reply on Nov 26, 2015 by remis.florent
Hello,

I'm currently working on a STM32F302VB and I need to perform a Soft Reset. On previous projects with STM32F030C8 and STM32F407, I've used the NVIC_SystemReset() function without any problems, but for some reason it doesn't work now.
The implementation I use is this one:

__STATIC_INLINE void NVIC_SystemReset(void)
{
  __DSB();                                                     /* Ensure all outstanding memory accesses included
                                                                  buffered write are completed before reset */
  SCB->AIRCR  = ((0x5FA << SCB_AIRCR_VECTKEY_Pos)      |
                 (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
                 SCB_AIRCR_SYSRESETREQ_Msk);                   /* Keep priority group unchanged */
  __DSB();                                                     /* Ensure completion of memory access */
  while(1);                                                    /* wait until reset */
}


found in core_cm4.h.
The function is called and all instructions are executed, but it gets stuck in the while loop and reset never happens.
After some research I've implemented the reset using assembly instead, as follows:

asm("\tdsb \n\t"
        "ldr r0, =0xE000ED0C\n\t"
         "ldr r1, =0x05FA0007\n\t"
         "str r1, [r0, #0]\n\t"
         "dsb\n"
         "Infinite_Loop:\n\t"
         "b  Infinite_Loop");

This does perform the Soft Reset.
The only difference I see is that NVIC_SystemReset() keeps the priority group unchanged, and doesn't set the VECTCLRACTIVE and VECTRESET bits (bits 1 and 0). Those bits aren't supposed to be set for a reset, as it says in the programming manual: "When writing to the register you must write 0 to [these] bit[s], otherwise behavior is unpredictable."
But when I use 0x05FA0004 instead of 0x05FA0007 in the above assembly code, the controller gets stuck in the while loop, as it does with the NVIC_SystemReset() function. 
I've also tried running it without debugging, and it doesn't work either, the processor gets stuck. So for now it seems I have no other choice than setting those two bits and hope the unpredictable behavior is tolerable.

Does anyone have an idea what's going on?

Thanks

Outcomes