Last edited 2 weeks ago

STM32MP2 low power firmware overview

Applicable for STM32MP21x lines, STM32MP23x lines, STM32MP25x lines

This article gives information about the low power management firmware for STM32MP2 series with M33-TD flavor .

Trusted domain applicability
This article is only applicable to M33-TD flavor of STM32MP2 series

1. Framework purpose[edit | edit source]

The purpose of this article is to explain how in FwST-M Packages this firmware handles the STM32MP2 series power management firmware for M33-TD flavor :

  • Cortex-M33 firmware based on HAL, running in RETRAM
  • loaded and used by TF-M, with the power management (PM) partition
  • set DDR in Software Self Refresh (SSR) mode
  • request system low power mode: Stop2 or Standby mode
  • store and restore the minimal part of the system configuration for Standby mode

See also the page STM32MP2 power overview.

2. System overview[edit | edit source]

STM32MP2 low power firmware is an element of the STM32MP2 series low power mode sequence M33-TD flavor , executed by Cortex-M33 in RETRAM:

  • last element for entry in low power mode: which sets the DDR in self refresh and requests the system low power mode.
  • first element for exit from low power mode: executed by hardware on Standby exit when RAMCFG CRC, restores minimal system resources for Standby exit before jumping to TF-M

2.1. Component description[edit | edit source]

The STM32MP2 low power firmware interacts directly with few components describe here; see the page STM32MP2 power overview for other components description.

TF-M overview: secure OS on Cortex-M33:

  • PM service: STM32MP2 service used to load the firmware in RETRAM and handle low power request by cortex-M33 non-secure firmware

STM32MP2 low power firmware:

  • DDR driver: manages DDR self refresh.

STM32 peripherals (Hardware):

2.2. API description[edit | edit source]

The CMake interface is provided to TF-M in interface/

3. Configuration[edit | edit source]

The firmware configuration is done with CMake with the variables:

  • STM32_SOC_NAME
  • STM32_DDR_TYPE
  • STM32_DDR_FREQ
  • STM32_DDR_SIZE

These parameters are provided by TF-M CMake when the firmware is compiled.

Other debug configuration flags exists:

  • STM32MP2_LP_HALT_ON_ERROR
  • STM32MP2_LP_FAULT_INFO
  • ENABLE_BACKTRACE

And other Cmake variables are defined and can be used by TF-M

  • STM32MP2_LP_SHARED_DATA: address of shared data used API, by default in RETRAM after firmware, need to be accessible by TF-M and low power firmware and preserved during Standby mode.

4. How to use the framework[edit | edit source]

The STM32MP2 low power firmware is compiled in TF-M with the PM partition. This PM partition loads the firmware in RETRAM, compute CRC for Standby exit and handle low power mode request:

TF-M configures this STM32MP2 low power firmware with a shared memory defined in API source and located at address defined by STM32MP2_LP_SHARED_DATA before executing it.

The expected mode (initialization or low power mode entry) for next firmware execution is provided by stm32mp2_lp_fw_set_lpmode(). The firmware is executed with a call to stm32mp2_lp_fw_exec() and the firmware returns to caller with restored registers and a result.

The available API functions are:

  • shared data management:
    • stm32mp2_lp_fw_clear_data()
    • stm32mp2_lp_fw_mark_data_valid()
    • stm32mp2_lp_fw_check_data_valid()
  • function for firmware initialization, executed with mode = STM32MP2_LP_FW_LPMODE_INIT
    • stm32mp2_lp_fw_set_uart_addr(): used uart instance for trace, the same UART instance that TF-M console by default
    • stm32mp2_lp_fw_set_mkey(): value of the encryption key, to be restore at standby exit
  • stm32mp2_lp_fw_set_lpmode(): configure the expected mode (initialization or entry in low power mode) for next execution
  • stm32mp2_lp_fw_exec(): jump to low power firmware

5. How to trace and debug the framework[edit | edit source]

5.1. How to trace[edit | edit source]

The STM32MP2 low-power firmware information, including the firmware code version and the versions of the hardware abstraction layer (HAL) components used is displayed during firmware initialization.

For low power mode request, the firmware can display a trace if console is not suspended, i.e. when STM32_CONSOLE_NO_SUSPEND is activated in TF-M compilation in TF-M UART driver suspend function.

For Standby exit, the trace is not available.

5.2. How to debug[edit | edit source]

When trace is not sufficient, use GDB to debug firmware execution.

To avoid debugger interference, deactivate the watchdog, add an infinite loop (with a volatile variable to avoid compiler optimization) in the part to debug, and connect to the running target only when this infinite loop is reached

Warning
On connection, the default OpenOCD script sets bits in the DBGMCU_CR register of DBGMCU to simulate low-power mode and avoid JTAG disconnection:
  • Bit 2: DBG_STANDBY
  • Bit 1: DBG_STOP
  • Bit 0: DBG_SLEEP

To test low-power mode correctly after OpenOCD starts, reset the device with a cold boot to clear these bits, or clear this register manually.

6. Source code location[edit | edit source]

The STM32MP2 low power firmware source code is composed of:

  • STM32MP2 HAL driver, GIT fetched by CMake rules in cmake/ or provided by TF-M (default)
  • code define in stm32mp2-low-power git repository, in directory src/

7. To go further[edit | edit source]

You can compile the firmware outside TF-M and with the compilation toolchain provided by the Developer Package.

Refer to Setup Cross Compile Environment.

For the default configuration

 cmake -S . 
 cmake --build .

or for a specific configuration:

 cmake -S . -DSTM32_SOC_NAME=STM32MP215Fxx -DSTM32_DDR_TYPE=STM32MP_LPDDR4_TYPE -DSTM32_DDR_FREQ=800000 -DSTM32_DDR_SIZE=0x80000000
 cmake --build .

8. References[edit | edit source]