2018-03-03 10:21 AM
Hi, I think there is a bug in code generated by CubeMX for RTC. Problem is that if you enable wake-up timer interrupt in Cube, it is only enabled after you first power up MCU.
MX_RTC_Init
checks value of backup register to prevent RTC registers being reinitialised, but also preventsHAL_RTC_Init
from being called./* RTC init function */
void MX_RTC_Init(void)
{
...
if (HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) != 0x32F2) {
...
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
...
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR0, 0x32F2);
}
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
HAL_RTC_Init
normally callsHAL_RTC_MspInit
, which enables RTC clock and enables interrupts in NVIC.void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
{
if(rtcHandle->Instance==RTC)
{
...
/* RTC clock enable */
__HAL_RCC_RTC_ENABLE();
/* RTC interrupt Init */
HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
...
}
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
So, if you now reset MCU, interrupt for wake-up timer will NOT be enabled (clock for RTC will stay enabled, because it issaved in BDCR register, which is preserved after reset). I think this would occur every time device is reset without power being disconnected from Vbat.
Easy fix would be to still call
HAL_RTC_MspInit,
even if RTC registers do not need to be initialised:/* RTC init function */
void MX_RTC_Init(void)
{
...
if (HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) != 0x32F2) {
...
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
...
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR0, 0x32F2);
}
else
{
HAL_RTC_MspInit(&hrtc);
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
Of course we can enable interrupts at different place, but it probably would be better solution if this worked correctly.
Thanks
#wake-up #rtc2018-03-04 10:38 AM
>
MX_RTC_Init
checks value of backup register to prevent RTC registers being reinitialised
if (HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) != 0x32F2)
In which CubeMX version and for which chip?
No such code in F4xx library or Cube-generated main.c.
-- pa
2018-03-04 11:51 AM
I'm using STM32F746ZG MCU and CubeMX version 4.24. Firmware package is 1.9.0.
2018-03-30 12:31 AM
The same for stm32f1 in firmware package 1.6.1.
2018-05-02 03:15 AM
hello,
will be fixed next release