2024-11-18 06:14 AM
Hi,
I am currently working on a Bluetooth application using the STM32WB5MMG module.
I want to configure the RTC such that it generates a WakeUp interrupt every 5ms to read sensors and do some computation before going to stop mode for the remainder of the 5ms interval.
For the Bluetooth stack to work I had to activate the RTC, so I guess the Bluetooth stack somehow interacts with the RTC.
The RTC wake-Up interrupt itself is not needed for Bluetooth, so my naive understanding is that activating and configuring this interrupt does not have any side-effects on Bluetooth and vice versa.
Yet, when I configure the RTC WakeUp as shown in the screenshots at the end of the post and add the call shown below to my initialization code in the main method, the intterupt is triggered exactly once and not periodically.
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 82, RTC_WAKEUPCLOCK_RTCCLK_DIV2);
Now, if I take a look at the interrupt callback in stm32wbxx_it.c, this looks as follows:
void RTC_WKUP_IRQHandler(void)
{
/* USER CODE BEGIN RTC_WKUP_IRQn 0 */
/* USER CODE END RTC_WKUP_IRQn 0 */
HAL_RTCEx_WakeUpTimerIRQHandler(&hrtc);
/* USER CODE BEGIN RTC_WKUP_IRQn 1 */
/* USER CODE END RTC_WKUP_IRQn 1 */
}
This function body contains a call to the HAL_RTCEx_WakeUpTimerIRQHandler function which is defined in stm32wbxx_hal_rtc_ex.h. This function clears the interrupt flags but otherwise does not touch the configuration of the RTC interrupt.
Exept, this is not the function that is actually called. The project also contains the following macro inside of Core/Inc/app_conf.h:
#define HAL_RTCEx_WakeUpTimerIRQHandler(...) HW_TS_RTC_Wakeup_Handler( )
So the function HAL_RTCEx_WakeUpTimerIRQHandler from stm32wbxx_hal_rtc_ex.h is overwritten using a macro, and now the function points to HW_TS_RTC_Wakeup_Handler() in Core/Src/hw_timeserver.c. And this implementation contains the following line:
/**
* Disable the Wakeup Timer
* This may speed up a bit the processing to wait the timer to be disabled
* The timer is still counting 2 RTCCLK
*/
__HAL_RTC_WAKEUPTIMER_DISABLE(&hrtc);
And of course with this implementation, the interrupt is only called once.
If I remove the define in app_conf.h, such that the implementation of HAL_RTCEx_WakeUpTimerIRQHandler points to stm32wbxx_hal_rtc_ex.h instead of hw_timeserver.c, then the behaviour of the interrupt is as intended, namely a periodic interrupt instead of a one-shot interrupt.
So, now I have the following questions:
Is it not possible to use the Interrupt in the intended way using the HAL with Bluetooth?
If possible, how can I configure the RTC to provide a periodic interrupt?
If the Bluetooth stack needs control over the RTC interrupt, I guess I have to use LPTIM1?
Why is the HAL hijacking it's own code for handling intterrupt flags?
Best,
Pascal
Appendix:
The configuration for the RTC looks as follows:
Appendix 2:
As a side note: The UI for inserting code snippets into the forum post is broken:
When I drag a code snippet with the mouse, a semi-transparent copy gets attached to my mouse and if I left-click, I can insert a ghost of this snippet in the UI:
The only way to dislodge the ghost from the cursor is to click on preview in the upper right. When coming back from the preview, the ghosts are still there though. Im using the latest Firefox on Windows 11...
2024-11-22 06:52 AM
Hello @PascalW
Thank you for bringing this issue to our attention.
I reported this internally.
Internal ticket number: 196844 (This is an internal tracking number and is not accessible or usable by customers).
2024-12-12 02:59 AM
Hello @Saket_Om
Any news on the topic? Just tell me if you need further input from me or if I can help in any way.
Best,
Pascal
2024-12-12 06:02 AM
Hi Pascal,
For your use case, the easiest way is to use the Timer Server.
In short, it's going to look something like this:
If you like, you can take a look at the BLE_HeartRate or P2P_Server examples, which also use the Timer Server.
For more details, see AN5289 (4.5 Timer server).
BR, Joé