Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 724 of 93610. Power Management and OptimizationFree lesson

Configuring Hardware Wake-up Sources from Low-Power States

Learners will program external interrupts and timers to trigger a transition from deep-sleep mode back to active processing mode.

In this lesson, you will learn how to configure external hardware events and internal timers as triggers to transition your microcontroller from a deep-sleep state back into active processing.

When a system enters a deep-sleep mode, the primary processor clock is typically gated off to minimize power consumption. However, the hardware must remain sensitive to specific signals to know when to "wake up" to resume tasks. These wake-up sources must be configured while the system is still in an active, high-power state, ensuring that the interrupt controllers and specific GPIO pins remain powered by a separate, low-frequency auxiliary domain.

Configuring External Interrupts

To use a GPIO pin as a wake-up source, you must map the pin to an External Interrupt (EXTI) controller that remains active in deep-sleep. Unlike standard interrupts that trigger an ISR during normal operation, these specific pins serve as hardware triggers that toggle the system’s power gate.

// Example: Configuring a pin for wake-up
void configure_wakeup_gpio(void) {
    // 1. Enable GPIO peripheral clock
    // 2. Set pin as input with internal pull-up/pull-down
    // 3. Configure the EXTI trigger for rising/falling edge
    // 4. Unmask the interrupt line to allow signal propagation
    EXTI->IMR |= EXTI_Line_Wakeup; 
    EXTI->EMR |= EXTI_Line_Wakeup; // Event mode for deep-sleep wake-up
}

Utilizing Low-Power Timers

When you need to wake the system periodically—for instance, to perform a sensor reading—you cannot rely on the main system clock. Instead, you must initialize a Low-Power Timer (LPTIM). This peripheral is clocked by an independent low-speed oscillator (like an LSE or LSI). You set the period to the required interval, and when the counter overflows, it sends a hardware pulse that triggers the Power Management Unit (PMU) to re-enable the high-speed system clocks.

Once the wake-up event is detected, the CPU resumes execution, usually starting from the instruction immediately following the sleep command. You must ensure that your system re-initializes clocks or peripherals if the wake-up process resets them, maintaining the integrity of your safety-certified state machine.

Key Takeaway: To transition from deep-sleep, you must configure peripherals to remain active in the low-power domain so they can generate the hardware signals necessary to re-enable the main system clock.