Clearing the RTC WUTF (saving your sanity by sharing my hard lesson learned :-)
I did RTFM, and the STM32WB55xx/35xx ref man was very clear:
29.7.4 RTC initialization and status register (RTC_ISR)
Bit 10 WUTF: Wakeup timer flag
This flag is set by hardware when the wakeup auto-reload counter reaches 0.
This flag is cleared by software by writing 0.
This flag must be cleared by software at least 1.5 RTCCLK periods before WUTF is set to 1 again.
But I obviously glossed over it - after all, there is a lot to learn!
So time goes on, and I get a LOT of run-time on my application on the STM32WB Nucleo dev board using the RTC as my SYSTICK. But there is this very, very, very rare (but obviously very disturbing) hang when the system stops waking from STOP2 on a software timer or OSAL SYSTICK. The time finally came when I had to track down the insidiously rare hang in a very complex FreeRTOS system. And I searched, and hunted, and pulled out hair searching for the source and finally found it when re-RTFM:
This flag must be cleared by software at least 1.5 RTCCLK periods before WUTF is set to 1 again.
Crap - I saw that the first time, but the ramifications of the insidious (dare I say hideous) race condition between software and the (documented) hardware behavior just didn't hit me (thus the days I spent flogging myself while finding this race).
So this is not enough:
LL_RTC_ClearFlag_WUT(RTC);
Instead, this is what is required to resolve the (hideous, albeit documented) race with hardware (and what I think that ST should implement as the LL_RTC_ClearFlag_WUT() behavior):
#define RTC_ClearFlag_WUT() do { LL_RTC_ClearFlag_WUT(RTC); __ISB(); } while (LL_RTC_IsActiveFlag_WUT(RTC));
So there you have it - a little gold nugget of sanity for any of you using the RTC ;)
