2

I am working on STM32F4 board. My IDE is IAR Embedded Work bench. I am trying to do a software reset from code. For that i used API ' NVIC_SystemReset(); ' defined in core_cm4.h header. But the system reset is not happening.

I tried the same thing in STM32F3, same IDE . I used the function NVIC_SystemReset(); from core_sc300.h header. Using that software reset is happening. I found the definition of functions in both file are same and both controllers are Cortex M4 only.What is the problem with STM32F4 board.? Can any one help me in solving this or can any one suggest an alternative way for system reset in STM32F4.

Please help. Thanks in advance

Asad Ali Choudhry
  • 4,985
  • 4
  • 31
  • 36
yemans
  • 917
  • 3
  • 12
  • 17

3 Answers3

5

In the HAL You can use

HAL_NVIC_SystemReset();
Vladimir
  • 109
  • 1
  • 2
2

You can use a watch-dog instead:

  • Call wdg_activate(n) in order to initiate system-reset within n milliseconds
  • Call wdg_reactivate() in order to reload the counter back to n milliseconds

void wdg_activate(unsigned short num_of_ms)
{
    uint8_t prescale_reg;
    uint8_t prescale_val;

    if (num_of_ms < 1)
    {
        num_of_ms = 1;
        prescale_reg = IWDG_Prescaler_32;
        prescale_val = 1;
    }
    else if (num_of_ms <= 4096)
    {
        prescale_reg = IWDG_Prescaler_32;
        prescale_val = 1;
    }
    else if (num_of_ms <= 8192)
    {
        prescale_reg = IWDG_Prescaler_64;
        prescale_val = 2;
    }
    else if (num_of_ms <= 16384)
    {
        prescale_reg = IWDG_Prescaler_128;
        prescale_val = 4;
    }
    else if (num_of_ms <= 32768)
    {
        prescale_reg = IWDG_Prescaler_256;
        prescale_val = 8;
    }
    else
    {
        num_of_ms = 32768;
        prescale_reg = IWDG_Prescaler_256;
        prescale_val = 8;
    }

    IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
    while (IWDG_GetFlagStatus(IWDG_FLAG_PVU));
    IWDG_SetPrescaler(prescale_reg);
    while (IWDG_GetFlagStatus(IWDG_FLAG_RVU));
    IWDG_SetReload(num_of_ms/prescale_val-1);
    IWDG_Enable();
}

void wdg_reactivate()
{
    IWDG_ReloadCounter();
}
barak manos
  • 29,648
  • 10
  • 62
  • 114
  • Hi Barak, Thanks a lot, Actually now i got it working fine, the issue was like - Eventhough my STM32F4 board getting reset, the slave board connected to that is not resetting in that small duration, so i gave a small delay after the board initialization and now it is working fine. Anyway i will try this WDT method also as u insist . Thanks a lot for your support – yemans Aug 05 '14 at 05:18
2

There have been several iterations of NVIC_SystemReset(). Please post the code for the version you are using. The current [working STM32F4] version that I am using is as follows:

/** \brief  System Reset
    The function initiates a system reset request to reset the MCU.
 */
__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 */
}
bunkerdive
  • 2,031
  • 1
  • 25
  • 28