使用指南
编译 PM 示例
该示例包含了多个唤醒源的测试。
编译,执行命令:
./nuwa.py build -d rtl8721f_evb//mcuboot -a applications/mcuboot_pm_system_manage --sysbuild
固件下载
重新上电,看到如下日志可以看到系统会进入 sleep 并依次被 rtc,counter,gpio 唤醒,其中 gpio 触发唤醒需要将
PB5连接到 3.3V15:21:27.245 Going sleep. 15:21:27.245 state: 4 15:21:27.246 [00:00:00.006,000] <inf> soc_pm: call pm_state_set: 4 15:21:29.130 ?NPPW 15:21:29.131 APPW 15:21:29.133 [00:00:00.006,000] <inf> soc_pm: [pm_state_exit_post_ops] AP wake: 4 15:21:29.134 Wake up by: rtc@4080aa00. 15:21:29.134 Created the thread. 15:21:29.135 Going sleep. 15:21:29.136 state: 4 15:21:29.312 [00:00:00.006,000] <inf> soc_pm: call pm_state_set: 4 15:21:29.312 APPG 15:21:29.312 NPPG 15:21:30.137 NPPW 15:21:30.137 APPW 15:21:30.140 [00:00:00.006,000] <inf> soc_pm: [pm_state_exit_post_ops] AP wake: 4 15:21:30.141 Wake up by: counter@40819000. 15:21:30.400 Connect pin gpiob5 with 3.3V to wakeup 15:21:30.400 Created the thread. 15:21:30.401 Going sleep. 15:21:30.401 state: 4 15:21:30.402 [00:00:00.006,000] <inf> soc_pm: call pm_state_set: 4 15:21:30.403 APPG 15:21:38.455 NPPG 15:22:56.501 NPPW 15:22:56.502 APPW 15:22:56.502 [00:00:00.006,000] <inf> soc_pm: [pm_state_exit_post_ops] AP wake: 4 15:22:56.503 Wake up by: gpio@40811400.
配置步骤
Kconfig 中打开 PM 以及要使用的唤醒源设备
# Enable PM
CONFIG_PM=y
# Increase stack to avoid crash due to Stack overflow
CONFIG_IDLE_STACK_SIZE=4096
# Enable RTC device as precondition of wakeup-source
CONFIG_RTC=y
CONFIG_RTC_ALARM=y
CONFIG_RTC_AMEBA=y
# Enable timer(counter) device as precondition of wakeup-source
CONFIG_COUNTER=y
# Enable GPIO device as precondition of wakeup-source
CONFIG_GPIO=y
在 dts(overlay) 中为唤醒源设备添加
wakeup-source属性使能其唤醒源功能,例如:
&rtc {
status = "okay";
wakeup-source;
};
&gpiob {
status = "okay";
wakeup-source;
};
&timer0 {
status = "okay";
wakeup-source;
};
在代码中为 device 进行初始化