处理器电源管理主要实现方式是什么?

电源管理组件
嵌入式系统低功耗管理的目的在于满足用户对性能需求的前提下,尽可能降低系统能耗以延长设备待机时间。高性能与有限的电池能量在嵌入式系统中矛盾最为突出,硬件低功耗设计与软件低功耗管理的联合应用成为解决矛盾的有效手段。现在的各种 mcu 都或多或少的在低功耗方面提供了管理接口。比如对主控时钟频率的调整、工作电压的改变、总线频率的调整甚至关闭、外围设备工作时钟的关闭等。有了硬件上的支持,合理的软件设计就成为节能的关键,一般可以把低功耗管理分为三个类别:
处理器电源管理主要实现方式:对 cpu 频率的动态管理,以及系统空闲时对工作模式的调整。
设备电源管理主要实现方式:关闭个别闲置设备
系统平台电源管理主要实现方式:针对特定系统平台的非常见设备具体定制。
随着物联网 (iot) 的兴起,产品对功耗的需求越来越强烈。作为数据采集的传感器节点通常需要在电池供电时长期工作,而作为联网的 soc 也需要有快速的响应功能和较低的功耗。
在产品开发的起始阶段,首先考虑是尽快完成产品的功能开发。在产品功能逐步完善之后,就需要加入电源管理 (power management,以下简称 pm) 功能。为了适应 iot 的这种需求,rt-thread 提供了电源管理组件。电源管理组件的理念是尽量透明,使得产品加入低功耗功能更加轻松。
pm 组件介绍
rt-thread 的 pm 组件采用分层设计思想,分离架构和芯片相关的部分,提取公共部分作为核心。在对上层提供通用的接口同时,也让底层驱动对组件的适配变得更加简单。
主要特点
rt-thread pm 组件主要特点如下所示:
基于模式来管理功耗,空闲时动态调整工作模式,支持多个等级的休眠。
对应用透明,组件在底层自动完成电源管理。
支持运行模式下动态变频,根据模式自动更新设备的频率配置,确保在不同的运行模式都可以正常工作。
支持设备电源管理,根据模式自动管理设备的挂起和恢复,确保在不同的休眠模式下可以正确的挂起和恢复。
支持可选的休眠时间补偿,让依赖 os tick 的应用可以透明使用。
向上层提供设备接口,如果打开了 devfs 组件,那么也可以通过文件系统接口访问。
工作原理
低功耗的本质是系统空闲时 cpu 停止工作,中断或事件唤醒后继续工作。在 rtos 中,通常包含一个 idle 任务,该任务的优先级最低且一直保持就绪状态,当高优先级任务未就绪时,os 执行 idle 任务。一般地,未进行低功耗处理时,cpu 在 idle 任务中循环执行空指令。rt-thread 的电源管理组件在 idle 任务中,通过对 cpu 、时钟和设备等进行管理,从而有效降低系统的功耗。
在上图所示,当高优先级任务运行结束或被挂起时,系统将进入 idle 任务中。在 idle 任务执行后,它将判断系统是否可以进入到休眠状态(以节省功耗)。如果可以进入休眠, 将根据芯片情况关闭部分硬件模块,os tick 也非常有可能进入暂停状态。此时电源管理框架会根据系统定时器情况,计算出下一个超时时间点,并设置低功耗定时器,让设备能够在这个时刻点唤醒,并进行后续的工作。当系统被(低功耗定时器中断或其他唤醒中断源)唤醒后,系统也需要知道睡眠时间长度是多少,并对os tick 进行补偿,让系统的os tick值调整为一个正确的值。
低功耗状态和模式
rt-thread pm 组件将系统划分为两种状态:运行状态(run)和休眠状态(sleep)。运行状态控制 cpu 的频率,适用于变频场景;休眠状态根据 soc 特性实现休眠 cpu,以降低功耗。两种状态分别使用不同的 api 接口,独立控制。
休眠状态休眠状态也就是通常意义上的低功耗状态,通过关闭外设、执行 soc 电源管理接口,降低系统功耗。休眠状态又分为六个模式,呈现为金字塔的形式。随着模式增加,功耗逐级递减的特点。下面是休眠状态下模式的定义,开发者可根据具体的 soc 实现相应的模式,但需要遵循功耗逐级降低的特点。
运行状态运行状态通常用于改变 cpu 的运行频率,独立于休眠模式。当前运行状态划分了四个等级:高速、正常、中速、低速,如下:
pm组件的实现接口
在 rt-thrad pm 组件中,外设或应用通过投票机制对所需的功耗模式进行投票,当系统空闲时,根据投票数决策出合适的功耗模式,调用抽象接口,控制芯片进入低功耗状态,从而降低系统功耗。当未进行进行任何投票时,会以默认模式进入(通常为空闲模式)。
pm组件的控制块:
static struct rt_pm _pm;
api接口:
请求休眠模式
void rt_pm_request(uint8_t sleep_mode);
sleep_mode 取以下枚举值:
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, };
调用该函数会将对应的模式计数加1,并锁住该模式。此时如果请求更低级别的功耗模式,将无法进入,只有释放(解锁)先前请求的模式后,系统才能进入更低的模式;向更高的功耗模式请求则不受此影响。该函数需要和 rt_pm_release 配合使用,用于对某一阶段或过程进行保护。下面是具体代码实现:
void rt_pm_request(rt_uint8_t mode) { rt_base_t level; struct rt_pm *pm; if (_pm_init_flag == 0) return; if (mode 》 (pm_sleep_mode_max - 1)) return; level = rt_hw_interrupt_disable(); pm = &_pm; if (pm-》modes[mode] 《 255) pm-》modes[mode] ++;//将对应的模式计数加1 rt_hw_interrupt_enable(level); }
释放休眠模式
void rt_pm_release(uint8_t sleep_mode);
调用该函数会将对应的模式计数减1,配合 rt_pm_request 使用,释放先前请求的模式。下面是具体代码实现:
void rt_pm_release(rt_uint8_t mode) { rt_ubase_t level; struct rt_pm *pm; if (_pm_init_flag == 0) return; if (mode 》 (pm_sleep_mode_max - 1)) return; level = rt_hw_interrupt_disable(); pm = &_pm; if (pm-》modes[mode] 》 0) pm-》modes[mode] --;//将对应的模式计数减1 rt_hw_interrupt_enable(level); }
特殊情况下,比如某个阶段并不允许系统进入更低的功耗模式,此时可以通过 rt_pm_request 和 rt_pm_release 对该过程进行保护。如 i2c 读取数据期间,不允许进入深度睡眠模式(可能会导致外设停止工作),因此可以做如下处理:
/* 请求轻度睡眠模式(i2c外设该模式下正常工作) */ rt_pm_request(pm_sleep_mode_light); /* 读取数据过程 */ /* 释放该模式 */ rt_pm_release(pm_sleep_mode_light);
设置运行模式
int rt_pm_run_enter(uint8_t run_mode);
run_mode 可以取以下枚举值:
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, };
调用该函数改变 cpu 的运行频率,从而降低运行时的功耗。此函数只提供级别,具体的 cpu 频率应在移植阶段视实际情况而定。
下面是具体代码实现:
int rt_pm_run_enter(rt_uint8_t mode) { rt_base_t level; struct rt_pm *pm; if (_pm_init_flag == 0) return -rt_eio; if (mode 》 pm_run_mode_max) return -rt_einval; level = rt_hw_interrupt_disable(); pm = &_pm; if (mode 《 pm-》run_mode) { /* change system runing mode */ pm-》ops-》run(pm, mode); /* changer device frequency */ _pm_device_frequency_change(mode); } else { pm-》flags |= rt_pm_frequency_pending; } pm-》run_mode = mode; rt_hw_interrupt_enable(level); return rt_eok; }
设置进入/退出休眠模式的回调通知
void rt_pm_notify_set(void (*notify)(uint8_t event, uint8_t mode, void *data), void *data);
event 为以下两个枚举值,分别标识进入/退出休眠模式。
enum { rt_pm_enter_sleep = 0, /* 进入休眠模式 */ rt_pm_exit_sleep, /* 退出休眠模式 */ };
在应用进入/退出休眠模式会触发回调通知。下面是具体代码实现:
void rt_pm_notify_set(void (*notify)(rt_uint8_t event, rt_uint8_t mode, void *data), void *data) { _pm_notify.notify = notify; _pm_notify.data = data; }
注册pm设备
void rt_pm_device_register(struct rt_device *device, const struct rt_device_pm_ops *ops)
与应用不同,某些外设可能在进入低功耗状态时执行特定操作,退出低功耗时采取措施恢复,此时可以通过注册pm设备来实现。通过注册 pm 设备,在进入低功耗状态之前,会触发注册设备的 suspend 回调,开发者可在回调里执行自己的操作;类似地,从低功耗状态退出时,也会触发 resume 回调。运行模式下的频率改变同样会触发设备的 frequency_change 回调。下面是具体代码实现:
void rt_pm_device_register(struct rt_device *device, const struct rt_device_pm_ops *ops) { rt_base_t level; struct rt_device_pm *device_pm; rt_debug_not_in_interrupt; level = rt_hw_interrupt_disable(); device_pm = (struct rt_device_pm *)rt_kernel_realloc(_pm.device_pm, (_pm.device_pm_number + 1) * sizeof(struct rt_device_pm)); if (device_pm != rt_null) { _pm.device_pm = device_pm; _pm.device_pm[_pm.device_pm_number].device = device; _pm.device_pm[_pm.device_pm_number].ops = ops; _pm.device_pm_number += 1; } rt_hw_interrupt_enable(level); }
设置进入/退出休眠模式的回调通知和注册为设备的回调通知流程:
首先应用设置进出休眠状态的回调函数,然后调用 rt_pm_request 请求休眠模式,触发休眠操作;pm 组件在系统空闲时检查休眠模式计数,根据投票数给出推荐的模式;接着 pm 组件调用 notfiy 通知应用,告知即将进入休眠模式;然后对注册的 pm 设备执行挂起操作,返回 ok 后执行 soc 实现的的休眠模式,系统进入休眠状态(如果使能时间补偿,休眠之前会先启动低功耗定时器)。此时 cpu 停止工作,等待事件或者中断唤醒。当系统被唤醒后,由于全局中断为关闭状态,系统继续从该处执行,获取睡眠时间补偿系统的心跳,依次唤醒设备,通知应用从休眠模式退出。如此一个周期执行完毕,退出,等待系统下次空闲。模式的切换代码实现:当任务进入到空闲线程,最终是调用此函数进入低功耗和唤醒的
static void _pm_change_sleep_mode(struct rt_pm *pm, rt_uint8_t mode) { rt_tick_t timeout_tick, delta_tick; rt_base_t level; int ret = rt_eok; if (mode == pm_sleep_mode_none) { pm-》sleep_mode = mode; pm-》ops-》sleep(pm, pm_sleep_mode_none); } else { level = rt_pm_enter_critical(mode); /* notify app will enter sleep mode */ if (_pm_notify.notify) _pm_notify.notify(rt_pm_enter_sleep, mode, _pm_notify.data); /* suspend all peripheral device */ ret = _pm_device_suspend(mode); if (ret != rt_eok) { _pm_device_resume(mode); if (_pm_notify.notify) _pm_notify.notify(rt_pm_exit_sleep, mode, _pm_notify.data); rt_pm_exit_critical(level, mode); return; } /* tickless*/ if (pm-》timer_mask & (0x01 《《 mode)) { timeout_tick = rt_timer_next_timeout_tick(); if (timeout_tick == rt_tick_max) { if (pm-》ops-》timer_start) { pm-》ops-》timer_start(pm, rt_tick_max); } } else { timeout_tick = timeout_tick - rt_tick_get(); if (timeout_tick 《 rt_pm_tickless_thresh) { mode = pm_sleep_mode_idle; } else { pm-》ops-》timer_start(pm, timeout_tick); } } } /* enter lower power state */ pm-》ops-》sleep(pm, mode); /* wake up from lower power state*/ if (pm-》timer_mask & (0x01 《《 mode)) { delta_tick = pm-》ops-》timer_get_tick(pm); pm-》ops-》timer_stop(pm); if (delta_tick) { rt_tick_set(rt_tick_get() + delta_tick); rt_timer_check(); } } /* resume all device */ _pm_device_resume(pm-》sleep_mode); if (_pm_notify.notify) _pm_notify.notify(rt_pm_exit_sleep, mode, _pm_notify.data); rt_pm_exit_critical(level, mode); } }
移植的实现原理
rt-thread 低功耗管理系统从设计上分离运行模式和休眠模式,独立管理,运行模式用于变频和变电压,休眠调用芯片的休眠特性。对于多数芯片和开发来说,可能并不需要考虑变频和变电压,仅需关注休眠模式。底层功能的实现已经有sunwancn大神对stm32做了全系列的适配,以下是底层实现原理,用户也可以自行根据自身情况对底层进行裁剪或增强。(注意: 驱动可能有更新,移植请到gitee下载最新pm驱动。地址在pm-ports-stm32-new 分支:https://gitee.com/sunwancn/rt-thread/tree/pm-ports-stm32-new)
pm 组件的底层功能都是通过struct rt_pm_ops结构体里的函数完成:
/** * low power mode operations */ struct rt_pm_ops { void (*sleep)(struct rt_pm *pm, uint8_t mode); 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); };
移植休眠模式移植休眠模式仅需关注 sleep 接口,下面是具体的实现:
void stm32_sleep(struct rt_pm *pm, rt_uint8_t mode) { switch (mode) { case pm_sleep_mode_none: break; case pm_sleep_mode_idle: if (pm-》run_mode == pm_run_mode_low_speed) { /* enter lp sleep mode, enable low-power regulator */ hal_pwr_entersleepmode(pwr_lowpowerregulator_on, pwr_sleepentry_wfi); } else { /* enter sleep mode, main regulator is on */ hal_pwr_entersleepmode(pwr_mainregulator_on, pwr_sleepentry_wfi); } break; case pm_sleep_mode_light: if (pm-》run_mode == pm_run_mode_low_speed) { __hal_flash_sleep_powerdown_enable(); /* enter lp sleep mode, enable low-power regulator */ hal_pwr_entersleepmode(pwr_lowpowerregulator_on, pwr_sleepentry_wfi); __hal_flash_sleep_powerdown_disable(); } else { /* enter sleep mode, main regulator is on */ hal_pwr_entersleepmode(pwr_mainregulator_on, pwr_sleepentry_wfi); } break; case pm_sleep_mode_deep: /* disable systick interrupt */ clear_bit(systick-》ctrl, (rt_uint32_t)systick_ctrl_tickint_msk); if (pm-》run_mode == pm_run_mode_low_speed) { /* clear lpr bit to back the normal run mode */ clear_bit(pwr-》cr1, pwr_cr1_lpr); /* enter stop 2 mode */ hal_pwrex_enterstop2mode(pwr_stopentry_wfi); /* set regulator parameter to lowpower run mode */ set_bit(pwr-》cr1, pwr_cr1_lpr); } else { /* enter stop 2 mode */ hal_pwrex_enterstop2mode(pwr_stopentry_wfi); } /* enable systick interrupt */ set_bit(systick-》ctrl, (rt_uint32_t)systick_ctrl_tickint_msk); /* re-configure the system clock */ systemclock_reconfig(pm-》run_mode); break; case pm_sleep_mode_standby: __hal_pwr_clear_flag(pwr_flag_wu); /* enter standby mode */ hal_pwr_enterstandbymode(); break; case pm_sleep_mode_shutdown: __hal_pwr_clear_flag(pwr_flag_wu); /* enter shutdownn mode */ hal_pwrex_entershutdownmode(); break; default: rt_assert(0); break; } }
移植时间补偿接口某些情况下,我们可能需要系统在空闲时进入 stop 模式,以达到更低的降功耗效果。根据手册可知,stop 2 模式会关闭系统时钟,当前的 os tick 基于内核的 systick 定时器。那么在系统时钟停止后,os tick 也会停止,对于某些依赖 os tick 的应用,在进入 stop 2 模式,又被中断唤醒后,就会出现问题,因此需要在系统唤醒后,对 os tick 进行补偿。stop 2 模式下,绝大多数外设都停止工作,仅低功耗定时器 1(lp_tim1)和rtc,选择 lsi 作为时钟源后,仍然能正常运行,所以可以选择 lp_tim1 或者rtc 作为 stop 2 模式的时间补偿定时器。
休眠的时间补偿需要实现三个接口,分别用于启动低功耗定时器、停止定时器、唤醒后获取休眠的 tick,下面是具体的实现:
static void stm32_pm_timer_start(struct rt_pm *pm, rt_uint32_t timeout) { rt_assert(pm != rt_null); rt_assert(timeout 》 0); if (timeout != rt_tick_max) { /* convert os tick to pm timer timeout value */ timeout = stm32_pm_tick_from_os_tick(timeout); if (timeout 》 stm32_pmtim_get_tick_max()) { timeout = stm32_pmtim_get_tick_max(); } /* enter pm_timer_mode */ stm32_pmtim_start(timeout); } }
static void stm32_pm_timer_stop(struct rt_pm *pm) { rt_assert(pm != rt_null); /* reset pm timer status */ stm32_pmtim_stop(); }
static rt_tick_t stm32_pm_timer_get_tick(struct rt_pm *pm) { rt_uint32_t timer_tick; rt_assert(pm != rt_null); timer_tick = stm32_pmtim_get_current_tick(); return stm32_os_tick_from_pm_tick(timer_tick); }
休眠时间补偿的移植相对并不复杂,根据 tick 配置低功耗定时器超时,唤醒后获取实际休眠时间并转换为os tick,告知 pm 组件即可。
移植运行模式移植休眠模式仅需关注 run接口,下面是具体的实现:
void stm32_run(struct rt_pm *pm, rt_uint8_t mode) { static rt_uint32_t last_mode; static char *run_str[] = pm_run_mode_names; struct rcc_conf_struct sconf = _rcc_conf[mode]; if (mode == last_mode) return; if (stm32_run_freq[mode][0] != stm32_run_freq[last_mode][0]) { if (_rcc_conf[last_mode].low_pow_run_en && !sconf.low_pow_run_en) { /* disable the low-power run mode */ hal_pwrex_disablelowpowerrunmode(); } systemclock_msi_on(last_mode); if (mode 《 last_mode) { /* frequency increase */ hal_pwrex_controlvoltagescaling(sconf.volt_scale); _set_sysclock[mode](); } else { /* frequency reduce */ _set_sysclock[mode](); hal_pwrex_controlvoltagescaling(sconf.volt_scale); } if (sconf.volt_scale == pwr_regulator_voltage_scale2 || _osc_conf.osc_type == rcc_oscillatortype_msi) { /* configure the wake up from stop clock to msi */ __hal_rcc_wakeupstop_clk_config(rcc_stop_wakeupclock_msi); } else { /* configure the wake up from stop clock to hsi */ __hal_rcc_wakeupstop_clk_config(rcc_stop_wakeupclock_hsi); } if (sconf.low_pow_run_en) { /* enable the low-power run mode */ hal_pwrex_enablelowpowerrunmode(); } systemclock_msi_off(mode); #if defined(rt_using_serial) /* re-configure the uarts */ uart_console_reconfig(); #endif /* re-configure the systick time */ hal_systick_config(hal_rcc_gethclkfreq() / rt_tick_per_second); /* re-configure the systick */ hal_systick_clksourceconfig(systick_clksource_hclk); } last_mode = mode; rt_kprintf(“switch to %s mode, frequency = %d %shz ”, run_str[mode], stm32_run_freq[mode][0], (stm32_run_freq[mode][1] == 1) ? “m” : “k”); if ((stm32_run_freq[mode][0] / stm32_run_freq[mode][1]) 》 osc_conf_sys_freq_max) rt_kprintf(“warning: the frequency has over than %d mhz ”, osc_conf_sys_freq_max); }
自定义运行级别时钟树配置函数pm 组件驱动在给定运行频率时,已经尽量自动最优化配置时钟树,但有时外设时钟还是没有达到自己想要的频率,这时可以自己配置时钟树,在 board.c 添加以下单个或所有函数,代码可参考 systemclock_config() 函数:
rt_uint16_t stm32_run_freq[pm_run_mode_max][2] = { /* the actual frequency is 1/divisor mhz, divisor = {1, 1000} */ /* {sysclk frequency, divisor} */ {/* 配置高频运行时的时钟 */, /* 分频系数 */}, /* high speed */ {/* 配置普通运行时的时钟 */, /* 分频系数 */}, /* normal speed */ {/* 配置中低运行时的时钟 */, /* 分频系数 */}, /* medium speed */ {/* 配置低频运行时的时钟 */, /* 分频系数 */}, /* low speed, msi clock 2.0 mhz */ }; void stm32_systemclock_high(void) { /* 添加代码,配置高频运行时的时钟树 */ } void stm32_systemclock_normal(void) { /* 添加代码,配置普通速度运行时的时钟树 */ } void stm32_systemclock_medium(void) { /* 添加代码,配置中低频运行时的时钟树 */ } void stm32_systemclock_low(void) { /* 添加代码,配置低频运行时的时钟树 */ }
当低速的频率小于2mhz时,要注意以下2点:
串口波特率如果设置过高,将不能正常通信
在时钟频率很低时,要适当减小 rt_tick_per_second 值,不然由于 os_tick 过短,某些线程将不能完成任务,从而不能进入低功耗模式
初始化pm组件注意:休眠模式的时间补偿需要在初始化阶段通过设置 timer_mask 的对应模式的 bit 控制开启。例如需要开启 deep sleep 模式下的时间补偿,在实现 timer 相关的 ops 接口后,初始化时设置相应的bit:
int drv_pm_hw_init(void) { static const struct rt_pm_ops _ops = { stm32_sleep, stm32_run, stm32_pm_timer_start, stm32_pm_timer_stop, stm32_pm_timer_get_tick }; rt_uint8_t timer_mask = 0; /* enable power clock */ __hal_rcc_pwr_clk_enable(); /* initialize timer mask */ timer_mask = 1ul 《《 pm_sleep_mode_deep; /* initialize system pm module */ rt_system_pm_init(&_ops, timer_mask, rt_null); return 0; } init_board_export(drv_pm_hw_init);
void rt_system_pm_init(const struct rt_pm_ops *ops, rt_uint8_t timer_mask, void *user_data) { struct rt_device *device; struct rt_pm *pm; pm = &_pm; device = &(_pm.parent); device-》type = rt_device_class_pm; device-》rx_indicate = rt_null; device-》tx_complete = rt_null; #ifdef rt_using_device_ops device-》ops = &pm_ops; #else device-》init = rt_null; device-》open = rt_null; device-》close = rt_null; device-》read = _rt_pm_device_read; device-》write = _rt_pm_device_write; device-》control = _rt_pm_device_control; #endif device-》user_data = user_data; /* register pm device to the system */ rt_device_register(device, “pm”, rt_device_flag_rdwr); rt_memset(pm-》modes, 0, sizeof(pm-》modes)); pm-》sleep_mode = _pm_default_sleep; pm-》run_mode = rt_pm_default_run_mode; pm-》timer_mask = timer_mask; pm-》ops = ops; pm-》device_pm = rt_null; pm-》device_pm_number = 0; _pm_init_flag = 1; }
stm32l4 移植 pm
stm32l4 的低功耗模式简介:
stm32l4系列 是 st 公司推出的一款超低功耗的 crotex-m4 内核的 mcu,支持多个电源管理模式,其中最低功耗 shutdown 模式下,待机电流仅 30 na。st 公司 把 l4系列 的电管管理分为很多种,但各个模式的并非功耗逐级递减的特点,下面是各个模式之间的状态转换图:
尽管 stm32l4系列 的低功耗模式很多,但本质上并不复杂,理解它的原理有助于我们移植驱动,同时更好的在产品中选择合适的模式。最终决定 stm32l4系列 系统功耗的主要是三个因素:稳压器(voltage regulator)、cpu 工作频率、芯片自身低功耗的处理,下面分别对三个因素进行阐述。
稳压器l4 使用两个嵌入式线性稳压器为所有数字电路、待机电路以及备份时钟域供电,分别是主稳压器(main regulator,下文简称 mr)和低功耗稳压器(low-power regulator,下文简称 lpr)。稳压器在复位后处于使能状态,根据应用模式,选择不同的稳压器对 vcore 域供电。其中,mr 的输出电压可以由软件配置为不同的范围(range 1 和 rnage 2)。稳压器应用场合
稳压器应用场合
mr(range 1)vcore = 1.2v,用于运行模式、睡眠模式和停止模式0,mr 未 vcore 域提供全功率
mr(range 2)vcore = 1.0v,使用的场景同上
lpr用于低功耗运行模式、低功耗休眠模式、停止模式 1、停止模式2
offstandby 和 shutdown 模式下,mr 和 lpr 都被关闭
cpu 工作频率通过降低 cpu 的主频达到降低功耗的目的:mr 工作在 range 1 正常模式时,sysclk 最高可以工作在 80m;mr 工作在 range 2 时,sysclk 最高不能超过 26 m;低功耗运行模式和低功耗休眠模式,即 vcore 域由 lpr 供电,sysclk 必须小于 2m。
芯片本身的低功耗处理芯片本身定义了一系列的休眠模式,如 sleeep、stop、standby 和 shutdown,前面的四种模式功耗逐渐降低,实质是芯片内部通过关闭外设和时钟来实现。
配置工程
配置 pm 组件:
配置内核选项:使用 pm 组件需要更大的 idle 线程的栈,这里使用了1024 字节
在空闲线程中会调用rt_system_power_manager接口来进入低功耗模式:
/** * this function will enter corresponding power mode. */ void rt_system_power_manager(void) { rt_uint8_t mode; if (_pm_init_flag == 0) return; /* cpu frequency scaling according to the runing mode settings */ _pm_frequency_scaling(&_pm); /* low power mode processing */ mode = _pm_select_sleep_mode(&_pm); _pm_change_sleep_mode(&_pm, mode); }
保存后,可以看到pm.c已经被添加到了工程:
然后添加pm组件的设备驱动,驱动的最新地址:pm-ports-stm32-new 分支:https://gitee.com/sunwancn/rt-thread/tree/pm-ports-stm32-new注意: 目前所使用的驱动不是最新版本,移植请到gitee下载最新pm驱动。
从 t-threadspstm32librarieshal_drivers,拷贝如下四个文件到工程的drivers文件夹下:
本项目选择的是使用rtc作为stop后的时间补偿,所以需要打开rtc设备和所使用的宏:
注: 如果没有使用rtt的自身的rtc函数的话,前面2个宏可以不要。


光纤传输设备的类型
意法半导体如何打造高功率密度USB-PD充电器
Razer将于10月10日发布旗下第二款手机
国产DSP芯片厂商苏州洪芯完成千万级Pre-A轮融资
【资料干货】入门IC设计,资深芯片设计工程师带你起飞(领IC设计资料)
处理器电源管理主要实现方式是什么?
iphone8刚上市就遭冷门,iPhone6S降至白菜价也无人问津
超声波焊接的优势有哪些
未来的AI计算领域,将是CPU、GPU、IPU并行
华为手机2019全年出货量2.3亿部左右 有可能超越苹果的全年销量
iOS10.3惊喜不断漏洞也惊人,iOS11曝光革命性新特性!前有狼后有虎,iOS10.2越狱该何时发布呢?
雷军对生态链企业的期待,小米航母舰队成形
知道iPhone XS Max的成本后你还会买么?
Parametric 系列 Pyramid 探针卡的主要特征
肌肤清洁黑科技,洁面仪哪种好用
唯斯特姆垃圾处理器,一键扫清厨余垃圾烦恼
2018年上海集成电路产业销售规模已经达1450亿元 占全国的1/5
芯片组在主板的什么位置
立锜科技起诉AMD和其它四家公司侵犯专利
上海建工 X 大界智造 | 成都科幻馆双曲幕墙的快速智造