历史上的今天
返回首页

历史上的今天

今天是:2025年03月29日(星期六)

2019年03月29日 | USART从低功耗模式唤醒STM32F0

2019-03-29 来源:eefocus

STM32F0的低功耗模式

详细内容见参考手册—Power control (PWR)


在STM32应用中,为了降低功耗共有以下三种工作模式:


Sleep mode 

CPU clock off, all peripherals including ARM® Cortex®-M0 core peripherals like NVIC, SysTick, etc. are kept running.. 

In Sleep mode, only the CPU is stopped. All peripherals continue to operate and can wake up the CPU when an interrupt/event occurs.

Stop mode 

all clocks are stopped 

(Stop mode achieves very low power consumption while retaining the content of SRAM and registers. All clocks in the 1.8 V domain are stopped, the PLL, the HSI RC and the HSE crystal oscillators are disabled. The voltage regulator can also be put either in normal or in low power mode. 

The device can be woken up from Stop mode by any of the EXTI lines. The EXTI line source can be one of the 16 external lines and RTC.)

Standby mode 

1.8V domain powered-off 

The Standby mode is used to achieve the lowest power consumption. The internal 

voltage regulator is switched off so that the entire 1.8 V domain is powered off. The 

PLL, the HSI RC and the HSE crystal oscillators are also switched off. After entering Standby mode, SRAM and register contents are lost except for registers in the RTC domain and Standby circuitry. 

The device exits Standby mode when an external reset (NRST pin), an IWDG reset, a rising edge on the WKUP pins, or an RTC event occurs.

备注: 

The RTC, the IWDG, and the corresponding clock sources are not stopped by entering Stop or Standby mode.


另外,在正常工作模式(Run mode)下,可以通过以下方法有效降低功耗:


降低系统时钟(system clocks)


关闭不需要的APB和AHB外设时钟


三种低功耗模式对比 


Low-power mode summary


官网参考资料

STM32F0-参考手册–>6 Power control (PWR) 

RM0360 Reference manual STM32F030x4/x6/x8/xC and STM32F070x6/xB 

STM32F0-数据手册–>3.5 Power management 

DS9773 STM32F030x4 STM32F030x6 STM32F030x8 

STM32F0-编程手册–>2.5 Power management 

PM0215 STM32F0xxx单片机编程手册 

STM32F0-应用笔记 

如何使用USART或LPUART从低功耗模式唤醒STM32F0 / F3 / L0 / L4微控制器


官方参考代码

应用平台:STM32F030


main.c


#include "stm32f0xx.h"

/* Private variables ---------------------------------------------------------*/

uint8_t DataReceived = 0;

extern __IO uint8_t InterruptCounter;

/* Private function prototypes -----------------------------------------------*/

static void USART_Config(void);

static void WakeUp_StartBitMethod(void);

static void RestoreConfiguration(void);


/**

  * @brief   Main program

  * @param  None

  * @retval None

  */

int main(void)

{    

  /* Initialize LEDs available  ***********************************************/

  STM_EVAL_LEDInit(LED);


  /* USART configuration */

  USART_Config();


  /* Wake up from USART STOP mode by Start bit Method */

  WakeUp_StartBitMethod();


  /* Configure SystemClock*/

  RestoreConfiguration();


  /* Configure and enable the systick timer to generate an interrupt each 1 ms */

  SysTick_Config((SystemCoreClock / 1000));


  while (1)

  {}

}


/**

  * @brief  Start Bit Method to Wake Up USART from Stop mode Test.

  * @param  None

  * @retval None

  */

static void WakeUp_StartBitMethod(void)

  /* Configure the wake up Method = Start bit */ 

  USART_StopModeWakeUpSourceConfig(USART1, USART_WakeUpSource_StartBit);


  /* Enable USART1 */ 

  USART_Cmd(USART1, ENABLE);


  /* Before entering the USART in STOP mode the REACK flag must be checked to ensure the USART RX is ready */

  while(USART_GetFlagStatus(USART1, USART_FLAG_REACK) == RESET)

  {}


  /* Enable USART STOP mode by setting the UESM bit in the CR1 register.*/

  USART_STOPModeCmd(USART1, ENABLE);


  /* Enable the wake up from stop Interrupt */ 

  USART_ITConfig(USART1, USART_IT_WU, ENABLE);   


  /* Enable PWR APB clock */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);


  /* Enter USART in STOP mode with regulator in low power mode */

  PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);


  /* Waiting Wake Up interrupt */

  while(InterruptCounter == 0x00)

  {}


  /* Disable USART peripheral in STOP mode */ 

  USART_STOPModeCmd(USART1, DISABLE);


  while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET)

  {}

  DataReceived = USART_ReceiveData(USART1);


  /* Clear the TE bit (if a transmission is on going or a data is in the TDR, it will be sent before efectivelly disabling the transmission) */

  USART_DirectionModeCmd(USART1, USART_Mode_Tx, DISABLE);


  /* Check the Transfer Complete Flag */

  while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)

  {}


  /* USART Disable */

  USART_Cmd(USART1, DISABLE);

}


/**

  * @brief Configure the USART Device

  * @param  None

  * @retval None

  */

static void USART_Config(void)

  USART_InitTypeDef USART_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure; 

  NVIC_InitTypeDef NVIC_InitStructure;


  /* Enable GPIO&USART clock */

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA , ENABLE);  

  RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);


  /* Configure the HSI as USART clock */

  RCC_USARTCLKConfig(RCC_USART2CLK_HSI);


  /* USARTx Pins configuration **************************************************/  

  /* Connect pin to Periph */

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);    

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1); 


  /* Configure pins as AF pushpull */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_Init(GPIOA, &GPIO_InitStructure); 


  /* USARTx configured as follow:

  - BaudRate = 115200 baud  

  - Word Length = 8 Bits

  - Stop Bit = 1 Stop Bit

  - Parity = No Parity

  - Hardware flow control disabled (RTS and CTS signals)

  - Receive and transmit enabled

  */


  USART_DeInit(USART1);

  USART_InitStructure.USART_BaudRate = 115200;

  USART_InitStructure.USART_WordLength = USART_WordLength_8b;

  USART_InitStructure.USART_StopBits = USART_StopBits_1;

  USART_InitStructure.USART_Parity = USART_Parity_No;

  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  USART_Init(USART1, &USART_InitStructure);


  /* USART2 IRQ Channel configuration */

  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

}


/**

  * @brief  Restore peripheral config before entering STOP mode.

  * @param  None

  * @retval None

  */

static void RestoreConfiguration(void)

{

  __IO uint32_t StartUpCounter = 0, HSEStatus = 0;


  /* SYSCLK, HCLK, PCLK configuration ----------------------------------------*/    

  /* Enable HSE */    

  RCC_HSEConfig(RCC_HSE_ON);


  /* Wait till HSE is ready and if Time out is reached exit */

  HSEStatus = RCC_WaitForHSEStartUp();


  if (HSEStatus == (uint32_t)0x01)

  {

    /* Enable Prefetch Buffer */

    FLASH_SetLatency(FLASH_Latency_1);


    /* HCLK = SYSCLK */

    RCC_HCLKConfig(RCC_SYSCLK_Div1); 


    /* PCLK = HCLK */

    RCC_PCLKConfig(RCC_HCLK_Div1);


    /*  PLL configuration:  = HSE *  6 = 48 MHz */

    RCC_PREDIV1Config(RCC_PREDIV1_Div1);

    RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_CFGR_PLLMULL6);


    /* Enable PLL */

    RCC_PLLCmd(ENABLE);


    /* PLL as system clock source */

    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

  } 

}


stm32f0xx_it.c


/* Includes ------------------------------------------------------------------*/

#include "stm32f0xx_it.h"

/* Private variables ---------------------------------------------------------*/

__IO uint8_t InterruptCounter = 0x00;

__IO uint8_t Counter = 0;


/**

  * @brief  This function handles SysTick Handler.

  * @param  None

  * @retval None

  */

void SysTick_Handler(void)

{  

  if (Counter == 20)

  {

    /* Toggle LED's */

    STM_EVAL_LEDToggle(LED);


    /* Reset Counter */

    Counter = 0;

  }

  else

  {

    /* increment Counter */

    Counter++; 

  }

}


/**

* @brief  This function handles USART interrupt request.

* @param  None

* @retval None

*/

void USART1_IRQHandler(void)

{

  if (USART_GetITStatus(USART1, USART_IT_WU) == SET)

  { 

    /* Clear The USART WU flag */  

    USART_ClearITPendingBit(USART1, USART_IT_WU);

    InterruptCounter = 0x01;

  }

}


实际参考代码

然而,在STM32F030中不能配置为USART的start位唤醒。


#define USART_IT_WU ((uint32_t)0x00140316) /*!< Not available for STM32F030 devices */


解决办法,配置USART的接收非空中断:USART_IT_RXNE 


这里写图片描述

推荐阅读

史海拾趣

常忆科技(CHINGIS)公司的发展小趣事

为了满足不断增长的市场需求,常忆科技积极拓展国内外市场。公司通过与全球知名的电子产品制造商建立合作关系,成功将产品打入国际市场。同时,常忆科技还积极参加各类国际电子展会和技术交流活动,展示其最新的技术和产品,吸引了众多国际客户的关注。

随着国际化战略的深入实施,常忆科技的产品逐渐在全球范围内得到应用。这不仅提升了公司的品牌知名度和影响力,也为公司带来了丰厚的经济回报。

HSMC公司的发展小趣事

HSMC的发展不仅为公司自身带来了显著的经济效益,也为当地社会和经济发展做出了重要贡献。项目全面达产后,预计可实现年产值600亿元,利税60亿元,直接带动就业人口3000人。此外,HSMC还通过技术创新和产业升级,带动了上下游产业链的发展,促进了整个电子行业的繁荣与进步。

以上五个故事共同描绘了HSMC在电子行业中的崛起与发展历程。作为一家充满活力和创新精神的企业,HSMC正以其独特的优势和不懈的努力,向着成为全球领先CIDM晶圆厂的目标不断迈进。

EPIGAP公司的发展小趣事

为了进一步扩大市场份额,EPIGAP公司开始实施国际化战略。公司先后在多个国家和地区设立了办事处和研发中心,以便更好地了解当地市场需求和技术发展趋势。通过与国际客户的深入合作,EPIGAP公司的产品逐渐打入国际市场,赢得了广泛的认可和赞誉。

GSME Electronics公司的发展小趣事

GSME Electronics的起点可以追溯到2001年,当时公司在广西桂林市成立,作为桂林国家高新区的高新技术企业。初期,公司面临着技术设备落后的挑战,但管理层高瞻远瞩,决定从日本、韩国、欧美等国家引进具有国际先进水平的自动化生产设备。这一决策为公司后续的发展奠定了坚实的基础,使得公司能够快速进入半导体器件的生产领域,并不断提升产品质量和生产效率。

CANOPUS公司的发展小趣事

CANOPUS公司最初由创始人Shinichi Usuda于1977年创立,当时他经营着一家乐器商店。他深知音乐的力量和乐器的重要性,于是决定将自己的商店逐渐转型为专注于鼓类乐器的制造与销售。经过几年的努力,CANOPUS逐渐在乐器市场上崭露头角,赢得了音乐爱好者的青睐。

Concord Semiconductor Corp公司的发展小趣事

Concord Semiconductor Corp自创立之初,便专注于半导体技术的研发与创新。公司在早期阶段成功开发出一种高效能、低功耗的半导体芯片,这一创新成果迅速在行业内引起关注。随着技术的不断完善和市场的广泛认可,公司的产品线逐渐丰富,客户群体也不断扩大。技术创新成为Concord Semiconductor Corp发展的核心驱动力,推动公司不断向前发展。

问答坊 | AI 解惑

晒板子28335

28335电力电子与电力传动专用控制板 …

查看全部问答>

机电领域中伺服电机的选择原则

提出的选择原则是将电机特性与负载特性分离开 ,并用图解的形式表示 ,这种表示方法使得驱动 装置的可行性检查和不同系统间的比较更方便 ,另外 ,还提供了传动比的一个可能范围.…

查看全部问答>

获取芯币的另一个小诀窍

快速获得芯币的另一种方法,就是与博客紧密结合。规则如下,请大家详细阅读啊! 1、注册博客 + 20 芯币 2、在论坛签名中注明自己博客地址  +5 芯币    3、博客个人信息注册完全,其中上传电子相片  +5芯币 4、 ...…

查看全部问答>

一本dsp2812的好书

最近刚刚从图书馆借到一本新书《dsp控制技术实践》。中国电力出版社出版,2009.5出版的。专门讨论dsp2812的片子的使用,比ti的中文手册薄多了,看起来挺舒服的。推荐给大家。…

查看全部问答>

LED行业竞争白热化,各大厂商拿什么取胜呢?打扰了。

LED行业竞争白热化,各大厂商拿什么取胜呢?打扰了。…

查看全部问答>

请问这几句汇编具体的意思是什么?

GBLS        MainEntry MainEntry        SETS        \"Main\"         IMPORT        $MainEntry MainEntry不是已经在第一行就已经定 ...…

查看全部问答>

MC2833/MC3363如何编程

这是朋友的一个毕业设计题目。别的部分没什么特别。但是,这个课题使用了MC2822/MC3363这一对摩托罗拉的音频收发芯片来实现无线收发。我的毕业设计用的是nRF24L01,所以我很习惯性用这个去套它的思路。可是我在网上查了查,似乎没有找到关于它的编程 ...…

查看全部问答>

关于QEI的问题

最近正在学习luminary,用的是周立功的easyArm8962的板子,在qei的实验例程中有这么两句话:SysCtlPeripheralEnable(SYSCTL_PERIPH_QEI);GPIODirModeSet(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_6,   GPIO_DIR_MODE_HW);GPIODirModeSet( ...…

查看全部问答>

Smart Debug网络与串口调试工具(原创)

最新版本号: 1.0.1.111031        更新日期: 2011.10.26 下载地址1 http://stu.cidp.edu.cn/SmartDebug.rar 下载地址1 下载地址2 http://www.vdisk.cn/down/index/8990713A3710 下 ...…

查看全部问答>

希望大家帮帮忙

不好意思 有件事情麻烦大家 老师布置了一项作业之前设计原理图时没看要求 搞错了 现在时间有点急希望大家有能人帮我设计一个原理图 要求如下: 九、彩灯控制器一 要求:1.有八只LED,L0……L72.显示顺序如下表3.显示间隔为0.25S,0.5S,1S,2S ...…

查看全部问答>