And here's the recipe to run programs from RAM instead of ROM:
Change the linker script such that the code points to RAM instead of ROM (0x20000000 instead of 0x08000000) and compile.
sudo openocd -f /usr/local/share/openocd/scripts/interface/stlink.cfg -f /usr/local/share/openocd/scripts/target/stm32l4x.cfg
arm-none-eabi-gdb -ex "target remote localhost:3333" cdcamc.elf
You should seem something like this:
Reading symbols from cdcacm.elf...done.
Remote debugging using localhost:3333
0x08000232 in ?? ()
Note that the STM32 was still running something in the 0x0800000 address range.
Load the binary into memory:
You will get this:
Loading section .text, size 0x4f4 lma 0x20000000
Start address 0x2000045c, load size 1268
Transfer rate: 9 KB/sec, 1268 bytes/write.
Set a breakpoint:
(gdb) br main
Breakpoint 1 at 0x20000188: file cdcacm.c, line 298.
Execute your code:
Breakpoint 1, main () at cdcacm.c:298
Yes. It's as simple as that: instead of "run", you need to use "continue", and it will do exactly what you need: execute your program in RAM.
It's interesting that openocd doesn't even allow the 'run' command, so I was forced to use continue. Not so for the Black Magic Probe, which supports both. I'm sure that by using 'continue' on the Black Magic, I'll be able to run from RAM instead of ROM just the same.