Skip to content

Instantly share code, notes, and snippets.

@kevinhikaruevans
Last active January 27, 2019 23:09
Show Gist options
  • Save kevinhikaruevans/302340f9729349c59ba239577537aff4 to your computer and use it in GitHub Desktop.
Save kevinhikaruevans/302340f9729349c59ba239577537aff4 to your computer and use it in GitHub Desktop.
Using the debugger in VS Code on Windows for mbed

Debugging the L496ZG on Windows using VS Code

This only works for Windows, but you can easily modify it for Linux. It would roughly be the same, except you would need to modify the "linux" sections in the json files.

  1. Download OpenOCD for Windows: http://gnutoolchains.com/arm-eabi/openocd/ (you'll need 7zip to extract it).

    • OpenOCD-20181130.7z is used in this guide. If you use a different version, you'll have to update the json files.
  2. Install libusb and stlink drivers

  3. Extract it to C:\ (or anywhere you want really).

  4. Place launch.json and tasks.json in your .vscode directory

    • The files are below. Just press 'Raw' and download it or copy-paste it into a new file called launch.json or tasks.json
    • The .vscode directory will be in the same directory as BUILD, bin, docs, mbed-os, etc. of your project
    • If the files don't exist, you'll have to create them
    • Example file structure:
      • CougSat1-IHU/.vscode/launch.json
      • CougSat1-IHU/.vscode/tasks.json
  5. Press the gutter/margin to add little red breakpoints. The area is just left of the line number.

  6. Press F5 to start debugging.

    • It'll say "Building..." in the lower status bar as it builds.
  7. Once OpenOCD (the debugger) is connected, LD4 on the board will flash green/red.

  8. It always catches an exception when it begins (in main.cpp) and I'm not exactly sure why... Just press Continue (:arrow_forward: button, or F5) and it'll work.

  9. Press Stop Debugging (:white_square_button:, or shift F5) to stop the debugger. It'll change the lower status bar from orange to blue once the process is ended.

Things to possibly change in the json files:

  • This is setup for the L496ZG. Just ctrl-f & replace it if you want to use the L476RG
  • MIDebuggerPath might have to be changed depending on where your ARM debugger is located at
  • debugServerPath might have to be changed if you didn't place OpenOCD in C:\

Troubleshooting

  • Try deleting the BUILD directory and rebuilding with F5
  • The Debug Console tab has information on the OpenOCD process
  • Output has information on the build

Additional links:

{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/BUILD/NUCLEO_L496ZG/GCC_ARM/${workspaceRootFolderName}.elf",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": false,
"debugServerArgs": "",
"serverLaunchTimeout": 40000,
"filterStderr": true,
"filterStdout": false,
"serverStarted": "GDB\\ server\\ started",
"preLaunchTask": "mbed",
"setupCommands": [
{ "text": "-target-select remote localhost:3333", "description": "connect to target", "ignoreFailures": false },
{ "text": "-file-exec-and-symbols ${workspaceRoot}/BUILD/NUCLEO_L496ZG/GCC_ARM/${workspaceRootFolderName}.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": "pyocd-gdbserver"
},
"osx": {
"MIMode": "gdb",
"MIDebuggerPath": "/usr/local/bin/arm-none-eabi-gdb",
"debugServerPath": "pyocd-gdbserver"
},
"windows": {
"preLaunchTask": "mbed.exe",
"MIMode": "gdb",
"MIDebuggerPath": "arm-none-eabi-gdb.exe",
//"miDebuggerServerAddress": "localhost:3333",
"serverStarted": "target halted due to debug-request, current mode: Thread",
//"debugServerPath": "C:\\Python27\\Scripts\\pyocd-gdbserver.exe",
"debugServerPath": "C:\\OpenOCD-20181130\\bin\\openocd.exe",
"debugServerArgs": "-s C:\\OpenOCD-20181130\\share\\openocd\\scripts -f board\\st_nucleo_l4.cfg -c init -c \"reset init\"",
"setupCommands": [
{ "text": "-environment-cd ${workspaceRoot}\\BUILD\\NUCLEO_L496ZG\\GCC_ARM\\", "ignoreFailures": false },
{ "text": "-target-select remote localhost:3333", "description": "connect to target", "ignoreFailures": false },
{ "text": "-file-exec-and-symbols ${workspaceRootFolderName}.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 }
]
}
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"name": "mbed",
"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
}
},
"args": ["compile", "--profile=debug", "-t", "GCC_ARM", "-m", "NUCLEO_L496ZG"],
"linux": {
"command": "mbed"
},
"osx": {
"command": "mbed"
},
"windows": {
"command": "mbed.exe"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment