Developer Configuration (Usrcfg)
This section describes the configuration methods for wake-up sources in both sleep and deep sleep modes.
Configuration Procedure
Sleep Configuration Procedure
To enable a wake-up source to bring the system out of sleep, it must be properly initialized and the corresponding wake-up event must be triggered. Please follow the steps below to configure a wake-up source for system wake-up from sleep:
Step 1: Initialize the corresponding wake-up source and register its interrupt handler.
Step 2: Configure the wake-up mask of the wake-up source according to Wake-up Source Configuration.
Step 3: Check if additional clock and power status configuration is required according to Clock and Voltage Configuration.
Step 4: Set the sleep type to either CG or PG using
pmu_set_sleep_type()(default sleep type is PG).Step 5: Release the sleep wakelock and wait for the system to enter sleep mode.
Step 6: During sleep, the interrupt of the wake-up source occurs, waking up the system and executing the corresponding interrupt handler.
Tip
After completing registration in Step 1, you can trigger an interrupt while the system is active to verify whether the correct interrupt handler is entered, ensuring that the wake-up source has been properly initialized.
Example code for sleep configuration can be found at sleep example.
Deep Sleep Configuration Procedure
To enable a wake-up source to bring the system out of deep sleep, follow these steps:
Step 1: Initialize the corresponding wake-up source. No additional parameters such as wake-up masks are required.
Step 2: Release both the sleep wakelock and deep sleep wakelock, and wait for the system to enter deep sleep mode.
Step 3: After the system wakes up, process the wake-up event and related behaviors according to the corresponding wake-up source.
Example code for deep sleep configuration can be found at deep sleep example.
Tip
After waking up from deep sleep, the CPU is powered on again and all interrupts registered before sleep are lost. Users can obtain the wake event via SOCPS_AONWakeReason() and register the corresponding interrupt handler according to the event.
Sleep Wake-up Source Configuration
Users can modify the above files to configure wake-up source parameters. The available configurations are shown below:
Wake-up Source Configuration
All available wake-up sources are listed in the array sleep_wevent_config[], where each entry represents a wake-up source configuration. Users can modify this array to configure whether the wake-up source can wake up the system and which CPU it wakes up.
WakeEvent_TypeDef sleep_wevent_config[] = {
// Module Wakeup
{WAKE_SRC_AON_WAKEPIN, WAKEUP_NULL},
{WAKE_SRC_AON_TIM, WAKEUP_NULL},
{WAKE_SRC_PWR_DOWN, WAKEUP_NULL},
{WAKE_SRC_BOR, WAKEUP_NULL},
{WAKE_SRC_ADC, WAKEUP_NULL},
{WAKE_SRC_RTC, WAKEUP_NULL},
{WAKE_SRC_GPIOB, WAKEUP_NULL},
{WAKE_SRC_GPIOA, WAKEUP_NULL},
{WAKE_SRC_UART_LOG, WAKEUP_NULL},
{WAKE_SRC_UART1, WAKEUP_NULL},
{WAKE_SRC_UART0, WAKEUP_NULL},
{WAKE_SRC_WIFI_FISR_FESR_IRQ, WAKEUP_NULL}, /* For WiFi wakeup, do not change it*/
...
{0xFFFFFFFF, WAKEUP_NULL},
};
The structure WakeEvent_TypeDef is defined as follows:
typedef struct {
u32 Module;
enum wakeup_mask Wakeup;
} WakeEvent_TypeDef;
Module: Wake-up source
Wakeup: Wake-up mask, specifies which CPU to wake up, available options are:
WAKEUP_KM4 : Wake up KM4
WAKEUP_KM0 : Wake up KM0
WAKEUP_NULL : Disable this wake-up source
For example, setting {WAKE_SRC_UART0, WAKEUP_KM4} means UART0 will wake up KM4;
Setting {WAKE_SRC_UART0, WAKEUP_KM0} means UART0 will wake up KM0. The wake-up mask should be set to the CPU running the user’s application, ensuring that both the interrupt and wake-up source are configured for the same CPU.
Note
If you select to wake up KM4, KM0 will also be awakened.
The SDK has already configured specific wake-up source masks, which cannot be modified. For example,
{WAKE_SRC_WIFI_FISR_FESR_IRQ, WAKEUP_KM0}is dedicated for Wi-Fi and cannot be changed.
WAKEUP_AP: Wake up KM4
WAKEUP_NP: Wake up KR4
WAKEUP_NULL: Disable this wake-up source
For example, setting {WAKE_SRC_UART0, WAKEUP_AP} means UART0 will wake up KM4;
setting {WAKE_SRC_UART0, WAKEUP_NP} means UART0 will wake up KR4. The wake-up mask should be set to the CPU running the user application, and both the interrupt and wake-up source configuration should point to the same CPU.
Note
If you choose to wake up KM4, KR4 will also be awakened.
Some wake-up sources with fixed wake-up masks are pre-defined in the SDK and cannot be changed. For example,
{WAKE_SRC_WIFI_FISR_FESR_IRQ, WAKEUP_NP}is reserved for Wi-Fi and cannot be modified.
WAKEUP_AP: Wake up KM4
WAKEUP_NP: Wake up KR4
WAKEUP_NULL: Disable this wake-up source
For example, setting {WAKE_SRC_UART0, WAKEUP_AP} means UART0 will wake up KM4;
setting {WAKE_SRC_UART0, WAKEUP_NP} means UART0 will wake up KR4. The wake-up mask should be set to the CPU running the user application, and both the interrupt and wake-up source configuration should point to the same CPU.
Note
If you choose to wake up KM4, KR4 will also be awakened.
Some wake-up sources with fixed wake-up masks are pre-defined in the SDK and cannot be changed. For example,
{WAKE_SRC_WIFI_FISR_FESR_IRQ, WAKEUP_NP}is reserved for Wi-Fi and cannot be modified.
WAKEUP_AP: Wake up KM4
WAKEUP_NP: Wake up KR4
WAKEUP_NULL: Disable this wake-up source
For example, setting {WAKE_SRC_UART0, WAKEUP_AP} means UART0 will wake up KM4;
setting {WAKE_SRC_UART0, WAKEUP_NP} means UART0 will wake up KR4. The wake-up mask should be set to the CPU running the user application, and both the interrupt and wake-up source configuration should point to the same CPU.
Note
If you choose to wake up KM4, KR4 will also be awakened.
Some wake-up sources with fixed wake-up masks are pre-defined in the SDK and cannot be changed. For example,
{WAKE_SRC_WIFI_FISR_FESR_IRQ, WAKEUP_NP}is reserved for Wi-Fi and cannot be modified.
WAKEUP_AP: Wake up KM4
WAKEUP_NP: Wake up KR4
WAKEUP_NULL: Disable this wake-up source
For example, setting {WAKE_SRC_UART0, WAKEUP_AP} means UART0 will wake up KM4;
setting {WAKE_SRC_UART0, WAKEUP_NP} means UART0 will wake up KR4. The wake-up mask should be set to the CPU running the user application, and both the interrupt and wake-up source configuration should point to the same CPU.
Note
If you choose to wake up KM4, KR4 will also be awakened.
Some wake-up sources with fixed wake-up masks are pre-defined in the SDK and cannot be changed. For example,
{WAKE_SRC_WIFI_FISR_FESR_IRQ, WAKEUP_NP}is reserved for Wi-Fi and cannot be modified.
WAKEUP_AP: Wake up CA32
WAKEUP_NP: Wake up KM4
WAKEUP_LP: Wake up KM0
WAKEUP_NULL: Disable this wake-up source
For example, setting {WAKE_SRC_UART0, WAKEUP_AP} means UART0 will wake up CA32;
setting {WAKE_SRC_UART0, WAKEUP_LP} means UART0 will wake up KM0. The wake-up mask should be set to the CPU that runs the user application, and both the interrupt and wake-up source settings should point to the same CPU.
Note
If you choose to wake up KM4, KM0 will also be awakened; if you choose to wake up CA32, both KM4 and KM0 will be awakened.
Some wake-up sources with fixed wake-up masks are pre-defined in the SDK and cannot be changed. For example,
{WAKE_SRC_WIFI_FISR_FESR_IRQ, WAKEUP_LP}is reserved for Wi-Fi and cannot be modified.
Tip
In addition to modifying the sleep_wevent_config[] array, users can also configure wake-up sources using APIs such as SOCPS_SetAPWakeEvent() and SOCPS_SetNPWakeEvent().
Clock and Voltage Configuration
Certain wake-up sources require configuration of parameters such as OSC, XTAL, and MCU core voltage during sleep to function correctly. These parameters can be configured through the ps_config[] structure.
When using UART or LOGUART as wake-up sources, it is necessary to modify the voltage and clock source settings for sleep mode. The configurable parameters are listed below:
PSCFG_TypeDef ps_config = {
.keep_OSC4M_on = FALSE, /* Keep OSC4M on or off during sleep */
.xtal_mode_in_sleep = XTAL_OFF, /* Set XTAL mode during sleep, see enum xtal_mode_sleep for details */
.sleep_to_08V = FALSE, /* Default sleep voltage is 0.7V; set TRUE to sleep at 0.8V */
};
Parameter Name |
Meaning |
Description |
|---|---|---|
keep_OSC4M_on |
OSC4M status during sleep |
TRUE: Turn on; FALSE: Turn off |
xtal_mode_in_sleep |
XTAL operation mode in sleep |
XTAL_OFF: Turn off the XTAL |
XTAL_LPS_With_40M: Maintain 40MHz in low power mode |
||
sleep_to_08V |
MCU Core voltage in sleep |
FALSE: 0.7V (default); TRUE: 0.8V |
Configuration principles are as follows:
When developing with the Raw API, the following configuration principles apply to both UART and LOGUART:
Clock selection: Before sleep, call
RCC_PeriphClockSource_UART_ROM()to choose the clock source.If OSC2M is selected, set
keep_OSC4M_on = TRUE.If XTAL is selected, set
xtal_mode_in_sleep = XTAL_LPS_With_40M.
Voltage setting: Set
sleep_to_08V = TRUEto ensure proper operation of OSC4M or XTAL.
When developing with the Mbed API, the following configuration principles only apply to UART:
Clock selection: Call
serial_baud()before sleep, which automatically selects the clock based on UART baud rate and low power configuration.If the baud rate is less than or equal to 115200 baud/s and
.LOW_POWER_RX_ENABLE = ENABLE, OSC2M is automatically selected. Setkeep_OSC4M_on = TRUE.If the baud rate is greater than 115200 baud/s or
.LOW_POWER_RX_ENABLE = DISABLE, XTAL is automatically selected. Setxtal_mode_in_sleep = XTAL_LPS_With_40M.
UARTCFG_TypeDef uart_config[4] = { /* UART0 */ { .LOW_POWER_RX_ENABLE = DISABLE, /*Enable low power RX*/ }, /* UART1 */ { .LOW_POWER_RX_ENABLE = DISABLE, }, ... };
Voltage setting: Set sleep voltage to
sleep_to_08V = TRUEto ensure proper operation of OSC4M or XTAL.
Note
Enabling XTAL during sleep will significantly increase power consumption.
When using UART or LOGUART as wake-up sources, the voltage and clock source settings during sleep need to be adjusted. Configurable parameters are as follows:
PSCFG_TypeDef ps_config = {
.keep_OSC4M_on = FALSE, /* keep OSC4M on or off for sleep */
.xtal_mode_in_sleep = XTAL_OFF, /* set xtal mode during sleep mode, see enum xtal_mode_sleep for detail */
};
Parameter Name |
Meaning |
Description |
|---|---|---|
keep_OSC4M_on |
OSC4M status during sleep |
TRUE: Turn on; FALSE: Turn off |
xtal_mode_in_sleep |
XTAL operation mode in sleep |
XTAL_OFF: Turn off the XTAL |
XTAL_LPS: Maintain 40MHz in low-power mode |
Configuration principles are as follows:
For Raw API development, the following rules apply to both UART and LOGUART:
Clock selection: Call
RCC_PeriphClockSource_UART_ROM()to select the clock source before sleepIf OSC2M is selected, set
keep_OSC4M_on = TRUE.If XTAL is selected, set
xtal_mode_in_sleep = XTAL_LPS.If XTAL/2 is selected, set
xtal_mode_in_sleep = XTAL_LPS.
For Mbed API development, the following rules only apply to UART:
Clock selection: Call
serial_baud()before sleep to automatically determine according to UART baud rate and low power configurationIf the baud rate is less than or equal to 115200 baud/s and
.LOW_POWER_RX_ENABLE = ENABLE, OSC2M will be automatically selected. Setkeep_OSC4M_on = TRUE.If the baud rate is greater than 115200 baud/s or
.LOW_POWER_RX_ENABLE = DISABLE, XTAL will be automatically selected. Setxtal_mode_in_sleep = XTAL_LPS.
UARTCFG_TypeDef uart_config[4] = { /* UART0 */ { .LOW_POWER_RX_ENABLE = DISABLE, /*Enable low power RX*/ }, /* UART1 */ { .LOW_POWER_RX_ENABLE = DISABLE, }, ... };
Note
Enabling XTAL during sleep will significantly increase power consumption.
When using UART or LOGUART as wake-up sources, the voltage and clock source settings during sleep need to be adjusted. Configurable parameters are as follows:
PSCFG_TypeDef ps_config = {
.keep_OSC4M_on = FALSE, /* keep OSC4M on or off for sleep */
.xtal_mode_in_sleep = XTAL_OFF, /* set xtal mode during sleep mode, see enum xtal_mode_sleep for detail */
};
Parameter Name |
Meaning |
Description |
|---|---|---|
keep_OSC4M_on |
OSC4M status during sleep |
TRUE: Turn on; FALSE: Turn off |
xtal_mode_in_sleep |
XTAL operation mode in sleep |
XTAL_OFF: Turn off the XTAL |
XTAL_LPS: Maintain 40MHz in low-power mode |
Configuration principles are as follows:
For Raw API development, the following rules apply to both UART and LOGUART:
Clock selection: Call
RCC_PeriphClockSource_UART_ROM()to select the clock source before sleepIf OSC2M is selected, set
keep_OSC4M_on = TRUE.If XTAL is selected, set
xtal_mode_in_sleep = XTAL_LPS.If XTAL/2 is selected, set
xtal_mode_in_sleep = XTAL_LPS.
For Mbed API development, the following rules only apply to UART:
Clock selection: Call
serial_baud()before sleep to automatically determine according to UART baud rate and low power configurationIf the baud rate is less than or equal to 115200 baud/s and
.LOW_POWER_RX_ENABLE = ENABLE, OSC2M will be automatically selected. Setkeep_OSC4M_on = TRUE.If the baud rate is greater than 115200 baud/s or
.LOW_POWER_RX_ENABLE = DISABLE, XTAL will be automatically selected. Setxtal_mode_in_sleep = XTAL_LPS.
UARTCFG_TypeDef uart_config[4] = { /* UART0 */ { .LOW_POWER_RX_ENABLE = DISABLE, /*Enable low power RX*/ }, /* UART1 */ { .LOW_POWER_RX_ENABLE = DISABLE, }, ... };
Note
Enabling XTAL during sleep will significantly increase power consumption.
When using UART or LOGUART as wake-up sources, the voltage and clock source settings during sleep need to be adjusted. Configurable parameters are as follows:
PSCFG_TypeDef ps_config = {
.keep_OSC4M_on = FALSE, /* keep OSC4M on or off for sleep */
.xtal_mode_in_sleep = XTAL_OFF, /* set xtal mode during sleep mode, see enum xtal_mode_sleep for detail */
};
Parameter Name |
Meaning |
Description |
|---|---|---|
keep_OSC4M_on |
OSC4M status during sleep |
TRUE: Turn on; FALSE: Turn off |
xtal_mode_in_sleep |
XTAL operation mode in sleep |
XTAL_OFF: Turn off the XTAL |
XTAL_LPS: Maintain 40MHz in low-power mode |
Configuration principles are as follows:
For Raw API development, the following rules apply to both UART and LOGUART:
Clock selection: Call
RCC_PeriphClockSource_UART_ROM()to select the clock source before sleepIf OSC2M is selected, set
keep_OSC4M_on = TRUE.If XTAL is selected, set
xtal_mode_in_sleep = XTAL_LPS.If XTAL/2 is selected, set
xtal_mode_in_sleep = XTAL_LPS.
For Mbed API development, the following rules only apply to UART:
Clock selection: Call
serial_baud()before sleep to automatically determine according to UART baud rate and low power configurationIf the baud rate is less than or equal to 115200 baud/s and
.LOW_POWER_RX_ENABLE = ENABLE, OSC2M will be automatically selected. Setkeep_OSC4M_on = TRUE.If the baud rate is greater than 115200 baud/s or
.LOW_POWER_RX_ENABLE = DISABLE, XTAL will be automatically selected. Setxtal_mode_in_sleep = XTAL_LPS.
UARTCFG_TypeDef uart_config[4] = { /* UART0 */ { .LOW_POWER_RX_ENABLE = DISABLE, /*Enable low power RX*/ }, /* UART1 */ { .LOW_POWER_RX_ENABLE = DISABLE, }, ... };
Note
Enabling XTAL during sleep will significantly increase power consumption.
When using UART or LOGUART as wake-up sources, the voltage and clock source settings during sleep need to be adjusted. Configurable parameters are as follows:
PSCFG_TypeDef ps_config = {
.keep_OSC4M_on = FALSE, /* keep OSC4M on or off for sleep */
.xtal_mode_in_sleep = XTAL_OFF, /* set xtal mode during sleep mode, see enum xtal_mode_sleep for detail */
};
Parameter Name |
Meaning |
Description |
|---|---|---|
keep_OSC4M_on |
OSC4M status during sleep |
TRUE: Turn on; FALSE: Turn off |
xtal_mode_in_sleep |
XTAL operation mode in sleep |
XTAL_OFF: Turn off the XTAL |
XTAL_LPS: Maintain 40MHz in low-power mode |
Configuration principles are as follows:
For Raw API development, the following rules apply to both UART and LOGUART:
Clock selection: Call
RCC_PeriphClockSource_UART_ROM()to select the clock source before sleepIf OSC2M is selected, set
keep_OSC4M_on = TRUE.If XTAL is selected, set
xtal_mode_in_sleep = XTAL_LPS.If XTAL/2 is selected, set
xtal_mode_in_sleep = XTAL_LPS.
For Mbed API development, the following rules only apply to UART:
Clock selection: Call
serial_baud()before sleep to automatically determine according to UART baud rate and low power configurationIf the baud rate is less than or equal to 115200 baud/s and
.LOW_POWER_RX_ENABLE = ENABLE, OSC2M will be automatically selected. Setkeep_OSC4M_on = TRUE.If the baud rate is greater than 115200 baud/s or
.LOW_POWER_RX_ENABLE = DISABLE, XTAL will be automatically selected. Setxtal_mode_in_sleep = XTAL_LPS.
UARTCFG_TypeDef uart_config[4] = { /* UART0 */ { .LOW_POWER_RX_ENABLE = DISABLE, /*Enable low power RX*/ }, /* UART1 */ { .LOW_POWER_RX_ENABLE = DISABLE, }, ... };
Note
Enabling XTAL during sleep will significantly increase power consumption.
When using UART or LOGUART as a wake-up source, the voltage and clock source settings during sleep must be modified.
PSCFG_TypeDef ps_config = {
.km0_pg_enable = FALSE,
.km0_pll_off = TRUE,
.km0_audio_vad_on = FALSE,
.km0_config_psram = TRUE, /* if device enter sleep mode or not, false for keep active */
.km0_sleep_withM4 = TRUE,
.keep_OSC4M_on = FALSE,
.xtal_mode_in_sleep = XTAL_OFF,
.swr_mode_in_sleep = SWR_PFM,
};
The configurable parameters are as follows:
Parameter Name |
Meaning |
Description |
|---|---|---|
keep_OSC4M_on |
OSC4M status during sleep |
TRUE: Turn on; FALSE: Turn off |
xtal_mode_in_sleep |
XTAL operation mode in sleep |
XTAL_OFF: Turn off the XTAL |
XTAL_LPS: Maintain 40MHz in low-power mode |
For other parameter changes, please contact RealTek for technical support.
Configuration principles are as follows:
When developing with the Raw API, the following rules apply to both UART and LOGUART:
Clock selection: Call
RCC_PeriphClockSource_UART_ROM()before sleep to select the clock source.If OSC2M is selected, set
keep_OSC4M_on = TRUE.If XTAL is selected, set
xtal_mode_in_sleep = XTAL_LPS.If XTAL 2M is selected, set
xtal_mode_in_sleep = XTAL_LPS.
When developing with the Mbed API, the following rules only apply to UART:
Clock selection: Call
serial_baud()before sleep, and the system will automatically determine according to the UART baud rate and low-power configuration.If the baud rate is less than or equal to 115200 baud/s and
.LOW_POWER_RX_ENABLE = ENABLE, OSC2M will be automatically selected. Setkeep_OSC4M_on = TRUE.If the baud rate is greater than 115200 baud/s or
.LOW_POWER_RX_ENABLE = DISABLE, XTAL will be automatically selected. Setxtal_mode_in_sleep = XTAL_LPS.
UARTCFG_TypeDef uart_config[4] = { /* UART0 */ { .LOW_POWER_RX_ENABLE = DISABLE, /* Enable low power RX */ }, /* UART1 */ { .LOW_POWER_RX_ENABLE = DISABLE, }, ... };
Note
Enabling XTAL during sleep will significantly increase power consumption.
Deep Sleep Wake-up Source Configuration
Wake-up Sources
The following wake-up sources can wake up the system from deep sleep mode:
AON Timer
RTC
BOR
PWR_DOWN
AON Wakepin
Parameter Configuration
Deep sleep wake-up sources can wake up the system from both deep sleep and sleep modes. No sleep wake-up mask, voltage, or related parameter configuration is required for deep sleep.
Wake Pin Configuration
Wake pins are a group of special GPIOs that can be used to wake up the system from both deep sleep and sleep modes. In sleep mode, wake pins can be multiplexed as GPIOs for GPIO wake-up, or configured as dedicated wake pin functions.
Example code for wake pin configuration can be found at wake pin example.