Adding external memory to a microcontroller (MCU) is common when your application needs more storage than the built-in Flash or SRAM (e.g., graphics buffers, audio, large sensor logs, ML models). The exact method depends on the MCU architecture and the type of memory.
How to Use External Memory with an MCU
1. Types of External Memory
- SRAM / SDRAM / PSRAM → for fast data storage (frame buffers, variables).
- NOR Flash → for code storage (execute-in-place, boot).
- NAND Flash → for large data storage (logs, firmware images).
- EEPROM → for small, non-volatile parameter storage.
- SD card / eMMC → for mass storage, file systems.
2. Connection Interfaces
Parallel Memory Bus
- Many MCUs (e.g., STM32 with FSMC/FMC, NXP i.MX RT) provide an external memory controller.
- Supports SRAM, NOR Flash, SDRAM.
-
Advantages:
- High throughput, wide bus (8/16/32 bits).
- Can allow execute-in-place (XIP) directly from external NOR Flash.
Disadvantages:
Requires many I/O pins.
Serial Interfaces (SPI / QSPI / HyperBus)
- SPI Flash / SPI SRAM: Easy, only 4–6 pins.
- QSPI (Quad SPI): Faster (up to 4× SPI), often used for external Flash in code execution.
- HyperRAM / HyperFlash: Newer, very high bandwidth with fewer pins than parallel SDRAM.
-
Advantages:
- Lower pin count.
- Widely supported.
Disadvantages:
Slower than parallel for random access.
I²C / UART Memory (rare)
- Used for small EEPROM chips (e.g., 24LCxx over I²C).
- Very simple but slow → suited for storing configuration/calibration values.
3. MCU Support Considerations
- Memory Controller Hardware: Check if your MCU has FSMC/FMC/EMC/QSPI controller. Without it, you’ll need bit-banging or slower drivers.
- Address Space Mapping: Some MCUs can map external memory into the CPU address space, making it look like internal memory.
- DMA Support: Improves throughput by offloading transfers.
- XIP (Execute in Place): Allows MCU to fetch instructions directly from external NOR/QSPI Flash, reducing code size pressure on internal Flash.
4. Firmware/Software Integration
- Use vendor HAL/driver libraries (e.g., STM32CubeMX FSMC for SDRAM, SPI driver for Flash).
- For storage devices (SD card, NAND, eMMC):
Use a file system stack (e.g., FATFS, LittleFS).
- For large RAM (frame buffer, AI model):
Configure linker script to place specific sections in external RAM.
5. Example Use Cases
- TFT Display Buffers → External SDRAM for image data.
- Audio Applications → External PSRAM for buffering samples.
- Bootloader/Firmware Updates → External QSPI Flash for staging images.
- Data Logging → SD card / NAND for long-term sensor storage.
- AI/ML on MCU → External DRAM for model weights & inference.
6. Design Tips
- Use proper decoupling capacitors close to memory ICs.
- Keep address/data buses short (for parallel SDRAM/NOR).
- Use matched impedance routing for high-speed QSPI/SDRAM.
- Ensure power-up sequencing matches MCU + memory timing.
- Consider ECC (Error Correction Code) for NAND/DRAM reliability.
Summary
To use external memory with an MCU:
- Pick memory type (SRAM, SDRAM, Flash, SD, EEPROM) based on speed and size needs.
- Choose interface: Parallel bus (fast, many pins) vs SPI/QSPI/HyperBus (compact, slower).
- Configure MCU memory controller or SPI drivers.
- Integrate with firmware via linker script (for RAM) or file system (for storage).
Top comments (0)