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外設時鐘
三種低功耗模式對比
官網參考資料
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
上一篇:Stm32待機模式的進入與喚醒
下一篇:STM32之低功耗——WKUP待機喚醒(LCD顯示)
推薦閱讀
史海拾趣
Alpha Wire公司是一家在電子行業中知名的制造商,專注于生產高性能電線、電纜和線束。雖然我無法提供準確的發展故事,但我可以向你介紹一些關于Alpha Wire公司的背景和其在行業中的重要性。
公司成立:Alpha Wire公司成立于1922年,總部位于美國新澤西州。創始人是一位名叫韋爾納·布雷德的工程師,他創立了Alpha Wire公司,旨在為不同領域的電子設備提供高質量的電線和電纜。
技術創新:Alpha Wire公司在其發展歷程中一直致力于技術創新和產品質量的提升。公司不斷投資于研發,并采用最新的材料和生產工藝,以確保其產品在性能和可靠性方面處于行業領先地位。
產品線擴展:隨著時間的推移,Alpha Wire公司不斷擴展其產品線,以滿足不斷變化的市場需求。除了標準的電線和電纜產品外,公司還開發了各種特種電線和線束,如耐高溫、耐化學腐蝕、防火等特性的產品,以滿足不同行業和應用的需求。
全球市場拓展:Alpha Wire公司在其發展過程中不斷拓展其市場份額,通過建立全球分銷網絡和合作伙伴關系,將其產品銷往世界各地。公司不僅在北美市場占據重要地位,還在歐洲、亞洲和其他地區建立了業務和生產基地,以更好地服務全球客戶。
質量和可靠性:作為一家具有悠久歷史的公司,Alpha Wire始終將質量和可靠性視為其產品的核心競爭力。公司嚴格遵循國際標準和質量管理體系,對原材料進行嚴格篩選和檢驗,并采用先進的生產工藝和嚴格的質量控制程序,以確保產品的穩定性和一致性。
以上是關于Alpha Wire公司的一些基本信息,雖然我無法提供具體的發展故事,但希望這些信息能夠幫助你了解該公司在電子行業中的重要性和影響力。
隨著產品性能的不斷提升和市場需求的持續增長,Crocus開始積極拓展市場。公司加強與全球知名企業的合作,共同推動TMR傳感器技術在各個領域的應用。同時,Crocus還注重品牌建設,通過參加國際電子展覽、發布技術論文等方式提升品牌知名度和影響力。
在全球電子行業遭遇供應鏈危機時,CBM_America_Corporation面臨著巨大的挑戰。公司的原材料采購受到影響,生產成本大幅上升。為了應對這一危機,CBM積極調整采購策略,尋找新的供應商和合作伙伴。同時,公司還加大了研發投入,開發出了更加環保、節能的產品,以適應市場需求的變化。通過一系列措施的實施,CBM成功度過了危機,并保持了穩定的發展態勢。
隨著EPC公司在氮化鎵技術領域的領先地位日益穩固,一些競爭對手開始試圖通過不正當手段獲取其技術。為了維護自身的合法權益,EPC公司積極尋求法律途徑來保護其專利。2023年,EPC公司向美國聯邦法院和美國國際貿易委員會提起訴訟,指控英諾賽科(珠海)科技有限公司及其子公司侵犯了其基礎專利組合中的四項專利。這一訴訟引起了行業的廣泛關注,也再次證明了EPC公司對專利保護的重視。
憑借卓越的產品質量和良好的市場口碑,茂達電子在國內電源模擬IC設計領域的地位逐漸提升。公司不僅在國內市場取得了顯著的成績,還積極拓展海外市場,與眾多國際知名企業建立了穩定的合作關系。茂達電子的產品廣泛應用于計算機、通信和消費者等領域,為全球客戶提供了高質量的電源解決方案。
隨著技術的不斷發展,茂達電子在產品研發上不斷取得突破。公司投入大量人力、物力進行技術研發,并與多家國內外著名大學和研究機構合作,共同推進模擬集成電路設計的創新。經過不懈的努力,茂達電子成功推出了一系列世界領先的半導體器件產品,贏得了市場的廣泛認可。
今天的電子電路(比如手機、服務器等領域)的切換速度、信號擺率比以前更高,同時芯片的封裝和信號擺幅卻越來越小,對噪聲更加敏感。因此,今天的電路設計者們比以前會更關心電源噪聲的影響。實時示波器是用來進行電源噪聲測量的一種常用工具,但是 ...… 查看全部問答∨ |
|
各位大人~~~~ 最近用C#在WinCE5.0系統下開發一個簡單的小游戲,有網絡連接功能(能兩個人一個玩,像QQ的找茬一樣),使用TCP/IP傳輸協議。實驗箱是博創的UP-NETARM2410-s。現在遇到一個很大的問題,就是用網 ...… 查看全部問答∨ |
|
wince新手:build新建項目出錯啦:Command returned non-zero exit code 1 (dec),跪求答案 build run-time image時出現錯誤.請大蝦指教。從網上看到在項目->屬性->配置屬性->Build Option->Run-time image can be larger than 32MB(IMGRAM64=1)復選框給選中了,還是不行。 我用的是vs2005+windows embbeded 6.0… 查看全部問答∨ |
|
本文大概就是講講散熱設計,并列舉在自然條件及強制通風條件制冷環境下溫度上升計算的范例。 看起來很厲害,小編也不太懂的。還有DC寄生現象等等等。 大家下來看看咯。。。 好羨慕大家都能看懂。。。… 查看全部問答∨ |
|
Error[e27]: Entry \"Delay5ms\" in module play ( F:\\工程\\Debug\\Obj\\play.r43 ) redefined in module playmain ( F:\\工程\\Debug\\Obj\\playmain.r43 ) 具體是我的play.c中有void Delay5ms(void),然后我的playmain.c里有 ...… 查看全部問答∨ |