CH32V3, debug in ram with vscode continued

Summary of previous episodes (CH32v3):

1- Reallocate shadow ram to have 128k of RAM

2- In flash, put a basic harmless loop

3- Tweak the linker script to put everything in ram

4- Load the code (to ram), change the PC  to the code in ram

5- You now upload much faster with infinite software breakpoints


Vscode

You can use the cortexm extension with riscv, it works fine with one caveat : you cannot "attach"

You can only "launch" (this is specific to riscv) and that's the root of the problem.

The init script looks like this :

    {
            "name": "riscv GCC (pico)",
"type": "gdb",
"request": "launch",
"cwd": "${workspaceRoot}",
"target": "${workspaceRoot}/build/swindle_bootloader_ch32v3x_GCC_DEBUG.elf",
"gdbpath" : "${config:riscv_gdb}",
"breakAfterReset" : "true",
//"showDevDebugOutput" : "true",
//"runToEntryPoint" : "true",
"autorun": [
"target extended-remote /dev/ttyBmpGdb3",
"set confirm off",
"set mem inaccessible-by-default off",
"set architecture riscv:rv32",
"set remotetimeout unlimited",
"mon reset",
"monitor fq 1500k",
"mon rvswdp_scan",
"attach 1",
"load ",
        ],

    }

It works, but it is hackish. Why is that ?
If you look at what the cortexm extension does , this is what happens :

....load

....read registers

k <= RESET

vRun

qC

g

vCont;c <= RUN


So whatever you do, a reset will happen followed by a run. As a result, even if you
changed the PC to your code in RAM, it is reverted to the code in flash and you have
to stop the code, change the PC and continue. It is annoying.


The hack is as follows : in the swindle dev4 branch there is a new command :
"mon enablereset 0"
That command disables the "k" command. You can now set the pc to the right value and it just works
The init script is now :
        "autorun": [
"target extended-remote /dev/ttyBmpGdb3",
"set confirm off",
"set mem inaccessible-by-default off",
"set architecture riscv:rv32",
"set remotetimeout unlimited",
"monitor fq 1500k",
"mon reset",
"mon rvswdp_scan",
"attach 1",
"load ",
"compare-sections",
"set $pc=0x20000000",
"mon enablereset 0",
"tb main" ,
],

NB : You can still reset the board using "mon reset".




Comments

Popular posts from this blog

Component tester with STM32 : Part 1 ADC, Resistor

Fixing the INA3221

INA3221, weird wiring