Skip to main content
Graduate
June 3, 2025
Question

RCC_FLAG_IWDGRST Always 0

  • June 3, 2025
  • 3 replies
  • 541 views

Hello,

 

I am working on adding an IWDG to firmware on a STM32F070CBT6TR. The Watchdog resets perfectly fine. I cause the watchdog to reset the MCU by not resetting the timer. I then try to read the RCC_FLAG_IWDGRST and it is always 0. This is what my main looks like before trying to read the flag.

bool g_wd_caused_reset = false;
int main(void)
{
 // MCU Configuration----------------------------------------------------------
 NVIC_SetVectorTable(); // Reset vecter table
 __HAL_REMAPMEMORY_SRAM(); // Remap boot address to SRAM

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();

 /* Configure the system clock */
 SystemClock_Config();
 if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET)
 {
 g_wd_caused_reset = true;
 }
...
...
}

 My expectation is that RCC_FLAG_IWDGRST would read 1 after the watchdog causes a reset, but I never see g_wd_caused_reset == true.

 

My IWDG is configured to reset after ~26 seconds.

 

Any help is appreciated,

Thank you.

    This topic has been closed for replies.

    3 replies

    Super User
    June 3, 2025

    Try reading it immediately after main(). Try verifying the bit directly by looking at the the RCC_CSR register.

    SudoObeyAuthor
    Graduate
    June 3, 2025

    Hello TDK,

    Thank you for the reply. I changed the code as follows:

    bool g_wd_caused_reset = false;
    int main(void)
    {
     if (RCC->CSR & RCC_CSR_IWDGRSTF)
     {
     g_wd_caused_reset = true;
     }
    
     // MCU Configuration----------------------------------------------------------
     NVIC_SetVectorTable(); // Reset vecter table
     __HAL_REMAPMEMORY_SRAM(); // Remap boot address to SRAM
    
     /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
     HAL_Init();
    
     /* Configure the system clock */
     SystemClock_Config();
    
    ...
    ...
    }

    I am still not seeing my boolean set to true. I connected my device to STM32CubeProgrammer while my firmware was running and the register is also 0 there. 

     

    Thank you.

    SudoObeyAuthor
    Graduate
    June 3, 2025

    I added a breakpoint at line 4 and stepped over to complete the read. This is what the registers look like after IWDG resets the MCU:

    SudoObey_0-1748995121788.png

    Note that LSION and LSIRDY aren't set because I am stopping before IWDG is initialized again.

    Super User
    June 4, 2025

    Something may be clearing those flags. One bit at least should always be set. Can you zip up your project and attach? You can set a breakpoint at Reset_Handler to catch it when it just resets.

    Super User
    June 4, 2025

    Given non-reset-default AHBENR/APBxENR (enabled DMA, TIM1, I2C1, TIM6) I bet you have some custom bootloader running before the application.

    JW

    SudoObeyAuthor
    Graduate
    June 4, 2025

    You are absolutely right. I completely overlooked my bootloader. I will look into that.

     

    Thank you!