Can't exit sleep mode
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:

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.
