Sleep mode is not reducing power consumption
I can’t see what I’m doing wrong. The processor seems to be going to sleep, but the current remains the same.
Here is the sleep code:
~
~ int sleep(void) { TIM_HandleTypeDef tim; uint32_t savedier = 0; // Reduce clock to 1 MHz SystemClock_Config_NOPLL_48M_100K(RCC_MSIRANGE_4); // Go to low-power run mode HAL_PWREx_EnableLowPowerRunMode(); tim.Instance = TIM1; if (0 != (TIM1->CR1 & TIM_CR1_CEN)) // Turn timer off This works! { ++savedier; HAL_TIM_Base_Stop_IT(&tim); } last_isr = 0xFF; wakeup_isr = 0; w_cnt = 0; // Request to enter SLEEP mode do { HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI); ++w_cnt; } while (0 == wakeup_isr); SetSysClock(); HAL_PWREx_DisableLowPowerRunMode(); if (0 != savedier) HAL_TIM_Base_Start_IT(&tim); return last_isr; } ~~
The system has FreeRTOS, the Hal timer is set to TIM1.
In the stm32l4xx_it.c I set last_isr to the interrupt position and wakeup_isr to 1 if this ISR is suppose to wake us up from sleep.
I do this because I can’t stop FreeRTOS’s system ticks and other service interrupts. I have created code that turned off those interrupts, but FreeRTOS would not work when I turned them back on.
But even with FreeRTOS running occationally, I should see some reduction in current consumption, but I see none. Not even a little.
I’ve been looking for manuals, but I can’t find anything that says what you should do to get it into low power, only what gets turned off and on and theory of operation.
I found out about the less than 2MHz and lower-power mode from comments in the HAL_PWR_EnterSLEEPMode routine.
I’ve done this before, on many different processors. Don’t know why I can’t get it to work here.
-Matt