STM32U5x5 - IWDG RLV update requires waiting until pending refresh is complete before using new RLV
- 1 reply
- 13 views
On STM32U5x5 (any variant it seems), when I reconfigure the IWDG reload value while a refresh is being processed, I am required to wait until the pending refresh is complete and then trigger another refresh before the new reload value is loaded into the down-counter. This behavior is sort of documented in the reference manual, Figure 769, which indicates in Yellow that new refreshes are ignored until a pending refresh is complete. However, it’s not explicitly stated the current reload value essentially gets “locked-in” when a refresh is requested. I would expect that if a the reload value is successfully updated and read-back while a refresh is pending, then the new value will be loaded when the refresh is completed.
My sequence that fails if an IWDG refresh is pending:
- Verify IWDG status flags are reset
- Enable IWDG register write access
- Set the new reload counter value
- Wait for the IWDG status flags to reset
- Read-back the IWDG reload counter value and verify it was set correctly
- Refresh IWDG counter
My sequence that works:
- Verify IWDG status flags are reset
- Enable IWDG register write access
- Set the new reload counter value
- Wait for the IWDG status flags to reset
- Read-back the IWDG reload counter value and verify it was set correctly
- Wait for < (2 * IWDG_KER_CK_PERIOD) + PRESC_CK_PERIOD > seconds (max refresh time from Table 623)
- Refresh IWDG counter
Essentially, I must wait for the maximum possible refresh time after an RLV update before requesting a new refresh to guarantee the new value is what gets loaded into the down-counter. I cannot read the down-counter directly, so I have no way of waiting the minimum time necessary, it must always be the maximum possible refresh time to be safe.
Why is this important? If I change the IWDG reset time from 10s while running to <sleep_time + 10s> for sleeping and the new reload value isn’t used, then the IWDG will trigger a reset while I’m sleeping for long periods of time. As an aside, my IWDG is running at ~ 1Hz (LSI / 128 / 256 ) so that I can enter a low-power state for a maximum of 1 hour. So after reconfiguring the IWDG, I must wait more than 1s to guarantee the new reload value is used before going to sleep.
I have seen this behavior on the NUCLEO-U545, NUCLEO-U575, NUCLEO-U5A5, and a custom PCB with the U585.
I have attached 3 STM32Cube projects (STM32CubeIDE v1.19.0, sorry).
- To experience the system running normally, without having the IWDG reset:
- Just program the associated NUCLEO board. You should see a solid LED at boot for 2s, then an LED flicker every 10s when the MCU exits the low-power state (STOP3).
- You can change the low-power state in the SYS__bedtime() of main.c. Don’t use STANDBY or SHUTDOWN for these IWDG tests as they trigger a reset on wake-up, obviously :D.
- To experience the IWDG being correctly configured:
- main.c: Uncomment “#define IWDG_TEST” (around line 205).
- This configures the IWDG to trigger after ~ 3s, which should cause a reset while in a low-power state. You should NOT see the LED flicker, which occurs after waking up.
- To experience the IWDG failing to use the new RLV even though the update appears to complete:
- main.c: Uncomment “#define IWDG_TEST” (around line 205).
- iwdg.c: Comment out “HAL_Delay( delay_for_new_reload_value_ms );” (line 203)
- Without the long delay after setting the new reload value, the MCU goes to goes to sleep with the old RLV and does not trigger the reset during the 1st sleep. You should see the LED flicker. Then the IWDG is refreshed, loading the new RLV, causing a reset on the second sleep.
I guess my questions are this:
- Is this the expected design behavior?
- Can this be explicitly stated the reference manual, or if it’s a bug, added to the Erratas?
