7. Low-power SRD domain application example

This section describes, through an example, how to use the SRD domain to implement low-power applications.

7.1 Introduction

The first part of the description explains how the EXTI, RCC and PWR blocks interact with each other and with the other system blocks. A detailed explanation on how the DMAMUX2 can be used to free the CPU is also provided.

The second part explains how to use the Autonomous mode to perform simple data transfers through an example of LPUART1 transmission.

Register programming is detailed only for the blocks related to the Autonomous mode.

7.2 EXTI, RCC and PWR interconnections

Figure 40 shows the main EXTI, RCC and PWR interconnections.

Figure 40. EXTI, RCC and PWR interconnections

Block diagram showing EXTI, RCC, and PWR interconnections between CD, SRD, and VSW domains.

The diagram illustrates the interconnections between various system components across three power domains: CD (orange), SRD (green), and VSW (blue). A central green block labeled EXTI manages event and interrupt signals. It receives Configurable Event inputs and Direct Event inputs from various sources:

The EXTI block outputs signals to other modules:

The RCC (green) block provides clock and control signals:

The CPU also sends a c[21]_deepsleep signal to the RCC.

Legend:
CD domain
SRD domain
VSW domain

MSv50666V3

Block diagram showing EXTI, RCC, and PWR interconnections between CD, SRD, and VSW domains.

7.2.1 Interrupts and wake-up

Three kinds of signals are exchanged between the peripherals. They can be used to wake up the system from Stop mode:

Some peripherals can generate interrupt events, even if their bus interface clock is not present. These interrupt events are called wake-up events (or asynchronous interrupts).

Example: i2c1_wkup, usart1_wkup and lptim1_wkup.

Some peripherals generate a pulse instead of an interrupt signal. These pulses are called signals.

Examples: lptim2_out and lptim3_out.

Contrary to signals, the interrupts should be cleared by a CPU or any other bus master, either by clearing the corresponding event bit in the peripheral register or by updating the FIFO interrupt level.

All the interrupts associated to system peripherals are directly connected to the NVIC, except for the peripherals which are able to wake up the system from Stop mode or the CPU from CStop. In this latter case, the interrupts, signals or wake-up events are connected to the NVIC via the EXTI.

Example: spi1_it, tim1_brk_it and tim1_upd_it.

The interrupt and wake-up sources that require to be cleared in the peripheral itself are connected to EXTI Direct Event inputs. The EXTI does not manage any CPU status pending bit.

The peripherals signals are connected to EXTI Configurable Event inputs. These EXTI inputs provide a CPU status pending bit which needs to be cleared by the application.

7.2.2 Block interactions

Interaction between EXTI and PWR blocks

The EXTI delivers wake-up requests signals ( exti_cd_wkup , exti_srd_wkup ) to the PWR controller. These signals are activated according to the state of the interrupts, signals or wake-up events connected to the EXTI. These wake-up requests are used by the PWR controller to supply the domain who needs to handle the activated wake-up event generated by the peripherals.

Interaction between PWR and RCC blocks

The PWR block controls the V CORE supply according to the system operating mode (CRun, CSleep or CStop). For DStop2 (Retention mode), the PWR controller also controls the power switch (ePOD) that cuts the supply of part of the CD domain.

The RCC block controls the clock generation in accordance with the system operating mode. It is also responsible for reset generation.

To synchronize the system mode transitions, the RCC block is tightly coupled with the PWR controller:

Interaction between EXTI and SRD domain

All the wake-up event inputs received by the EXTI from the peripherals located in SRD domain can be used to perform operations in Autonomous mode without activating the CPU.

The EXTI SRD_PenClear[3:0] inputs received from the SRD domain are used to acknowledge the ongoing wake-up requests generated by peripherals located in the SRD domain. The SRD_PenClear[3:0] inputs allow switching the system SRD domain from Run to Stop mode.

7.2.3 Role of DMAMUX2 in SRD domain

The DMAMUX2 implemented in the SRD domain allows chaining BDMA2 transfers. BDMA2 requests are synchronized thanks to trigger events ( dmamux2_evttx ) which can be generated when the expected amount of data has been transferred.

These events can also trigger DMAMUX2 request generators ( REQ_GEN[3:0] ), and thus chain several BDMA2 transfers. In fact REQ_GEN[3:0] can be triggered indirectly by all the wake-up events generated by all SRD domain peripherals.

Like LPTIM3 and LPTIM2 outputs, dmamux2_evt7 and dmamux2_evt6 events are connected to the EXTI. They can be used to switch the SRD domain from DRun to DStop or DStop2 mode when the task requested by the wake-up event is complete.

7.3 Low-power application example based on LPUART1 transmission

This section illustrates, through an example, the benefit of the SRD domain usage on power consumption. To help the user program the device, only the key register settings are given herein.

Refer to Sections Reset and clock control (RCC) and Power control (PWR) for additional details.

7.3.1 Memory retention

The SRD domain features 32 Kbytes of SRAM (SRD SRAM). When the CD domain is in DStop or DStop2 mode while the system is in Run mode, data can be transferred between this RAM area and to/from a peripheral located in the SRD domain.

DStop2 and DStop are very similar from user point of view. In DStop2 mode the asynchronous logic is switched off while RAM and register contents are maintained. This allows further leakage current consumption reduction compared to DStop mode. When exiting DStop2, the CPU domain resumes normal execution at the cost of a slightly higher startup time.

In DStop/DStop2 modes, all the CD domain clocks are OFF but data are retained. The power consumption in DStop/DStop2 mode can be further optimized by choosing to shut off some SRAMs with the consequence to lose their content (see Section 6: Power control (PWR) ).

Note: SRD SRAM remains available as long as the system is not in Standby mode.
If the system is in Standby mode, it is still possible to use the BKUP_SRAM. However, its size is limited to 4 Kbytes.

7.3.2 Memory-to-peripheral transfer using LPUART1 interface

Example description

Figure 41 shows the proposed implementation. At a regular time interval given by LPTIM2, the CPU wakes up from CStop mode (which domain is in DStop/DStop2). When the CPU is in Run mode, it prepares the data to be transmitted via LPUART1, transfers them to SRD SRAM, and goes back to CStop. The SRD domain is configured to perform data transfers via LPUART1 and go back to Stop mode when the transfer is complete.

The LPTIM2 interface is used to wake up the system from Stop at regular time intervals. the CPU must then perform the following operations:

  1. 1. Recover the application from the system Stop mode (RECO).
  2. 2. Process the new data to be sent via LPUART1 (PROC).
  3. 3. Transfer the data into SRD SRAM (XFER).
  4. 4. Configure the DMAMUX2, the BDMA2, the LPUART1, and the RCC (CFG).
  5. 5. Configure the EXTI (CFG).
  6. 6. Configure the PWR block to allow the CD domain to go to DStop/DStop2 mode.
  7. 7. Set the CPU to Stop mode.

The SRD domain executes the following tasks in Autonomous mode:

  1. 1. Transfer the data from SRD SRAM to LPUART1, using BDMA2.
  2. 2. When the LPUART1 interface indicates that the last byte has been transferred, the SRD domain is switched to Stop mode.

Figure 41. Timing diagram of SRD SRAM-to-LPUART1 transfer with BDMA2 and SRD domain in Autonomous mode

Timing diagram showing the sequence of events for SRD SRAM-to-LPUART1 transfer. The diagram includes four horizontal timelines: Iptim2_wkup (wake-up signal), CPU processing (showing startup, config, data processing, and stop phases), CD State (Core Domain state: OFF, DRun, DStop/DStop2), and SRD processing (showing memory transfer to LPUART1). The System / SRD State timeline shows the transition from OFF to Run, then Autonomous, then Stop, and finally Run again when the wake-up signal is active. A legend defines the CPU processing phases: STRT (Power-on reset startup), CFG (Peripherals initialization), RECO (Recover from the Stop), XFER (Transfer of processed data to SRD SRAM), PROC (Data processing), and STP (Control of EXTI, BDMA2 and LPUART1 prior to go to CSTOP).

Legend:

MSv50667V3

Timing diagram showing the sequence of events for SRD SRAM-to-LPUART1 transfer. The diagram includes four horizontal timelines: Iptim2_wkup (wake-up signal), CPU processing (showing startup, config, data processing, and stop phases), CD State (Core Domain state: OFF, DRun, DStop/DStop2), and SRD processing (showing memory transfer to LPUART1). The System / SRD State timeline shows the transition from OFF to Run, then Autonomous, then Stop, and finally Run again when the wake-up signal is active. A legend defines the CPU processing phases: STRT (Power-on reset startup), CFG (Peripherals initialization), RECO (Recover from the Stop), XFER (Transfer of processed data to SRD SRAM), PROC (Data processing), and STP (Control of EXTI, BDMA2 and LPUART1 prior to go to CSTOP).

Note: The RUN_SRD bit can be used to force the SRD domain to remain in Run mode when the CD domain enters DStop or DStop2 mode.

If the CPU is not running, the SRD domain is not able to switch on its own from Run to Stop mode.

The proposed solution is explained in details in the following sections. It consists in setting a wake-up event for the SRD domain before the CD domain enters DStop/DStop2 mode. In this way the SRD domain remains in run mode and enters Stop mode only when this request is cleared.

RCC programming

Before entering Autonomous mode (CD domain in DStop/DStop2 mode with SRD domain in Run mode), the RCC must be programmed to request the needed clocks to remain enabled. In this example, they are required for the SRD SRAM, BDMA2/DMAMUX2, LPTIM2, GPIOs and LPUART1

LPUART1 can use its own APB clock as kernel clock. Since the system will not enter Stop mode before LPUART1 has completed data transfer, PLLx can be used to provide clocks to the peripherals.

PWR programming

In this example, the PWR block must be programmed in order to:

Note: SRD domain could enter Standby as well, but in this case the LPTIM2 could not be used to wake up the system and the AWU should be used instead. In addition, everything must be reprogrammed when the system wakes up.

EXTI programming

The EXTI block must be configured to provide the following services:

The EXTI block is configured once before performing the first data transfer. For incoming data transfers, the programmed configuration remains unchanged; only some events need to be triggered or acknowledged.

Note: The CPU uses the event input number 0 to generate a software event. LPTIM2 wake-up signal is connected to event input number 48 (direct event input).

All other event inputs must be disabled: EXTI_RTSRx_TRy = '0' and EXTI_FTSRx_TRy = '0'.

To generate a wake-up event for SRD domain, the CPU must write SWIER0 bit of EXTI_SWIER1 to '1'.

BDMA2 and DMAMUX2 programming

Two BDMA2 channels are required to execute data transfers via LPUART1.

BDMA2 channel 0 does not use DMAMUX2 trigger capabilities. Refer to Table 48 for initialization details.

BDMA2 channel 7 uses REQ_GEN0 to generate BDMA2 requests. The generation of BDMA2 requests is triggered by the LPUART1 transmit interrupt ( lpuart1_tx_it ). The LPUART1 interface generates lpuart1_tx_it interrupt when the transmit complete event is detected. The BDMA2 then clears the pending interrupt by performing a write operation to the LPUART1.

The SYNC7 block is programmed in Free-running mode. It generates a pulse on its dmamux2_evt7 output when the BDMA2 request generated by the REQ_GEN0 is complete. dmamux2_evt7 signal is used by the EXTI to switch back the SRD domain to Stop mode.

Figure 42 shows the active signal paths via DMAMUX2. The grayed blocks represent the unused paths.

Figure 42. BDMA2 and DMAMUX2 interconnection

Block diagram showing the interconnection between LPUART1, DMAMUX2, BDMA2, and EXTI. LPUART1's TX DMA signal (lpuart1_tx_dma) and IT_T signal are connected to DMAMUX2. DMAMUX2 contains REQ_GEN0, which is triggered by the IT_T signal via dmamux_trg[31:0]. DMAMUX2 has multiple output paths: dmamux_req[15:6] and dmamux_req7 connect to SYNC0, which then connects to BDMA2 channel CH0; dmamux_req[15:1] and dmamux_req0 connect to SYNC7, which connects to BDMA2 channel CH7. Both channels of BDMA2 have TC_ReqCnt signals (TC_ReqCnt_ch0 and TC_ReqCnt_ch7) connected to the EXTI block. The EXTI block also receives dmamux2_evt7 from SYNC7 and has a SRD_PendClear[1] signal. A 22-bit constant is also shown as an input to REQ_GEN0. The diagram is labeled MSv50668V1.
Block diagram showing the interconnection between LPUART1, DMAMUX2, BDMA2, and EXTI. LPUART1's TX DMA signal (lpuart1_tx_dma) and IT_T signal are connected to DMAMUX2. DMAMUX2 contains REQ_GEN0, which is triggered by the IT_T signal via dmamux_trg[31:0]. DMAMUX2 has multiple output paths: dmamux_req[15:6] and dmamux_req7 connect to SYNC0, which then connects to BDMA2 channel CH0; dmamux_req[15:1] and dmamux_req0 connect to SYNC7, which connects to BDMA2 channel CH7. Both channels of BDMA2 have TC_ReqCnt signals (TC_ReqCnt_ch0 and TC_ReqCnt_ch7) connected to the EXTI block. The EXTI block also receives dmamux2_evt7 from SYNC7 and has a SRD_PendClear[1] signal. A 22-bit constant is also shown as an input to REQ_GEN0. The diagram is labeled MSv50668V1.

Table 48 explain how to program BDMA2 and DMAMUX2 key functions. The way errors are handled is not described.

Table 48. BDMA2 and DMAMUX2 initialization sequence (DMAMUX2_INIT)

PeripheralsRegister contentRelated actions
DMAMUX2
SYNC0
DMAREQ_ID of DMAMUX2_C0CR = '10'
SE of DMAMUX2_C0CR = '0'
EGE of DMAMUX2_C0CR = '0'
NBREQ of DMAMUX2_C0CR = '0'
Selects LPUART_TX BDMA2 request.
Disables block synchronization.
No event generation.
Generates an event every BDMA2 transfer (Free-running mode).
DMAMUX2
SYNC7
DMAREQ_ID of DMAMUX2_C7CR = '0'
SE of DMAMUX2_C7CR = '0'
EGE of DMAMUX2_C7CR = '1'
NBREQ of DMAMUX2_C7CR = '0'
Selects of REQ_GEN0 as BDMA2 request.
Disables block synchronization.
Enables event generation.
Generates an event every BDMA2 transfer (Free-running mode).
DMAMUX2
REQ_GEN0
SIG_ID of DMAMUX2_RG0CR = '0d24'
GPOL of DMAMUX2_RG0CR = '0b01'
GNBREQ of DMAMUX2_RG0CR = '0'
GE of DMAMUX2_RG0CR = '1'
Selects LPUART TX interrupt as trigger.
Trigger on rising edge of the event.
Generates only one BDMA2 request.
Enables generator.

Table 48. BDMA2 and DMAMUX2 initialization sequence (DMAMUX2_INIT) (continued)

PeripheralsRegister contentRelated actions
BDMA2 - CH0NDT bits of BDMA_CNDTR0 = DatNber
PA of BDMA_CPAR0 = &LPUART1_TDR
MA of BDMA_CMAR0 = &DatBuff
DIR of BDMA_CCR0 = '1'
CIRC of BDMA_CCR0 = '0'
PINC of BDMA_CCR0 = '0'
MINC of BDMA_CCR0 = '1'
PSIZE of BDMA_CCR0 = '0'
MSIZE of BDMA_CCR0 = '1'
MEM2MEM of BDMA_CCR0 = '0'
Number of data to transfer.
Address of LPUART1_TDR.
Address of memory buffer of SRD SRAM.
Read from memory.
Circular mode disabled.
Peripheral increment disabled.
Memory increment enabled.
Peripheral size = 8 bits.
Memory size = 8 bits.
Memory to memory disabled.
BDMA2 - CH7NDT bits of BDMA_CNDTR7 = '1'
PA of BDMA_CPAR7 = &LPUART1_ICR
MA of BDMA_CMAR7 = &DatClrTC
DIR of BDMA_CCR7 = '1'
CIRC of BDMA_CCR7 = '0'
PINC of BDMA_CCR7 = '0'
MINC of BDMA_CCR7 = '1'
PSIZE of BDMA_CCR7 = 2
MSIZE of BDMA_CCR7 = 2
MEM2MEM of BDMA_CCR7 = '0'
Only one data transferred.
Address of LPUART1_ICR (Interrupt Flag Clear Reg.).
Address of a variable located into SRD SRAM. This variable must contain 0x0040 in order to clear the TC flag.
Read from memory.
Circular mode disabled.
Peripheral increment disabled.
Memory increment disabled.
Peripheral size = 32 bits.
Memory size = 32 bits.
Memory to memory disabled.

LPTIM2 programming

When LPTIM2 wake-up event occurs, the CPU reboots and SRD domain mode is also set to Run mode.

An interrupt issued by LPTIM2 is pending on the CPU NVIC. LPTIM2 interrupt handler must acknowledge this LPTIM2 interrupt by writing ARRMCF bit in LPTIM2_ICR register to '1' (LPTIM2_Ack).

LPUART programming

In the use-case described herein, the capability of the LPUART1 to request the kernel clock according to some events is not used.

LPUART1 is programmed so that it generates a BDMA request when its TX-FIFO is not full.

LPUART1 also generates an interrupt when the TX-FIFO and its transmit shift register are empty. This interrupt is used to switch the SRD domain to Stop mode.

Table 49 gives the key settings concerning the handling of Stop mode for LPUART1.

Table 49. LPUART1 Initial programming (LPUART1_INIT)
Register contentRelated actions
FIFOEN of LPUART1_CR1 = '1'Enables FIFO. BDMA2 will then use TXFNF (TXFIFO Not Full) flag for generating the BDMA2 requests.
TCIE of LPUART1_CR1 = '0'Disables interrupt when the transmit buffer is empty.
UE of LPUART1_CR1 = '1'Enables BDMA2.
TE of LPUART1_CR1 = '1'Enables the LPUART1.
TXE of LPUART1_CR1 = '1'Enables transmission.
DMAT of LPUART1_CR3 = '1'Enables the BDMA2 mode for transmission.

Respect the sequence described in Table 50 to enable LPUART1.

Table 50. LPUART1 start programming (LPUART1_Start)
Register contentRelated actions
TCCF of LPUART1_ICR = '1'Clears the TC flag, to avoid immediate interrupt generation, which would clear the SRD_PendClear[1] in EXTI.
TCIE of LPUART1_CR1 = '1'Enables interrupt when the transmit buffer is empty.

7.3.3 Overall description of the low-power application example based on LPUART1 transmission

After a Power-on reset, the CPU perform the following operations:

  1. 1. Boot sequence (not described here).
  2. 2. Full initialization of RCC, PWR, EXTI, LPUART1, GPIOs, LPTIM2, DMAMUX2, BDMA2 and NVIC.
    Only the relevant steps of RCC, EXTI, PWR, LPUART1, BDMA2 and DMAMUX2 initialization related to the Autonomous mode are described herein. Refer to the previous sections for additional details.
  3. 3. The CPU processes the data to be transferred and copies them to SRD SRAM.
  4. 4. The CPU generates a wake-up event (EXTI_Event) to maintain SRD in Run mode when CD enters DStop/DStop2.
  5. 5. The CPU enables the BDMA2 to start LPUART transmission and goes to CStop mode. As it is allowed to do so, CD domain enters DStop/DStop2 while SRD remains in Run mode. The data stored in SRD SRAM are retained while the CD domain is in DStop/DStop2 mode.
  6. 6. As soon as the BDMA2 is enabled, it serves the request from LPUART1 in order to fill its TX-FIFO. In parallel, serial data transmission can start.
  7. 7. When the expected amount of data has been transmitted (NDT bits of BDMA_CNDTR0 set to 0), the BDMA2 no longer provides data to the LPUART1. The LPUART1 generates an interrupt when the TX-FIFO and the transmit buffer are empty.
  8. 8. This interrupt triggers DMAMUX2 REQ_GEN0, thus activating a data transfer via BDMA2 channel 7 (BDMA_Ch7). This transfer clears LPUART1 TC flag, and the lpuart1_tx_it is reset to '0'.
  9. 9. The end of this transfer triggers a dmamux2_evt7 signal which is used to clear the wake-up request generated by the CPU.
  10. 10. As a consequence, the SRD domain (i.e. the system) enters Stop mode and the system clock is gated. LPTIM2 still operates since it uses ck_lsi clock.
  1. 11. LPTIM2 lptim2_wkup interrupt wakes up the system. The device exits from Stop mode with the HSI clock. The CPU must restore the proper clock configuration during the warm re-boot sequence and perform the following tasks:
    1. a) Acknowledge LPTIM2 wake-up interrupt,
    2. b) Process the next data block and transfers them to SRD SRAM,
    3. c) Generate again a wake-up event for SRD domain,
    4. d) Start the BDMA2.
    5. e) Go back to CStop mode.

Note: The CPU does not need to initialize BDMA2, DMAMUX2 and LPUART1 again.

Figure 43. Timing diagram of LPUART1 transmission with SRD domain in Autonomous mode

Timing diagram of LPUART1 transmission with SRD domain in Autonomous mode. The diagram shows the sequence of events for CPU processing, LPTIM2 wake-up, CD State, System / SRD State, LPUART1_TXD, bdma_ch0, lpuart1_tx_it, bdma_ch7 (REQ_GEN0), dmamux2_evt7, and System Clock. The sequence starts with Boot, followed by RCC_INIT, PWR_INIT, EXTI_INIT, LPTIM2_INIT, LPTIM2_Start, LPUART1_INIT, DMAMUX2_INIT, Data Proc., EXTI_Event, LPUART1_Start, BDMA2_Start, and Go to CStop. The CPU processing line shows a warm boot sequence. The LPTIM2_wkup line shows a pulse. The CD State line shows OFF, DRun, DStop/DStop2, DRun, DStop/DStop2. The System / SRD State line shows OFF, Run, Autonomous, Stop, Run, Autonomous, Stop. The LPUART1_TXD line shows data blocks D1, D2, D3, DN. The bdma_ch0 line shows pulses. The lpuart1_tx_it line shows a pulse. The bdma_ch7 (REQ_GEN0) line shows a pulse. The dmamux2_evt7 line shows a pulse. The System Clock line shows a shaded area.

The timing diagram illustrates the sequence of events for LPUART1 transmission in autonomous mode with the SRD domain. The diagram is divided into several horizontal timelines:

Numbered callouts (1-6) indicate key events: 1. LPTIM2_Start, 2. LPUART1_Start, 3. BDMA2_Start, 4. EXTI_Event, 5. lpuart1_tx_it, 6. Warm Boot.

MSv50669V3

Timing diagram of LPUART1 transmission with SRD domain in Autonomous mode. The diagram shows the sequence of events for CPU processing, LPTIM2 wake-up, CD State, System / SRD State, LPUART1_TXD, bdma_ch0, lpuart1_tx_it, bdma_ch7 (REQ_GEN0), dmamux2_evt7, and System Clock. The sequence starts with Boot, followed by RCC_INIT, PWR_INIT, EXTI_INIT, LPTIM2_INIT, LPTIM2_Start, LPUART1_INIT, DMAMUX2_INIT, Data Proc., EXTI_Event, LPUART1_Start, BDMA2_Start, and Go to CStop. The CPU processing line shows a warm boot sequence. The LPTIM2_wkup line shows a pulse. The CD State line shows OFF, DRun, DStop/DStop2, DRun, DStop/DStop2. The System / SRD State line shows OFF, Run, Autonomous, Stop, Run, Autonomous, Stop. The LPUART1_TXD line shows data blocks D1, D2, D3, DN. The bdma_ch0 line shows pulses. The lpuart1_tx_it line shows a pulse. The bdma_ch7 (REQ_GEN0) line shows a pulse. The dmamux2_evt7 line shows a pulse. The System Clock line shows a shaded area.

7.3.4 Alternate implementations

More power efficient implementations are also possible. As an example the system clock can be stopped once the data have been transferred to LPUART1 TX-FIFO, instead of remaining activated during the whole transmission as in the example presented above. In this case, the LPUART1 must use ck_hsi or ck_csi as kernel clock when the system switches from Run to Stop mode. LPUART1 must be programmed to wake up SRD domain when its TX-FIFO is almost empty. This asynchronous interrupt can be used as trigger by the REQ_GENx of the DMAMUX2, which will perform a given number (e.g. 14) of data transfers to LPUART1_TDR and then switch back the SRD domain to Stop mode. This implementation is possible because the LPUART1 can request the kernel clock as long as the TX-FIFO and transmit buffer are not empty.

Further power consumption reduction during DStop/DStop2 mode can be achieved by shutting off the SRAMs located in the CD domain. Their content is then lost (see Section 6: Power control (PWR) for more details).

7.4 Other low-power applications

Other peripherals located in SRD domain, such as I2C4, SPI6/I2S6, DFSDM2 or DAC2, can be used to implement low-power applications.