Arduino Due Memory Segment manegment

project with PlatformIO to Due.
how to, Set memory address Star.

my case:
example: set memory start

Start SRAM 0x20080000 32k ram user global

Data: 0x20000000 64k to execute code


Does what you want work within Arduino IDE?

Hi maxgerhardt,
IDE VScode, to Arduino Due.
converting project m4 ok, to m3 Arduino.
my project use execute code in sram(loader execute, via usb).

set start sram 32k
relocate vector to sram
will creat code to sram 0x20000000.


I’m still not sure if I understand you correctly.

The thing you’re working on, does it function correctly in the Arduino IDE, but doesn’t yet work on PlatformIO? If so, what options did you use with the Arduino IDE?

You mean a Cortex M4 and M3 here?

Does your bootloader first boot from Flash? And then loads the data via USB into RAM and should then start it?

You could force the allocation of a buffer at 0x20000000, relocate all vectors using NVIC_SetVector() and then jump to the code with a simple pointer

/* 32K SRAM buffer in specific RAM region */
uint8_t __attribute__((section (".mySpecialSection"))) sram_firmware_buffer[32 * 1024];

void load_firmware_from_usb() {
   //fill sram_firmware_buffer...

void jump_to_sram_entry() {
   //disable interrupts..
   //set all vectors from sram_firmware_buffer 
   //for(int i=0; i < NVIC_VECTORS_LEN; i++) { 
   //   nvic_vector is an array with all NVIC IRQs. Depends on the specific MCU.
   //  see
   //    NVIC_SetVector(nvic_vector[i],  ((uint32_t*)sram_firmware_buffer)[i]);
   // }
   //declare entry function as return type void, no params
   typedef void(*entry_function_t)();
   //cast from memory address
   entry_function_t entry = (entry_function_t) (sram_firmware_buffer);
   //enable interrupts..
   //set stack pointer to point to SRAM1 or 2.. 

This would also need a modification of the flash.ld linker script to create this new section (see here). You might also need to modify to only place things in SRAM1 instead of ram (which is SRAM1 & 2). This script the same as here and is in the PlaformIO home folder (C:\Users\<user>\.platformio or /home/<user>/.platformio) under \packages\framework-arduinosam\variants\arduino_due_x\linker_scripts\gcc.

Or, if you just want to use the RAM linker script (your entire firmware is put into RAM and executed from there), you want to use this linker script. You can set it in PlatformIO using the platformio.ini commands

build_flags = -Wl,-Tsram.ld

See docs

1 Like

Hi maxgerhardt,

startup 0x0 fash, relocate VTOR, loader code in sram, jump code.

I’ll test you with your answer,