LPTIM interrupt can't wake STM32u5 from STOP low power mode
I am trying to us the LPTIM low power timer to trigger interrupts intermittently while the MCU is in STOP2 mode, but I am unable to do so. I am testing the interrupts by toggling a GPIO pin and checking the output on a scope.
Without STOP mode I see the interrupts and GPIO toggle as expected. Once I enter STOP2 mode I don't see any interrupts. Interestingly, if I debug the microcontroller via STLINK, I can see the GPIO toggle and a single interrupt trigger if I pause and then resume the debugger.
Is the LPTIM capable of doing this? I want to achieve repeated wake events to perform actions at specified times. The datasheet and reference manual say the LPTIM1 should be fully functional in this low power mode. If this is possible, what am I missing?
Using STMcube to configure the LPTIM and enable interrupts. I have tried configuring with LSI, MSI, and LSE as clock sources.
I am using HAL_LPTIM_Counter_Start_IT(&hlptim1) to start the interrupts and have used callbacks: LPTIM1_IRQHandler() and HAL_LPTIM_AutoReloadMatchCallback().
I am using the development kit B-U585I-IOT02A Discovery.
Some excerpts from the code:
/**
* Enter stop 2 mode
*/
void GoToSleep()
{
__disable_irq(); //Disable interrupt to avoid timing issues
HAL_SuspendTick();
// Useful if already in low power run mode, see https://community.st.com/s/question/0D50X00009XkWAMSA3/stop2-mode-voltage-regulator-stm32cube
// HAL_PWREx_DisableLowPowerRunMode();
is_asleep = true;
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
HAL_ResumeTick();
__enable_irq();
}
/**
* Interrupt that results in wake from stop 2 mode
*/
void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim)
{
interrupts++;
if(hlptim == &hlptim1)
{
toggle = true;
}
}
/* In main: */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
__HAL_RCC_LPTIM1_CLK_SLEEP_ENABLE();
HAL_StatusTypeDef status = HAL_LPTIM_Counter_Start_IT(&hlptim1);
(void)status;
while (1)
{
if(toggle == true)
{
if(is_asleep == true)
{
SystemClock_Config(); // Need to reconfigure the clock on exit from sleep mode to use HSI clock
is_asleep = false;
}
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
toggle = false;
}
GoToSleep();
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}