当前位置:网站首页>[Bi design teaching] STM32 and FreeRTOS realize low power consumption
[Bi design teaching] STM32 and FreeRTOS realize low power consumption
2022-07-28 12:55:00 【Mdc_ stdio】
Record
In the development process , Encounter such a product , It's based on Cortex-M7 Kernel STM32F769 chip , At the same time FreeRTOS Real-time operating system .
Because the product uses battery power , Therefore, there is a demand for low power consumption .
Next , The senior student will briefly describe STM32 And FreeRTOS Their low power consumption characteristics , And how to realize the low power consumption of the product when used together .
One 、STM32F769 Three low power consumption modes of the chip
STM32F769 Support three low power consumption modes , They are :SLEEP、STOP and STANDBY, Its power saving capacity is enhanced in turn .
SLEEP
stay SLEEP In mode , Only Cortex-M7 The kernel stopped working , The peripherals are still running .
When entering SLEEP After the model , All interrupts wake up MCU, So as to exit SLEEP Pattern .
STOP
stay STOP In mode , The kernel stops working , And all the clocks ( Such as HCLK, PCLK1, PCLK2 etc. ) And stop working , That is, all peripherals stop working , Here's one thing to pay special attention to , here SYSTICK Will also be stopped . Of course , In our products RTC It's still running , Because its clock source is external 32.768K Crystal oscillator .
When entering STOP After the model , Only external interrupts (EXTI) To wake up MCU( because RTC The interrupt is hung on the external interrupt line , therefore RTC Interruptions can also wake up MCU).
STANDBY
stay STANDBY In mode , kernel 、 All the clocks 、 And backup 1.2V The power supply stops working .
from STANDBY Wake up in mode , The system is equivalent to performing a reset operation , The program will start over .
in summary , Obviously , stay STM32 Of the three low-power modes provided , We can only use one of them SLEEP and STOP These two kinds of ,STANDBY Do not apply .
About STM32769 More detailed introduction to low power consumption , Please check out Reference Manual Of 4.3 section – Low-power modes.
Two 、FreeRTOS Low power implementation [2]
When starting the task scheduler ,FreeRTOS Will create a IDLE Mission , Its task priority is the lowest , If and only if all other tasks are blocked ,IDLE The task will get CPU Right to use .
therefore , It's easy to think of in IDLE To achieve entry and exit in the task STM32F769 Low power consumption mode , That is, cutting into IDLE After the task , Give Way STM32 Also enter low power mode , And I'm about to switch out IDLE Before the mission , To wake up STM32.
in addition , Newer versions of FreeRTOS in , Added Tickless mode, For a more detailed introduction, please refer to the references [2].
3、 ... and 、 The low-power realization of the whole product
So in IDLE In the mission , How to determine the current STM32 It should be entering SLEEP still STOP How about the model ?
in consideration of SLEEP and STOP The difference between the two , namely SLEEP Any interrupt can wake up STM32, And in the STOP Next , Can only be awakened by an external interrupt , therefore , Our product adopts the following mechanism :
For a certain period of time in the future , If the programmer knows that a non external interrupt will occur during this period , At this time , You can't let STM32 Get into STOP Pattern . because , Once in STOP,STM32 You can only respond to external interrupts , Not for non external interrupts ( Such as serial port 、I2C Wait for the peripheral to interrupt ) A response .
For example, it would be easier to understand . Suppose such a scenario —— Read by interrupt I2C data . After the programmer configures I2C After reading data interrupt , The system is waiting I2C The state of interruption . Then if there is I2C interrupt , It means that the data has been read , The programmer can then process the data .
Take the one above , The configured I2C After reading data interrupt , If at this time IDLE The task is carried out , that , In this case, you can't let STM32 Get into STOP Pattern , And can only enter SLEEP Pattern . Once it happens I2C interrupt , be STM32 It will start from SLEEP To be awakened . And if before STM32 Into the STOP Pattern , So this I2C The interruption will be omitted .
therefore , In this product , We provide two interfaces ,disable_enter_stop_mode and enable_enter_stop_mode, Used separately to inform , Cannot enter... At present STOP Mode and current can enter STOP The model .
Sort it out , We can get the following flow chart :

If you can enter STOP Pattern , Before really entering STOP Before , There is one more thing to do —— To configure RTC Wake up timer , Let it wake up at some point STM32. It can be found in STOP How long do you sleep in mode , from FreeRTOS Medium prvGetExpectedIdleTime Interface calculation results .
RTC After the wake-up timer is configured , You can call HAL_PWR_EnterSTOPMode Give Way STM32 Get into STOP The model . If there is no interruption at this time, it is in PENDING state , be STM32 Will enter immediately STOP Pattern , If there is an interrupt at this time, it is in PENDING state , be STM32 Will not enter the STOP Pattern , The code continues to execute .
stay STM32 be in STOP Mode period , If any external interrupt is generated (EXTI interrupt ), be STM32 Will be awakened immediately , No matter RTC Whether the wake-up timer has timed out . If there has been no external interruption during , that STM32 Will always be in STOP Pattern , until RTC Wake up timer timed out , So that STM32 Wake up the .
in addition , Because in STOP Next , by FreeRTOS Provides a heartbeat clock SYSTICK Also stopped working , therefore , After being awakened , Also need to be in STOP Tell me about the passing time FreeRTOS.
All in all , The basic idea of reducing the power consumption of the whole product , Is to make FreeRTOS Only as much time as possible in IDLE Mission , Give Way STM32 Spend as much time as possible in STOP Pattern , Finally, the purpose of reducing power consumption as much as possible .
Last
边栏推荐
- Redis implements distributed locks
- Leetcode394 string decoding
- Unity加载Glb模型
- 1331. Array sequence number conversion: simple simulation question
- 试用copilot过程中问题解决
- Problem solving during copilot trial
- 第九章 REST 服务安全
- Chapter IX rest Service Security
- Library automatic reservation script
- What if the win11 folder cannot be opened
猜你喜欢

Science 重磅:AI设计蛋白质再获突破,可设计特定功能性蛋白质

Markdown concise grammar manual

非标自动化设备企业如何借助ERP系统,做好产品质量管理?

Leetcode94. Middle order traversal of binary trees

Machine learning practice - integrated learning-23

GMT installation and use

Uncover why devaxpress WinForms, an interface control, discards the popular maskbox property

VS1003调试例程

Connected Block & food chain - (summary of parallel search set)

04 pyechars 地理图表(示例代码+效果图)
随机推荐
力扣315计算右侧小于当前元素的个数
New progress in the implementation of the industry | the openatom openharmony sub forum of the 2022 open atom global open source summit was successfully held
Unity加载Glb模型
Which big model is better? Openbmb releases bmlist to give you the answer!
JSP自定义标签之自定义分页标签02
C# 泛型是什么、泛型缓存、泛型约束
利用依赖包直接实现分页、SQL语句
连通块&&食物链——(并查集小结)
04 pyechars 地理图表(示例代码+效果图)
云原生—运行时环境
[half understood] zero value copy
Leetcode remove element & move zero
leetcode:数组
STM32 loopback structure receives and processes serial port data
leetcode:704二分查找
Uniapp 应用开机自启插件 Ba-Autoboot
The openatom openharmony sub forum was successfully held, and ecological and industrial development entered a new journey
Sliding Window
Jinshanyun rushes to the dual main listing of Hong Kong stocks: the annual revenue of 9billion is a project supported by Lei Jun
Science 重磅:AI设计蛋白质再获突破,可设计特定功能性蛋白质