STM32L562的低功耗模式包括Sleep,Low-power run,Low-power sleep,Stop 0,Stop 1,Stop 2,Standby以及Shutdown模式
Sleep模式:在Sleep模式下,只有CPU停止。所有外围设备继续运行,并在发生中断/事件时唤醒CPU。
Low-power run模式:此模式通过低功率稳压器提供的VCORE来实现,以最小化稳压器的工作电流。该代码可以从SRAM或闪存执行,CPU频率限制为2MHz。具有独立时钟的外围设备可以由HSI16计时。
Low-power sleep模式:此模式从Low-power run运行模式进入。只有CPU时钟停止。当事件或中断触发唤醒时,系统将恢复到低功耗运行模式。
Stop 0,Stop 1,Stop 2模式:Stop模式实现了最低的功耗,同时保留了SRAM和寄存器的内容。VCORE域中的所有时钟停止,PLL、MSI RC、HSI16 RC和HSE晶体振荡器禁用。LSE或LSI仍在运行。RTC可以保持活动状态(带RTC的停止模式,不带RTC的关闭模式)。一些具有唤醒功能的外围设备可以在停止模式下启用HSI16 RC来检测其唤醒状态。有三种停止模式可供选择:Stop 0、Stop 1和Stop 2模式。在Stop 2模式下,大部分VCORE域处于较低泄漏模式。停止1提供了最多的活动外围设备和唤醒源,唤醒时间比停止2短,但消耗量更高。在Stop 0模式下,主调节器保持开启状态,允许非常快的唤醒时间,但消耗要高得多。退出Stop 0、Stop 1或Stop 2模式时的系统时钟可以是高达48 MHz的MSI或HSI16,具体取决于软件配置。
Standby模式:Standby模式用于实现BOR的最低功耗。内部稳压器关闭,VCORE域断电。PLL、MSI RC、HSI16 RC和HSE晶体振荡器也关闭。RTC可以保持活动状态(带RTC的待机模式,不带RTC的备用模式)。Brownout重置(BOR)在Standby模式下始终处于活动状态。Standby模式下每个I/O的状态可以通过软件选择:带内部上拉、内部下拉或浮动的I/O。进入待机模式后,SRAM1和寄存器内容将丢失,备份域和待机电路中的寄存器除外。可选完整的SRAM2或4KB可以在Standby模式下保留,由低功耗稳压器提供(在RAM2保留模式下待机)。BORL(低功耗探测器)可以配置为超低功耗模式,以进一步降低Standby模式下的功耗。当外部复位(NRST引脚)、IWDG复位、WKUP引脚事件(可配置上升沿或下降沿)或RTC事件发生(报警、定期唤醒、时间戳、篡改)或LSE上检测到故障(LSE上的CSS)时,设备退出Standby模式。唤醒后的系统时钟MSI高达8MHz。
Shutdown模式:Shutdown模式允许实现最低功耗。内部调节器关闭,VCORE域断电。PLL、HSI16、MSI、LSI和HSE振荡器也关闭。RTC可以保持活动状态(带RTC的关机模式,不带RTC的停机模式)。BOR在Shutdown模式下不可用。在此模式下无法进行电源电压监测,因此不支持切换到备份域。SRAM1、SRAM2和寄存器内容丢失,备份域中的寄存器除外。当发生外部重置(NRST引脚)、WKUP引脚事件(可配置的上升沿或下降沿)或RTC事件(报警、定期唤醒、时间戳、篡改)时,设备退出关机模式。唤醒后的系统时钟为4MHz的MSI。
不同功耗模式下相关外设运行状态如下
官方例程中给出了低功耗运行、睡眠、低功耗睡眠以及待机模式的代码
低功耗运行模式
可以看到通过操作相关寄存器的位实现了模式的使能和失能。
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] Enter Low-power Run mode
* [url=home.php?mod=space&uid=536309]@NOTE[/url] In Low-power Run mode, all I/O pins keep the same state as in Run mode.
* [url=home.php?mod=space&uid=536309]@NOTE[/url] When Regulator is set to PWR_LOWPOWERREGULATOR_ON, the user can optionally configure the
* Flash in power-down monde in setting the RUN_PD bit in FLASH_ACR register.
* Additionally, the clock frequency must be reduced below 2 MHz.
* Setting RUN_PD in FLASH_ACR then appropriately reducing the clock frequency must
* be done before calling HAL_PWREx_EnableLowPowerRunMode() API.
* @retval None
*/
void HAL_PWREx_EnableLowPowerRunMode(void)
{
/* Set Regulator parameter */
SET_BIT(PWR->CR1, PWR_CR1_LPR);
}
/**
* [url=home.php?mod=space&uid=247401]@brief[/url] Exit Low-power Run mode.
* @note Before HAL_PWREx_DisableLowPowerRunMode() completion, the function checks that
* REGLPF has been properly reset (otherwise, HAL_PWREx_DisableLowPowerRunMode
* returns HAL_TIMEOUT status). The system clock frequency can then be
* increased above 2 MHz.
* @retval HAL Status
*/
HAL_StatusTypeDef HAL_PWREx_DisableLowPowerRunMode(void)
{
uint32_t wait_loop_index;
/* Clear LPR bit */
CLEAR_BIT(PWR->CR1, PWR_CR1_LPR);
/* Wait until REGLPF is reset */
/* and at least one iteration loop */
wait_loop_index = ((PWR_REGLP_SETTING_DELAY_VALUE * (SystemCoreClock / 100000U)) / 10U) + 1U;
while ((HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF)) && (wait_loop_index != 0U))
{
wait_loop_index--;
}
if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF))
{
return HAL_TIMEOUT;
}
return HAL_OK;
}
睡眠和低功耗睡眠模式
二者模式的选择可以根据传参的不同实现。根据代码,可以看出睡眠模式需要从低功耗运行模式进入
/**
* @brief Enter Sleep or Low-power Sleep mode.
* @note In Sleep/Low-power Sleep mode, all I/O pins keep the same state as in Run mode.
* @param Regulator specifies the regulator state in Sleep/Low-power Sleep mode.
* This parameter can be one of the following values:
* [url=home.php?mod=space&uid=2817080]@ARG[/url] [url=home.php?mod=space&uid=144993]@ref[/url] PWR_MAINREGULATOR_ON Sleep mode (regulator in main mode)
* [url=home.php?mod=space&uid=2817080]@ARG[/url] [url=home.php?mod=space&uid=144993]@ref[/url] PWR_LOWPOWERREGULATOR_ON Low-power Sleep mode (regulator in low-power mode)
* @note Low-power Sleep mode is entered from Low-power Run mode. Therefore, if not yet
* in Low-power Run mode before calling HAL_PWR_EnterSLEEPMode() with Regulator set
* to PWR_LOWPOWERREGULATOR_ON, the user can optionally configure the
* Flash in power-down monde in setting the SLEEP_PD bit in FLASH_ACR register.
* Additionally, the clock frequency must be reduced below 2 MHz.
* Setting SLEEP_PD in FLASH_ACR then appropriately reducing the clock frequency must
* be done before calling HAL_PWR_EnterSLEEPMode() API.
* @note When exiting Low-power Sleep mode, the MCU is in Low-power Run mode. To move in
* Run mode, the user must resort to HAL_PWREx_DisableLowPowerRunMode() API.
* @param SLEEPEntry specifies if Sleep mode is entered with WFI or WFE instruction.
* This parameter can be one of the following values:
* @arg @ref PWR_SLEEPENTRY_WFI enter Sleep or Low-power Sleep mode with WFI instruction
* @arg @ref PWR_SLEEPENTRY_WFE enter Sleep or Low-power Sleep mode with WFE instruction
* @note When WFI entry is used, tick interrupt have to be disabled if not desired as
* the interrupt wake up source.
* @retval None
*/
void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
{
/* Check the parameters */
assert_param(IS_PWR_REGULATOR(Regulator));
assert_param(IS_PWR_SLEEP_ENTRY(SLEEPEntry));
/* Set Regulator parameter */
if (Regulator == PWR_MAINREGULATOR_ON)
{
/* If in low-power run mode at this point, exit it */
if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF))
{
if (HAL_PWREx_DisableLowPowerRunMode() != HAL_OK)
{
return ;
}
}
/* Regulator now in main mode. */
}
else
{
/* If in run mode, first move to low-power run mode.
The system clock frequency must be below 2 MHz at this point. */
if (HAL_IS_BIT_SET(PWR->SR2, PWR_SR2_REGLPF) == RESET)
{
HAL_PWREx_EnableLowPowerRunMode();
}
}
/* Clear SLEEPDEEP bit of Cortex System Control Register */
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
/* Select SLEEP mode entry -------------------------------------------------*/
if (SLEEPEntry == PWR_SLEEPENTRY_WFI)
{
/* Request Wait For Interrupt */
__WFI();
}
else
{
/* Request Wait For Event */
__SEV();
__WFE();
__WFE();
}
}
待机模式
/**
* @brief Enter Standby mode.
* @note In Standby mode, the PLL, the HSI, the MSI and the HSE oscillators are switched
* off. The voltage regulator is disabled, except when SRAM2 content is preserved
* in which case the regulator is in low-power mode.
* SRAM1 and register contents are lost except for registers in the Backup domain and
* Standby circuitry. SRAM2 content can be preserved if the bit RRS is set in PWR_CR3 register.
* To enable this feature, the user can resort to HAL_PWREx_EnableSRAM2ContentRetention() API
* to set RRS bit.
* The BOR is available.
* @note The I/Os can be configured either with a pull-up or pull-down or can be kept in analog state.
* HAL_PWREx_EnableGPIOPullUp() and HAL_PWREx_EnableGPIOPullDown() respectively enable Pull Up and
* Pull Down state, HAL_PWREx_DisableGPIOPullUp() and HAL_PWREx_DisableGPIOPullDown() disable the
* same.
* These states are effective in Standby mode only if APC bit is set through
* HAL_PWREx_EnablePullUpPullDownConfig() API.
* @retval None
*/
void HAL_PWR_EnterSTANDBYMode(void)
{
/* Set Stand-by mode */
MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_STANDBY);
/* Set SLEEPDEEP bit of Cortex System Control Register */
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
/* This option is used to ensure that store operations are completed */
#if defined ( __CC_ARM)
__force_stores();
#endif
/* Request Wait For Interrupt */
__WFI();
}
停止模式
/**
* @brief Enter Stop mode
* @note This API is named HAL_PWR_EnterSTOPMode to ensure compatibility with legacy code running
* on devices where only "Stop mode" is mentioned with main or low power regulator ON.
* @note In Stop mode, all I/O pins keep the same state as in Run mode.
* @note All clocks in the VCORE domain are stopped; the PLL, the MSI,
* the HSI and the HSE oscillators are disabled. Some peripherals with the wakeup capability
* (I2Cx, USARTx and LPUART) can switch on the HSI to receive a frame, and switch off the HSI
* after receiving the frame if it is not a wakeup frame. In this case, the HSI clock is propagated
* only to the peripheral requesting it.
* SRAM1, SRAM2 and register contents are preserved.
* The BOR is available.
* The voltage regulator can be configured either in normal (Stop 0) or low-power mode (Stop 1).
* @note When exiting Stop 0 or Stop 1 mode by issuing an interrupt or a wakeup event,
* the HSI RC oscillator is selected as system clock if STOPWUCK bit in RCC_CFGR register
* is set; the MSI oscillator is selected if STOPWUCK is cleared.
* @note When the voltage regulator operates in low power mode (Stop 1), an additional
* startup delay is incurred when waking up.
* By keeping the internal regulator ON during Stop mode (Stop 0), the consumption
* is higher although the startup time is reduced.
* @param Regulator specifies the regulator state in Stop mode.
* This parameter can be one of the following values:
* @arg @ref PWR_MAINREGULATOR_ON Stop 0 mode (main regulator ON)
* @arg @ref PWR_LOWPOWERREGULATOR_ON Stop 1 mode (low power regulator ON)
* @param STOPEntry specifies Stop 0 or Stop 1 mode is entered with WFI or WFE instruction.
* This parameter can be one of the following values:
* @arg @ref PWR_STOPENTRY_WFI Enter Stop 0 or Stop 1 mode with WFI instruction.
* @arg @ref PWR_STOPENTRY_WFE Enter Stop 0 or Stop 1 mode with WFE instruction.
* @retval None
*/
void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)
{
/* Check the parameters */
assert_param(IS_PWR_REGULATOR(Regulator));
if (Regulator == PWR_LOWPOWERREGULATOR_ON)
{
HAL_PWREx_EnterSTOP1Mode(STOPEntry);
}
else
{
HAL_PWREx_EnterSTOP0Mode(STOPEntry);
}
}
|