Configure memory area on STM32

Hello everyone,

I’m trying to upload my program to SRAM on STM32F103RC for debugging purpose. This can be easily done using Keil5.


How can I make this happen with PlatformIO?

The compilation process uses a pre-configured linkerscript that determines where things end up in memory. These are preconfigured for Flash. You’ll need to copy & modify the linkerscript that your exact project is using and point to it using board_build.ldscript in the platformio.ini. You can see the used linkerscript by looking at the -T "path/to/linkerscript" command contained in the final linker command, that is displayed when doing executing the Advanced → Verbose Build project task.

There is no 1-click button for this.

Thanks for your response,

I tried modifying original linker script, the program can be built, but openOCD reported some errors, and the program wont run. My board uses STM32F103RCT6.

The output of openOCD:

Error: stm32f1x.cpu -- clearing lockup after double fault
Polling target stm32f1x.cpu failed, trying to reexamine
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x200001e0 msp: 0x20005000
** Programming Started **
Warn : no flash bank found for address 0x20000000
Warn : no flash bank found for address 0x20000930
** Programming Finished **
** Verify Started **
Error: checksum mismatch - attempting binary compare
embedded:startup.tcl:521: Error: ** Verify Failed **
in procedure 'program' 
in procedure 'program_error' called at file "embedded:startup.tcl", line 582
at file "embedded:startup.tcl", line 521
*** [upload] Error 1

The memory section of my linker script:

  RAM    (xrw)    : ORIGIN = 0x20001020,  LENGTH = 0x2800 
  FLASH    (rx)   : ORIGIN = 0x20000200,  LENGTH = 0x1000 

Does your MCU have flash at address 0x20000200?

Looking at page #40 here

Of course not. I said I want to upload my program into SRAM, not flash. :joy:

Mhm yes that’s a problem that OpenOCD doesn’t allow you to do that. I’ll look into it.

Have you seen this discussion? c - Executing code from RAM in STM32 - Stack Overflow

They define the section as RAM and use a boot mode to executed from RAM, after a few manual tweaks with the debugger.