Library 39- Power consumption modes for STM32F4

For library 39, I made a low power modes library. This allows you to simple put STM32F4 into SLEEP, STOP or STANDBY mode. Point of this modes is simple. You want decrease current on device. If you are working on battery project, this will be very helpful.

You can set current down to about 2uA with proper low power mode.

I will tell you only the highlights of all 3 power down modes in this post. For detailed informations, check ST’s manual here.

STM32F4 Power consumption image from ST

STM32F4 Power consumption image from ST

Library

Features

  • Enable SLEEP mode
  • Enable STOP mode
  • Enable STANDBY mode
    • You can also test, if system was reset because of wakeup from Standby mode.
  • Enable/disable wakeup pin, pin PA0

Dependencies

  • CMSIS
    • STM32F4xx
    • STM32F4xx RCC
    • STM32F4xx PWR
  • TM
    • TM DELAY
    • defines.h
STM32F4 Description
PA0 If STM32F4 is in standby mode, rising edge on this pin will wake him up if it is activated.

STM32F4 power consumption modes

Highlights below are from st’s manual from their website.

SLEEP mode

  • Cortex-M4 core is stopped.
  • Peripherals kept running.
  • How to enter this mode?
    • Look for example 1 below.
  • How to exit this mode?
    • Any peripheral interrupt acknowledged by the nested vectored interrupt controller (NVIC).
      • Systick timer will also wake up MCU!
    • After exit, MCU continues where it stopped.

STOP mode

  • All clocks in 1.2V domain are stopped.
  • PLL, HSI and HSE RC oscillators disabled.
  • Internal SRAM and register contents are preserved.
  • Voltage regulator in low-power mode.
  • How to enter this mode?
    • Look for example 2 below.
  • How to exit this mode?
    • Any EXTI Line (Internal or External) configured in Interrupt/Event mode.
    • After exit, MCU continue there where it stopped. HSI is used for system core clock, but my library set it back to PLL as source.

STANDBY mode

  • Cortex-M4 deepsleep mode.
  • Voltage regulator disabled.
  • 1.2V domain consequently powered off.
  • PLL, HSI and HSE RC oscillators disabled.
  • SRAM and register contents are lost except for the RTC registers, RTC backup registers, backup SRAM and Standby circuitry.
  • How to enter this mode?
    • Look for example 3 below.
  • How to exit this mode?
    • Wakeup pin rising edge.
    • RTC alarm (Alarm A and B) and wakeup.
    • Tamper and time-stamp event.
    • External reset in NRST pin.
    • IWDG reset.
    • After exit, STM32F4xx reset.

VBAT mode

  • Main digital supply is turned off.
  • The circuit is supplied through VBAT pin which should be connected to an external supply voltage (a battery or any other source).
  • RTC is running in this mode.
  • How to enter this mode?
    • If you disable main power and put supply voltage on VBAT pin, then MCU will be in VBAT mode.
  • How to exit this mode?
    • Put power supply on main Vdd pins.

Note

If you put your STM32F4 into low power mode, it will become unavailable for normal programming. You will have to program it under reset mode or wake it up before programming.

Functions and enumerations

Example 1

This example will put STM32F4 into sleep mode.

  • RTC is configured with internal clock to generate wakeup interrupts every 10 seconds.
  • After STM is wake, it will toggle green LED 20 times (10 times on, 10 times off) and MCU will go to SLEEP mode.
  • Each time MCU will be waked up, RED led will be toggled.
  • If you put Ammeter on IDD pins on STM32F4/29-Discovery or Nucleo board, you will see how current vary.

Example 2

  • RTC is configured with internal clock to generate wakeup interrupts every 10 seconds
  • After STM is wake, it will toggle green LED 20 times (10 times on, 10 times off) and MCU will go to STOP mode
  • Each time MCU will be waked up, RED led will be toggled.
  • If you put Ammeter on IDD pins on STM32F4/29-Discovery or Nucleo board, you will see how current vary.
  • Main difference between SLEEP and STOP mode is that in sleep mode only processor sleep, peripherals work, in STOP mode everything is stopped, except EXTI.

Example 3

  • RTC is configured with internal clock to generate wakeup interrupts every 10 seconds
  • After STM is wake, it will toggle green LED 20 times (10 times on, 10 times off) and MCU will go to STANDBY mode
  • Each time MCU will be waked up, RED led will be toggled.
  • If you put Ammeter on IDD pins on STM32F4/29-Discovery or Nucleo board, you will see how current vary.
  • RED led should never be ON, because MCU will reset after wakeup
  • RED led will toggle, when MCU will reset after wakeup from MCU
    • If you reset system with “Reset button”, then RED led should not be toggled
  • You want wake up device if you press the button (rising edge on PA0 pin) or waiting for RTC to make it every 10 seconds for you

All examples are available separately on Github, download library below.

Icon
TM STM32F4 LOW Power Library

Allows you to put STM32F4 dvice into different low power modes.

tilz0R

Owner of this site. Also electronic enthusiasts, web developer, 3D printer fan, handball player and more. Big fan of STM32F4 devices. In anticipation of the new Discovery board for STM32F7 lines.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!
  • Greg

    Hi,
    I’m trying to use low power mode together with GPS and RTC libraries but I have encountered a problem – MCU is not going to sleep (at least not for the time that I specify in IRQ handler. Please advise what can wake up the MCU, I’m only using USART1, USART3 and RTC. Do I need to Deinit USARTs before going to sleep?

    • Any interrupt. Can you show me your project? Probably systick is waking up device back.

      • Greg

        Of course, here you go: http://pastebin.com/w4tKaaEA
        I have used TM_LOWPOWER_SleepUntilInterrupt(1); //(line 231) so the Systick should be disabled, but maybe I’m doing something wrong, any help will be appreciated.
        BTW. are you planning to make library for Ethernet MAC + PHY?

        • I would say that this is because of usart gps’s interrupt. 9600 is quite slow and GPS sends you a lot of data, so i think that this is the problem. When you show your new data, then you go to sleep, but data arrives immidetely and MCU is wake-up until next valid GPS data.

          Can you try one of my example here for low power mode and say if it is working?

          For ethernet, i’m planning this, but have some problems with my PHY DPsomething 😀
          I’m waiting for stable release for ESP8266 wifi modules, will post this for sure 🙂 They are waiting me home.

          • Greg

            I’ll try to change the speed of UART, or I’ll Deinit it before going to sleep, maybe this will help. I’ll try this tomorrow because currently I do not have access to the development board.
            BTW. What kind of problem do you have with Ethernet PHY? I’m planning to use KSZ8041FLT in my project (100Base-FX optical connection) and I really have hope that everything will run smoothly 😀

          • But if you deinit usart, you will disable usart receive and will MCU stay in a sleep a long time.
            You will have to wake him up with RTC.

          • Greg

            I was thinking that it will be awaken by RTC IRQ, like in your first example for low power mode (sleep). Please look at my code one more time and advise if you have some free time (my C is a bit rusty, I’m back in C programming after 8 years so…) Also sorry for my english, it is not my native language

          • Before you put stm in sleep mode, disable USART with USART_Cmd(USART1, DISABLE);

            then go to sleep mode

            and after the statement for sleep mode, iniialize usart back, with USART_Cmd(USART1, ENABLE);

          • Greg

            Hi,
            I have tried to use USART_DeInit and it worked. Also USART_Cmd is working OK. Can you explain to me the difference between those two functions?

          • Deinit will set all registers to default values probably, but cmd will just one bit that says if usart is enabled or not. Full description is in stm32f4xx_usart.c file.

  • Khoa Tran

    Hi,
    What are differences between WFI (wait for interrupt) and WFE (wait for event)?
    Thank you.

    • Event would be for example that entire packet from ethernet is received.
      Interrupt is any interrupt.
      Difference is a very poor explained in datasheet.

      • Khoa Tran

        Hi Majerle Tilen,Can I wakeup from stop mode using External Interrupt ? (using Push Button (pin PA0)).
        Khoa Tran.

        • First read post then ask. You can.
          Just set pin to trigger interrupt.

  • Pingback: All STM32F4 libraries - STM32F4 Discovery()

  • Tính

    That a good project!
    But how can RTC configured with internal clock to generate wakeup interrupts every 1 hour? I’m using sleep mode.

    • Init rtc with onternal clock and enable wakeup interrupt. Probably 1h is too large interval.

      • Tính

        Thanks! I’m using for loop(i=1;i<61;i++) every sleep 60s, How do you think about that?

        • This is one sort of solution. Not sure if best one 🙂

  • Mike

    Beautifully written!
    Any idea for a clean solution to freeze IWDG while in standby?

  • Gary

    Tilen,

    Very good and useful article!
    I looked in the ST manual on power consumption, but still not clear as they don’t show what they call sleep mode power consumption. Using your example for sleep mode, with peripherals running, what is the power consumption in uA/MHz?

    Thanks!