2019-05-22 01:23 PM
I'm trying to enter STOP2 mode to save energy but the MCU get stuck in the function HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI). I have cleared all EXTI pending flags and RTC flags, and disable all five wake up pins. The MCU is supposed to wake up via RTC alarm interrupt. The program resumes by clearing RTC flag and calling system clock config and gpio init functions.
I have done this with STANDBY and SHUTDOWN modes without trouble, and I can't understand why I can't enter STOP2 mode as well. Anyone has got an idea?
Solved! Go to Solution.
2019-05-29 06:16 AM
[RESOLVED] Thank you all, your advices have been useful and convicing!
Finally, I could get it working by disabling SysTick interrupt and then resuming the interrupt when the MCU wakes up.
2019-05-23 12:54 AM
Hello,
You can refer to the STM32Cube_FW_L4 power example "STM32Cube\Repository\STM32Cube_FW_L4_V1.13.0\Projects\NUCLEO-L432KC\Examples\PWR\PWR_STOP2_RTC".
You can try with this project.
Best Regards,
Mohamed Aymen.
2019-05-23 06:30 AM
Thank you for your answer Mohamed Aymen.
I have tried with this project and other STM32Cube_FW_L4 examples, but in my own project, something might prevent the MCU from entering STOP2 mode. What are the prerequisites to enter this low power mode, regarding the clocks, interrupt flags, and registers?
I have been going through the datasheet and programming manual but perhaps I have missed something else.
Best Regards,
Tristan
2019-05-23 07:48 AM
Hello Tristan,
Can you please share you code.
Best Regards,
Mohamed Aymen.
2019-05-23 08:05 AM
According to the Reference Manual:
"All the peripherals which cannot be enabled in Stop 2 mode must be either disabled by
clearing the Enable bit in the peripheral itself, or put under reset state by setting the
corresponding bit in the AHB1 peripheral reset register (RCC_AHB1RSTR), AHB2
peripheral reset register (RCC_AHB2RSTR), AHB3 peripheral reset register
(RCC_AHB3RSTR), APB1 peripheral reset register 1 (RCC_APB1RSTR1), APB1
peripheral reset register 2 (RCC_APB1RSTR2), APB2 peripheral reset register
(RCC_APB2RSTR)."
Not sure if this would affect, though.
Are you using the Auto-wakeup from low power mode with RTC?
You indicate in your post that the program resumes by clearing RTC flag and calling system clock config and gpio init functions. Is that what you were expecting?
Weren't you supposed to resume on the alarm interrupt handler?
2019-05-23 11:34 AM
void MCU_StopMode(void) {
/* Clear all wake up flags */
if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUFI)) {
/* Clear Internal WU Flag (RTC) */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUFI);
}
__HAL_RTC_ALARM_EXTI_CLEAR_FLAG();
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
EXTI->PR1 = 0x00000000;
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
printf("MCU entering stop2 mode...\n------------------------------\n\n");
//__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI);
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
printf("Wake up!\n");
}
void HAL_RTC_AlarmAEventCallback(RTC_HandleTypeDef *hrtc) {
/* Configures system clock after wake-up from STOP: enable HSE, PLL and select
PLL as system clock source (HSE and PLL are disabled in STOP mode) */
SystemClockConfig_ExitSTOPMode();
/* Clear Wake Up Flag */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
printf("Alarm A event!\n");
}
Are you using the Auto-wakeup from low power mode with RTC? Yes
You indicate in your post that the program resumes by clearing RTC flag and calling system clock config and gpio init functions. Is that what you were expecting? Weren't you supposed to resume on the alarm interrupt handler? I am doing this through the alarm A callback (see above), but I do not know if it is correct this way... is it a mistake?
2019-05-23 11:51 AM
The question is: does the processor execute the AlarmEventCallback when the alarm expires?
Also: it is not clear how you implement the printf() statements, but it might no be a good idea to place them on interrupt handlers (callbacks). It might be better to put a breakpoint and debug the code single step, or use GPIO pins and a logic analyzer to trace the code execution.
2019-05-24 08:15 AM
The question is: does the processor execute the AlarmEventCallback when the alarm expires? Yes, but the program is still running while it should stop.
Also: it is not clear how you implement the printf() statements, but it might no be a good idea to place them on interrupt handlers (callbacks). It might be better to put a breakpoint and debug the code single step, or use GPIO pins and a logic analyzer to trace the code execution. Following your advice, I am debugging through GPIOs (with a logic analyzer). Thanks for the tip.
Is the stop mode supposed to stop the program from running, till an interrupt occurs? Seems weird that the code is still executing.
2019-05-24 09:14 AM
The interrupts need to be cleaned and the extra peripherals turned off, otherwise the thing doesn't go to sleep.
also debug probe keeps it from going to sleep, unless the setting is made to enable sleep-time debugging.
2019-05-24 09:31 AM
Thank you turboscrew.
Unplugged probe.
What are the HAL functions to clear all interrupts and turn off extra peripherals?