cancel
Showing results for 
Search instead for 
Did you mean: 

[stm32u585] HAL_IWDG_Init reconfig does not take effect

lll
Associate III

hello,

I encountered a problem while developing for stm32u585.

I change the iwdg reload value by HAL_IWDG_Init(), and then HAL_PWR_EnterSTANDBYMode(), but the new reload value does not take effect:

    hiwdg.Instance = IWDG;
    hiwdg.Init.Prescaler = IWDG_PRESCALER_64;
    hiwdg.Init.Window = 4095;
    hiwdg.Init.Reload = 3600;
    hiwdg.Init.EWI = 0;
    HAL_IWDG_Init(&hiwdg);
    HAL_IWDG_Refresh(&hiwdg);
    HAL_Delay(300);  //more than one downcount
    HAL_PWR_EnterSTANDBYMode();

if delay before refresh, it seems work

    hiwdg.Instance = IWDG;
    hiwdg.Init.Prescaler = IWDG_PRESCALER_64;
    hiwdg.Init.Window = 4095;
    hiwdg.Init.Reload = 3600;
    hiwdg.Init.EWI = 0;
    HAL_IWDG_Init(&hiwdg);
    HAL_Delay(300);  //more than one downcount
    HAL_IWDG_Refresh(&hiwdg);
    HAL_PWR_EnterSTANDBYMode();

Is this the correct process ? If I want to ensure the modification is successful, what should I pay attention to

1 ACCEPTED SOLUTION

Accepted Solutions
Saket_Om
ST Employee

Hello @lll 

after changing the IWDG prescaler/reload, the new configuration is not guaranteed to be fully effective if you enter STANDBY immediately. Even though HAL_IWDG_Init() waits for update flags, the IWDG (running on LSI in another clock domain) needs a short time to synchronize internally. Therefore, your second sequence is the correct approach: add a small delay after HAL_IWDG_Init() and before the first HAL_IWDG_Refresh() / HAL_PWR_EnterSTANDBYMode(), to ensure the new reload value is properly taken into account.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om

View solution in original post

2 REPLIES 2
Saket_Om
ST Employee

Hello @lll 

after changing the IWDG prescaler/reload, the new configuration is not guaranteed to be fully effective if you enter STANDBY immediately. Even though HAL_IWDG_Init() waits for update flags, the IWDG (running on LSI in another clock domain) needs a short time to synchronize internally. Therefore, your second sequence is the correct approach: add a small delay after HAL_IWDG_Init() and before the first HAL_IWDG_Refresh() / HAL_PWR_EnterSTANDBYMode(), to ensure the new reload value is properly taken into account.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om

LSI=32K, prescaler=128 ==> IWDG=250Hz

before: prescaler=64, reload=40

after: prescaler=512, reload=3600

if i only config once, i need to delay about 3s. if i config twice, it seems that only a delay of 300ms is needed:

    hiwdg.Instance = IWDG;
    hiwdg.Init.Prescaler = IWDG_PRESCALER_64;
    hiwdg.Init.Window = 4095;
    hiwdg.Init.Reload = 3600;
    hiwdg.Init.EWI = 0;
    HAL_IWDG_Init(&hiwdg);
    HAL_Delay(350);
    HAL_IWDG_Refresh(&hiwdg);

    hiwdg.Instance = IWDG;
    hiwdg.Init.Prescaler = IWDG_PRESCALER_512;
    hiwdg.Init.Window = 4095;
    hiwdg.Init.Reload = 3600;
    hiwdg.Init.EWI = 0;
    HAL_IWDG_Init(&hiwdg);

is this sequence correct?