2025-06-03 3:00 PM
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.
2025-06-03 3:43 PM
Try reading it immediately after main(). Try verifying the bit directly by looking at the the RCC_CSR register.
2025-06-03 4:20 PM
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.
2025-06-03 4:59 PM
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:
Note that LSION and LSIRDY aren't set because I am stopping before IWDG is initialized again.
2025-06-03 5:30 PM
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.
2025-06-04 3:46 AM
Given non-reset-default AHBENR/APBxENR (enabled DMA, TIM1, I2C1, TIM6) I bet you have some custom bootloader running before the application.
JW
2025-06-04 8:22 AM - edited 2025-06-04 8:34 AM
You are absolutely right. I completely overlooked my bootloader. I will look into that.
Thank you!