Microcontroller Memory

Created:  
Updated:   07Aug2024   03:48:24   UTC 2024-08-07T03:48:24Z
Rating:   (0 reviewsThis article has not been rated yet)

Microcontrollers usually contain volatile memory (RAMRandom Access Memory) and non-volatile memory (Flash and/or EEPROMElectrically Erasable Programmable Read-Only Memory). This article covers these different kinds of microcontroller memory components.

The contents of volatile memory are lost if the microcontroller loses power, whereas the contents of non-volatile memory persists between power cycles. A description of the different types of memory in microcontrollers is given below.

RAMRandom Access Memory or SRAMStatic Random Access Memory:
Volatile memory that is the working data space for storing transient data, such as variables, the heap, and the stack, and can be written to and read from during program execution.
Flash:
Non-volatile memory used to store programs (code) and also any constant data values. It can be read, erased, and written to.
EEPROMElectrically Erasable Programmable Read-Only Memory:
Non-volative memory to hold data that needs to persist between software changes and power cycles. It can be erased and written to, making it useful for logging system malfunctions and fault data during program execution. It is also useful for storing special data or configuration data that must be retained during a power failure but might need to be changed periodically.

In most microcontrollers, RAM is usually smaller in size than flash memory because it costs more. RAM has lower latency (faster read/write) than flash memory. Some microcontrollers, like the RPiRaspberry Pi Pico, do not have EEPROM and rely entirely on Flash memory to store permanent data. While other microcontrollers, like the Arduino Uno Rev3, use the Flash memory to store programs and rely on EEPROM for storing permanent data.

MCU Memory

ATmega328P

The Arduino Uno Rev3, Nano, and Mini microcontrollers with the ATmega328P MCU have 32KB of flash memory (0.5KB is used for Bootloader), 2KB of SRAM, and 1KB of EEPROM. These memory components are shown in the figure below from the ATmega328P Datasheet.

Memory in ATmega328P Block Diagram (source datasheet)

The ATmega328P EEPROM is not only scarce with a limit of 1024 bytes, but also has the limitation that it can only save one byte: you can only store 8-bit numbers, which includes integer values between 0 and 255.

You might think to just use the 32KB Flash memory instead of EEPROM to write your data to. Normally, the ATmega328P only allows you to write to flash memory when when it's in bootloader mode. The standard bootloader allows you to write to flash when a new program is being installed, but does not allow runtime programs to write to flash. However, there is a hack to the bootloader that does allow you to run functions that enable you to write to flash (check out this Hackaday post on the subject).

RP2040

The RP2040 MCU has 16KB of ROMRead-Only Memory, 264KB of SRAM, and supports external QSPIQuad Serial Peripheral Interface (QSPI) is a serial communication interface designed for talking to flash chips by using 4 data lines. Flash (e.g., the RPiRaspberry Pi Pico boards have 2MB of QSPI Flash). These memory components are shown in the figure below from the RP2040 Datasheet.

Memory in RP2040 Block Diagram (source RP2040 Datasheet)

The ROM contents are fixed at the time the RP2040 silicon is manufactured and contains:

  • Initial startup routine
  • Flash boot sequence
  • Flash programming routines
  • USB mass storage device with UF2 support
  • Utility libraries such as fast floating point

The RP2040 datasheet states that it has 264KB of internal RAM, but when you check the RAM availability using commands (mem_info) on the RPiRaspberry Pi Pico, it outputs only about 192KB of RAMRandom Access Memory available for use. This is because some of the memory is used by the Python interpreter, stack, buffers, etc.

Besides the SRAM main memory, there are two other dedicated RAM blocks that may be used in some circumstances:

  • If flash XIPExecute In Place (XIP) is a method of executing programs directly from long-term storage rather than copying it into RAM caching is disabled, the cache becomes available as a 16KB memory
  • If the USB is not used, the USB data DPRAMDual-Ported RAM (DPRAM) is a type of random-access memory that allows multiple reads or writes to occur at the same time, or nearly the same time, unlike single-ported RAM which allows only one access at a time. can be used as a 4KB memory

The RP2040 does not have a separate non-volatile EEPROM like the Arduino Uno R3 and Nano. Instead, it relies entirely on external QSPI Flash memory to store permanent data. QSPI is faster than traditional SPISerial Peripheral Interface because it uses 4 data lines (I0, I1, I2, and I3) as opposed to just 2 data lines (MOSIMaster Out Slave In (MOSI) is the SPI data output line from the master device and MISOMaster In Slave Out (MISO) is the SPI data output line from the slave device) on the traditional SPI. The RPi Pico boards come with 2MB QSPI Flash chips, but other boards with the RP2040 may have up to 16MB flash chips.

RAM

Random Access Memory (RAM) is volatile memory that is the temporary working data space for a program to store and access transient data. Having more RAM means that more data can be accessed and read faster than being written to flash or EEPROM. A table of the RAM used in popular microcontrollers is provided below that shows a wide capacity range from 512 bytes for the ATtiny85 to 520KB for the ESP32.

Microcontroller RAM Memory
MCU Boards RAM
ATmega328P
  • Arduino Uno R3, Nano, Pro Mini
  • Adafruit Pro Trinket, Metro, Metro Mini
2048 bytes SRAM
Atmega32U4
  • Arduino Leonardo, Micro
  • Adafruit ItsyBitsy, Feather Basic Proto
  • SparkFun Pro Micro
  • DFRobot Beetle
2.5KB SRAM
SAMD21
  • Arduino Nano 33 IoT
  • Adafruit Metro M0 Express, QT Py, Trinket, ItsyBitsy, Gemma
  • SparkFun Redboard Turbo, Micro, Mini
  • Seeed Studio XIAO
4/8/16/32KB SRAM
SAMD51/
SAME51
  • Adafruit Metro M4, ItsyBitsy M4 Express
  • SparkFun Thing Plus
128/192/256KB SRAM
RP2040
  • RPi Pico, Pico H, Pico W
  • Arduino Nano RP2040 Connect
  • Adafruit QT Py, ItsyBitsy, Feather
  • SparkFun Pro Micro, Thing Plus
  • Pimoroni Tiny 2040, Pico LiPo
  • Seeed Studio XIAO
264KB SRAM
STM32F103
  • Blue Pill Minimum System Dev Board
  • Core Dev Board
  • Nucleo-64 Dev Board
  • LQFP48
20KB SRAM
STM32F4
  • Black Pill Minimum System Dev Board (401/405/411)
  • Core Dev Board
  • Nucleo-64 Dev Board
  • SparkFun Thing Plus
64/96/128KB SRAM
ATtiny85
  • Digispark Kickstarter
  • Adafruit Trinket
512 bytes SRAM
ESP8266EX
  • ESP-01, ESP-01S, ESP-12E, ESP-12F, ESP-12S
  • Adafruit Huzzah and Feather ESP8266
  • Sparkfun ESP8266 Thing
80KB/96KB RAM
ESP32
  • ESP32-WROOM-32
  • Adafruit Huzzah and Feather ESP32
  • Sparkfun ESP32 Thing and Thing Plus
  • Seeed Studio XIAO ESP32
  • 520KB SRAM
  • 448KB ROM

Data Storage

Flash and EEPROM are the two main types of non-volatile memory used by microcontrollers to store long term data. Both Flash and EEPROM can be read, erased, and written to, but flash must be erased in big blocks, while EEPROM can overwrite individual bytes. Flash memory is typically used these days to hold program code and variables, while EEPROM is used to hold persistent data, such as configuration data, measurements, or computations. Both of these memory types could be internal/external to the MCU chip. A table of the data storage memory used in popular microcontrollers is provided below that shows a wide flash capacity range from 8KB for the ATtiny85 up to 16MB for the ESP32.

Microcontroller Data Storage Memory
MCU Boards Data Storage
ATmega328P
  • Arduino Uno R3, Nano, Pro Mini
  • Adafruit Pro Trinket, Metro, Metro Mini
  • 32KB Flash
  • 1KB EEPROM
Atmega32U4
  • Arduino Leonardo, Micro
  • Adafruit ItsyBitsy, Feather Basic Proto
  • SparkFun Pro Micro
  • DFRobot Beetle
  • 32KB Flash
  • 1KB EEPROM
SAMD21
  • Arduino Nano 33 IoT
  • Adafruit Metro M0 Express, QT Py, Trinket, ItsyBitsy, Gemma
  • SparkFun Redboard Turbo, Micro, Mini
  • Seeed Studio XIAO
32/64/128/256KB Flash
SAMD51/
SAME51
  • Adafruit Metro M4, ItsyBitsy M4 Express
  • SparkFun Thing Plus
256KB/512KB/1MB Flash
RP2040
  • RPi Pico, Pico H, Pico W
  • Arduino Nano RP2040 Connect
  • Adafruit QT Py, ItsyBitsy, Feather
  • SparkFun Pro Micro, Thing Plus
  • Pimoroni Tiny 2040, Pico LiPo
  • Seeed Studio XIAO
2MB QSPI Flash
STM32F103
  • Blue Pill Minimum System Dev Board
  • Core Dev Board
  • Nucleo-64 Dev Board
  • LQFP48
64/128KB Flash
STM32F4
  • Black Pill Minimum System Dev Board (401/405/411)
  • Core Dev Board
  • Nucleo-64 Dev Board
  • SparkFun Thing Plus
256/512KB Flash
ATtiny85
  • Digispark Kickstarter
  • Adafruit Trinket
  • 8KB Flash
  • 512 bytes EEPROM
ESP8266EX
  • ESP-01, ESP-01S, ESP-12E, ESP-12F, ESP-12S
  • Adafruit Huzzah and Feather ESP8266
  • Sparkfun ESP8266 Thing
External QSPI flash up to 16MB
ESP32
  • ESP32-WROOM-32
  • Adafruit Huzzah and Feather ESP32
  • Sparkfun ESP32 Thing and Thing Plus
  • Seeed Studio XIAO ESP32
MCU External Flash:
  • 4MB (typical), 16MB (max)
  • Supports multiple external QSPI flash
    and external RAM (SRAM) chips

Conclusion

This was an overview of the different kinds of RAM and data storage memory that most microcontrollers have. The RAM capacity of microcontrollers mentioned here range from 512 bytes for the lower end processors like the ATtiny85 to 520KB on the higher end processors such as the ESP32. Flash and EEPROM are the two main types of non-volatile memory used by microcontrollers to store long term data. The EEPROM capacity range is just a few kilobytes, whereas the flash capacity has a wider range from 8KB for the ATtiny85 up to 16MB for the ESP32.

Related Content

Products

Article Rating

Sign in to rate this article

Sign In


(0) Comments

Sign in to leave a comment

Sign In