当前位置:网站首页>STM32通过串口进入和唤醒停止模式
STM32通过串口进入和唤醒停止模式
2022-07-06 16:03:00 【Kay Note】
STM32 具有运行、睡眠、停止和待机四种工作模式。上电复位后 STM32 处于运行状态,当内核不需要继续运行,就可以选择进入后面的三种低功耗模式降低功耗,这三种模式中,电源消耗不同、唤醒时间不同、唤醒源不同,我们可以根据不同的应用需求,选择最佳的低功耗模式。

睡眠模式:CM3 内核停止,外设仍然运行,此功耗是最高的。
停止模式:所有时钟都停止,此功耗较低,典型大概在20uA左右 。
待机模式:1.8V 内核电源关闭,此功耗最低,典型大概在2uA左右。
在实际的开发运用时,我们常用的低功耗模式是停止模式,唤醒方式是任一外部中断。本文主要讲的是通过串口唤醒和进入停止模式,要实现通过串口唤醒停止模式,就需要用到外部中断。把串口Rx引脚设置成外部中断,上升沿触发,这样在串口收到数据时就会触发外部中断,从而唤醒停止模式。相关代码如下
首先是配置串口接收端为外部中断:
/*************************************************
Function: void EXIT_UART_Init(void)
Description: 外部中断初始化
Calls:
Called By:
Input: 无
Output: 无
Return:
Others:
*************************************************/
void EXIT_UART_Init(void)
{
LL_EXTI_InitTypeDef EXTI_InitStruct = {0};
/* GPIO Portd Clock Enable */
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
/**/
LL_EXTI_SetEXTISource(LL_EXTI_CONFIG_PORTA, LL_EXTI_CONFIG_LINE3);
/**/
EXTI_InitStruct.Line_0_31 = LL_EXTI_LINE_3;
EXTI_InitStruct.LineCommand = ENABLE;
EXTI_InitStruct.Mode = LL_EXTI_MODE_IT;
EXTI_InitStruct.Trigger = LL_EXTI_TRIGGER_RISING;
LL_EXTI_Init(&EXTI_InitStruct);
/**/
LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_3, LL_GPIO_PULL_DOWN);
/**/
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_3, LL_GPIO_MODE_INPUT);
/* EXTI interrupt init*/
NVIC_SetPriority(EXTI2_3_IRQn, 1);
NVIC_EnableIRQ(EXTI2_3_IRQn);
}然后使能相关时钟,进入停止模式。
/*************************************************
Function: void enter_stop_mode(void)
Description: 进入停止模式
Calls:
Called By:
Input: 无
Output: 无
Return:
Others:
*************************************************/
void enter_stop_mode(void)
{
EXIT_UART_Init(); //配置串口引脚为外部中断
__HAL_RCC_PWR_CLK_ENABLE(); //使能 PER 时钟
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); //进入 stop 模式
}在低功耗模式唤醒之后,默认使用的系统时钟是HSI,所以就需要重新配置系统时钟。为了方便这里直接使用了复位系统的操作,如果在实际的项目中需要保持外部的IO口状态不变,就不能使用系统复位命令,需要重新配置系统时钟和其他外设时钟。
/*
************************************************************
* 函数名称: void exit_stop_mode(void)
*
* 函数功能: 系统复位
*
* 入口参数: 无
*
* 返回参数: 无
*
* 说明:
************************************************************
*/
void exit_stop_mode(void)
{
__set_FAULTMASK(1); //关闭所有中断
NVIC_SystemReset();
}边栏推荐
- CRMEB 商城系统如何助力营销?
- Should the jar package of MySQL CDC be placed in different places in the Flink running mode?
- Face recognition class attendance system based on paddlepaddle platform (easydl)
- 短链的设计
- 亚朵三顾 IPO
- The worse the AI performance, the higher the bonus? Doctor of New York University offered a reward for the task of making the big model perform poorly
- 云原生(三十二) | Kubernetes篇之平台存储系统介绍
- 让 Rust 库更优美的几个建议!你学会了吗?
- 英国都在试行4天工作制了,为什么BAT还对996上瘾?
- What can be done for traffic safety?
猜你喜欢

服务器SMP、NUMA、MPP体系学习笔记。

Koa2 addition, deletion, modification and query of JSON array

(1)长安链学习笔记-启动长安链

今日睡眠质量记录78分
![[communication] optimal power allocation in the uplink of two-layer wireless femtocell network with matlab code](/img/47/741b89d94a2b0003937f32bdedfa19.png)
[communication] optimal power allocation in the uplink of two-layer wireless femtocell network with matlab code

人均瑞数系列,瑞数 4 代 JS 逆向分析

JS addition, deletion, modification and query of JSON array

Station B boss used my world to create convolutional neural network, Lecun forwarding! Burst the liver for 6 months, playing more than one million

MySQL connected vscode successfully, but this error is reported

Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
随机推荐
英国都在试行4天工作制了,为什么BAT还对996上瘾?
PDF批量拆分、合并、书签提取、书签写入小工具
《数字经济全景白皮书》保险数字化篇 重磅发布
Wasserstein slim gain with gradient poverty (wsgain-gp) introduction and code implementation -- missing data filling based on generated countermeasure network
Cloud native (32) | kubernetes introduction to platform storage system
Can online reload system software be used safely? Test use experience to share with you
I've been laid off, and I'll lose money for everything. The days when I once made a monthly salary of 20000 are not coming back
达晨史上最大单笔投资,今天IPO了
js對JSON數組的增删改查
CRMEB 商城系统如何助力营销?
让 Rust 库更优美的几个建议!你学会了吗?
B站大佬用我的世界搞出卷积神经网络,LeCun转发!爆肝6个月,播放破百万
Where does this "judge the operation type according to the op value and assemble SQL by yourself" mean? It means simply using Flink tab
Example code of MySQL split string as query condition
人均瑞数系列,瑞数 4 代 JS 逆向分析
机器人材料整理中的套-假-大-空话
Today, I met a senior test developer from Tencent and saw the ceiling of the foundation
借助这个宝藏神器,我成为全栈了
Station B Big utilise mon monde pour faire un réseau neuronal convolutif, Le Cun Forward! Le foie a explosé pendant 6 mois, et un million de fois.
The important data in the computer was accidentally deleted by mistake, which can be quickly retrieved by this method