cancel
Showing results for 
Search instead for 
Did you mean: 

Can't exit sleep mode

BuderBrodas
Associate II

Hello.

Using "ITEMIS Create" I've designed this simple statechart diagram to figure out the working principles of sleep mode. The diagram is shown below:

BuderBrodas_0-1710617515754.png

The program should work like this: Device boots up, starts a timer, that has a period of 2 seconds, and enters the statechart model in "Awake" state. Firstly, it calls the LedOn() function. After 2 seconds the timer raises an interrupt which in turn raises an event "TimerInt". That changes the state to "Asleep". LedOff() turns the Led off and after that the device should be put to sleep. When the timer raises an interrupt again it should wake up and immediately jump to "Awake" state. Loop should go on.

 

The problem is, the device does not comeback from the sleep. It just stays there forever. So I have a couple questions:

1) When an interrupt wakes the proccessor up does it firstly execute the ISR (Interrupt service routine) of the interrupt that woke it up or does it just acknowledge the interrupt, leave it unservised and continue from "HAL_PWR_EnterSLEEPMode()"?

2) What could be the cause of proccessor staying in the sleep mode? Too cosy sheets?

 

Snippet of code that I felt like was the most relevant to my issue:

 

 

 

 

 

 

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){
	if(htim == &htim16){
		statechart_raise_timerInt(&myStateChart);
	}
}

void statechart_ledOn( Statechart* handle){
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);
}
void statechart_ledOff( Statechart* handle){
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
}
void statechart_goToSleep( Statechart* handle){
	HAL_SuspendTick();
	HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
	HAL_ResumeTick();
}

 

 

 

 

 

 

 

Additional information:

  • I'm using an STM32F091RC dev board
  • The timer seems to be set right. It raises the interrupt after two seconds from the start of the program.
  • I've used the debug mode with breakpoints. I'm not sure whether I should trust the debbuger when tinkering with sleep mode but it showed me that the program freezes at the end of the "HAL_PWR_EnterSLEEPMode()" function's execution

Any help would be appreciated and if any additional information is needed, please let me know.

2 REPLIES 2
Sarra.S
ST Employee

Hello @BuderBrodas

>>1) When an interrupt wakes the proccessor up does it firstly execute the ISR (Interrupt service routine) of the interrupt that woke it up or does it just acknowledge the interrupt, leave it unservised and continue from "HAL_PWR_EnterSLEEPMode()"?

When an interrupt is raised at let’s say process i, the processor first completes the execution of instruction i. Then it loads the program counter (PC) with the address of the first instruction of the ISR.

The fact that the program freezes at the end of the HAL_PWR_EnterSLEEPMode() function's execution suggests two paths: the issue may be related to the sleep mode configuration or the wake-up process.

Could you share the code inside the statechart_raise_timerInt function

Ps: the cozy sheets made my day 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

I've figured that I should not to put the proccessor to sleep from the "ITEMIS Create" generated functions. Why exactly is that – no clue. However if I put the device to sleep from within the main() function everything works as expected.

 

As for the function's code, it's "ITEMIS" generated, not hand written. So it'd be quite a while before I understand all the interlocked fuctions that make it up and post the relevant ones here.

 

Anyways, since I've found a way to work around my issue, I'm no longer seeking the solution. Still, thank you for the reply.