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.
WAKEUP_AP: Wake up KM4TZ
WAKEUP_NP: Wake up KM4NS
WAKEUP_NULL: Disable this wake-up source
For example, setting {WAKE_SRC_UART0, WAKEUP_AP} means UART0 will wake up KM4TZ;
setting {WAKE_SRC_UART0, WAKEUP_NP} means UART0 will wake up KM4NS. The wake-up mask should be set to the CPU running the user’s application, and both the interrupt and wake-up source should point to the same CPU.
Note
If you choose to wake up KM4TZ, KM4NS will also be awakened.
The SDK has set fixed wake-up masks for certain wake-up sources, which cannot be modified. For example,
{WAKE_SRC_WIFI_FISR_FESR_IRQ, WAKEUP_NP}is reserved for Wi-Fi and cannot be changed.
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 a wakeup source, the voltage and clock source during sleep need to be modified. The configurable parameters are as follows:
struct 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 */
.sleep_to_08V = FALSE, /* default sleep to 0.7V, set this option to TRUE will sleep to 0.8V */
};
Parameter |
Meaning |
Description |
|---|---|---|
|
Whether OSC4M is on during sleep |
|
|
XTAL working mode during sleep |
|
|
MCU Core voltage during sleep |
|
Configuration principles are as follows:
When developing with Raw API, the following configuration principles apply to UART and LOGUART:
Clock Selection: Call
RCC_PeriphClockSource_UART_ROMbefore 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_With_40M.
Voltage Setting: Must be set to
sleep_to_08V = TRUEto ensure OSC4M or XTAL works properly.
When developing with Mbed API, the following configuration principles apply only to UART:
Clock Selection: Call
serial_baudbefore sleep. The decision is made automatically based on the UART baud rate and low-power settings:When baud rate ≤ 115200 baud/s and
.LOW_POWER_RX_ENABLE = ENABLE, OSC2M is automatically selected; need to setkeep_osc4m_on = TRUE.When baud rate > 115200 baud/s or
.LOW_POWER_RX_ENABLE = DISABLE, XTAL is automatically selected; need to setxtal_mode_in_sleep = XTAL_LPS_With_40M.
Configuration example:
UARTCFG_TypeDef uart_config[3] = { /* UART0 */ { .LOW_POWER_RX_ENABLE = DISABLE, /* Enable low power RX */ }, /* UART1 */ { .LOW_POWER_RX_ENABLE = DISABLE, }, // ... };
Voltage Setting: The sleep voltage needs to be set to
sleep_to_08V = TRUEto ensure OSC4M or XTAL works properly.
Note
Enabling XTAL during sleep will significantly increase power consumption.
When using UART or LOGUART as a wakeup source, the clock source during sleep need to be modified. The configurable parameters are as follows:
struct 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 |
Meaning |
Description |
|---|---|---|
|
Whether OSC4M is on during sleep |
|
|
XTAL working mode during sleep |
|
The configuration principles are as follows:
When developing with Raw API, the following configuration principles apply to 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/2 is selected, set
xtal_mode_in_sleep = XTAL_LPS.
When developing with Mbed API, the following configuration principles apply only to UART:
Clock Selection: Call
serial_baud()before sleep. The decision is made automatically based on the UART baud rate and low-power settings:When baud rate ≤ 115200 baud/s and
.LOW_POWER_RX_ENABLE = ENABLE, OSC2M is automatically selected; need to setkeep_osc4m_on = TRUE.When baud rate > 115200 baud/s or
.LOW_POWER_RX_ENABLE = DISABLE, XTAL is automatically selected; need to setxtal_mode_in_sleep = XTAL_LPS.
Configuration example:
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 wakeup source, the clock source during sleep need to be modified. The configurable parameters are as follows:
struct 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 |
Meaning |
Description |
|---|---|---|
|
Whether OSC4M is on during sleep |
|
|
XTAL working mode during sleep |
|
The configuration principles are as follows:
When developing with Raw API, the following configuration principles apply to 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/2 is selected, set
xtal_mode_in_sleep = XTAL_LPS.
When developing with Mbed API, the following configuration principles apply only to UART:
Clock Selection: Call
serial_baud()before sleep. The decision is made automatically based on the UART baud rate and low-power settings:When baud rate ≤ 115200 baud/s and
.LOW_POWER_RX_ENABLE = ENABLE, OSC2M is automatically selected; need to setkeep_osc4m_on = TRUE.When baud rate > 115200 baud/s or
.LOW_POWER_RX_ENABLE = DISABLE, XTAL is automatically selected; need to setxtal_mode_in_sleep = XTAL_LPS.
Configuration example:
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 wakeup source, the clock source during sleep need to be modified. The configurable parameters are as follows:
struct 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 |
Meaning |
Description |
|---|---|---|
|
Whether OSC4M is on during sleep |
|
|
XTAL working mode during sleep |
|
The configuration principles are as follows:
When developing with Raw API, the following configuration principles apply to 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/2 is selected, set
xtal_mode_in_sleep = XTAL_LPS.
When developing with Mbed API, the following configuration principles apply only to UART:
Clock Selection: Call
serial_baud()before sleep. The decision is made automatically based on the UART baud rate and low-power settings:When baud rate ≤ 115200 baud/s and
.LOW_POWER_RX_ENABLE = ENABLE, OSC2M is automatically selected; need to setkeep_osc4m_on = TRUE.When baud rate > 115200 baud/s or
.LOW_POWER_RX_ENABLE = DISABLE, XTAL is automatically selected; need to setxtal_mode_in_sleep = XTAL_LPS.
Configuration example:
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 wakeup source, the clock source during sleep need to be modified. The configurable parameters are as follows:
struct 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 |
Meaning |
Description |
|---|---|---|
|
Whether OSC4M is on during sleep |
|
|
XTAL working mode during sleep |
|
The configuration principles are as follows:
When developing with Raw API, the following configuration principles apply to 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/2 is selected, set
xtal_mode_in_sleep = XTAL_LPS.
When developing with Mbed API, the following configuration principles apply only to UART:
Clock Selection: Call
serial_baud()before sleep. The decision is made automatically based on the UART baud rate and low-power settings:When baud rate ≤ 115200 baud/s and
.LOW_POWER_RX_ENABLE = ENABLE, OSC2M is automatically selected; need to setkeep_osc4m_on = TRUE.When baud rate > 115200 baud/s or
.LOW_POWER_RX_ENABLE = DISABLE, XTAL is automatically selected; need to setxtal_mode_in_sleep = XTAL_LPS.
Configuration example:
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 wakeup source, the clock source during sleep need to be modified. The configurable parameters are as follows:
struct PSCFG_TypeDef ps_config = {
.km0_audio_vad_on = FALSE,
.keep_osc4m_on = FALSE, /* keep OSC4M off or on during sleep */
.xtal_mode_in_sleep = XTAL_OFF, /* set xtal mode during sleep mode */
};
Parameter |
Meaning |
Description |
|---|---|---|
|
Whether OSC4M is on during sleep |
|
|
XTAL working mode during sleep |
|
For modifications to other parameters, please contact RealTek for technical support.
The configuration principles are as follows:
When developing with Raw API, the following configuration principles apply to 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 Mbed API, the following configuration principles apply only to UART:
Clock Selection: Call
serial_baud()before sleep. The decision is made automatically based on the UART baud rate and low-power settings:When baud rate ≤ 115200 baud/s and
.LOW_POWER_RX_ENABLE = ENABLE, OSC2M is automatically selected; need to setkeep_osc4m_on = TRUE.When baud rate > 115200 baud/s or
.LOW_POWER_RX_ENABLE = DISABLE, XTAL is automatically selected; need to setxtal_mode_in_sleep = XTAL_LPS.
Configuration example:
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 wakeup source, it is necessary to modify the voltage and clock source during sleep. The configurable parameters are as follows:
struct PSCFG_TypeDef ps_config = {
.keep_osc4m_on = FALSE, /* keep OSC4M off or on during sleep */
.xtal_mode_in_sleep = XTAL_OFF, /* set xtal mode during sleep mode */
.sleep_to_08V = FALSE, /* default sleep to 0.7V, set this option to TRUE will sleep to 0.8V */
};
Parameter |
Meaning |
Description |
|---|---|---|
|
Whether OSC4M is on during sleep |
|
|
XTAL working mode during sleep |
|
|
MCU Core voltage during sleep |
|
The configuration principles are as follows:
When developing with Raw API, the following configuration principles apply to UART and LOGUART:
Clock Selection: Call
RCC_PeriphClockSourceSet()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_With_40M.
Voltage Setting: Must be set to
sleep_to_08V = TRUEto ensure OSC4M or XTAL works properly.
When developing with Mbed API, the following configuration principles apply only to UART:
Clock Selection: Call
serial_baud()before sleep. The decision is made automatically based on the UART baud rate and low-power settings:When baud rate ≤ 115200 baud/s and
.LOW_POWER_RX_ENABLE = ENABLE, OSC4M is automatically selected; need to setkeep_osc4m_on = TRUE.When baud rate > 115200 baud/s or
.LOW_POWER_RX_ENABLE = DISABLE, XTAL is automatically selected; need to setxtal_mode_in_sleep = XTAL_LPS_With_40M.
Configuration example:
UARTCFG_TypeDef uart_config[4] = { /* UART0 */ { .LOW_POWER_RX_ENABLE = DISABLE, /* Enable low power RX */ }, /* UART1 */ { .LOW_POWER_RX_ENABLE = DISABLE, }, // ... };
Voltage Setting: The sleep voltage needs to be set to
sleep_to_08V = TRUEto ensure OSC4M or XTAL works properly.
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.