Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 45

Processor Low-Power Modes and Wake-Up Sources

Recommended resources

Hello! Welcome to the fourth lesson in our module on Advanced System Optimization.

In our last lesson, we saw how integrating DMA with an SPI driver offloads data transfer tasks from the CPU, enabling high-throughput communication without constant CPU intervention. This is a powerful optimization, but it also means the CPU will spend more time idle, waiting for the DMA to complete or for the next event to occur. Our focus today is on making that idle time as efficient as possible.

This lesson directly addresses the learning outcome: Describe processor low-power modes (e.g., Sleep, Stop, Standby) and their wake-up sources. Understanding how to leverage these modes is fundamental to developing power-efficient drivers, a critical skill for any senior embedded role, especially in automotive ECUs where thermal and power budgets are tight.

1. The "Why" Behind Low-Power Modes

Before we dive into the specific modes, let's establish why they are so important. Power consumption in a CMOS-based microcontroller primarily comes from two sources:

  • Static Power: Caused by leakage currents, even when the chip is not actively switching. This is generally low but non-zero.
  • Dynamic Power: The dominant source, caused by the charging and discharging of parasitic capacitances every time a logic gate switches state. This is directly proportional to the clock frequency.

The fundamental principle of low-power design is simple: if a part of the chip isn't being used, turn off its clock. Turning off the CPU clock itself is the most significant step, and this is what we call a "sleep mode."

#52 Using low-power sleep modes in the "superloop" architecture

The video 'Using low-power sleep modes in the "superloop" architecture' from Quantum Leaps, LLC provides a concise explanation of dynamic power dissipation.

Please watch from 01:03 to 02:31. The video uses a simple analogy of filling and emptying buckets to explain how switching logic gates consumes power and introduces the concept of stopping the CPU clock to enter a sleep mode.


2. A Hierarchy of Power-Saving Modes

Most modern microcontrollers, like the ARM-based STM32 family, offer a hierarchy of low-power modes. These modes provide a trade-off between power consumption and wake-up time. The deeper the sleep, the more power you save, but the longer it takes for the MCU to wake up and resume execution.

Let's explore the three main modes you'll encounter.

Sleep & Low Power Modes with STM32

The video 'Sleep & Low Power Modes with STM32' by 1s and 0s offers an excellent practical overview of the Sleep, Stop, and Standby modes. It clearly explains what is turned off in each mode and demonstrates the real-world current consumption.

Watch the segments from 00:37 to 01:23 and 02:14 to 04:42. This will give you a clear, high-level understanding of the three modes before we examine each one in detail.

As the video explains, the modes differ in which components (CPU, clocks, regulators) are powered down. This directly impacts both power savings and how the system can be woken up.

STM32 Low-Power Modes and Transitions State Diagram
This state diagram illustrates the various low-power modes available on an STM32 microcontroller and the transitions between them. It provides a great mental map for understanding the hierarchy from the active 'Run mode' down to the ultra-low-power 'Shutdown mode'.

3. Deep Dive: Sleep, Stop, and Standby Modes

Let's use a common microcontroller family, the STM32, as a concrete example to understand the characteristics of each mode.

a) Sleep Mode

  • What's Off: Only the CPU clock (FCLK) is stopped.
  • What's On: Peripherals and their clocks (e.g., timers, UART, SPI), RAM, and all regulators remain active.
  • Power Savings: Modest. You save the dynamic power consumed by the CPU core itself.
  • Wake-up Time: Fastest. Wake-up is almost instantaneous.
  • Wake-up Sources: Any peripheral interrupt or a specific "wake-up event" (WFE). Since peripherals are running, a timer expiring or a character arriving on a UART will wake the CPU.
  • State Retention: Full. The CPU resumes execution from the exact instruction where it went to sleep, with all register and RAM contents intact.

The HAL_Delay() function is a common but inefficient pattern. A better approach is to put the MCU to sleep and let a timer interrupt wake it up. However, the default SysTick interrupt used by the HAL for timing will constantly wake the CPU from sleep. To achieve a proper sleep state, you often need to suspend it.

Sleep & Low Power Modes with STM32

Let's return to the 'Sleep & Low Power Modes with STM32' video to see a practical implementation of Sleep mode.

Watch from 05:35 to 21:53. This long segment is very valuable. It demonstrates entering Sleep mode and waking up using both a wake-up event from a GPIO and a wake-up interrupt. Pay close attention to how the SysTick is suspended before sleep and how the current drops from ~20mA to ~5mA.

b) Stop Mode

  • What's Off: All high-speed clocks (HSI, HSE, PLLs) and the CPU clock are stopped. The main voltage regulator might be put in a low-power mode.
  • What's On: SRAM and CPU registers retain their content. Low-speed oscillators (LSI, LSE) can remain active to drive peripherals like the RTC or IWDG.
  • Power Savings: Significant. Current consumption can drop to the microampere range.
  • Wake-up Time: Slower than Sleep mode, as the main system clocks (like the PLL) need to be re-initialized upon waking.
  • Wake-up Sources: Fewer than Sleep mode. Typically limited to external interrupt lines (EXTI), I2C, UART, and the Real-Time Clock (RTC).
  • State Retention: Full, but with a caveat. While RAM and registers are preserved, you must reconfigure the system clock in your wake-up code before using peripherals that depend on it.

Sleep & Low Power Modes with STM32

The same video also provides a clear demonstration of Stop mode.

Now watch from 21:53 to 28:30. Notice the critical difference: after waking from Stop mode, the SystemClock_Config() function must be called again. The video also shows the current dropping much further, to around 1.5mA.

c) Standby Mode

  • What's Off: Almost everything. The main voltage regulator is turned off, and all high/low-speed clocks are stopped.
  • What's On: Only a very small "backup domain," which includes the RTC, some backup registers, and optionally a small backup SRAM, can remain powered if a separate battery is supplied to the VBAT pin.
  • Power Savings: Maximum. This is the lowest power mode, with current consumption dropping into the sub-microampere range.
  • Wake-up Time: Slowest. The MCU performs a full reboot.
  • Wake-up Sources: Very limited. Typically an external rising edge on a specific WKUP pin, an RTC alarm, or a system reset.
  • State Retention: None, except for the backup domain. When the MCU wakes from Standby, it is equivalent to a power-on reset. Execution starts from the beginning of main(). Your application must check a status flag in the power controller to determine if the boot is a "cold start" or a wake-from-standby.

Sleep & Low Power Modes with STM32

Finally, let's look at the implementation and behavior of Standby mode.

Watch from 28:30 to 37:45. The key takeaway is the reboot behavior. The code structure changes significantly: you now have to check a flag at the very beginning of your program to know if you are waking from standby or starting fresh.

Test your understanding!

You are designing a data logger that needs to write sensor data to an SD card every 5 minutes. Between logging events, the system should consume the absolute minimum amount of power possible. The data from the last reading must be preserved in RAM for comparison with the next reading.

Which low-power mode would you choose and why? What is the main challenge you would face upon wake-up?

Show answer

The best choice would be Stop Mode.

Why:

  • It offers significant power savings, much more than Sleep mode.
  • Crucially, it preserves the contents of SRAM, which is a requirement for comparing with the last reading. Standby mode would wipe the RAM.
  • A 5-minute interval is easily handled by the Real-Time Clock (RTC), which can be configured to generate a wake-up interrupt from Stop mode.

Main Challenge: The primary challenge upon wake-up is that the main system clocks (like the PLL) are disabled in Stop mode. The first thing your wake-up code must do, before interacting with high-speed peripherals like the SD card interface (SDIO/SPI), is to re-initialize the system clock to its full operational frequency.


4. Interview Corner: Explaining Power Modes and Wake-up Sources

A common interview question for a role like this would be: "Contrast the different low-power modes on a typical ARM microcontroller. What are the key trade-offs, and what determines your choice for a given application?"

Your answer should be structured, demonstrating a clear understanding of the trade-offs.

Low Power Modes and Interview Guide

The document 'Low Power modes on STM32' and the 'Embedded Systems Engineer Interview Guide' provide excellent, structured information to help formulate a strong answer.

Skim through this document, paying special attention to the summary tables and diagrams. Focus on: Section 2.2 (Figures 9 & 10): These tables provide a perfect summary of entry/wake-up conditions for each mode. Section 2.2.3 (Figure 13): This diagram clearly shows how Deep Sleep is subdivided into Stop and Standby. Section 6 (Table 21 & 23): These tables give real-world data on current consumption vs. wake-up time for different Stop mode configurations, which is excellent detail for an advanced answer. Then, cross-reference this with the 'Power Management Strategies' table in the Interview Guide (Resource ID: LINK, Section 2), which provides a high-level summary of power savings.

Structuring Your Answer:

  1. Start with the trade-off: "The choice of a low-power mode is always a trade-off between three factors: power consumption, wake-up latency, and state retention."
  2. Describe the modes in order of power savings:
    • Sleep Mode: "This is the lightest sleep. It stops the CPU clock but keeps all peripherals and RAM powered. It offers the fastest wake-up but the least power savings. It's ideal for short, frequent pauses where the system must be responsive, like waiting for the next byte in a UART transmission."
    • Stop Mode: "This is a deep sleep mode where high-speed clocks are off, but RAM and register contents are preserved. This offers substantial power savings, reducing current to the microamp range. Wake-up is slower because the system clock needs to be reconfigured. It's perfect for applications that sleep for seconds or minutes but need to retain their state, like a battery-powered device waiting for user input."
    • Standby Mode: "This is the deepest sleep, offering the lowest possible power consumption by shutting down almost everything, including the main regulator. The cost is that RAM and registers are lost, and the MCU reboots on wake-up. It's suitable for applications that sleep for very long periods and can re-initialize from scratch, using the backup domain (RTC, backup registers) to maintain critical long-term state."
  3. Mention Wake-up Sources: Briefly list the typical wake-up sources for each, showing you understand the limitations (e.g., "Wake-up from Stop is limited to specific sources like external interrupts or the RTC, whereas any peripheral interrupt can wake the MCU from Sleep.").

Conclusion

You have now explored the hierarchy of processor low-power modes, a cornerstone of modern embedded systems design. You can describe the functional differences between Sleep, Stop, and Standby modes and articulate the critical trade-offs involved.

Key Takeaways:

  • Low-power modes save power by turning off clocks and other hardware components.
  • There is a direct trade-off between how much power you save and how quickly the system can wake up and respond.
  • Sleep Mode: Lowest savings, fastest wake-up, full state retention.
  • Stop Mode: High savings, slower wake-up, full state retention (but requires clock reconfiguration).
  • Standby Mode: Maximum savings, slowest wake-up (reboot), no state retention outside of the backup domain.
  • The choice of mode depends entirely on the application's requirements for power, responsiveness, and state management.

Next Lesson Preview:
Knowing these modes is the first step. The next step is integrating them intelligently into a real-time system. In our next lesson, we will learn how to implement a tickless idle hook in an RTOS. This advanced technique allows an RTOS-based system to automatically enter a low-power mode whenever all tasks are idle, dramatically improving the power efficiency of your applications.