当前位置:网站首页>STM32 enters and wakes up the stop mode through the serial port
STM32 enters and wakes up the stop mode through the serial port
2022-07-06 23:42:00 【Kay Note】
STM32 Have run 、 sleep 、 Stop and standby four working modes . After power on reset STM32 In operation , When the kernel doesn't need to continue running , You can choose to enter the following three low-power modes to reduce power consumption , Of the three models , Different power consumption 、 Wake up time is different 、 Different wake-up sources , We can according to different application requirements , Choose the best low-power mode .
Sleep mode :CM3 Kernel stop , The peripheral is still running , This power consumption is the highest .
Stop mode : All clocks stop , This power consumption is low , Typical is probably 20uA about .
Standby mode :1.8V Kernel power off , This power consumption is the lowest , Typical is probably 2uA about .
In the actual development and Application , Our commonly used low-power mode is stop mode , The wake-up mode is any external interrupt . This article mainly talks about waking up and entering the stop mode through the serial port , To realize the wake-up stop mode through the serial port , External interrupts are needed . Put the serial port Rx The pin is set to external interrupt , Rising edge trigger , In this way, the external interrupt will be triggered when the serial port receives data , This wakes up the stop mode . The relevant code is as follows
First, configure the serial port receiving end as an external interrupt :
/*************************************************
Function: void EXIT_UART_Init(void)
Description: External interrupt initialization
Calls:
Called By:
Input: nothing
Output: nothing
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);
}
Then enable the relevant clock , Enter stop mode .
/*************************************************
Function: void enter_stop_mode(void)
Description: Enter stop mode
Calls:
Called By:
Input: nothing
Output: nothing
Return:
Others:
*************************************************/
void enter_stop_mode(void)
{
EXIT_UART_Init(); // Configure the serial port pin as an external interrupt
__HAL_RCC_PWR_CLK_ENABLE(); // Can make PER The clock
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); // Get into stop Pattern
}
After wakeup in low power mode , The default system clock is HSI, So you need to reconfigure the system clock . For convenience, the operation of the reset system is directly used here , If you need to keep external in the actual project IO Port state unchanged , You cannot use the system reset command , You need to reconfigure the system clock and other peripheral clocks .
/*
************************************************************
* The name of the function : void exit_stop_mode(void)
*
* The functionality : System reset
*
* Entrance parameters : nothing
*
* Returns the parameter : nothing
*
* explain :
************************************************************
*/
void exit_stop_mode(void)
{
__set_FAULTMASK(1); // Turn off all interrupts
NVIC_SystemReset();
}
边栏推荐
- Eureka Client启动后就关闭 Unregistering application xxx with eureka with status DOWN
- Server SMP, NUMA, MPP system learning notes.
- 士大夫哈哈哈
- Microsoft win11 is still "unsatisfactory". Multi user feedback will cause frequent MSI crashes
- 不要再说微服务可以解决一切问题了
- 使用MitmProxy离线缓存360度全景网页
- [212] what are three methods for PHP to send post requests
- JS import excel & Export Excel
- 【系统分析师之路】第七章 复盘系统设计(面向服务开发方法)
- B 站弹幕 protobuf 协议还原分析
猜你喜欢
Entropy information entropy cross entropy
Can online reload system software be used safely? Test use experience to share with you
零代码高回报,如何用40套模板,能满足工作中95%的报表需求
11 preparations for Web3 and Decentralization for traditional enterprises
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
Detailed explanation of regular expression (regexp) in MySQL
leetcode:236. 二叉树的最近公共祖先
Docker starts MySQL and -emysql_ ROOT_ Password = my secret PW problem solving
内网穿透zerotier 外网(手机、电脑等)访问内网设备(树莓派、NAS、电脑等)
(1) Chang'an chain learning notes - start Chang'an chain
随机推荐
士大夫哈哈哈
B站大佬用我的世界搞出卷積神經網絡,LeCun轉發!爆肝6個月,播放破百萬
借助这个宝藏神器,我成为全栈了
After 3 years of testing bytecan software, I was ruthlessly dismissed in February, trying to wake up my brother who was paddling
One minute to learn how to install the system, win7 XP, win10 and win11 become very simple
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
短链的设计
leetcode:236. 二叉树的最近公共祖先
自动更新Selenium驱动chromedriver
Leetcode problem solving - 889 Construct binary tree according to preorder and postorder traversal
【OFDM通信】基于深度学习的OFDM系统信号检测附matlab代码
Is the more additives in food, the less safe it is?
快讯 l Huobi Ventures与Genesis公链深入接洽中
内网穿透zerotier 外网(手机、电脑等)访问内网设备(树莓派、NAS、电脑等)
flinksql select id ,count(*) from a group by id .
食品里的添加剂品种越多,越不安全吗?
Huawei cloud gaussdb (for redis) unveils issue 21: using Gauss redis to achieve secondary indexing
Master binary tree in one article
docker mysql5.7如何设置不区分大小写
Spark Tuning (II): UDF reduces joins and judgments