2017-07-26 08:59 AM
Hello everybody.
I simply can not figure out the settings needed for lowpower sleep. I am aware of fact, that i need to enter lowpower run first. My setup: - MSI 1048KHz- PWR Reg Voltage Scale Scale 2
- TIM3 counter period 1048 (1ms) /TIM3 global interrupt enabled
- GPIO output PA4 (for debug pin toggle)
Unfortunately, my code goes into
void HardFault_Handler(void)
when i get toHAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
What am I missing? with MAINREGULATOR_ON it works fine ... but thats not a lowpower sleep right?
CODE:
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim3);
HAL_Delay(500);
HAL_PWREx_EnableLowPowerRunMode();
while(__HAL_PWR_GET_FLAG(PWR_FLAG_REGLP) == RESET){
HAL_Delay(1);
}
HAL_SuspendTick();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_GPIO_TogglePin(S1_GPIO_Port,S1_Pin);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
//enter sleep mode and wait for interrupt
HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
// HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
}
/* USER CODE END 3 */�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
#lowpower-sleep #stm32l1
2017-07-27 03:04 AM
Hello Jan,
This is correct that difference between SLEEP mode and LPSLEEP mode is voltage regulator. In SLEEP MCU uses main regulator, while in LPSLEEP MCU uses low power regulator.
If you want to enter LPSLEEP, it is not mandatory to enter LPRUN first. You can go directly from RUN to LPSLEEP. The confdition, which you have to meet, is reduced system frequency. So the minimum number of steps are:
1. reducing system frequency to MSI 65kHz or 131kHz
2. switching from main regulator to low power regulatorI perpared an example application using CubeMX, Cube package and Keil IDE (all in latest revisions). Here is the complete list of steps, which I did to enter LPSLEEP and in addition to reduce the current consumption to minimum.
In CubeMX:
1. I configured PC13 as EXTI (wake-up source from LPSLEEP) and PA5 as GPIO (to toggle LED in RUN mode).
2. In reconfigured MSI clock from default value to 65kHz.
3. I reconfigured regulator voltage scale to 3.
4. I enabled interrupt for EXTI.
5. I enabled feature 'set all free pins as analog'.
In Keil IDE, in main.c file:
6. I disabled all clocks for unused GPIOs.
7. I enabled FLash power down feature in SLEEP mode.
8. I suspended Systick and entered LPSLEEP mode.
9. After wake up I resumed Systick and toggled LED in infinite loop.
Please find the complete project (CubeMX + Keil IDE) attached. I tested this application on STM32L1 Nucleo kit (STM32L152RE). Everything works fine (MCU goes to LPSLEEP and wakes up after button press, then toggles LED). In LPSLEEP mode I measured current consumption 7uA.
Regards
Szymon ________________ Attachments : L1_LPSLEEP.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HyYc&d=%2Fa%2F0X0000000b9Q%2FU9kgeCsU.7Vs0frhcYqcq9d8nx_CT86uwrfUlU1h71Q&asPdf=false2018-10-25 01:28 AM
Hello Szymon,
I am in a very similar situation as Jan.
I am using a STM32L151 with the CubeMX.
I would very much like to see the example code you mention in this post, but I cant seem to find it attached?
Can you send me the code again? @Szymon PANECKI
Kind Regards.