Advance Innovation Centre
  • AIC Knowledge @ EEC for All
  • 😎Logical Thinking
    • Karel Robot
    • Code to Flowchart
    • Play with Docker
    • CNX Software
  • MCU & Interfacing with Infineon PSOC™
    • Basic MCU Interfacing
      • Introduction to CY8CKIT-062S2-43012 Pioneer Kit
      • Development Environment Preparation
      • PSoC™ 6S2 Peripherals Interfacing (GPIO)
        • Hello World and LED Blinking
        • GPIO Principles
        • PSoC™ 6S2 GPIO-HAL LED Blink Lab
        • PSoC™ 6S2 GPIO-PDL LED Blink Lab
        • Button "Bounce" Principles
          • Push/Pull Button to Turn ON/OFF LED via HAL
          • Push/Pull Button to Turn ON/OFF LED via PDL
          • GPIO Button Interrupt via HAL
          • GPIO Button Interrupt via PDL
        • GPIO variables & functions
      • PSoC™ 6S2 Peripherals Interfacing (ADC, PWM)
        • PSoC™ 6S2 SAR ADC
          • ADC Principles
          • PSoC™ 6S2 with ADC Labs
            • Reading potentiometer sensor value via an ADC HAL
            • Reading potentiometer sensor value via an ADC PDL
        • PSoC™ 6S2 PWM & TCPWM
          • PWM Principles
          • PSoC™ 6S2 for PMW Function Labs
            • LED Brightness using PWM via HAL
            • LED Brightness using PWM via PDL
    • Sensor Interfacing and HMI
      • OLED Display
        • OLED Display Principles
        • Calling BDH’s OLED functions
        • Display ADC via Potentiometer on OLED
      • BDH Shell
        • Shell Principles
        • LED Blinking and CAPSENSE via BDH Shell
        • Adding "History" command
        • Adding "Reboot" command
        • CAPSENSE Button and Slider
          • CAPSENSE Button and Slider with Capsense Tuner
          • CAPSENSE Button and Slider using FreeRTOS
    • Serial Communication & Visualization
      • UART, I2C, SPI Communication via Infineon PSoC™6
      • BMX160 Sensor Communication via Infineon PSoC™6
        • Reading ADC via HAL with Potentiometer and Displaying GUI on Serial Studio
        • Reading XENSIV-DPS-3XX Pressure Sensor and Displaying GUI on Serial Studio
        • Motion Sensors GUI Integration via Serial Studio
    • IoT Connectivity & Data Analytics via Node-Red
      • Node-Red Installation
      • Setting MQTTS to MQTT Broker
      • Sending PSoC6’s sensor to MQTT (node-red)
    • Edge AI on PSoC™
      • Machine Learning on PSoC™6 via Edge-Impulse
    • Infineon PSoC™ Troubleshooting
  • IoT Development with Infineon PSOC™ & BDH Platform
    • PSoC™ IoT Development Kit
      • Introduction to CY8CKIT-062S2-43012 Pioneer Kit
      • Development Environment Preparation
        • Hello World and LED Blinking
    • IoT Connectivity
      • Node-Red Installation
      • Controlling PSoC™ LED using MQTT
      • Setting MQTTS to MQTT Broker
      • Sending PSoC6’s sensor to MQTT (node-red)
    • BDH IoT Connectivity
    • WireLinX™ IoT PLC
    • BDH X-Brain Data Analytics
      • PSoC6 Data Collection to CSV log file
    • Data Visualization
      • สร้าง Dashboard ด้วย Looker Studio
  • 🖥️Operation Systems
    • Prerequisites
      • Guideline from Ubuntu
        • Ubuntu and VSCode on WSL2
      • ติดตั้ง WSL 2
      • Run Ubuntu on VirtualBox7
    • Zero to Linux Hero
      • Computer OS Architecture
      • Anatomy of Linux System
        • UNIX/Linux History
        • UNIX/Linux Evolution
        • GNU Project
        • Linux OS Architecture
        • Command Line Interface (CLI)
          • Basic Commands
          • 😎Level up your Linux Shell
          • File & Dir. Commands
          • Searching Commands
          • 😎ChatGPT-based Terminal
          • SysAdmin Commands
          • Network Commands
          • Hacker Commands
        • Busybox
        • Shell Script
          • Awk Script
          • Bash Shell Script
            • Bash Snippets
            • Bash Useful Examples
      • Anatomy of Linux Kernel
        • Linux Kernel Principles
        • Linux Environment for Developer
      • Anatomy of Embedded Linux
        • Embedded Linux
        • Host & Target
        • Cross Toolchains
        • Bootloader
        • Building Embedded Linux
    • Linux OS Dev. Engineer
      • Process Management
        • Process Basic
        • Process State
        • Basic Process Mgmt. Commands
        • Advance Process Mgmt. Commands
        • Process API Programming
      • IPC
        • IPC Anatomy
        • Signal Programming
        • Pipe Programming
        • FIFO Programming
        • Msg. Queue Programming
          • System V
        • Share Memory Programming
          • System V
        • Socket Programming
      • POSIX Threads
        • Multi-tasking Basic
        • POSIX Thread Anatomy
        • Threading Programming
      • Applied IPC
        • Remote Commander
        • Multi-Remote Commanders
      • Process Synchronization
        • Mutex Programming
        • Semaphore Programming
      • Applied IPC with Semaphore
  • ⌚Embedded Systems Development
    • Introduction to ESD
      • Why's ESD?
      • What it use for?
      • How it works?
    • Enbedded System Development via PSoC6
      • Basic MCU Interfacing
        • Introduction to CY8CKIT-062S2-43012 Pioneer Kit
        • Development Environment Preparation
        • PSoC™ 6S2 Peripherals Interfacing (GPIO)
          • Hello World and LED Blinking
          • GPIO Principles
          • PSoC™ 6S2 GPIO-HAL LED Blink Lab
          • PSoC™ 6S2 GPIO-PDL LED Blink Lab
          • Button "Bounce" Principles
            • Push/Pull Button to Turn ON/OFF LED via HAL
            • Push/Pull Button to Turn ON/OFF LED via PDL
            • GPIO Button Interrupt via HAL
            • GPIO Button Interrupt via PDL
          • GPIO variables & functions
        • PSoC™ 6S2 Peripherals Interfacing (ADC, PWM)
          • PSoC™ 6S2 SAR ADC
            • ADC Principles
            • PSoC™ 6S2 with ADC Labs
              • Reading potentiometer sensor value via an ADC HAL
              • Reading potentiometer sensor value via an ADC PDL
          • PSoC™ 6S2 PWM & TCPWM
            • PWM Principles
            • PSoC™ 6S2 for PMW Function Labs
              • LED Brightness using PWM via HAL
              • LED Brightness using PWM via PDL
      • Sensor Interfacing and HMI
        • OLED Display
          • OLED Display Principles
          • Calling BDH’s OLED functions
          • Display ADC via Potentiometer on OLED
        • BDH Shell
          • Shell Principles
          • LED Blinking and CAPSENSE via BDH Shell
          • Adding "History" command
          • Adding "Reboot" command
          • CAPSENSE Button and Slider
            • CAPSENSE Button and Slider with Capsense Tuner
            • CAPSENSE Button and Slider using FreeRTOS
      • Serial Communication & Visualization
        • UART, I2C, SPI Communication via Infineon PSoC™6
        • BMX160 Sensor Communication via Infineon PSoC™6
          • Reading ADC via HAL with Potentiometer and Displaying GUI on Serial Studio
          • Reading XENSIV-DPS-3XX Pressure Sensor and Displaying GUI on Serial Studio
          • Motion Sensors GUI Integration via Serial Studio
    • Edge Computing and IoT Connectivity
    • Cloud-Based Data Analytics and Digital Twin
    • Edge Vision AI
    • Resources
      • Basic Hardware and Firmware
        • Environment Preparation
          • การติดตั้งโปรแกรม Arduino IDE
            • ตัวอย่างการเริ่มต้นใช้งาน Arduino IDE
          • การติดตั้งโปรแกรมสำหรับใช้งานเครื่องมือวัด NI MyDAQ
            • ตัวอย่างการตั้งค่าใช้ Digital Multimeter -NI ELVISmx
            • ตัวอย่างการตั้งค่าใช้ Oscilloscope-NI ELVISmx
          • ติดตั้งโปรแกรม KingstVIS
        • Basic measurement
          • Basic Digital and Analog I/O
            • LAB: Basic Digital Input/Output
            • LAB: Basic Analog Input/Output
          • Waveform
            • LAB: Oscilloscope
            • LAB: Oscilloscope and Function Generator
            • LAB: Pulse Width Modulation (PWM)
              • Homework
        • Interfacing and Communication
          • LAB: UART, RS485, RS232 Protocol
          • LAB: I2C Protocol
            • HOMEWORK
          • LAB: SPI Protocol
      • IoT Connectivity
        • Example: IoT with MQTT on Node-red
        • Data logger
        • LAB: Data Visualization
  • 🛠️C/C++ for Embedded Programming
    • Development Environment Preparation
      • ติดตั้ง WSL 2
      • ติดตั้ง Ubuntu environment
      • ติดตั้งโปรแกรม Visual Studio Code
      • การเชื่อมต่อ Virtual studio code เข้ากับ WSL
      • ติดตั้ง docker on WSL
    • Principle C/C++ Programming
      • Get started with C++
      • Makefile
        • Makefile Examples
      • Compiling and running
        • How to create a program that you can enter inputs.
          • Lab 1 Exercise
      • Arguments
        • Command line arguments in C and C++
      • signed and unsigned data types
      • Variable and Operator
      • If and If else
      • Loop, Infinite loop, and flag
        • Loop and Flag exercise
      • Array
        • Get to know with arrays
        • Implement example
      • Vector
    • Object Oriented Programming (OOP) in C++
      • Class and Object
      • Encapsulation and Abstraction
      • Polymorphism and Inheritance
    • C/C++ Preprocessing
      • Macro
        • Quiz Macro
      • File Inclusion
      • Conditional Compilation
      • Pragma directive
        • Quiz Pragma
    • String in C++
      • Concatenation
      • Split
    • Type conversions for C/C++
      • Conversion using Cast operator
    • Error handling
    • Data logger
      • การสร้างไฟล์และเขียนไฟล์
      • การอ่านไฟล์
      • การเก็บข้อมูลกับTime stamp
    • High performance programing
      • Multi-task and Multi-thread
        • Multi-threading example
      • Mutex
      • Queue
      • OpenCV
    • C/C++ Techniques
      • Makefile in action
      • Object Oriented Programming (OOP) in C++
        • Class and Object
        • Encapsulation and Abstraction
        • Polymorphism and Inheritance
      • C/C++ Preprocessing
        • Macro
          • Quiz Macro
        • File Inclusion
        • Conditional Compilation
        • Pragma directive
          • Quiz Pragma
      • Binary, Octal and Hexadecimal Numbers
      • Array and properties of an array
        • Get to know with arrays
        • Implement example
      • What's next?
  • 🤖Artificial Intelligence (AI)
    • VAMStack Design House, BUU
    • Data Analytics
      • Data cleansing
      • Data analytics
      • Data analytic exercise
    • Machine Learning
      • Neural Network Layers
      • Machine learning type
      • Dataset
      • Using Edge Impulse for AI Model
    • Basic Image Processing
      • Computer Vision using Python Language
        • Installation
        • Computer Vision Basics
          • Pixel and Color
          • Draw image
          • Basic Image processing
          • Morphology Transformations
          • Gaussian blur
          • Simple Thresholding
          • Contour
          • Canny edge detection
        • Case Study
          • Coin counting
          • Color detection & tracking
        • VAM_CV SDK
  • ⚙️FPGA Design and Development
    • Verilog HDL via Vivado IDE
      • LAB1: Setting Environment and Create Project
        • Create Vivado Project
      • LAB2: Hardware Description Language Work Flow
        • Simulation code
      • LAB3: Design HDL Project
        • Top Level Design
        • Top-level Simulation
      • LAB4: Asynchronous VS Synchronous Circuit
        • Simulation Synchronous counter
    • C/C++ Programming on Ultra96v2 FPGA Board
      • Application C/C++ on Ultra96v2 Part 1
        • Design Overview
        • Step 1 - Burn the image to SD card
        • Step 2 - Bring up Ultra96v2
        • Step 3 - Installing the Vitis-AI runtime packages
      • Application C/C++ on Ultra96v2 Part 2
        • STEP 1 : Setting auto boot Wifi
        • STEP 2 : How to working on Embedded
        • STEP 3 : How to run the test code
  • 🤖Robotics
    • Dobot Magician
      • Instruction of Dobot
      • Software Download
      • Basically of Program
        • Teaching and Playback
        • Write and Draw
        • LaserEngraving
        • 3D Printer
    • Robotino
      • Software Download
        • Robotino View
        • Robotino SIM
      • Charging
      • Connecting
      • Follow Line example
        • Basic block in Follow Line
    • RaspBlock
      • Get Started with Raspblock
  • 🚩Special Topics
    • Node-Red
      • Set up Raspberry Pi
      • Install node red in Raspberry Pi
      • Get started with Node Red
        • Open node-red
        • Turn off node red
        • Install Dashboard on Node-red
        • Use node red to show message
        • Using Ultrasonic sensor with node-red
    • IoT Cloud
      • Overview
        • How do they work?
          • Basic Knowlege
      • Installations
        • Install Docker
        • Install Mosquitto Broker
        • Install InfluxDB
        • Install Telegraf
        • Install Grafana
      • Get Sensor Value and Send to MQTT
        • Connect ESP3266 to sensor
        • Connect ESP3266 to MQTT
      • Integration
    • Senses IoT
      • SENSES IoT Platform
      • LAB8: MCU send data to IoT platform
    • CrowPi Dev Kit
      • Raspberry Pi with CrowPi
      • Remote to Raspberry Pi
      • Cross-Compile
        • Lab 1: Programming and cross complier
      • Hardware and Interfaces Usage CLI
        • LAB: Usage GPIO via CLI
        • LAB: Scan I2C bus via CLI
      • Python library for Crow Pi
      • wiringPi library (C) for CrowPi
        • Lab2: Crowpi and sensors
    • LVGL Development
      • LVGL - Light and Versatile Embedded Graphics Library
        • Setting program for LVGL Simulator
        • Get started with LVGL simulator
        • Example Library of LVGL
        • Create your own screen
          • Exercise
        • Style
          • Exercise
        • Event
    • Docker OS
      • Docker OS Part 1
        • Part 1 : Installation
        • Part 2 : Basic Docker OS and Linux CLI
      • Docker OS Part 2
        • Part 1 : Docker communication
        • Part 2 : Docker compose
      • Application Gstreamer on devcontainer
        • STEP 1 : Setting gstreamer environment
        • STEP 2 : Create the Gstreamer element on template
        • STEP 3 : Testing and application on your gst element
  • 🤟Recommended by AIC
    • Skill Roadmap
      • Embedded Engineer
      • Developer
    • Hardware Programming
    • Embedded Programming
    • General-propose Programming
    • Algorithmica
    • Thai Expert Knowledge
    • RT-Thread University Program
      • Infineon PSoC6
      • Kernel
        • Kernel Basics
        • Thread Management
        • Clock Management
        • Inter-thread synchronization
        • Inter-thread communication
        • Memory Management
        • Interrupt Management
        • Kernel porting
        • Atomic Operations
        • RT-Thread SMP
        • Kernel API Changelog
      • Tools
      • Devices & Drivers
        • SENSOR Devices
        • Touch Equipment
        • CRYPTO Devices
        • AUDIO Devices
        • Pulse Encoder Devices
      • Components
        • C Library (libc)
        • ISO/ANSI C Standard
        • POSIX Standard
          • FILE (File IO)
          • Pthread
          • Timer
          • IPC Semaphore
          • IPC Message Queues
          • Dynamic Modules
        • Network Components
          • FinSH Console
          • FAL: Flash Abstraction Layer
          • Virtual File System
          • tmpfs: temporary file system
          • ulog log
          • utest testing framework
          • Power Management
          • RT-Link
        • Software Packages
          • Internet of Things
            • MQTT-umqtt
            • Telnet
          • Tools
            • SystemView
            • SEGGER_RTT
          • LVGL Manual
            • Touch Screen Driver
      • Demo
        • Infineon Gateway
        • Handwriting Recognition (MNIST)
        • Object Detection (Darknet)
        • ROS using RT-Thread
        • Control the car using RT-Thread
        • LiDAR via RT-Thread
        • Detection via RT-Thread and ROS
        • Sensor Driver Development Guide
Powered by GitBook

Assoc. Prof. Wiroon Sriborrirux, Founder of Advance Innovation Center (AIC) and Bangsaen Design House (BDH), Electrical Engineering Department, Faculty of Engineering, Burapha University

On this page
  • PM Component Introduction
  • Design Architecture
  • Low-power states and modes
  • Calling process
  • API Introduction
  • Instructions
  • Migration Instructions
  • MSH Commands
  • Common problems and debugging methods

Was this helpful?

  1. Recommended by AIC
  2. RT-Thread University Program
  3. Components
  4. Network Components

Power Management

Previousutest testing frameworkNextRT-Link

Last updated 7 months ago

Was this helpful?

The purpose of low-power management in embedded systems is to reduce system energy consumption as much as possible to extend device standby time while meeting user performance requirements. The contradiction between high performance and limited battery energy is most prominent in embedded systems, and the combined application of hardware low-power design and software low-power management has become an effective means to resolve the contradiction. Various MCUs now provide management interfaces in terms of low power consumption to a greater or lesser extent. For example, the adjustment of the main control clock frequency, the change of the operating voltage, the adjustment or even shutdown of the bus frequency, the shutdown of the peripheral device working clock, etc. With hardware support, reasonable software design becomes the key to energy saving. Generally, low-power management can be divided into three categories:

  • The main implementation methods of processor power management are: dynamic management of CPU frequency and adjustment of working mode when the system is idle.

  • The main implementation method of device power management is to shut down individual idle devices.

  • The main implementation method of system platform power management is: specific customization for uncommon devices on a specific system platform.

With the rise of the Internet of Things (IoT), the demand for power consumption of products is becoming increasingly strong. Sensor nodes for data collection usually need to work for a long time when powered by batteries, while SOCs for networking also need to have fast response functions and low power consumption.

At the beginning of product development, the first consideration is to complete the product function development as soon as possible. After the product functions are gradually improved, it is necessary to add power management (PM) functions. In order to meet the needs of IoT, RT-Thread provides a power management component. The concept of the power management component is to be as transparent as possible, making it easier to add low-power functions to the product.

RT-Thread's PM component adopts a layered design concept, separating the architecture and chip-related parts, and extracting the common parts as the core. While providing a common interface to the upper layer, it also makes it easier for the underlying driver to adapt to the component.

PM component overview

The main features of RT-Thread PM components are as follows:

  • Manage power consumption based on mode, dynamically adjust working mode when idle, and support multiple levels of sleep.

  • Transparent to applications, components automatically complete power management at the bottom layer.

  • Supports dynamic frequency conversion in operating mode, automatically updates the frequency configuration of the device according to the mode, and ensures normal operation in different operating modes.

  • Supports device power management, automatically manages device suspend and resume according to the mode, and ensures correct suspend and resume in different sleep modes.

  • Supports optional sleep time compensation, allowing applications that rely on OS Tick to use it transparently.

  • Provides a device interface to the upper layer. If the devfs component is enabled, it can also be accessed through the file system interface.

The essence of low power consumption is that the CPU stops working when the system is idle, and continues to work after being woken up by an interrupt or event. In RTOS, there is usually an IDLE task, which has the lowest priority and always remains in a ready state. When a high-priority task is not ready, the OS executes the IDLE task. Generally, when low power consumption processing is not performed, the CPU loops and executes empty instructions in the IDLE task. In the IDLE task, the power management component of RT-Thread manages the CPU, clock, and devices, thereby effectively reducing the power consumption of the system.

As shown in the figure above, when the high-priority task ends or is suspended, the system will enter the IDLE task. After the IDLE task is executed, it will determine whether the system can enter the sleep state (to save power). If it can enter the sleep state, some hardware modules will be turned off according to the chip situation, and OS Tick is also very likely to enter the pause state. At this time, the power management framework will calculate the next timeout point according to the system timer situation, and set the low-power timer so that the device can wake up at this time point and perform subsequent work. When the system is awakened by (low-power timer interrupt or other wake-up interrupt source), the system also needs to know the length of the sleep time and compensate the OS Tick to adjust the system's OS tick value to a correct value.

In the RT-Thread PM component, peripherals or applications vote on the required power consumption mode through a voting mechanism. When the system is idle, the appropriate power consumption mode is determined based on the number of votes, and the abstract interface is called to control the chip to enter a low-power state, thereby reducing system power consumption. When no vote is performed, it enters the default mode (usually idle mode). Unlike applications, some peripherals may perform specific operations when entering a low-power state, and take measures to recover when exiting low power. This can be achieved by registering PM devices. By registering a PM device, the suspend callback of the registered device will be triggered before entering the low-power state, and the developer can perform his own operations in the callback; similarly, the resume callback will be triggered when exiting from a low-power state.

The RT-Thread PM component divides the system into two states: Run and Sleep. The Run state controls the CPU frequency and is suitable for variable frequency scenarios; the Sleep state implements the sleep CPU according to the SOC characteristics to reduce power consumption. The two states use different API interfaces and are independently controlled.

  • Hibernation

The sleep state is a low-power state in the usual sense. It reduces system power consumption by shutting down peripherals and executing the SOC power management interface. The sleep state is divided into six modes, which are presented in the form of a pyramid. As the modes increase, the power consumption decreases step by step. The following is the definition of the modes in the sleep state. Developers can implement the corresponding modes according to the specific SOC, but they need to follow the characteristics of the power consumption decreasing step by step.

model

level

describe

PM_SLEEP_MODE_NONE

0

The system is in an active state and no power reduction state is adopted

PM_SLEEP_MODE_IDLE

1

Idle mode, in which the CPU and some clocks are stopped when the system is idle, and any event or interrupt can wake up

PM_SLEEP_MODE_LIGHT

2

Light sleep mode, CPU stops, most clocks and peripherals stop, time compensation is required after waking up

PM_SLEEP_MODE_DEEP

3

Deep sleep mode, CPU stops, only a few low-power peripherals work, can be woken up by special interrupts

PM_SLEEP_MODE_STANDBY

4

Standby mode, CPU stopped, device context lost (can be saved to special peripherals), usually reset after wakeup

PM_SLEEP_MODE_SHUTDOWN

5

Shutdown mode, lower power consumption than Standby mode, context is usually not recoverable, reset after wakeup

Note: Due to differences in chips from different manufacturers, the implementation of power management is also different. The above description only gives some recommended scenarios, not all of which need to be implemented. Developers can choose a few of them to implement according to their own situation, but they need to follow the principle that the higher the level, the lower the power consumption!

  • Running status

The operating state is usually used to change the CPU's operating frequency, independent of the sleep mode. The current operating state is divided into four levels: high speed, normal speed, medium speed, and low speed, as follows:

model

describe

PM_RUN_MODE_HIGH_SPEED

High speed mode, suitable for some overclocking scenarios

PM_RUN_MODE_NORMAL_SPEED

Normal mode, which is the default operating state

PM_RUN_MODE_MEDIUM_SPEED

Medium speed mode reduces CPU speed and thus reduces power consumption

PM_RUN_MODE_LOW_SPEED

Low speed mode, CPU frequency is further reduced

In the PM component, upper-level applications can actively participate in power management by requesting and releasing sleep modes. Applications can request different sleep modes based on scenarios and release them after processing. As long as any application or device requests a high-level power mode, it will not switch to a lower mode. Therefore, the request and release operations of sleep mode usually appear in pairs, which can be used to protect a certain stage, such as the DMA transfer process of peripherals.

In the PM component, switching to a new operating mode may cause the CPU frequency to change. If the peripherals and the CPU share a part of the clock, the peripheral clock will be affected; when entering a new sleep mode, most clock sources will be stopped. If the peripheral does not support the freeze function of sleep, then when waking up from sleep, the peripheral clock needs to be reconfigured. Therefore, the PM component supports PM devices that are sensitive to PM mode. This allows the device to work normally when switching to a new operating mode or a new sleep mode. This function requires the underlying driver to implement the relevant interface and register as a device that is sensitive to mode changes.

First, the application sets the callback function for entering and exiting the sleep state, and then calls rt_pm_request to request the sleep mode, triggering the sleep operation; the PM component checks the sleep mode count when the system is idle, and gives a recommended mode based on the number of votes; then the PM component calls notify to notify the application that it is about to enter the sleep mode; then the registered PM device is suspended, and after returning OK, the sleep mode implemented by the SOC is executed, and the system enters the sleep state (if time compensation is enabled, the low power timer will be started before sleep). At this time, the CPU stops working and waits for events or interrupts to wake up. When the system is awakened, since the global interrupt is turned off, the system continues to execute from there, obtains the heartbeat of the sleep time compensation system, wakes up the devices in turn, and notifies the application to exit from the sleep mode. In this way, a cycle is completed, exits, and waits for the next idle time of the system.

  • Request sleep mode

    void rt_pm_request(uint8_t sleep_mode);copymistakeCopy Success

    parameter

    model

    sleep_mode

    Requested sleep mode level

sleep_mode takes the following enumeration values:

enum
{
    /* sleep modes */
    PM_SLEEP_MODE_NONE = 0,    /* 活跃状态 */
    PM_SLEEP_MODE_IDLE,        /* 空闲模式(默认) */
    PM_SLEEP_MODE_LIGHT,       /* 轻度睡眠模式 */
    PM_SLEEP_MODE_DEEP,        /* 深度睡眠模式 */
    PM_SLEEP_MODE_STANDBY,     /* 待机模式 */
    PM_SLEEP_MODE_SHUTDOWN,    /* 关断模式 */
    PM_SLEEP_MODE_MAX,
};copymistakeCopy Success

Calling this function will increase the corresponding mode count by 1 and lock the mode. If you request a lower power mode at this time, you will not be able to enter. Only after releasing (unlocking) the previously requested mode can the system enter a lower mode; requests for higher power modes are not affected by this. This function needs to be used in conjunction with rt_pm_release to protect a certain stage or process.

  • Release sleep mode

    void rt_pm_release(uint8_t sleep_mode);copymistakeCopy Success

    parameter

    model

    sleep_mode

    Released sleep mode level

Calling this function will reduce the corresponding mode count by 1, and can be used with rt_pm_request to release the previously requested mode.

  • Set the operating mode

    int rt_pm_run_enter(uint8_t run_mode);copymistakeCopy Success

    parameter

    model

    run_mode

    Set the operating mode level

run_mode can take the following enumeration values:

enum
{
    /* run modes*/
    PM_RUN_MODE_HIGH_SPEED = 0,    /* 高速 */
    PM_RUN_MODE_NORMAL_SPEED,      /* 正常(默认) */
    PM_RUN_MODE_MEDIUM_SPEED,      /* 中速 */
    PM_RUN_MODE_LOW_SPEED,         /* 低速 */
    PM_RUN_MODE_MAX,
};copymistakeCopy Success

Call this function to change the CPU operating frequency, thereby reducing the power consumption during operation. This function only provides the level, and the specific CPU frequency should be determined according to the actual situation during the transplantation stage.

  • Set callback notification for entering/exiting sleep mode

    void rt_pm_notify_set(void (*notify)(uint8_t event, uint8_t mode, void *data), void *data);copymistakeCopy Success

    parameter

    model

    notify

    Application callback function

    data

    Private Data

event is one of the following two enumeration values, which respectively indicate entering/exiting sleep mode.

enum
{
    RT_PM_ENTER_SLEEP = 0,    /* 进入休眠模式 */
    RT_PM_EXIT_SLEEP,         /* 退出休眠模式 */
};
copymistakeCopy Success
  • Setting low power consumption level

If the system needs to enter a specified level of low power consumption, it can be achieved by calling rt_pm_request. For example, to enter deep sleep mode:

/* 请求进入深度睡眠模式 */
rt_pm_request(PM_SLEEP_MODE_DEEP);copymistakeCopy Success

Note: If a higher power consumption mode is requested elsewhere in the program, such as Light Mode or Idle Mode, the corresponding mode needs to be released before the deep sleep mode can be entered.

  • Protect a stage or process

In special cases, such as when the system is not allowed to enter a lower power mode at a certain stage, the process can be protected by rt_pm_request and rt_pm_release. For example, during I2C reading data, entering deep sleep mode is not allowed (which may cause the peripheral to stop working), so the following processing can be done:

/* 请求轻度睡眠模式(I2C外设该模式下正常工作) */
rt_pm_request(PM_SLEEP_MODE_LIGHT);

/* 读取数据过程 */

/* 释放该模式 */
rt_pm_release(PM_SLEEP_MODE_LIGHT);
copymistakeCopy Success
  • Change CPU operating frequency

Lowering the operating frequency can effectively reduce the power consumption of the system. The CPU operating frequency can be changed through the rt_pm_run_enter interface. Generally speaking, lowering the frequency means that the CPU performance is reduced and the processing speed is slowed down, which may lead to an increase in the execution time of the task, and a reasonable trade-off needs to be made.

/* 进入中等速度运行模式 */
rt_pm_run_enter(PM_RUN_MODE_MEDIUM_SPEED);copymistakeCopy Success

Low power management is a very detailed task. When porting, developers not only need to fully understand the power management of the chip itself, but also need to be familiar with the peripheral circuits of the board and process them one by one when entering the low power state to avoid the situation where the peripheral circuit leakage increases the overall power consumption. The RT-Thread PM component abstracts each part and provides different ops interfaces for developers to adapt. The parts that need to be paid attention to during porting are as follows:

/**
 * low power mode operations
 */
struct rt_pm_ops
{
    /* sleep 接口用于适配芯片相关的低功耗特性 */
    void (*sleep)(struct rt_pm *pm, uint8_t mode);
    /* run 接口用于运行模式的变频和变电压 */
    void (*run)(struct rt_pm *pm, uint8_t mode);
    /* 以下三个接口用于心跳停止后启动低功耗定时器以补偿心跳 */
    void (*timer_start)(struct rt_pm *pm, rt_uint32_t timeout);
    void (*timer_stop)(struct rt_pm *pm);
    rt_tick_t (*timer_get_tick)(struct rt_pm *pm);
};

/* 该 ops 用于管理外设的功耗 */
struct rt_device_pm_ops
{
    /* 进入休眠模式之前挂起外设,返回非 0 表示外设未就绪,不能进入 */
    int (*suspend)(const struct rt_device *device, uint8_t mode);
    /* 从休眠模式退出后恢复外设 */
    void (*resume)(const struct rt_device *device, uint8_t mode);
    /* 运行状态下模式改变通知外设处理 */
    int (*frequency_change)(const struct rt_device *device, uint8_t mode);
};

/* 注册一个 PM 设备 */
void rt_pm_device_register(struct rt_device *device, const struct rt_device_pm_ops *ops);copymistakeCopy Success
  • The power consumption characteristics of the chip itself

    void (*sleep)(struct rt_pm *pm, uint8_t mode);copymistakeCopy Success

    Each chip has different definitions and management of low-power modes. The PM component abstracts chip-related features into a sleep interface. This interface adapts to chip-related low-power management. When entering different sleep modes, some hardware-related configurations, saves, and other related processes are performed.

  • Sleep time compensation

void (*timer_start)(struct rt_pm *pm, rt_uint32_t timeout);
void (*timer_stop)(struct rt_pm *pm);
rt_tick_t (*timer_get_tick)(struct rt_pm *pm);copymistakeCopy Success

In some sleep modes (Light Sleep or Deep Sleep), the heartbeat timer may be stopped. In this case, you need to start a timer to measure the sleep time and compensate the heartbeat after waking up. The timer for time compensation must still work normally in this mode and wake up the system, otherwise it is meaningless!

timer_start: Start the low power timer, the input parameter is the nearest task ready time; timer_get_tick: Get the sleep time when the system is awakened; timer_stop: Used to stop the low power timer after the system wakes up.

Note : The time compensation of sleep mode needs to be enabled during the initialization phase by setting the bit control of the corresponding mode of timer_mask. For example, if you need to enable the time compensation of Deep Sleep mode, after implementing the timer-related ops interface, set the corresponding bit during initialization:

rt_uint8_t timer_mask = 0;

/* 设置 Deep Sleep 模式对应的 bit,使能休眠时间补偿 */
timer_mask = 1UL << PM_SLEEP_MODE_DEEP;

/* initialize system pm module */
rt_system_pm_init(&_ops, timer_mask, RT_NULL);copymistakeCopy Success
  • Operation mode variable frequency

void (*run)(struct rt_pm *pm, uint8_t mode);copymistakeCopy Success

The frequency conversion of the running mode is achieved by adapting the run interface in rt_pm_ops, and the appropriate frequency is selected according to the usage scenario.

  • Power management of peripherals

Peripheral power consumption processing is an important part of the low power management system. When entering certain levels of sleep mode, some peripherals usually need to be processed, such as clearing DMA, turning off the clock, or setting IO to reset state; and recovering after exiting sleep. In this case, you can register the PM device through the interface. When entering/exiting sleep mode, the and callbacks rt_pm_device_registerof the registered device will be executed ; frequency changes in the running mode will also trigger the device's callback.suspendresumefrequency_change

For more detailed porting examples, please refer to the stm32l476-nucleo bsp in the RT-Thread repository.

You can use pm_requestthe command request mode. The usage example is as follows:

msh />pm_request 0
msh />copymistakeCopy Success

The parameter value is 0-5, corresponding to the following enumeration values:

enum
{
    /* sleep modes */
    PM_SLEEP_MODE_NONE = 0,    /* 活跃状态 */
    PM_SLEEP_MODE_IDLE,        /* 空闲模式(默认) */
    PM_SLEEP_MODE_LIGHT,       /* 轻度睡眠模式 */
    PM_SLEEP_MODE_DEEP,        /* 深度睡眠模式 */
    PM_SLEEP_MODE_STANDBY,     /* 待机模式 */
    PM_SLEEP_MODE_SHUTDOWN,    /* 关断模式 */
    PM_SLEEP_MODE_MAX,
};copymistakeCopy Success

You can use pm_releasethe command to release the mode. The parameter value is 0-5. The usage example is as follows:

msh />pm_release 0
msh />copymistakeCopy Success

You can use pm_runthe command to switch the operation mode. The parameter value is 0-3. The usage example is as follows

msh />pm_run 2
msh />copymistakeCopy Success

Parameter value 0-3

enum
{
    /* run modes*/
    PM_RUN_MODE_HIGH_SPEED = 0,
    PM_RUN_MODE_NORMAL_SPEED,
    PM_RUN_MODE_MEDIUM_SPEED,
    PM_RUN_MODE_LOW_SPEED,
    PM_RUN_MODE_MAX,
};copymistakeCopy Success

You can use pm_dumpthe command to view the mode status of the PM component. The usage example is as follows:

msh >
msh >pm_dump
| Power Management Mode | Counter | Timer |
+-----------------------+---------+-------+
|             None Mode |       0 |     0 |
|             Idle Mode |       0 |     0 |
|       LightSleep Mode |       1 |     0 |
|        DeepSleep Mode |       0 |     1 |
|          Standby Mode |       0 |     0 |
|         Shutdown Mode |       0 |     0 |
+-----------------------+---------+-------+
pm current sleep mode: LightSleep Mode
pm current run mode:   Normal Speed
msh >copymistakeCopy Success

In pm_dumpthe mode list, the priority of sleep mode is arranged from high to low. CounterOne column indicates the request count value. The figure shows that the LightSleep mode is requested once, so the current work is in light sleep state; Timer one column indicates whether to enable sleep time compensation. In the figure, only the DeepSleep mode performs time compensation. The bottom indicates the current sleep mode and operating mode level.

  • The power consumption is high after the system enters low power mode

According to the peripheral circuit, check whether the device is in a reasonable state to avoid peripheral leakage; according to the product itself, turn off the peripherals and clocks that are not used during the corresponding sleep mode.

  • Unable to enter lower power consumption levels

Check whether the high-level power consumption mode has not been released. The PM component of RT-Thread uses rt_pm_requestrequest sleep mode. If a high-power consumption mode is requested but not released, the system will not be able to switch to a lower level of power consumption. For example, after requesting the Light Sleep mode, the Deep Sleep mode is then requested, and the system is still in the Light Sleep mode. By calling the interface rt_pm_releaseto release the Light Sleep mode, the system will automatically switch to the Deep Sleep mode.

How PM works

PM Design Architecture

PM Timing Diagram

🤟
Main Features
How it works
Design Architecture
Low-power states and modes
Request and release of mode
Devices sensitive to mode changes
Calling process
API Introduction
Instructions
Migration Instructions
MSH Commands
Request sleep mode
Release sleep mode
Set the operating mode
View Mode Status
Common problems and debugging methods
PM Component Introduction