Debugging Using Custom Hardware

You may want to alter the existing Hardware Debugger settings, or try out a completely new setup which isnt pre-configured in Visual Micro.

All steps are below, and this is added into your local project via the "debugger_launch.json" file, so is not lost via updates to Visual Micro / Visual Studio.

 

Further Information on Microsoft MI: https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md#customlaunchsetupcommands

 

VSCode Style Configuration 

Warning 16Warning:
This is the most intricate layer of configuration and will require setting paths to debugging tools.

Warning 16Warning:
This will override the debugger selections until the debugger_launch.json file is removed

 

 

Add debugger_launch.json

Right Click on the Project in Solution Explorer > Add > Custom GDB Debugger (Advanced)

This will create a [variant].[configuration_name][.]debugger_launch.json file which is the launch command passed to the Microsoft MI Debugger which powers the debugging in Visual Studio.

 

NOTE - All parameters are defaulted to the global parameters supplied by vMicro using the merge syntax $(optionName)

 

JSON NOTES -
  • GDB Paths can be obtained from another board, for the appropriate debuggers' location (review Micro Build output when attaching debugger to view final launch JSON)
  • COM Port is the port of the Black Magic Probe, not your Arduino DUE
  • JSON escaping for '\' > '\\' and '"' > '\"' (Visual Studio will perform this for you when pasting)
  • $(progam) and $(buildpath) will be automatically populated by vMicro

Getting Current Settings

If you want to amend an existing debugger, you can expose the current JSON in use by:

 

  1. Enable vMicro > Upload > Verbose
  2. Perform a Build, then try to Attach the Debugger closest to what you need
  3. Inspect the Output > Micro Build Window, there will be the JSON output which can be used in a debugger_launch.json file.

 

 

JSON Example - Setup Arduino Due on Black Magic with GDB

For this configuration we only need to launch GDB, so do not need to complete the debugServer properties.

{
 "serverLaunchTimeout": 5000,
  "filterStdout": false,
  "filterStderr": true,
  "targetArchitecture": "arm",
  "stopAtEntry": false,
  "externalConsole": false,
  "MIMode": "gdb",
  "MIDebuggerServerAddress": "",
  "cwd": "$(buildPath)",
  "MIDebuggerPath": "C:\\Users\\vMicro\\AppData\\Local\\arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1\\bin\\arm-none-eabi-gdb.exe",
  "MIDebuggerArgs": "-nh -b 115200 -ex \"target extended-remote \\\\.\\COM52\" -ex \"monitor swdp_scan\" -ex \"attach 1\"",
  "debugServerPath": "",
  "debugServerArgs": "",
  "program": "$(program)",
  "logging": {
    "moduleLoad": false,
    "trace": false,
    "engineLogging": false,
    "programOutput": false,
    "exceptions": false,
    "traceResponse": false
  }
}

 

This results in the below command:- 

C:\Users\vMicro\AppData\Local\arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1\bin\arm-none-eabi-gdb.exe -nh -b 115200 -ex \"target extended-remote \\.\COM52\" -ex \"monitor swdp_scan\" -ex \"attach 1\"

 

NOTE - GDB will be passed the ELF file automatically, from the program parameter.

 

 

JSON Example - Setup Arduino Due on Atmel ICE with OpenOCD + GDB

In this setup we need to run OpenOCD to interface with the debugger, and then GDB to interface with OpenOCD and MI.

 

# MI Debugger Properties
{
  "serverLaunchTimeout": 5000,
  "filterStdout": false,
  "filterStderr": true,
  "targetArchitecture": "arm",
  "stopAtEntry": false,
  "externalConsole": false,
  "MIMode": "gdb",
  "MIDebuggerServerAddress": "localhost:3333",
  "cwd": "$(buildPath)",
  "MIDebuggerPath": "C:\\Users\\Simon\\AppData\\Local\\arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin\\arm-none-eabi-gdb.exe",
  "MIDebuggerArgs": "",
  "debugServerPath": "C:\\ProgramData\\vmicro\\tools\\openocd-0.10.0.1\\bin/openocd.exe",
  "debugServerArgs": "-d2 -s \"C:\\ProgramData\\vmicro\\tools\\openocd-0.10.0.1/share/openocd/scripts/\" -c \"interface cmsis-dap\" -c \"cmsis_dap_vid_pid 0x03eb 0x2141\" -c \"set CHIPNAME at91sam3X8E\" -c \"source [find target/at91sam3ax_8x.cfg]\" -c \"init; reset halt\"",
  "program": "$(program)",
  "logging": {
    "moduleLoad": false,
    "trace": false,
    "engineLogging": false,
    "programOutput": false,
    "exceptions": false,
    "traceResponse": false
  }
}

This results in two commands running, one for the debugServer and one for the GDB Debugger

"C:\ProgramData\vmicro\tools\openocd-0.10.0.1\bin/openocd.exe" -d2 -s "C:\ProgramData\vmicro\tools\openocd-0.10.0.1/share/openocd/scripts/" -c "interface cmsis-dap" -c "cmsis_dap_vid_pid 0x03eb 0x2141" -c "set CHIPNAME at91sam3X8E" -c "source [find target/at91sam3ax_8x.cfg]" -c "init; reset halt"

"C:\Users\Simon\AppData\Local\arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin\arm-none-eabi-gdb.exe" --interpreter=mi

NOTE - GDB will be passed the ELF file automatically, from the program parameter, as well as targeted to the MIDebuggerServerAddress to connect to OpenOCD

 

 

 

JSON Example - Setup Arduino Due for J-Link using Segger JLink GDB Server

Using these configuration tools you can use alternative debugging software provided it is compatible with GDB.

Here we have modified the JSON Output from vMicro to amend the MIDebuggerServerAddress, debugServerPath, and debugServerArgs, allowing us to use the JLink software directly instead of OpenOCD.

NOTE - It is best to work out the JLink Command line options via the GUI Tool, to ensure the correct target is selected for debugging.

NOTE - If you have overridden the driver for your JLink, re-install the Segger driver from the \USBDriver folder within your Segger Software installation.

{
  // Modifications for using Segger JLink Software instead of OpenOCD with vMicro
  "serverLaunchTimeout": 5000,
  "filterStdout": false,
  "filterStderr": true,
  "targetArchitecture": "arm",
  "stopAtEntry": false,
  "externalConsole": false,
  "MIMode": "gdb",
  // NOTE - The GDBServer address default is 2331 for Segger
  "MIDebuggerServerAddress": "localhost:2331",
  "cwd": "C:\\Users\\Simon\\AppData\\Local\\Temp\\VMBuilds\\JLinkGDB_DUE\\arduino_due_x_dbg\\Debug",
  "MIDebuggerPath": "C:\\Users\\Simon\\AppData\\Local\\arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\4.8.3-2014q1/bin\\arm-none-eabi-gdb.exe",
  "MIDebuggerArgs": "",
  // NOTE - Your path may differ for your Segger Software Installation
  "debugServerPath": "C:\\Program Files (x86)\\SEGGER\\JLink_V644g\\JLinkGDBServer.exe",
  // NOTE - Ensure the right -device is specified - check tool setup by running the above tool in Windows
  "debugServerArgs": " -select USB -device ATSAM3X8E -endian little -if JTAG -speed 4000 -noir -LocalhostOnly",
  "program": "C:/Users/Simon/AppData/Local/Temp/VMBuilds/JLinkGDB_DUE/arduino_due_x_dbg/Debug/JLinkGDB_DUE.ino.elf",
  "logging": {
    "moduleLoad": false,
    "trace": false,
    "engineLogging": false,
    "programOutput": false,
    "exceptions": false,
    "traceResponse": false
  }
}

Got One Working?

Please Click here to Email us if you have built a working configuration you would like to see in Visual Micro!