Electronic – Running executable from external SRAM

bootloadersramstm32

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.

Best Answer

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.