cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L431 can't enter STOP2 mode

TClar.8
Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
TClar.8
Associate II

[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.

View solution in original post

11 REPLIES 11
Mohamed Aymen HZAMI
ST Employee

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.

TClar.8
Associate II

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

Mohamed Aymen HZAMI
ST Employee

Hello Tristan,

Can you please share you code.

Best Regards,

Mohamed Aymen.

Alex R
Senior

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?

TClar.8
Associate II
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?

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.

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.

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.

Thank you turboscrew.

Unplugged probe.

What are the HAL functions to clear all interrupts and turn off extra peripherals?