Setting up vscode+bmp/vscode to debug code in ram (RP2040)

 The main problem when debugging the code in ram is that the CPU will have started to execute

whatever is in flash before you catch it, including potentially clearing the ram.

As a result , the setup has to be done in 2 steps :

- Have a "null" program in flash that does nothing

-Tweak a little bit the vscode debug startup sequence


Loop in flash

The idea here is to modify the very first instruction and replace it with a endless loop.

When you use lnArduino that means changing 

mcus/arm_rp2040/sdk_copy/crt0.S

and replacing the first instruction by 

    b _entry_point

That way, after reset, it will harmelessly loop in the flash.


Cortex-debug setup

{
  "version": "0.2.0",
 "configurations": [   {
 "name": "RAM- pico-load",
 "cwd": "${workspaceFolder}",  "svdFile" : "${workspaceRoot}/.vscode/rp2040.svd",  "executable": "build/st7789.elf",
 "gdbPath" : "${config:armToolchainPath}/arm-none-eabi-gdb",
 "request": "launch",
 "type": "cortex-debug",  "servertype": "bmp",
 "interface": "swd",  "device": "rp2040",
 "BMPGDBSerialPort" : "/dev/ttyBmpGdb3",
 "runToMain": false,  "overrideLaunchCommands":[  "mon ws 2",  "set mem inaccessible-by-default off",
 "set confirm off",
 "interrupt",  ],
 "postLaunchCommands" : [
 "load",
 "compare-sections",
 "set $pc=_entry_point",
 ],
 "preRestartCommands": [
 "enable breakpoint",  ]

  

You'll have to tweak that a little bit for your own config.

It should work for both blackmagic and swindle.

The gist of it is we stop it, load the code, verify it and change the PC so that it starts in RAM.
Now it works fine and you upload the code at 80kB/S






Comments

Popular posts from this blog

Component tester with STM32 : Part 1 ADC, Resistor

Fixing the INA3221

INA3221, weird wiring