How to exit Stop 2 mode
I have implemented a fully working usart keyboard with interrupts in a Nucleo L412Kb. The main code loop checks whether a pending-key flag and no-bouncing flag are set, then scans the rows in the selected keyboard matrix column, and sends the key via usart.
The ISR for the GPIOs (columns) sets the pending flag, selects the column to scan, and starts a debouncing timer TIM2. The ISR for the timer TIM2 interrup is setting the no-bouncing flag.
void TIM2_IRQHandler(void) {
if (TIM2->SR & (1<<0)) {
TIM2->SR &= ~(1<<0); // clear flag
bouncing = 0;
TIM2->CR1 &= ~(1<<0); // Disable timer
}
}
void col_IRQ(uint8_t col) {
if (pendingkey == 0) {
pendingkey = 1;
bouncing = 1;
coln = col;
set_triggers(0);
TIM2->CNT = 0;
TIM2->CR1 |= (1<<0); // Enable timer
set_all_rows(0);
}
}
void EXTI0_IRQHandler(void) {
if (EXTI->PR1 & (1 << 0)) {
EXTI->PR1 |= (1 << 0);
col_IRQ(0);
}
}
Now I want the MCU to go into STOP2 mode and wake up with the EXTI interrupts, but my main code get blocked.
Im using ony GPIOs, a timer (TIM2), the systicks, and one USART. In the stopkbd() function I disable the clocks for the peripherals, call the __WFI() function and restore the clocks. What Im missing?
Im running with the HSI16 oscillator only, and I have the STOPWUCK bit set in order to wake up with the HSI16.
Do I need to clear the SLEEPDEEP bit after? Or do I need to wait for the HSI16 or something else?
From the RM manual, I can not get to understand how the GPIOs EXTI interrupts can work if the clocks are stopped or the peripherals are disabled. Do I need to perhaps enable at least one clock in order for the interrupts to trigger? I see in the manual that the LSI can be enabled in STOP2.
