RA Flexible Software Package Documentation  Release v5.2.0

 
Low Power Modes (r_lpm)

Functions

fsp_err_t R_LPM_Open (lpm_ctrl_t *const p_api_ctrl, lpm_cfg_t const *const p_cfg)
 
fsp_err_t R_LPM_LowPowerReconfigure (lpm_ctrl_t *const p_api_ctrl, lpm_cfg_t const *const p_cfg)
 
fsp_err_t R_LPM_LowPowerModeEnter (lpm_ctrl_t *const p_api_ctrl)
 
fsp_err_t R_LPM_IoKeepClear (lpm_ctrl_t *const p_api_ctrl)
 
fsp_err_t R_LPM_Close (lpm_ctrl_t *const p_api_ctrl)
 

Detailed Description

Driver for the LPM peripheral on RA MCUs. This module implements the Low Power Modes Interface.

Overview

The low power modes driver is used to configure and place the device into the desired low power mode. Various sources can be configured to wake from standby, request snooze mode, end snooze mode or end deep standby mode.

Features

The LPM HAL module has the following key features:

Configuration

Build Time Configurations for r_lpm

The following build time configurations are defined in fsp_cfg/r_lpm_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.
Standby Limit
  • Enabled
  • Disabled
Disabled If enabled, standby configuration only applies in R_LPM_LowPowerModeEnter. Otherwise, standby configuration applies to any WFI call.

Configurations for Power > Low Power Modes (r_lpm)

This module can be added to the Stacks tab via New Stack > Power > Low Power Modes (r_lpm). Non-secure callable guard functions can be generated for this module by right clicking the module in the RA Configuration tool and checking the "Non-secure Callable" box.

ConfigurationOptionsDefaultDescription
General
NameName must be a valid C symbolg_lpm0 Module name.
Low Power ModeMCU Specific OptionsPower mode to be entered.
Output port state in standby and deep standbyMCU Specific OptionsSelect the state of output pins during standby. Applies to address output, data output, and other bus control output pins.
Deep Sleep and Standby Options
Deep Sleep and Standby Options > Snooze Options (Not available on every MCU)
Snooze Request SourceMCU Specific OptionsSelect the event that will enter snooze.
Snooze End SourcesMCU Specific OptionsEnable wake from snooze from these sources.
DTC state in Snooze ModeMCU Specific OptionsEnable wake from snooze from this source.
Snooze Cancel SourceMCU Specific OptionsSelect an interrupt source to cancel snooze.
Wake SourcesMCU Specific OptionsEnable wake from deep sleep and standby from these Sources.
RAM Retention Control (Not available on every MCU)
RAM retention in Standby modeMCU Specific OptionsSelect the memory regions that are retained in standby mode.
TCM retention in Deep Sleep and Standby modesMCU Specific OptionsSelect if Tightly Coupled Memory (TCM) is retained in deep sleep and standby modes.
Standby RAM retention in Standby and Deep Standby modesMCU Specific OptionsSelect if Standby RAM is retained in standby and deep standby modes.
Oscillator LDO Control (Not available on every MCU)
PLL1 LDO State in standby modeMCU Specific OptionsSelect the state PLL1 LDO state in standby mode.
PLL2 LDO State in standby modeMCU Specific OptionsSelect the state PLL2 LDO state in standby mode.
HOCO LDO State in standby modeMCU Specific OptionsSelect the state HOCO LDO state in standby mode.
Deep Standby Options
I/O Port RetentionMCU Specific OptionsSelect the state of the IO Pins after exiting deep standby mode.
Power-Supply ControlMCU Specific OptionsSelect the state of the internal power supply in deep standby mode.
Cancel SourcesMCU Specific OptionsEnable wake from deep standby using these sources.
Cancel EdgesMCU Specific OptionsFalling edge trigger is default. Select sources to enable wake from deep standby with rising edge.

Clock Configuration

This module does not have any selectable clock sources.

Pin Configuration

This module does not use I/O pins.

Usage Notes

Sleep Mode

At power on, by default sleep is set as the low-power mode. Sleep mode is the most convenient low-power mode available, as it does not require any special configuration (other than configuring and enabling a suitable interrupt or event to wake the MCU from sleep) to return to normal program-execution mode. The states of the SRAM, the processor registers, and the hardware peripherals are all maintained in sleep mode, and the time needed to enter and wake from sleep is minimal. Any interrupt causes the MCU device to wake from sleep mode, including the Systick interrupt used by the RTOS scheduler.

Deep Sleep Mode

Deep sleep mode is similar to sleep mode with the exception that DTC and DMAC are stopped, access to TCM memory is not available, and only a subset of interrupts are available for waking the CPU.

Software Standby Mode

In software-standby mode, the CPU, as well as most of the on-chip peripheral functions and all of the internal oscillators, are stopped. The contents of the CPU internal registers and SRAM data, the states of on-chip peripheral functions, and I/O Ports are all retained. Software-standby mode allows significant reduction in power consumption, because most of the oscillators are stopped in this mode. Like sleep mode, standby mode requires an interrupt or event be configured and enabled to wake up.

Snooze Mode

Snooze mode can be used with some MCU peripherals to execute basic tasks while keeping the MCU in a low-power state. Many core peripherals and all clocks can be selected to run during Snooze, allowing for more flexible low-power configuration than Software Standby mode. To enable Snooze, select "Software Standby mode with Snooze mode enabled" for the "Low Power Mode" configuration option. Snooze mode settings (including entry/exit sources) are available under "Standby Options".

Deep Software Standby Mode

The MCU always wakes from Deep Software Standby Mode by going through reset, either by the negation of the reset pin or by one of the wakeup sources configurable in the "Deep Standby Options" configuration group.

The Reset Status Registers can be used to determine if the reset occured after coming out of deep sofware standby. For example, R_SYSTEM->RSTSR0_b.DPSRSTF is set to 1 after a deep software standby reset.

I/O Port Retention can be enabled to maintain I/O port configuration across a deep software standby reset. Retention can be cancelled through the R_LPM_IoKeepClear API.

Limitations

Developers should be aware of the following limitations when using the LPM:

Examples

LPM Sleep Example

This is a basic example of minimal use of the LPM in an application. The LPM instance is opened and the configured low-power mode is entered.

void r_lpm_sleep (void)
{
fsp_err_t err = R_LPM_Open(&g_lpm_ctrl, &g_lpm_cfg_sleep);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
err = R_LPM_LowPowerModeEnter(&g_lpm_ctrl);
assert(FSP_SUCCESS == err);
}

LPM Deep Software Standby Example

void r_lpm_deep_software_standby (void)
{
fsp_err_t err;
/* Check the Deep Software Standby Reset Flag. If it is set, then the MCU is exiting
* Deep Software Standby mode. */
if (1U == R_SYSTEM->RSTSR0_b.DPSRSTF)
{
/* Clear the IOKEEP bit to allow I/O Port use.
* Note that this function should be called before opening the LPM driver. */
err = R_LPM_IoKeepClear(&g_lpm_ctrl);
assert(FSP_SUCCESS == err);
}
err = R_LPM_Open(&g_lpm_ctrl, &g_lpm_cfg_deep_software_standby);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Add user code here. */
/* Reconfigure the module to set the IOKEEP bit before entering deep software standby. */
err = R_LPM_LowPowerReconfigure(&g_lpm_ctrl, &g_lpm_cfg_deep_software_standby);
assert(FSP_SUCCESS == err);
err = R_LPM_LowPowerModeEnter(&g_lpm_ctrl);
/* Code after R_LPM_LowPowerModeEnter when using Deep Software Standby never be executed.
* Deep software standby exits by resetting the MCU. */
assert(FSP_SUCCESS == err);
}

Data Structures

struct  lpm_instance_ctrl_t
 

Data Structure Documentation

◆ lpm_instance_ctrl_t

struct lpm_instance_ctrl_t

LPM private control block. DO NOT MODIFY. Initialization occurs when R_LPM_Open() is called.

Function Documentation

◆ R_LPM_Open()

fsp_err_t R_LPM_Open ( lpm_ctrl_t *const  p_api_ctrl,
lpm_cfg_t const *const  p_cfg 
)

Perform any necessary initialization

Return values
FSP_SUCCESSLPM instance opened
FSP_ERR_ASSERTIONNull Pointer
FSP_ERR_ALREADY_OPENLPM instance is already open
FSP_ERR_UNSUPPORTEDThis MCU does not support Deep Software Standby
FSP_ERR_INVALID_ARGUMENTOne of the following:
  • Invalid snooze entry source
  • Invalid snooze end sources
FSP_ERR_INVALID_MODEOne of the following:
  • Invalid low power mode
  • Invalid DTC option for snooze mode
  • Invalid deep standby end sources
  • Invalid deep standby end sources edges
  • Invalid power supply option for deep standby
  • Invalid IO port option for deep standby
  • Invalid output port state setting for standby or deep standby
  • Invalid sources for wake from standby mode
  • Invalid power supply option for standby
  • Invalid IO port option for standby
  • Invalid standby end sources
  • Invalid standby end sources edges

◆ R_LPM_LowPowerReconfigure()

fsp_err_t R_LPM_LowPowerReconfigure ( lpm_ctrl_t *const  p_api_ctrl,
lpm_cfg_t const *const  p_cfg 
)

Configure a low power mode

NOTE: This function does not enter the low power mode, it only configures parameters of the mode. Execution of the WFI instruction is what causes the low power mode to be entered.

Return values
FSP_SUCCESSLow power mode successfuly applied
FSP_ERR_ASSERTIONNull Pointer
FSP_ERR_NOT_OPENLPM instance is not open
FSP_ERR_UNSUPPORTEDThis MCU does not support Deep Software Standby
FSP_ERR_INVALID_ARGUMENTOne of the following:
  • Invalid snooze entry source
  • Invalid snooze end sources
FSP_ERR_INVALID_MODEOne of the following:
  • Invalid low power mode
  • Invalid DTC option for snooze mode
  • Invalid deep standby end sources
  • Invalid deep standby end sources edges
  • Invalid power supply option for deep standby
  • Invalid IO port option for deep standby
  • Invalid output port state setting for standby or deep standby
  • Invalid sources for wake from standby mode
  • Invalid power supply option for standby
  • Invalid IO port option for standby
  • Invalid standby end sources
  • Invalid standby end sources edges

◆ R_LPM_LowPowerModeEnter()

fsp_err_t R_LPM_LowPowerModeEnter ( lpm_ctrl_t *const  p_api_ctrl)

Enter low power mode (sleep/deep sleep/standby/deep standby) using WFI macro.

Function will return after waking from low power mode.

Return values
FSP_SUCCESSSuccessful.
FSP_ERR_ASSERTIONNull pointer.
FSP_ERR_NOT_OPENLPM instance is not open
FSP_ERR_INVALID_MODEOne of the following:
  • HOCO was not system clock when using snooze mode with SCI0/RXD0.
  • HOCO was not stable when using snooze mode with SCI0/RXD0.
  • MOCO was running when using snooze mode with SCI0/RXD0.
  • MAIN OSCILLATOR was running when using snooze mode with SCI0/RXD0.
  • PLL was running when using snooze mode with SCI0/RXD0.
  • Unable to disable ocillator stop detect when using standby or deep standby.

◆ R_LPM_IoKeepClear()

fsp_err_t R_LPM_IoKeepClear ( lpm_ctrl_t *const  p_api_ctrl)

Clear the IOKEEP bit after deep software standby

Return values
FSP_SUCCESSDPSBYCR_b.IOKEEP bit cleared Successfully.
FSP_ERR_UNSUPPORTEDDeep standby mode not supported on this MCU.

◆ R_LPM_Close()

fsp_err_t R_LPM_Close ( lpm_ctrl_t *const  p_api_ctrl)

Close the LPM Instance

Return values
FSP_SUCCESSLPM driver closed
FSP_ERR_NOT_OPENLPM instance is not open
FSP_ERR_ASSERTIONNull Pointer