I'm beginning to play around again with using the low power modes in the STM32L1 series. I did this years ago on a Chibi-3.x based system with a tick, but I think I'm missing something in tickless mode.
I have started with a basic threaded blinker framework copied from demos/STM32/RT-STM32L152-DISCOVERY (I'm using ChibiOS_21.6.0, but same behaviour on 19.1.3)
Then, if the button is pressed, I enter sleep using:
Code: Select all
chSysLock();
PWR->CR |= (PWR_CR_LPSDSR | PWR_CR_CSBF | PWR_CR_CWUF);
PWR->CR &= ~PWR_CR_PDDS;
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
chSysUnlock();
__WFI();
If I press the button again (generating an interrupt) the mcu wakes back up, but as expected the timings change because the STM32L1 leaves STOP/STANDBY states running from the MSI clock. This was discussed years back in viewtopic.php?f=16&t=2927
So now, if I follow my __WFI() with the following:
Code: Select all
chSysLock();
stm32_clock_init();
chSysUnlock();
The blinker threads never resume blinking. It seems that re-initializing the clocks messes up the virtual timers they have been programmed to wait on perhaps? I manually unblocked my threads using chSchReadyI() and they ran until the next call to chSThdSleepMilliseconds() then never seem to get woken again and the OS just stays in the idle thread.
Any help would be greatly appreciated.
Dave