I have an STM32 dev board with some external SRAM. I would like to execute my code from that external SRAM, but my processor only supports booting from the Flash, internal SRAM or System memory (a part of the internal SRAM).

What is the easiest way to run code from an external SRAM?

Notes: I load code with OpenOCD through JTAG, and I use GDB.

  • 3
    \$\begingroup\$ How is your program going to be get into the external SRAM in the first place? \$\endgroup\$
    – vicatcu
    May 8, 2012 at 14:28
  • \$\begingroup\$ @vicatcu: I have a working driver written in C. \$\endgroup\$
    – Randomblue
    May 8, 2012 at 14:36

1 Answer 1


Before you can start executing code from external RAM, you have to first initialize FSMC and copy your code into that RAM, so you have to boot from flash anyway. A properly written linker script (with an additional code section linked at the correct address but placed in flash, like the .data section) will help greatly. You'll be able to mark functions you need placed in RAM with a correct section attribute. After FSMC is initialized, copy that section into RAM the same way .data is copied in your startup code. All that's left is calling your RAM functions in a normal way.

Note two serious problems with running from external SRAM:

  1. It's going to be slow. Like 6...8 times slower than running from flash or even internal SRAM according to this. This microcontroller architecture simply isn't optimized for this kind of use.

  2. Some STM32 chips have a silicon bug where FSMC access by two bus masters crashes the chip. This will basically preclude you from using DMA. This concerns STM32F103 revision Y IIRC, probably other chips too.

So I wouldn't do this personally. Once again I have to repeat on this website that microcontroller != CPU even if it's an ARM.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.