2020-03-25 02:53 AM
I use HAL to go to STOP mode with interrupt (WFI), but the microcontroller immediately exits stop mode.
I have LPTIM setup with HAL_LPTIM_Counter_Start_IT() to give interrupt after a few seconds, but even without setting up LPTIM I can't get the microcontroller to stay in STOP mode.
Perhaps some interrupt keeps it from going to STOP mode? Where do I look? I don't have enough experience debugging, any help appreciated.
HAL_SuspendTick(); // avoid systick interrupt waking up core from stop mode
HAL_LPTIM_Counter_Start_IT(&hlptim1, (uint32_t)(4*1156));
__HAL_LPTIM_CLEAR_FLAG(&hlptim1,LPTIM_IER_ARROKIE);
__HAL_LPTIM_CLEAR_FLAG(&hlptim1,LPTIM_IER_CMPMIE);
__HAL_LPTIM_DISABLE_IT(&hlptim1,LPTIM_IT_ARROK);
__HAL_LPTIM_DISABLE_IT(&hlptim1,LPTIM_IT_CMPM);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); // says to run this before entering stop mode
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); // enter stop mode
HAL_LPTIM_Counter_Stop_IT(&hlptim1); // stop timer
// Exit Stop mode
SystemClock_Config(); // setup clocks after sleep
HAL_ResumeTick(); // resume systick interrupt
2020-04-01 02:23 AM
It magically works now, I don't know why.
Thanks.