Debugging UBLOX_EVK_ODIN_W2 with OpenOCD and Visual Studio Code

Debugging this target using OpenOCD and GDB is quite straight forward. For other targets, see these docs!

  1. Install OpenOCD.
  2. Build your application with debug symbols enabled, via: mbed compile --profile=debug.
  3. Start a debug server via: openocd -f /path/to/openocd/scripts/board/st_nucleo_f4.cfg -f /path/to/openocd/scripts/interface/stlink-v2-1.cfg -c init -c "reset init".
  4. Attach via GDB (arm-none-eabi-gdb, then target remote localhost:3333).

Note: If you want to debug an application with a bootloader, first flash the full image via drag-n-drop, then flash the application (_application.bin) via GDB. This ensures that the bootloader remains in place.

Here's a Visual Studio Code configuration to do visual debugging of an Mbed Cloud Client application (replace '/Users/janjon01/openocd' with your own path to OpenOCD).

.vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/BUILD/UBLOX_EVK_ODIN_W2/GCC_ARM/${workspaceRootFolderName}_application.elf",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": false,
            "debugServerArgs": "-f /Users/janjon01/openocd/scripts/board/st_nucleo_f4.cfg -f /Users/janjon01/openocd/scripts/interface/stlink-v2-1.cfg -c init -c \"reset init\"",
            "serverLaunchTimeout": 20000,
            "filterStderr": true,
            "filterStdout": false,
            "serverStarted": "target halted due to debug-request, current mode: Thread",
            "preLaunchTask": "mbed",
            "setupCommands": [
                { "text": "-target-select remote localhost:3333", "description": "connect to target", "ignoreFailures": false },
                { "text": "-file-exec-and-symbols ${workspaceRoot}/BUILD/UBLOX_EVK_ODIN_W2/GCC_ARM/${workspaceRootFolderName}_application.elf", "description": "load file", "ignoreFailures": false},
                { "text": "-interpreter-exec console \"monitor endian little\"", "ignoreFailures": false },
                { "text": "-interpreter-exec console \"monitor reset\"", "ignoreFailures": false },
                { "text": "-interpreter-exec console \"monitor halt\"", "ignoreFailures": false },
                { "text": "-interpreter-exec console \"monitor arm semihosting enable\"", "ignoreFailures": false },
                { "text": "-target-download", "description": "flash target", "ignoreFailures": false }
            ],
            "logging": {
                "moduleLoad": true,
                "trace": true,
                "engineLogging": true,
                "programOutput": true,
                "exceptions": true
            },
            "linux": {
                "MIMode": "gdb",
                "MIDebuggerPath": "/usr/bin/arm-none-eabi-gdb",
                "debugServerPath": "openocd"
            },
            "osx": {
                "MIMode": "gdb",
                "MIDebuggerPath": "/usr/local/bin/arm-none-eabi-gdb",
                "debugServerPath": "openocd"
            },
            "windows": {
                "preLaunchTask": "mbed",
                "MIMode": "gdb",
                "MIDebuggerPath": "C:\\Program Files (x86)\\GNU Tools ARM Embedded\\4.9 2015q3\\bin\\arm-none-eabi-gdb.exe",
                "debugServerPath": "openocd.exe",
                "setupCommands": [
                    { "text": "-environment-cd ${workspaceRoot}\\UBLOX_EVK_ODIN_W2\\GCC_ARM\\BUILD" },
                    { "text": "-target-select remote localhost:3333", "description": "connect to target", "ignoreFailures": false },
                    { "text": "-file-exec-and-symbols ${workspaceRootFolderName}_application.elf", "description": "load file", "ignoreFailures": false},
                    { "text": "-interpreter-exec console \"monitor endian little\"", "ignoreFailures": false },
                    { "text": "-interpreter-exec console \"monitor reset\"", "ignoreFailures": false },
                    { "text": "-interpreter-exec console \"monitor halt\"", "ignoreFailures": false },
                    { "text": "-interpreter-exec console \"monitor arm semihosting enable\"", "ignoreFailures": false },
                    { "text": "-target-download", "description": "flash target", "ignoreFailures": false }
                ]
            }
        }
    ]
}

.vscode/tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "isShellCommand": true,
    "showOutput": "always",
    "problemMatcher": {
        "owner": "cpp",
        "fileLocation": ["relative", "${workspaceRoot}/mbed-os"],
        "pattern": {
            "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
            "file": 1,
            "line": 2,
            "column": 3,
            "severity": 4,
            "message": 5
        }
    },
    "command": "mbed",
    "args": ["compile", "--profile=debug"],
    "windows": {
        "command": "mbed.exe",
        "args": ["compile", "--profile=debug"]
    }
}

Put these files in your .vscode folder, and hit F5 to start debugging. Check the 'Debug console' tab in VSCode for info on the flash progress.

/media/uploads/janjongboom/screen_shot_2017-11-11_at_11.19.29.png


Please log in to post comments.