no RTC wake up
I’m working on a project with the Nucleo-L476RG. I want to perform a measurement, then put the microcontroller into Sleep Mode for 2 seconds, after which it should be woken up by the RTC clock.
I followed the tutorial:
How to configure the RTC to wake up the STM32 from Low Power modes
Unfortunately, Sleep Mode is entered but not exited properly.
Down below are my project settings:




In my measurement function, I call a custom sleep() function.
void start_measurement(hx711_t *hx711){
hx711->processed_reading = get_weight(active_hx711, 10);
menu_refresh();
pack_data(hx711);
if (HAL_UART_Transmit_DMA(&huart2, (uint8_t *)( active_hx711->tx_buffer), HX711_TX_BUFFER_SIZE) == HAL_OK){
active_hx711->measurement_count = 0U;
active_hx711->tx_in_progress = 1U;
}
sleep();
}there's the call of the sleep function:
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
{
//HAL_ResumeTick();
printf("Inside the HAL_RTCEx_WakeUpTimerEventCallback function");
rtc_wakeup_flag = 1;
start_measurement(active_hx711);
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
}
void sleep(void){
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 4096, RTC_WAKEUPCLOCK_RTCCLK_DIV16) != HAL_OK) {
Error_Handler();
}
printf("the HAL_RTCEx_SetWakeUpTimer_IT has been called \n");
uint32_t pending = HAL_NVIC_GetPendingIRQ(RTC_WKUP_IRQn);
printf("the pending bit for the RTC clock interrupt %lu\n", pending);
//HAL_SuspendTick();
counter++;
DBGMCU->CR = 0;
printf("Entering the sleep mode...");
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
}
void disable_wakeup(void) {
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
//HAL_ResumeTick();
rtc_wakeup_flag = 0;
}
Initially, when I used the default debugging configuration, the HAL_RTCEx_WakeUpTimerEventCallback() function was successfully entered — but only during debugging. Without the debugger attached, it was never called.
Later, I enabled SWV ITM Data printing, and observed the following:
HAL_RTCEx_SetWakeUpTimer_IT() was called successfully.
The pending bit for the RTC wake-up interrupt appeared to be set.
However, after enabling SWV/ITM, the debugger began printing the following repeatedly:
Target is not responding, retrying...
Target is not responding, retrying...
Target is not responding, retrying...Even after I disabled SWV ITM again, the message “Target is not responding...” continued to appear. At this point, things became a bit confusing and I’m unsure what’s causing this behavior.
