当前文档版本为 v0.9.0,您可以访问当前页面的 开发中 版本以获取最近可能的更新。

Driver: Power Management

1 功能概述

本例程演示通过 Zephyr Power Management (PM) 机制进出低功耗的方法。

2 环境要求

  • PAN1080 EVB 一块

  • 电流计(本文使用电流可视化测量设备 PPK2 [Nordic Power Profiler Kit II] 进行演示)

  • USB-TypeC 线一条(用于供电和查看串口打印 Log)

  • 硬件接线:

    • 使用 USB 线,将 PC USB 与 EVB USB-TypeC(USB->UART)相连

    • 根据 EVB 核心板芯片的封装不同,使用杜邦线将 EVB 底板上的:

      • TX0 与 P00 相连, RX0 与 P01 相连(若 EVB 板芯片为 QFN32 或 LQFP64 封装)

      • TX0 与 P30 相连, RX0 与 P31 相连(若 EVB 板芯片为 QFN48 封装)

  • PC 软件: 串口调试助手(UartAssist)或终端工具(SecureCRT),波特率921600

3 编译和烧录

例程位置:zephyr\samples_panchip\drivers\pm

使用 ZAL 工具可以对其进行编译、烧录、打开 VS Code 调试等操作。关于 ZAL 工具的详细介绍请参考:Zephyr APP Launcher 工具介绍

4 演示说明

  1. 程序烧录完成后,从串口工具中看到如下的打印信息:

    Try to load HW calibration data.. DONE.
    - Chip Type         : 0x80
    - Chip CP Version   : None
    - Chip FT Version   : 5
    - Chip MAC Address  : D0000C0293CA
    - Chip Flash UID    : 31373237300A29494330FFFFFFFFFFFF
    - Chip Flash Size   : 1024 KB
    *** Booting Zephyr OS build zephyr-v2.7.0-1347-g4073b5da347f  ***
    
    Reset Reason: NVIC System Reset.
    
    Sleep 100ms to enter zephyr pm cpu-idle state..
    Waked up from zephyr cpu-idle state.
    
    Sleep 300ms to enter zephyr pm runtime-idle state..
    Waked up from zephyr runtime-idle state.
    
    Sleep 600ms to enter zephyr pm suspend-to-idle state..
    Waked up from zephyr suspend-to-idle state.
    
    Sleep 900ms to enter zephyr pm suspend-to-ram state..
    Try to load HW calibration data.. DONE.
    - Chip Type         : 0x80
    - Chip CP Version   : None
    - Chip FT Version   : 5
    - Chip MAC Address  : D0000C0293CA
    - Chip Flash UID    : 31373237300A29494330FFFFFFFFFFFF
    - Chip Flash Size   : 1024 KB
    *** Booting Zephyr OS build zephyr-v2.7.0-1347-g4073b5da347f  ***
    
    Reset Reason: Waked up from zephyr suspend-to-ram state.
    
    Sleep 1600ms to enter zephyr pm soft-off state..
    

    由上述 Log 可得知以下信息:

    • 第一次芯片 Reset 原因为 NVIC System Reset,这是因为本次芯片是程序烧录后由 JLink 触发的软件 Reset

    • 接着系统进入持续 100ms 的 cpu-idle 状态,此状态对应芯片的 Sleep 模式

    • cpu-dle 状态唤醒后,系统又进入持续 300ms 的 runtime-idle 状态,此状态同样对应芯片的 Sleep 模式

    • runtime-dle 状态唤醒后,系统又进入持续 600ms 的 suspend-to-idle 状态,此状态对应芯片的 DeepSleep 模式

    • suspend-to-dle 状态唤醒后,系统又进入持续 900ms 的 suspend-to-ram 状态,此状态对应芯片的 Standby M1 (with SRAM Retention) 模式

    • suspend-to-ram 状态唤醒后,系统复位,此次 Reset 原因显示为 Waked up from zephyr suspend-to-ram state

    • 然后芯片进入了持续 1600ms(实际上是无限时间)的 soft-off 状态,此状态对应芯片的 Standby M0 模式,只能通过 GPIO P56 引脚唤醒

  2. 按一下 EVB 底板上的 WKUP (P56) 按键,由串口打印信息可知触发了芯片唤醒:

    Try to load HW calibration data.. DONE.
    - Chip Type         : 0x80
    - Chip CP Version   : None
    - Chip FT Version   : 5
    - Chip MAC Address  : D0000C0293CA
    - Chip Flash UID    : 31373237300A29494330FFFFFFFFFFFF
    - Chip Flash Size   : 1024 KB
    *** Booting Zephyr OS build zephyr-v2.7.0-1347-g4073b5da347f  ***
    
    Reset Reason: Waked up from zephyr soft-off state.
    
    Sleep 100ms to enter zephyr pm cpu-idle state..
    Waked up from zephyr cpu-idle state.
    
    Sleep 300ms to enter zephyr pm runtime-idle state..
    Waked up from zephyr runtime-idle state.
    
    Sleep 600ms to enter zephyr pm suspend-to-idle state..
    Waked up from zephyr suspend-to-idle state.
    
    Sleep 900ms to enter zephyr pm suspend-to-ram state..
    Try to load HW calibration data.. DONE.
    - Chip Type         : 0x80
    - Chip CP Version   : None
    - Chip FT Version   : 5
    - Chip MAC Address  : D0000C0293CA
    - Chip Flash UID    : 31373237300A29494330FFFFFFFFFFFF
    - Chip Flash Size   : 1024 KB
    *** Booting Zephyr OS build zephyr-v2.7.0-1347-g4073b5da347f  ***
    
    Reset Reason: Waked up from zephyr suspend-to-ram state.
    
    Sleep 1600ms to enter zephyr pm soft-off state..
    

    由上述 Log 可得知以下信息:

    • 本次芯片 Reset 原因为 Waked up from zephyr soft-off state.

    • 接着芯片重复进入各个低功耗模式,最终再次停在 soft-off 状态等待下一次 P56 按键唤醒

5 开发者说明

5.1 低功耗模式说明

image

低功耗模式说明

PAN1080 芯片级低功耗流程请参考:

Zephyr OS 低功耗流程框架请参考:

5.2 进入低功耗的时机

&cpu0 {
	cpu-power-states = <&state0 &state1 &state2 &state3>;
};

&state0 {
	compatible = "zephyr,power-state";
	power-state-name = "runtime-idle";
	min-residency-us = <200000>;
	exit-latency-us = <32>;
};

&state1 {
	compatible = "zephyr,power-state";
	power-state-name = "suspend-to-idle";
	min-residency-us = <500000>;
	exit-latency-us = <32>;
};

&state2 {
	compatible = "zephyr,power-state";
	power-state-name = "suspend-to-ram";
	min-residency-us = <800000>;
	exit-latency-us = <32>;
};

&state3 {
	compatible = "zephyr,power-state";
	power-state-name = "soft-off";
	min-residency-us = <1500000>;
	exit-latency-us = <32>;
};

以该参数来说明:

cpu0 有四种低功耗状态,分别为

  • state0:runtime-idle(sleep mode)

  • state1:suspend-to-idle(deepsleep mode)

  • state2:suspend-to-ram(standby mode1)

  • state3:soft-off(standby mode0)

如果idle时间满足以下条件:

if (time_to_next_scheduled_event >= (state.min_residency_us + state.exit_latency))) {
	return state
}

则进入相应的state。

6 RAM/Flash资源使用情况

Memory region         Used Size  Region Size  %age Used
           FLASH:       23504 B       256 KB      8.97%
            SRAM:        7000 B        64 KB     10.68%