Debug not working with Cortex-Debug on relocated application on STM32

186 views Asked by At

I'm working on STM32F407 device, developing a Bootloader and Application

The environnement is Visual Studio Code, and using Cortex-Debug extension for the debug.

The bootloader at address 0x0800 0000 is launching the application relocated at 0x0802 0000 in FLASH. So the application linker file specified the new start address @0x0802 000, and the system_stm32f4xx.c file define a VECT_TAB_OFFSET = 0x00020000

When running without debuger, the bootloader start the application and everything is fine. But in debug mode, main() is never reached and no debug is possible. But Cortex-debug do not crash. I can pause/play it, but is it not showing anything. It seems "lost"

So, in run mode, everything works as expected. The boot call the application and the application execute.

If I relocate the application @0x0800 0000 with VECT_TAB_OFFSET == 0, I am able to debug the code using Cortex Debug. But debugging @0x0802 0000 with VECT_TAB_OFFSET == 0x0002 0000 is not possible. Main() is never called. I have checked memory, the .bin is correctly loaded at 0x0802 0000

Here is my launch.json file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Cortex Debug",
            "cwd": "${workspaceFolder}",
            "executable": "./build/Debug/APP.bin",
            "request": "launch",
            "type": "cortex-debug",
            "servertype": "openocd",
            "device": "STM32F407",
            "configFiles": [
                "interface/stlink.cfg",
                "target/stm32f4x.cfg"
            ],
            "symbolFiles": [
                "${workspaceFolder}/build/Debug/APP.elf"                
            ],
            "loadFiles": [
                "${workspaceFolder}/build/Debug/APP.hex"
            ],
            "gdbPath": "arm-none-eabi-gdb.exe",
            "interface": "swd"
        }
    ]
}

Is there a parameter to say the debugger to work at 0x0802 0000? I supposed that loading the .hex file was enough be maybe i'm wrong

1

There are 1 answers

0
Max Ir On

I was having the same issue. After adding overrideLaunchCommands to the configurations node in launch.json file, I am able to debug successfully.

"configurations": [
    {
        "showDevDebugOutput": "parsed",
        "cwd": "${workspaceRoot}",
        "executable": "${workspaceRoot}/build/app.elf",
        "name": "Debug STM32",
        "request": "launch",
        "type": "cortex-debug",
        "servertype": "openocd",
        "preLaunchTask": "CMake: build",
        "device": "stm32f407",
        "configFiles": [
            "openocd.cfg"
        ],
        "overrideResetCommands": [],
        "overrideLaunchCommands": [
            "cd ${workspaceRoot}/build",
            "file app.elf",
            "target extended-remote localhost:50000",
            "monitor reset halt",
            "load",
            "set output-radix 16"
        ],
        "svdFile": "${workspaceRoot}/STM32F407.svd"
    }
]