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.

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 */
};
Sleep-related Parameters

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:

  1. When developing with the Raw API, the following configuration principles apply to both UART and LOGUART:

    1. Clock selection: Before sleep, call RCC_PeriphClockSource_UART_ROM() to choose the clock source.

      1. If OSC2M is selected, set keep_OSC4M_on = TRUE.

      2. If XTAL is selected, set xtal_mode_in_sleep = XTAL_LPS_With_40M.

    2. Voltage setting: Set sleep_to_08V = TRUE to ensure proper operation of OSC4M or XTAL.

  2. When developing with the Mbed API, the following configuration principles only apply to UART:

    1. Clock selection: Call serial_baud() before sleep, which automatically selects the clock based on UART baud rate and low power configuration.

      1. If the baud rate is less than or equal to 115200 baud/s and .LOW_POWER_RX_ENABLE = ENABLE, OSC2M is automatically selected. Set keep_OSC4M_on = TRUE.

      2. If the baud rate is greater than 115200 baud/s or .LOW_POWER_RX_ENABLE = DISABLE, XTAL is automatically selected. Set xtal_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,
       },
       ...
    };
    
    1. Voltage setting: Set sleep voltage to sleep_to_08V = TRUE to ensure proper operation of OSC4M or XTAL.

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.