Skip to main content
Soham Jani
Associate III
September 11, 2018
Solved

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

  • September 11, 2018
  • 1 reply
  • 1907 views

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.

This topic has been closed for replies.
Best answer by MPlan.17

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.

1 reply

MPlan.17
MPlan.17Best answer
Visitor II
February 28, 2019

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.