cancel
Showing results for 
Search instead for 
Did you mean: 

How to wake up from 'Sleep mode' on STM32L152 with interrupt.

Soham Jani
Associate II

I'm working on a low power driver for our project and want to put the mcu into sleep mode to be woken up by a timer.

The mcu enters the Sleep mode but does not exit from the same. Since I have the Seggar J-link connected to over a JTAG port for debug, I can see that the RTC Alarm call back is being serviced and prints out the debugging information but the mcu does not exit the sleep mode.

Here is the code.

void PMODE_EnterSleep(void)
{
    HAL_PWR_EnableSleepOnExit();
 
    HAL_SuspendTick();
 
   // Request to enter STOP PMODE with regulator in low power PMODE
    HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
}
 
 
void PMODE_ExitSleep(void)
{
	HAL_PWR_DisableSleepOnExit();
 
	SWD_PRINTF("Exiting Sleep\n");
}
 
// .... A general power mode servicing module
 
void PMODE_ServicePower(PMODE_eOperatingMode_t eModeToEnter)
{
	switch (eModeToEnter)
	{
		case PMODE_eRun:
			break;
 
		case PMODE_eSleep:
			SWD_PRINTF("Sleep\n");
			PMODE_EnterSleep();
			PMODE_ExitSleep();
			break;
 
		case PMODE_eStop:
			SWD_PRINTF("Stop\n");
			PMODE_EnterStop();
			PMODE_ExitStop();
			break;
 
		case PMODE_eStandby:
			SWD_PRINTF("Standby\n");
			ALARM_ActivateWkup();
			PMODE_EnterStandby();
			break;
	}
}

Maybe I'm doing something wrong or not clearing a flag somewhere.

Further, I have several interrupts enabled in the applications main program, even those do not wake up the mcu.

I would appreciate any help.

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
MPlan.17
Associate

Hello!

This answer is very late, but...

This line here:

HAL_PWR_EnableSleepOnExit();

That function enables sleep on exit functionality, which means that your MCU will enter the sleep mode after exiting the lowest priority interrupt.

View solution in original post

1 REPLY 1
MPlan.17
Associate

Hello!

This answer is very late, but...

This line here:

HAL_PWR_EnableSleepOnExit();

That function enables sleep on exit functionality, which means that your MCU will enter the sleep mode after exiting the lowest priority interrupt.