SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: How much RAM does STM32F407 have?
SUBSCRIBE
SoCSoC
Font ResizerAa
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Search
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Have an existing account? Sign In
Follow US
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
© S-O-C.ORG, All Rights Reserved.
Arm

How much RAM does STM32F407 have?

Elijah Erickson
Last updated: October 5, 2023 9:55 am
Elijah Erickson 10 Min Read
Share
SHARE

The STM32F407 is an ARM Cortex-M4 based microcontroller from STMicroelectronics. It has 192 KB of RAM available for code and data storage during runtime operations.

Contents
Overview of STM32F407SRAM Memory in STM32F407Using the SRAM in CodeExternal RAM OptionsCaching and Memory Access PerformanceTypical Memory Usage in ApplicationRAM Usage OptimizationSRAM Usage TradeoffsSummary

Overview of STM32F407

The STM32F407 is part of STMicroelectronics’ F4 series of high-performance microcontrollers based on the ARM Cortex-M4 core. The F4 series combines high computing power with low power consumption, making these MCUs well-suited for demanding applications in areas like motor control, digital signal processing, medical devices, and industrial automation.

Some key features of the STM32F407 include:

  • ARM 32-bit Cortex-M4 core running at up to 168 MHz
  • 192 KB of SRAM for data and code storage
  • 1 MB of flash memory for code and data
  • Extensive peripheral set including USB, Ethernet, CAN, SPI, I2C, USARTs, ADCs, DACs, and more
  • Floating point unit and DSP instructions for mathematical calculations
  • Memory protection unit and hardware CRC calculation

With its balance of performance, features, and power efficiency, the STM32F407 is a versatile choice suitable for many embedded systems and IoT applications.

SRAM Memory in STM32F407

The STM32F407 contains 192 KB of SRAM (static random access memory) available for storing both data and executable code. This on-chip SRAM provides fast access for the CPU during runtime, allowing frequently used variables, stack data, and code to be accessed without the latency of fetching from slower flash storage.

The 192 KB SRAM is divided into the following blocks:

  • 64 KB of Core Coupled Memory (CCM)
  • 128 KB of System SRAM

The CCM SRAM is directly connected to the Cortex-M4 core, allowing zero wait state access. This makes it well suited for storing critical code and real-time data that needs low latency access. The System SRAM provides additional general purpose memory with only slightly higher access times.

By integrating a relatively large SRAM directly on chip, the STM32F407 eliminates the need for external SRAM in many applications. The generous 192 KB allows for significant amounts of data and intermediate computations to be stored locally, avoiding slow external memory access.

Using the SRAM in Code

The SRAM memory is accessible in code using standard variable declarations and memory access instructions. At the linking stage, the compiler and linker will automatically place variables and functions into SRAM as needed for optimal access times.

Certain key memory regions can also be manipulated directly for specific use cases. For example, the CCM SRAM can be used for time-critical routines by placing functions in specific address ranges. The core coupled nature of CCM allows for zero wait execution when accessed properly.

Typical uses of the SRAM include:

  • Global and static variables
  • Function call stack
  • Heap for dynamic memory allocation
  • Time-critical interrupt routines
  • Frequently accessed lookup tables and data structures
  • Buffers for peripheral data transfer

With careful usage of the SRAM resources, the 192 KB on the STM32F407 allows for highly responsive real-time performance even with significant amounts of application data.

External RAM Options

While the STM32F407’s 192 KB of embedded SRAM will be sufficient for many applications, some high memory usage cases may require additional external RAM. Adding external RAM is an option to expand the available memory for data storage and operations.

Some options for adding external RAM include:

  • Parallel interface – Add a parallel RAM chip, configurable from 8 to 32 bit width
  • FSMC interface – Connect a RAM chip via the flexible static memory controller
  • External bus interface – Use the EBI peripheral to add more RAM

When using external RAM, the access speeds will be slower than the on-chip SRAM due to interface signaling and off-chip delays. So the embedded SRAM should still be used where fast access is required.

The complexity of interfacing external RAM also increases, involving additional connections, memory controllers, and glue logic. So for many designs the on-chip SRAM will be sufficient when used judiciously.

Caching and Memory Access Performance

To optimize memory access times and performance when using external memory, the Cortex-M4 core includes configurable instruction and data caches. These small high-speed caches can store frequently used code and data, providing low latency access for cached regions.

Cache support allows optimizing the typical case execution speed, even when slower memories are present. The caches handle the overhead of interfacing with external memories, while retaining fast access for cached code and data.

Other configurable options to improve memory performance include:

  • Bus matrix for flexible peripheral assignments
  • Prefetch buffers to reduce instruction access overhead
  • Memory region write protection for safety critical code segments

So while the 192 KB of on-chip SRAM provides excellent performance, the M4’s caches and external memory connectivity options allow reliably interfacing with peripherals and larger off-chip memories when needed.

Typical Memory Usage in Application

In a typical application, the 192 KB of SRAM memory may be used like:

  • 32 KB for CCM data – critical real-time variables, sensor data buffers
  • 16 KB for CCM code – key time-sensitive interrupt routines
  • 60 KB for heap – dynamic variable allocation pool
  • 20 KB for hardware and protocol stacks – USB, TCP/IP, and similar buffers
  • 32 KB for application global data – global variables and constants
  • 32 KB for stack space – function call and interrupt stack usage

This provides a good rule of thumb split, with ample SRAM left for additional application variables and temporary buffers as needed. The CCM SRAM is used for the most time-critical data and code regions.

For applications requiring more RAM, external memory can be added. But with mindful usage, the sizable 192 KB internal SRAM enables many complex applications without needing external memory.

RAM Usage Optimization

To make the best use of the available SRAM, and minimize reliance on slower external memory, various optimization techniques can be applied in application code:

  • Minimize global variables, use locals where possible
  • Declare variables as static or const instead of global when applicable
  • Use smaller data types where practical – ex. 16-bit ints vs 32-bit
  • Avoid unused variables and dead code
  • Reuse buffers instead of multiple allocations
  • Use memory pools for fixed size buffer allocation

Profiling memory usage can also help identify usage hotspots to optimize. The compiler may provide memory analysis reports to help guide optimization efforts.

Using these techniques can allow complex applications to run solely within the STM32F407’s internal SRAM for many cases.

SRAM Usage Tradeoffs

SRAM provides fast temporary working memory during program execution, while flash stores code and read-only data. So SRAM usage comes with tradeoffs:

  • Higher SRAM usage reduces available flash storage, since they use the same embedded silicon area.
  • Increasing SRAM size increases the device cost and footprint.
  • Larger SRAM can allow more data processing, but needs a bigger chip.
  • External RAM adds flexibility, but at a cost of speed, power and interfacing complexity.

So the 192 KB SRAM size represents STMicro’s chosen balance point of performance, flexibility, cost and power savings for this Cortex-M4 MCU. It aims to handle a wide variety of applications without needing external RAM.

Summary

In summary, the STM32F407 microcontroller contains 192 KB of embedded SRAM, split into 64 KB of fast Core Coupled Memory (CCM) and 128 KB of general System SRAM. This on-chip RAM provides high speed storage for variables, stack data, and code execution during runtime.

The ample 192 KB SRAM enables many advanced applications without requiring slower external RAM. Usage can be optimized through careful allocation and programming techniques. The CCM SRAM is ideal for time-critical data and code. Additional external RAM can be added if needed for high memory applications.

So for most typical applications, the 192 KB of SRAM on the STM32F407 provides an excellent balance of performance, flexibility, cost-effectiveness, and power efficiency for embedded projects using this popular Cortex-M4 microcontroller.

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article What is the use of STM32F407?
Next Article What is the specification of STM32F407G?
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

2k Followers Like
3k Followers Follow
10.1k Followers Pin
- Sponsored-
Ad image

You Might Also Like

What is the xPSR register in ARM Cortex-M?

The xPSR (program status register) is one of the key…

6 Min Read

Interrupt Handling During Multi-Cycle Atomic Operations in ARM Cortex M3

The ARM Cortex M3 processor implements interrupt handling in a…

5 Min Read

What is the difference between Cortex-M33 and M23?

The Cortex-M33 and Cortex-M23 are 32-bit processor cores designed by…

7 Min Read

Implementing a Round-Robin Scheduler on Cortex-M

A round-robin scheduler is a scheduling algorithm that sequentially cycles…

5 Min Read
SoCSoC
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
Welcome Back!

Sign in to your account