cancel
Showing results for 
Search instead for 
Did you mean: 

How to access SRAM under debug in Sleep mode with the STM32L476

paradouxe
ST Employee

Introduction

Accessing SRAM during Sleep mode for debugging purposes on the STM32L476 MCU requires a specific device configuration, relative to the memory architecture of the STM32L4 and the optimization strategies for low-power consumption.  

To summarize, SRAM access is constraint in the following contexts:

  • SRAM access is disabled in Sleep mode to reduce power consumption, which is a default behavior in low-power operations.
  • The debug interface loses its ability to read or write to SRAM memory during Sleep mode, affecting real-time debugging capabilities.
  • Tools and functionalities that depend on uninterrupted memory access, such as SEGGER Real Time Transfer (RTT), are unable to operate as intended when the microcontroller is in a low-power state.

This article explores the memory architecture of the STM32L476, the limitations encountered in low-power modes, and presents a DMA-based workaround to overcome these challenges.

1. Explanation: STM32L476 memory architecture

1.1. SRAM memory structure and access

In the STM32L476 microcontroller, the memory architecture is built around a BusMatrix that manages access arbitration between various controllers. This includes the Cortex®-M4 core's I-bus, D-bus, and S-bus, as well as DMA controllers. This matrix also connects to eight target components, such as internal flash, SRAM1, and SRAM2. This architecture ensures efficient data transfer tailored to specific use cases.

The D-bus (S1) is a crucial link between the Cortex®-M4 core's data bus and the BusMatrix. It is utilized by the core for literal loads and during debug access, providing uninterrupted access to SRAM. This facilitates efficient operation and debugging by offering a direct pathway to SRAM via the D-bus, enabling real-time data inspection and manipulation.

ArticlePicture1.png

1.2. Impact on power supply consumption and access in low-power modes

The STM32L476 has several low-power modes available to save power when the CPU does not need to be kept running. Each of these modes is designed to provide a balance between power conservation and the ability to maintain system state, keep some peripherals available or respond to external events.

For example, in Sleep and low-power Sleep modes, the CPU is halted while all other functions remain operational (excepted USB OTG_FS and RNG in low-power Sleep mode). SRAM and register contents can be preserved, but the debug interface's access to SRAM is disabled to reduce power supply consumption.

ArticlePicture2.png

1.3. Limitation in low power modes

As mentioned above, the D-bus allows for the manipulation of variables and analysis of the program in debug mode with the STM32L476.

In Sleep and low-power Sleep modes, the VCORE domain is halted to reduce power consumption, and the SRAM clock can be gated on or off (the contents of the SRAM and registers can be nevertheless preserved). However, to further minimize power usage, the access paths to these SRAM memory blocks are power off.

ArticlePicture3.png

While the STM32L476's low power modes are beneficial for power conservation, they introduce a configuration change for developers who need to debug applications:

  • Debugging in Sleep and low-power Sleep modes: The debug interface, which typically uses SRAM access for monitoring and modifying application state, is unable to perform these operations when the microcontroller is in Sleep and low-power Sleep mode.
  • SEGGER RTT and other debug tools: Real-time debugging tools that rely on continuous memory access are particularly affected, as they can only function with active SRAM access.

 

2. The direct memory access usage with SRAM access debugging

2.1. Using DMA to enable debug Sleep mode

The Direct Memory Access (DMA) controller in the STM32L476 offers the solution to the SRAM access challenge during Sleep and low-power Sleep modes. While the CPU and its buses may be inactive during these modes, the DMA can remain operational. This is because the DMA is designed to perform high-speed data transfers independently of the CPU. It's particularly useful for power-saving strategies where the CPU is not required to be active.

The DMA's ability to access memory and peripherals without CPU intervention can be leveraged to maintain a "hidden" access path to SRAM during Sleep mode. By configuring the DMA to perform transfers involving SRAM, we can ensure that the BusMatrix, which arbitrates access to memory, remains active. This is due to the BusMatrix's design, which automatically activates when at least one master (such as the DMA) is on.

ArticlePicture4.png

2.2. How to use DMA to access SRAM

To utilize DMA for SRAM access during Sleep mode, follow these steps:

  • DMA configuration:

Begin by configuring the DMA channel with SRAM as the destination address. This can be SRAM1 or SRAM2, depending on where the data of interest resides.

Set the source address to a peripheral that is active during Sleep mode or another memory region that is not restricted in low-power modes.

Configure the transfer size and enable the DMA channel, ensuring that the transfer does not start immediately but is ready to be triggered.

  • Trigger source:

Identify a trigger source that remains active during Sleep mode. This could be a timer or an external interrupt line.

Configure the trigger source to initiate the DMA transfer when required. This could be set up to occur periodically or based on a specific event.

  • Entering Sleep mode:

Before entering Sleep mode, ensure that all necessary peripherals, including the DMA and its trigger source, are correctly configured and enabled.

Enter Sleep mode with the confidence that the DMA maintains access to SRAM.

  • Data transfer:

Once in Sleep mode, the DMA responds to the trigger source and carries out the memory transfer. This effectively creates a window during which SRAM can be accessed, despite the CPU being inactive.

The data transferred by the DMA can be used to monitor the application state or facilitate debugging by moving relevant data to a location where it can be accessed post-wake-up.

  • Monitoring and Debugging:

After waking up from Sleep mode, the data transferred by the DMA to SRAM can be inspected.

This allows developers to analyze the state of the application during low-power mode without disrupting the low-power consumption benefits.

By following these steps, developers can create a system that allows for SRAM access during Sleep mode. It allows for effective debugging and monitoring without compromising on the low-power consumption that the STM32L476 is designed for.

 

3. Conclusion: Embracing low-power and debugging capabilities

The architecture of the STM32L476 is meticulously designed to minimize power usage, particularly in its various low-power modes such as Sleep and low-power Sleep. This design philosophy is evident in the way SRAM access is disabled during these modes to conserve energy. However, this power optimization introduces challenges for developers who need to debug applications in low-power conditions.

The highlighted configuration presented in this article, utilizing the DMA controller, addresses these challenges by providing a method to maintain access to SRAM even when the core CPU is inactive. This configuration leverages the inherent capabilities of the DMA, which is designed to operate independently of the CPU, thus ensuring that the Bus Matrix remains active and that memory access is preserved.

The implications of this configuration extend beyond the STM32L476 to other products and families within the STM32 series that share similar low-power characteristics and memory architectures (DMA available in Sleep mode). By applying this setup, developers can ensure that their debugging processes are not hindered by the low-power modes of these devices.

Third-party debugging tools, such as SEGGER (RTT), which rely on continuous memory access, are particularly impacted by the power-saving features of the STM32L476. The DMA-based workaround can mitigate these impacts by providing an alternative path for memory access, allowing these tools to function effectively even when the microcontroller is in a low-power state.

 

Related links

Comments
Mitja
Associate

Is this behavior (bus matrix disconnecting debug access to SRAM) also valid for STM32G0x1 devices?

paradouxe
ST Employee

Hello @Mitja 

Yes I can confirm that the STM32G0x1 is affected by this article in the same way as the STM32L4.

Regards,

Antoine

Mitja
Associate

@paradouxe ,

Thanks for clarification.

Version history
Last update:
‎2024-06-17 07:01 AM
Updated by: