cancel
Showing results for 
Search instead for 
Did you mean: 

How to drop clock frequency when entering low power mode and then increase when exiting low power mode?

noobmaster69
Associate III

Hi. I am working on a battery operated project using STM32L031 microcontroller. I am using 32 MHz clock for normal operation. But if I use same clock in low power mode then it consumes current of about 2.7mA. But for higher battery life, current consumption should be minimum. So I tried running controller at 2MHz and the current consumption was found to be around 350uA in low power mode.

So I was thinking of using 32MHz for normal operation and when entering low power mode, drop that clock frequency to 2 MHz. And when exiting low power mode, clock frequency should be again switched to 32MHz.

My UART (with DMA) is always active since whenever I receive data, I come out of low power mode. My baud rate is 115200 and hence I cant go below 2MHz clock frequency.

So how can I implement this operation of changing clock frequency from low to high and vice versa?

Regards,

noobmaster69

8 REPLIES 8
Aime
ST Employee

Hi @Community member​ ,

Thank you for sharing your request, first can you provide me more information about your project. ;)

What's low power mode are you referring to ?

The STM32Lx31 supports five low-power modes :

  • Sleep mode : where only the CPU is stopped. All peripherals continue to operate and can wake up the CPU when an interrupt/event occurs.
  • Low-power run mode : achieved with the multispeed internal (MSI) RC oscillator set to the low-speed clock (max 131kHz). In this mode the clock frequency and number of enabled peripherals are both limited.
  • Low-power sleep mode : achieved by entering Sleep mode with the internal voltage regulator in low-power mode to minimize the regulator's operating current. In this mode the clock frequency and number of enabled peripherals are both limited.
  • Stop mode : achieves the lowest power consumption while retaining the RAM and register contents. All clocks are stopped, the PLL, MSI, HSE and HSO oscillators are disabled. The LSE or LSI is still running.
  • Standby mode : achieves the lowest power consumption. All clocks are stopped, the PLL, MSI, HSE and HSO oscillators are disabled. The LSE or LSI is still running. After entering Standby mode the RAM and most of the register contents are lost.

Please refer to the section 3.1 Low-power modes of the datasheet for more details.

Best regards,

A.MVE

Hi @Aime​ ,

Thanks for your reply. I am planning to use Low power Sleep mode. Because in this mode DMA is active which is required for USART. In low power mode, I need only USART active. It wakes up from lwo power mode when I receive data. It ccan also wakeup from Interrupt from a input pin. Also I might need SysTick running because I am using it as a timer to hourly read battry voltage using ADC.

And for the info on my project, it is a battery operated access control system with NFC, Bluetooth functionality.

Regards,

noobmaster69

JPeac.1
Senior

Not familiar with your application but in certain cases you can manipulate the RCC bus dividers to ease the transition from 32MHz to 2MHz. A simple example that requires little programming: configure AHB and APB bus dividers to /16, so your peripherals always run at 2MHz. When you slow down the oscillator, reduce the bus dividers to /1 so the UART continues to function.

Obviously using this method is dependent on how you must configure your other peripherals, but if you shut them down to save power at 2MHz then it's a moot point.

Also, be sure to use SLEEP mode to halt the CPU when idling at 2MHz, waking only when the UART signals end of transmission (TE interrupt, preferable to DMA end). Halting instruction execution saves power in the processor core.

Jack Peacock

Thanks for your reply. Much appriciated. Will try to implement what you said.

Regards,

noobmaster69

Understand @Community member​ ,

Please notice that to use Low power Sleep mode you need to :

  • Make sure that the system frequency should not exceed f_MSI range1.
  • And Low-power sleep mode can only be entered when VCORE is in range 2.

I recommend to you to have two System_Clock_Config functions one for running at 32MHz and the other for your Low Power Sleep mode.

On the second one you need to configurate your System frequency up to MSI range 1 (e.g 2MHz) and update your MCU voltage to range 2. This function should be call before entering Low power Sleep mode.

When exiting from Low power Sleep mode first call the other System_Clock_Config function to run at 32MHz.

Best regards,

A.MVE

MM..1
Chief III

For normal battery app is better use RUN MODE optimized speed and STOP MODE while wait for events to run.

Also I wanted to know how to disable and enable systick when entering and exiting low power mode.

  1. Should I suspend systick before changing the clock frequency when entering low power mode or should I suspend it after clock configuration?
  2. Also, when exiting low power mode, when should I resume systick? before clock configuration to 32MHz or after clock configuration?
  3. I am using HAL_PWR_EnterSLEEPMode() function to enter low power mode. Is this correct? or should I be doing something else?

Hi,

Here are my answers.

  1. Suspend tick after changing the clock frequency when entering in low power mode
  2. Resume tick just after exiting in low power mode after that you can call your clock configuration
  3. It's the right function but you need to add extra arguments, please review the function description.