RAM linker script for Bluepill and Arduino

I would like use custom linker script so I copied

.platformio\platforms\ststm32\ldscripts\stm32f103x8.ld

to RAM.ld in project directory and added

board_build.ldscript = $PROJECT_DIR/RAM.ld

when add this code to project ( for simple led blinking test)

pinMode(PC13, OUTPUT); 

and compile get this message:

c:/users/user/.platformio/packages/toolchain-gccarmnoneeabi/bin/…/lib/gcc/arm-none-eabi/9.2.1/…/…/…/…/arm-none-eabi/bin/ld.exe: .pio/build/bluepill_f103c8/SrcWrapper/src/syscalls.c.o: in function _sbrk': syscalls.c:(.text._sbrk+0x38): undefined reference to _Min_Stack_Size’
c:/users/user/.platformio/packages/toolchain-gccarmnoneeabi/bin/…/lib/gcc/arm-none-eabi/9.2.1/…/…/…/…/arm-none-eabi/bin/ld.exe: .pio/build/bluepill_f103c8/SrcWrapper/src/syscalls.c.o:(.data.heap_end.7096+0x0): undefined
reference to `_end’
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\bluepill_f103c8\firmware.elf] Error 1

if I comment out this code its compile, but if remove ld script its works too.

What am I missing? in theory .ld is just a copy why not work from project directory?
(digitalWrite and delay functions compile with RAM.LD as well Serial1.begin )

Your linker script must contain these symbols, otherwise heap allocations and the stack will not work correctly.

This will not put make the code execute from RAM at all, it puts it in flash. (notice > FLASH for th .text segment in platform-ststm32/stm32f103x8.ld at d74987f984c9ff01dcb8c2f35396df3e7926c7db · platformio/platform-ststm32 · GitHub).

Just base your ldscript of the one actually used by Arduino-STM32, it has the right symbols

but modify all the > FLASH directives in the script to go into RAM, except for the ISR vector.

Thank you, original ldscript works. Of cours I planned to change flash and ram location and size.

/* Specify the memory areas */

MEMORY
{
/***RAM (xrw)      : ORIGIN = 0x20000000, LENGTH = LD_MAX_DATA_SIZE
FLASH (rx)      : ORIGIN = 0x8000000 + LD_FLASH_OFFSET, LENGTH = LD_MAX_SIZE - LD_FLASH_OFFSET**/
  FLASH (rwx) : ORIGIN = 0x20008000, LENGTH = 12K
  RAM (rwx)  :  ORIGIN = 0x20004000, LENGTH = 4K
}

Just for note, the 0x1000 = 4k so better to write this :slight_smile:

FLASH (rwx) : ORIGIN = 0x20002000, LENGTH = 12K
RAM (rwx) : ORIGIN = 0x20001000, LENGTH = 4K