2024-09-12 05:42 AM - edited 2024-09-12 11:19 PM
Hello everyone,
I’m working with an STM32WB55 microcontroller with BLE stack. I use also low-power modes in my app. Before entering a low-power mode, I set an RTC ALARM_A to wake the system up at a specific time. The device then enters either Sleep or STOP2 mode with the RTC enabled.
However, I’m noticing an issue where, when in these low-power modes, the RTC ALARM_A does not seem to wake the device as expected. The timing appears to freeze or behave unpredictably, and the alarm sometimes triggers late or not at all.
Here is the output just before entering sleep mode with the configured alarm:
Current time vs Alarm RTC Settings:
(PREDIV_S = maximal SubSec = 32000)
| Field | Current (Cur) | Alarm (Alm) |
|------------|------------|--------|
| SubSec | 7234 | 6594|
| Sec | 21 | 21 |
| Min | 0 | 0 |
| Hr | 0 | 0 |
| Day | 1 | 1 |
| Mon | 1 | 1 |
| Yr | 0 | 0 |
When I pause the execution, I see that the program is halted right after the WFI() instruction. I also see that the current time is much further ahead (by the duration I was stuck), the seconds were already at 25.
All the relevant registers appear to be configured correctly for the RTC ALARM_A interrupt:
Has anyone else encountered similar issues with RTC alarms in these low-power modes? Could there be any configuration or known issue that might cause this behavior?
Any insights or suggestions would be greatly appreciated!
Solved! Go to Solution.
2024-09-16 07:22 AM
Finally, I managed to get the code working as I wanted. I can't exactly say what the problem was, but the RTC is now behaving correctly even in low power modes. Thank you.
2024-09-12 06:19 AM
2024-09-12 11:14 PM - edited 2024-09-12 11:14 PM
@STTwo-32 @waclawek.jan @Piranha I studied ES0394, and I think this is not my problem. The situation described there warns about shared EXTI lines. However, I have only activated ALARM_A, and even then, the hazard would occur very rarely. In my case, however, it happens in the vast majority of the set alarms.
From the data I wrote, it's clear that ALARM A should have already occurred, but no IRQ was triggered. It's as if the alarm wasn't activated. When stopped in debug, ALRAF is not set either!
2024-09-13 12:01 AM
Hello @JR2963
Are you facing the same issue will the BLE stack is not activated?
Best Regards.
STTwo-32
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.
2024-09-13 12:21 AM
I tried disabling all initialization related to the BLE stack and radio, and the behavior is the same.
2024-09-13 12:31 AM
Could you share a firmware that reproduce the issue (with and without BLE stack if possible).
Best Regards.
STTwo-32
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.
2024-09-13 12:47 AM
Well, I'm not sure how to approach this; it's quite a complex firmware with a built-in custom tickless mode. I'll try to trim it down as much as possible.
2024-09-13 02:01 AM
@STTwo-32 That won't work. I've created a clean project (WITHOUT BLE) where I enter sleep mode using HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);. Now, it behaves such that, although the sleep should last one second, the MCU wakes up immediately. I don't know the source of the wake-up, but it's not the RTC, so I'm facing a different problem here. In this project, there is only a FreeRTOS timer that blinks an LED every second, nothing more - nothing what should wakes up the MCU
BTW: By the way, is there some sort of protection against sleep in this MCU? Why does it immediately wake up from sleep? What is causing it to wake up?
2024-09-15 12:17 PM
Hi, Please are you going to provide any solution or advice from your side? I'm really stuck and don't know what to do next. Thank you.
2024-09-16 12:29 AM
Hi, Finally, I managed to create an empty project where I only enter STOP and SLEEP modes (without the BLE stack) and wake up using the RTC ALARM_A. In this project, everything seems to work as expected. The RTC always wakes up the MCU at the correct time. I suspect that the problem in the application with the BLE stack is caused either by the BLE stack itself or by some other peripheral (there are quite a few, like SPI, TIMERS, ADC, DMA, UART). However, it is difficult to pinpoint exactly where the problem lies.