Skip to main content
Ccui.1
Associate II
January 19, 2021
Question

Could not set IWDG timeout to max (~32s) for STM32G031?

  • January 19, 2021
  • 7 replies
  • 1970 views

I am using Nucleo-G031K board and attempt to set IWDG timeout to max value of ~32s. Got hard fault. Here is the code. Any idea?

 iwdg_hIwdg.Instance = IWDG;

 iwdg_hIwdg.Init.Prescaler = IWDG_PRESCALER_256;

 iwdg_hIwdg.Init.Window = IWDG_WINDOW_DISABLE;

 iwdg_hIwdg.Init.Reload = 4095; 

 if (HAL_IWDG_Init(&iwdg_hIwdg) != HAL_OK)

 {

  iwdg_ErrorHandler();

 }  

This topic has been closed for replies.

7 replies

waclawek.jan
Super User
January 19, 2021

Other values work?

Did you try with a simple "blinky" program?

> Got hard fault.

Then debug it as usually with hardfaults.

JW

Ccui.1
Ccui.1Author
Associate II
January 19, 2021

Other values work. For example, the following code works as expected.

 iwdg_hIwdg.Instance = IWDG;

 iwdg_hIwdg.Init.Prescaler = IWDG_PRESCALER_128;

 iwdg_hIwdg.Init.Window = IWDG_WINDOW_DISABLE;

 iwdg_hIwdg.Init.Reload = 4095; 

 if (HAL_IWDG_Init(&iwdg_hIwdg) != HAL_OK)

 {

  iwdg_ErrorHandler();

 }  

I will checkout sample application.

waclawek.jan
Super User
January 20, 2021

And using the same prescaler but different reload value?

JW

PDAMN.1
Visitor II
February 8, 2021

Hello

I have the same problem as you. Did you find the solution?

Can you help me ?

Thank you

Ccui.1
Ccui.1Author
Associate II
February 8, 2021

HAL_IWDG_DEFAULT_TIMEOUT could be as high as 48ms. I configured system tick for 0.5ms. After I more than doubled the value as shown below

/* Status register need 5 RC LSI divided by prescaler clock to be updated. With

  higher prescaler (256), and according to LSI variation, we need to wait at

  least 6 cycles so 48 ms. */

#define HAL_IWDG_DEFAULT_TIMEOUT      110 // 48u

it works.

pierre-yves
Associate III
February 10, 2021

Hello

To test, I modified the define:

#define HAL_IWDG_DEFAULT_TIMEOUT 2000

it is indeed the macro IWDG_ENABLE_WRITE_ACCESS (hiwdg) which generates an error (HardFault_Handler).

I also changed the values

hiwdg.Instance = IWDG;

hiwdg.Init.Prescaler = IWDG_PRESCALER_128;

hiwdg.Init.Window = IWDG_WINDOW;

hiwdg.Init.Reload = 4095;

Not easy .... any ideas? .. I block

Thnak you

pierre-yves
Associate III
February 10, 2021

In fact it is indeed a timeout error made by the HAL_IWDG_Init function. But I don't know what to do.

I am in version 1.3.0 at the HAL software