2022-02-24 06:27 AM
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?
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?
2022-02-24 06:34 AM
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.
2022-02-24 09:57 PM
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?
2022-02-25 07:02 AM
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.