BigFatFlo
BigFatFlo

Reputation: 77

NVIC_SystemReset() stuck in while loop (STM32F302VB)

I'm currently developing on a STM32F302VB and I need to perform a software reset. On all my previous projects (with STM32F427 and STM32F030C8), I've always used the NVIC_SystemReset() function successfully. But for some reason it won't work with this chip. The implementation is in CMSIS core_cm4.h and is as follows:

__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 */
}

The function is called and all instructions are executed, but it gets stuck in the while loop, and reset never happens. I then have to reset it via JTAG to get it out of that state.

I checked the programming manual and the implementation seems fine (not surprising since it works perfectly on F4 and F0).

I really don't know what the problem might be, does someone have an idea what's going on?

Edit: The function is still not working but as a workaround, after the function gets stuck, I pull down the nRST pin and then up. It's ugly, but it works for now. I would rather do it all in software though.

Upvotes: 0

Views: 3159

Answers (1)

BigFatFlo
BigFatFlo

Reputation: 77

Tony K was right in his comment, the nRST pin was indeed being pulled high externally, because of a routing mistake.

And contrary to what I thought, the nRST pin is taken into account even in a software reset: the reference manual says: "[Reset] sources act on the NRST pin and it is always kept low during the delay phase", so I should have known!

Removing the pull-up did the trick, the NVIC_SystemReset() function now works as expected!

Thank you very much!

Upvotes: 3

Related Questions