cancel
Showing results for 
Search instead for 
Did you mean: 

RCC_FLAG_IWDGRST Always 0

SudoObey
Associate

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.

6 REPLIES 6
TDK
Super User

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

If you feel a post has answered your question, please click "Accept as Solution".

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.

SudoObey
Associate

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.

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.

If you feel a post has answered your question, please click "Accept as Solution".
waclawek.jan
Super User

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

JW

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

 

Thank you!