2020-12-02 05:23 AM
The processor never wakes up from STOP1 mode and I do not know why.
Reading RTC time and date works, so I know the RTC clock is running. With debugger (using HAL_EnableDBGStopmode()), I notice that the firmware is stuck in __WFI()
I'm using STM32Cube_FW_L4_V1.13.0
static void deepsleep(uint32_t intervalms)
{
__HAL_RCC_PWR_CLK_ENABLE(); // Enable Power Control clock
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR1, 0x32F2);
HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
if (HAL_RTCEx_DeactivateWakeUpTimer(&hrtc) != HAL_OK) {
Error_Handler();
}
// clear wake up flags
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUFI);
uint32_t _time = (intervalms * 2314) / 1000;
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, _time, RTC_WAKEUPCLOCK_RTCCLK_DIV16) != HAL_OK) {
Error_Handler();
}
HAL_SuspendTick();
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
// Issue: remains stuck in __WFI(), never wakes up
HAL_ResumeTick();
// Reinit clocks
SystemClock_Config();
// Deactivate RTC wakeUp
if (HAL_RTCEx_DeactivateWakeUpTimer(&hrtc) != HAL_OK) {
Error_Handler();
}
}
int main(void)
{
HAL_Init();
SystemClock_Config();
// For debugging:
HAL_EnableDBGStopMode();
MX_GPIO_Init();
MX_RTC_Init();
while (1)
{
HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_SET);
HAL_Delay(1000);
HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);
deepsleep(1000);
}
}
**
* @brief RTC Initialization Function
* @param None
* @retval None
*/
static void MX_RTC_Init(void)
{
/* USER CODE BEGIN RTC_Init 0 */
/* USER CODE END RTC_Init 0 */
RTC_TimeTypeDef sTime = {0};
RTC_DateTypeDef sDate = {0};
/* USER CODE BEGIN RTC_Init 1 */
/* USER CODE END RTC_Init 1 */
/** Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
hrtc.Init.AsynchPrediv = 127;
hrtc.Init.SynchPrediv = 255;
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN Check_RTC_BKUP */
/* USER CODE END Check_RTC_BKUP */
/** Initialize RTC and set the Time and Date
*/
sTime.Hours = 0x0;
sTime.Minutes = 0x0;
sTime.Seconds = 0x0;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
sDate.Month = RTC_MONTH_JANUARY;
sDate.Date = 0x1;
sDate.Year = 0x0;
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
{
Error_Handler();
}
/** Enable the WakeUp
*/
if (HAL_RTCEx_SetWakeUpTimer(&hrtc, 0, RTC_WAKEUPCLOCK_RTCCLK_DIV16) != HAL_OK)
{
Error_Handler();
}
}
Solved! Go to Solution.
2020-12-03 08:45 AM
After updating to STM32Cube_FW_L4_V1.16.0, that is.
2020-12-02 12:14 PM
Okay, and without entering sleep, does the respective interrupt fire?
JW
2020-12-03 02:54 AM
No, without entering STOP1 mode, interrupt also does not fire.
Reading out time and date every second while waiting in vain for the interrupt does see the RTC time advancing every second.
But HAL_RTCEx_GetWakeUpTimer() stays as-is.
2020-12-03 06:46 AM
It seems like this was a bug in the STM32Cube_FW_L4_V1.13.0 that I was using; after updating to STM32Cube_FW_L4_V1.13.0, I'm getting interrupts.
In V1.13.0, the ST's HAL library was doing " __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_EVENT();" in HAL_RTCEx_SetWakeUpTimer_IT(), and in later versions it is doing " __HAL_RTC_WAKEUPTIMER_EXTI_ENABLE_IT();" instead.
2020-12-03 08:45 AM
After updating to STM32Cube_FW_L4_V1.16.0, that is.