NVIC_SystemReset () not working for STM32F4

yemans picture yemans · Aug 4, 2014 · Viewed 37.6k times · Source

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

Answer

barak manos picture barak manos · Aug 4, 2014

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();
}