Power Architecture๏ƒ

SoC has an advanced Power Management Controller (PMC), which can flexibly power up different power domains of the chip, to achieve the best balance between chip performance and power consumption.

There are generally three main power domains in the digital system of the SoC: AON, SYSON, and SOC.

Functions in different power domains will be turned off differently in different power-saving modes.

Power-Saving Mode๏ƒ

Ameba SoC supports two low power modes:

  • Sleep mode

    • Clock Gating (CG): Shuts off the clock to the SOC domain while retaining its power supply.

    • Power Gating (PG): Shuts off the power supply to the SOC domain.

  • Deep-Sleep mode

    • Shuts off the power supply to both the SYSON domain and SOC domain. Compared to sleep mode, deep-sleep mode turns off more power domains, resulting in lower power consumption.

Tickless is a low power feature of FreeRTOS. When the system is idle, the CPU will be paused (without disabling clock and power). Both sleep mode and deep sleep mode workflows are based on Tickless.

The following table explains power-saving related terms.

Mode

AON domain

SYSON domain

SOC domain

Description

Tickless

ON

ON

ON

  • FreeRTOS low power feature

  • CPU periodically enters WFI, and exits WFI when interrupts happen.

  • Radio status can be configured off/periodically on/always on, which depends on the application.

Sleep

ON

ON

  • CG:ON

  • PG:OFF

  • A power saving mode on chip level, including clock-gating mode and power-gating mode.

  • CPU can restore stack status when the system exits from sleep mode.

  • The system RAM will be retained, and the data in system RAM will not be lost.

Deep-Sleep

ON

OFF

OFF

  • A more power-saving mode on chip-level.

  • CPU cannot restore stack status. When the system exits from deep-sleep mode, the CPU follows the reboot process.

  • The system RAM will not be retained.

  • The retention SRAM will not be power off.

Tickless for FreeRTOS๏ƒ

The FreeRTOS supports a low-power feature called Tickless. It is implemented in an idle task which has the lowest priority. That is, it is invoked when there is no other task under running.

Note

  • configUSE_TICKLESS_IDLE must be enabled for power-saving application because sleep mode flow is based on Tickless.

  • Unlike the original FreeRTOS, We donโ€™t wake up based on the xEpectedIdleTime.

../_images/freertos_tickless_in_an_idle_task.svg

FreeRTOS Tickless in an idle task๏ƒ

The figure above shows idle task code flow. In idle task, it will check sleep conditions (wakelock, sysactive_time, details in Section Wakelock APIs and pmu_set_sysactive_time) to determine whether needs to enter sleep mode or not.

  • If not, the CPU will execute an ARM instruction WFI (wait for interrupt) which makes the CPU suspend until the interrupt happens. Normally systick interrupt resumes it. This is the software Tickless.

  • If yes, it will execute the function freertos_pre_sleep_processing() to enter sleep mode or deep-sleep mode.

Note

  • Even FreeRTOS time control like software timer or vTaskDelay is set, it still enters the sleep mode if meeting the requirement as long as the idle task is executed.

Wi-Fi Power Saving๏ƒ

Please reference Wi-Fi Power Saving chapter for detailed information.

Wakeup Source๏ƒ

The following table lists the wakeup sources that can be used to wake up the system under different power modes.

Wakeup source

Sleep CG

Sleep PG

Deep-Sleep

Restriction

WLAN

โˆš

โˆš

X

BT

โˆš

โˆš

X

IPC

โˆš

โˆš

X

Only KM0 can use the IPC to wake up KM4.

Basic Timer4~7

โˆš

โˆš

X

PMC Timer

โˆš

โˆš

X

For internal usage

UART0~2

โˆš

โˆš

X

  • When using UART as a wakeup source, the Rx clock source can only be OSC2M, and do not turn off OSC4M during sleep.

  • When the baudrate is larger than 115200, it is not recommended to use UART as a wakeup source.

  • The portion of the command used to wake up that exceeds the FIFO depth (64B) will be lost.

LOGUART

โˆš

โˆš

X

When using LOGUART as a wakeup source:

  • If the Rx clock source is XTAL40M, do not turn off XTAL or OSC4M during sleep.

  • If the Rx clock source is OSC2M, do not turn off OSC4M during sleep.

  • The portion of the command used to wake up that exceeds the FIFO depth (16B) will be lost.

GPIO

โˆš

โˆš

X

I2C

โˆš

โˆš

X

CAP_TOUCH

โˆš

โˆš

X

ADC

โˆš

โˆš

X

SDIO

โˆš

โˆš

X

Key-Scan

โˆš

โˆš

X

BOR

โˆš

โˆš

โˆš

PWR_DOWN

โˆš

โˆš

โˆš

AON_TIMER

โˆš

โˆš

โˆš

AON_WAKEPIN

โˆš

โˆš

โˆš

RTC

โˆš

โˆš

โˆš

Entering Sleep Mode๏ƒ

Sleep mode is based on FreeRTOS Tickless, thus it is recommended to enter sleep mode by releasing the wakelock.

  1. Initialize the specific peripheral.

  2. Enable and register the peripheralโ€™s interrupt.

  3. Set sleep_wevent_config[] in ambea_sleepcfg.c, and the interrupt should be registered on the same CPU selected by sleep_wevent_config[].

  4. For peripherals that need special clock settings, set ps_config[] in ameba_sleepcfg.c if needed.

  5. Register sleep/wakeup callback if needed.

  6. Enter sleep mode by releasing the wakelock in application core (AP) (PMU_OS needs to be released since it is acquired by default when boot).

  7. Clear the peripheralโ€™s interrupt when wakeup.

Entering Deep-Sleep Mode๏ƒ

Deep-Sleep can also be entered from FreeRTOS Tickless flow.

When the system boots, AP holds the deepwakelock PMU_OS, thus freertos_ready_to_dsleep() will be checked fail and the system does not enter deep-sleep mode in idle task by default. Since freertos_ready_to_dsleep() will be checked only after freertos_ready_to_sleep() is checked pass, both the wakelock and deepwakelock need to be released for entering deep-sleep mode.

Configuration:

  1. Initialize the related peripheral and enable its interrupt.

  2. Set sleep_wakepin_config[] in ameba_sleepcfg.c when using AON wakepin as a wakeup source.

  3. Enter deep-sleep mode by releasing the deepwakelock and wakelock in AP.

Power-Saving Configuration๏ƒ

github source code

Wakeup Mask Setup

For sleep mode, only one CPU is required to wake up to execute the program in some situations. The wakeup mask module is designed to implement this function. In general, in addition to configuring the wakeup mask, it is also necessary to register the wakeup source interrupt so that the specific CPU can handle it upon wakeup.

By setting a wakeup mask, you can choose to wake up only one CPU core. If KM4 is chosen, KM0 will be waked up first and then KM0 will resume KM4.

Users can set the wakeup attribute in sleep_wevent_config[] in ameba_sleepcfg.c to choose which CPU you want to wake up. The wakeup attribute of each wakeup source can be set to WAKEUP_KM4 or WAKEUP_KM0 or WAKEUP_NULL, respectively indicating that this wakeup source is only to wake up KM4, or wake up KM0, or not used as a wakeup source.

/* Wakeup entry can be set to WAKEUP_NULL/WAKEUP_KM4/WAKEUP_KM0 */
WakeEvent_TypeDef sleep_wevent_config[] = {
   //   Module                    Wakeup
   {WAKE_SRC_SDIO,                WAKEUP_NULL},
   {WAKE_SRC_AON_WAKEPIN,         WAKEUP_NULL},
   {WAKE_SRC_AON_TIM,             WAKEUP_NULL},
   {WAKE_SRC_Keyscan,             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_CTOUCH,              WAKEUP_NULL},
   {WAKE_SRC_I2C1,                WAKEUP_NULL},
   {WAKE_SRC_I2C0,                WAKEUP_NULL},
   {WAKE_SRC_GPIOB,               WAKEUP_NULL},
   {WAKE_SRC_GPIOA,               WAKEUP_NULL},
   {WAKE_SRC_UART_LOG,            WAKEUP_NULL},
   {WAKE_SRC_UART2_BT,            WAKEUP_NULL},
   {WAKE_SRC_UART1,               WAKEUP_NULL},
   {WAKE_SRC_UART0,               WAKEUP_NULL},
   {WAKE_SRC_pmc_timer1,          WAKEUP_KM0},  /* Internal use, do not change it */
   {WAKE_SRC_pmc_timer0,          WAKEUP_KM4},  /* Internal use, do not change it */
   {WAKE_SRC_Timer7,              WAKEUP_NULL},
   {WAKE_SRC_Timer6,              WAKEUP_NULL},
   {WAKE_SRC_Timer5,              WAKEUP_NULL},
   {WAKE_SRC_Timer4,              WAKEUP_NULL},
   {WAKE_SRC_IPC_KM4,             WAKEUP_KM4},  /* IPC can only wake up KM4, do not change it */
   {WAKE_SRC_BT_WAKE_HOST,        WAKEUP_NULL},
   {WAKE_SRC_KM4_WAKE_IRQ,        WAKEUP_KM0},  /* Internal use, do not change it */
   {WAKE_SRC_WIFI_FTSR_MAILBOX,   WAKEUP_KM0},  /* Wi-Fi wakeup, do not change it */
   {WAKE_SRC_WIFI_FISR_FESR_IRQ,  WAKEUP_KM0},  /* Wi-Fi wakeup, do not change it */
   {0xFFFFFFFF,                   WAKEUP_NULL},
};

AON Wakepin Configuration

AON wakepin is one of the peripherals that can be set as a wakeup source. SoC has two AON wakepins (PB30 and PB31), which can be configured in sleep_wakepin_config[] in ameba_sleepcfg.c. The config attribute can be set to DISABLE_WAKEPIN or HIGH_LEVEL_WAKEUP or LOW_LEVEL_WAKEUP, meaning not wake up, or GPIO level high will wake up, or GPIO level low will wake up respectively.

/* can be used by sleep mode & deep sleep mode */
/* config can be set to DISABLE_WAKEPIN/HIGH_LEVEL_WAKEUP/LOW_LEVEL_WAKEUP */
WAKEPIN_TypeDef sleep_wakepin_config[] = {
   //   wakepin      config
   {WAKEPIN_0,    DISABLE_WAKEPIN},  /* WAKEPIN_0 corresponding to _PB_30 */
   {WAKEPIN_1,    DISABLE_WAKEPIN},  /* WAKEPIN_1 corresponding to _PB_31 */
   {0xFFFFFFFF,  DISABLE_WAKEPIN},
};

Note

  • By default, AON_WAKEPIN_IRQ will not be enabled in sleep_wakepin_config[], and users need to enable it by themselves.

  • The wakeup mask will not be set in sleep_wakepin_config[]. If wakepin is used for sleep mode, WAKE_SRC_AON_WAKEPIN entry needs to be set in sleep_wevent_config[].

Clock and Voltage Configuration

The XTAL, OSC4M state, and sleep mode voltage are configurable in ps_config[] in ameba_sleepcfg.c. Users can use this configuration for peripherals that need XTAL or OSC4M on in sleep mode.

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 details */
   .sleep_to_08V = FALSE,        /* Default sleep to 0.7V, setting this option to TRUE will sleep to 0.8V */
};

Sleep mode Configuration

  • Application software can set sleep mode to CG or PG by calling pmu_set_sleep_type(uint32_t type)().

  • Users can get CPUโ€™s sleep mode by calling pmu_get_sleep_type().

Note

  • KM0 and KM4 are in the same power domain, so they will have the same sleep type, thus pmu_set_sleep_type() should be set to KM4, and KM0 will follow KM4โ€™s sleep mode type.

  • Sleep mode is set to PG by default. If users want to change the sleep type, pmu_set_sleep_type() needs to be called before sleep.

UART and LOGUART๏ƒ

For peripherals that require specific clock settings, such as UART and LOGUART, the configuration procedures are described in the following sections.

  1. Initialize UART/LOGUART and enable their interrupts.

  2. Set the wake-up source: In sleep_wevent_config[], configure the wake-up source (UART0/UART1/UART2_BT/UART_LOG) and specify the CPU to be woken up (WAKEUP_KM4 or WAKEUP_KM0). Ensure the interrupt is registered on the CPU to be woken up.

  3. Select the clock source:

    1. XTAL: In ps_config[], set xtal_mode_in_sleep to XTAL_Normal and set keep_OSC4M_on to TRUE.

    2. OSC2M: In ps_config[], set keep_OSC4M_on to TRUE.

  4. Set the operating voltage: In ps_config[], set sleep_to_08V to TRUE.

  5. Enter sleep mode by releasing the wake lock on KM4 (PMU_OS needs to be released because it is acquired by default at system startup).

  6. Clear the UART/LOGUART interrupt after waking up.

Note

  • When using UART as a wake-up source, the following limitations apply:

  • The Rx clock source can only be OSC2M, and OSC4M must not be turned off during sleep. It is not recommended to use UART as a wake-up source when the baud rate is greater than 115200.

    • Before sleep, you need to call the API RCC_PeriphClockSource_UART(UARTx_DEV, UART_RX_CLK_OSC_LP) to switch the clock to OSC2M.

    • If higher baud rate is required after waking up, you can use the API RCC_PeriphClockSource_UART(UARTx_DEV, UART_RX_CLK_XTAL_40M) to switch to XTAL40M Rx clock.

  • Any part of commands used for wake-up that exceed the FIFO depth (64 bytes) will be lost.

  • When using LOGUART as a wake-up source, the following limitations apply:

  • If the Rx clock source is OSC2M, OSC4M must not be turned off during sleep.

    • Before sleep, you need to call the API RCC_PeriphClockSource_LOGUART(LOGUART_CLK_OSC_LP) to switch the clock to OSC2M.

    • If higher baud rate is required after waking up, you can use the API RCC_PeriphClockSource_LOGUART(LOGUART_CLK_XTAL_40M) to switch to XTAL40M Rx clock.

  • If the Rx clock source is XTAL40M, XTAL must not be turned off during sleep.

  • Any part of commands used for wake-up that exceed the FIFO depth (16 bytes) will be lost.