I have a project in which the main loop basically does the following
Code: Select all
while( 1 ) {
chWaitSem( &sensor_data ); // Posted in EXT handler
i2cMasterTransmitTimeout( ... ); // Read sensor data samples
process();
}
I noted on my scope that I spend a lot of time waiting, so I decided I might try using a low power mode of the processor while just loafing. I added the following at the end of my main loop:
Code: Select all
if( palReadPad( GPIOB, 14 )) { // For safety to disable sleeping if desired
PWR->CR |= (PWR_CR_LPSDSR | PWR_CR_CSBF | PWR_CR_CWUF);
PWR->CR &= ~PWR_CR_PDDS;
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
__WFI();
}
After doing this, I noted that my i2c transactions were going at 1/16th the speed they were programmed for (after the first sleep). This is because on resume, the uC is using MSI as a clock source. So I added a call to stm32_clock_init() right after __WFI() returns to re-initialize the clocks and PLL to the way they were.
However, after resuming, i2c was no longer working. I made it work again by adding i2cStop() before going to sleep, and i2cStart() after resuming. I was just wondering if this is a recommended way of using STOP mode, and if not what should I be doing. Are there any other things I should consider stopping and restarting before/after STOP mode? The only other HAL driver I am using currently is the call to extStart() which I assume is OK and doesn't require re-initialization.