cancel
Showing results for 
Search instead for 
Did you mean: 

IWDG reset is happening after flashing the code in DEBUG option through STM32 CUBE IDE

PB.4
Associate II

Hello all,

I'm using STM32F030CC uC and in that I'm reading the @KB of flash data before initializing the peripheral and for every debugging sessions the reset is identified as IWDG reset, can anyone help me to understand this logic?

0693W00000KaQXhQAN.png

int main(void)
{
  /* USER CODE BEGIN 1 */
     uint32_t  iDx = 0;
     uint32_t  i = 0;
     char *temp = '\0';
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 /* Configure the system clock */
  SystemClock_Config();
 Flash_Read_Data_word(0x0803F800,(uint32_t*)&rxData,511);
 while(rxData[iDx] != 0xFF)
	  {
		  iDx++;
	  }
 if(iDx > 0)
	  {
              /* Copying the read data to RAM variables*/
          }
/* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  MX_USART6_UART_Init();
  MX_USART3_UART_Init();
  MX_USART4_UART_Init();
  MX_USART5_UART_Init();
  MX_TIM6_Init();
  MX_IWDG_Init();
  /* USER CODE BEGIN 2 */
 
  if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET)
  {
	  temp = "SystemResetDueToWDG\n";
	   sendToUart1(temp);
  }
  else
  {
	  temp = "SystemResetUnknownReason\n";
	   sendToUart1(temp);
  }
  /* Clear reset flags in any cases */
    __HAL_RCC_CLEAR_RESET_FLAGS();
  /* USER CODE END 2 */
while (1)
  {
  }

Also what is the purpose of IWDG window value here?

3 REPLIES 3
TDK
Guru

IWDG is resetting since you never reload it. You should call HAL_IWDG_Refresh periodically within your main loop to avoid a reset.

The reference manual covers the functionality of the window field. It is used when you want to ensure reloads of the IWDG are done periodically. At its max value of 4095, it is effectively disabled.

0693W00000KaQbKQAV.png 

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

Hello @TDK​ , thanks for your reply. I actually calling the IWDG refresh call insisde the whie(1) function, do I need to call it in he main function as well. I have missed to mention the function HAL_IWDG_Refresh calling in the code I have attached, it is actually being like

int main(void)
{
  /* USER CODE BEGIN 1 */
     uint32_t  iDx = 0;
     uint32_t  i = 0;
     char *temp = '\0';
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 /* Configure the system clock */
  SystemClock_Config();
 Flash_Read_Data_word(0x0803F800,(uint32_t*)&rxData,511);
 while(rxData[iDx] != 0xFF)
	  {
		  iDx++;
	  }
 if(iDx > 0)
	  {
              /* Copying the read data to RAM variables*/
          }
/* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART1_UART_Init();
  MX_USART2_UART_Init();
  MX_USART6_UART_Init();
  MX_USART3_UART_Init();
  MX_USART4_UART_Init();
  MX_USART5_UART_Init();
  MX_TIM6_Init();
  MX_IWDG_Init();
  /* USER CODE BEGIN 2 */
 
  if (__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET)
  {
	  temp = "SystemResetDueToWDG\n";
	   sendToUart1(temp);
  }
  else
  {
	  temp = "SystemResetUnknownReason\n";
	   sendToUart1(temp);
  }
  /* Clear reset flags in any cases */
    __HAL_RCC_CLEAR_RESET_FLAGS();
  /* USER CODE END 2 */
while (1)
  {
       HAL_IWDG_Refresh(&hiwdg);
  }

 Does it required to call the IWDG is prior to start read the data from flash? As it need to read 2KB of data from flash is it cosuming more time? Also IWDG init itself calling after the read completed from the flash, are there any default WDG setting sone even prior to init IWDG? As per the my configuration values I'm asssuming the IWDG reload interval is 5S, is that correct?

Your code above did not call HAL_IWDG_Refresh in the while loop. I don't know how a copy/paste operation could remove that statement.

All IWDG requires is that you refresh it before it resets.

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