Starting 2.3.0 debugger with J-Link fails: "unable to find CMSIS-DAP device"

Hi @HarrySatt. A significant rework of the debugger configuration system was released in Arduino IDE 2.3.0. This was necessary because as more and more Arduino boards platforms started taking advantage of the debugger feature, some advanced requirements emerged that were not properly accommodated by the original the initial experimental system.

The new system is more powerful and flexible, so this change will greatly benefit the platform developers and users in the years to come, but unfortunately it does require that those who are using a J-Link debug probe (or any other configuration that requires the use of the IDE's debug_custom.json feature) must make some adjustments to their workflow.

Instructions

  1. Open the sketch you want to debug in Arduino IDE.
  2. Select the "debug_custom.json" editor tab.
  3. Add this line at the top of the file:
    [
    
  4. Add this line at the top of the file:
    ]
    
  5. Add the following lines in the middle of the file
    "configId": "arduino:samd:mkrwan1310:programmer=jlink",
    "server": "jlink",
    "serverPath": "<JLinkGDBServer path>",
    
  6. Replace <JLinkGDBServer path> with the path to the J-Link GDB server tool, which you will find in the value of the existing serverpath key (note the lowercase p in path).
    You should now have something like this:
    [
      {
        "servertype": "jlink",
        "device": "ATSAMD21G18",
        "configId": "arduino:samd:mkrwan1310:programmer=jlink",
        "server": "jlink",
        "serverPath": "C:/Program Files/JLink/JLinkGDBServerCL",
        "interface": "swd",
        "serverpath": "C:/Program Files/JLink/JLinkGDBServerCL"
      }
    ]
    
  7. Select File > Save from the Arduino IDE menus.
  8. Select Tools > Board > Arduino SAMD Boards (32-bits ARM Cortex-M0+) > Arduino MKR WAN 1310 from the Arduino IDE menus.
  9. Select Tools > Programmer > Segger J-Link from the Arduino IDE menus.
  10. Select Sketch > Optimize for Debugging from the Arduino IDE menus (if it is not already enabled).
  11. Select Sketch > Verify/Compile from the Arduino IDE menus.
  12. Wait for the compilation to finish successfully.
  13. Connect your J-Link and MKR WAN 1310 to your computer as usual.
  14. Click the "Start Debugging" button on the Arduino IDE toolbar.

The debugger should now start up and work as expected.


Please let me know if you have any questions or problems while following those instructions.

Explanation

The instructions above will allow you to get back to using the debugger in this specific application of a J-Link debug probe and a MKR WAN 1310 board, but you (or others who have similar questions and find this thread during their researches) might be interested in understanding why these changes were necessary and how you might make equivalent migrations for other configurations. I'll provide relevant information below. If you aren't interested in "the boring details", you can feel free to skip the rest of this reply.

There are two separate factors you should be aware of:

Breaking change to debug_custom.json format

Previously, the data structure of the file was an object. For example:

{
  "servertype": "jlink",
  "device": "ATSAMD21G18",
  "interface": "SWD",
  "serverpath": "C:/Program Files/SEGGER/JLink/JLinkGDBServerCL"
}

It is now an array of objects. For example:

[
  {
    "servertype": "jlink",
    "device": "ATSAMD21G18",
    "interface": "SWD",
    "serverpath": "C:/Program Files/SEGGER/JLink/JLinkGDBServerCL"
  }
]

The benefit of this new structure is that it allows you to define multiple custom debugger configurations. For this reason, it is necessary to provide an identifier for each configuration so that Arduino IDE will know which one is appropriate to apply. This is done via the configId key. The value has the following format:

<board FQBN>:programmer=<programmer ID>

For example:

[
  {
    "configId": "arduino:samd:mkrwan1310:programmer=jlink",
    "servertype": "jlink",
    "device": "ATSAMD21G18",
    "interface": "SWD",
    "serverpath": "C:/Program Files/SEGGER/JLink/JLinkGDBServerCL"
  }
]

It might seem too confusing to figure out the FQBN and programmer ID, but you can get Arduino IDE to generate it for you:

  1. Select the board you are using from the Arduino IDE menus.
  2. Select the debug probe you are using from the Tools > Programmer menu in Arduino IDE.
    If there is no Tools > Programmer menu, you can skip this step.
  3. Select Sketch > Verify/Compile from the Arduino IDE menus.
  4. Wait for the compilation to finish successfully.
  5. Click the "Start Debugging" button on the Arduino IDE toolbar.
  6. Wait for the process to fail, as indicated by the appearance of an error notification at the bottom right corner of the Arduino IDE menu.
    The failure is expected since we haven't yet added the configId key to the debug_custom.json file. The purpose of clicking the "Start Debugging" button is only to cause Arduino IDE to generate the configId value, which is accomplished even when the debugger doesn't successfully start.
  7. Click the debugger icon on the activity bar on the left side of the Arduino IDE window.
    The "DEBUG" view will open in the left side panel.
  8. Click the gear icon ('Open "launch.json"') on the debugger toolbar.
    A "launch.json" tab will open in the editor.
  9. Find the appropriate configurations[*].configId key in launch.json and copy the value.
    For example, if the file contains this content:
    {
      "version": "0.2.0",
      "configurations": [
        {
          "configId": "arduino:samd:mkrwan1310:programmer=jlink",
    
    Then copy the "configId": "arduino:samd:mkrwan1310:programmer=jlink",.
  10. Select the "debug_custom.json" editor tab.
  11. Paste the copied configId key into the file.
  12. Select File > Save from the Arduino IDE menus.

Bug when overriding certain configuration keys

In addition to the intentionally introduced breaking change I described above, unfortunately a bug was also accidentally introduced that impacts users of the debug_custom.json feature:

I have already submitted a fix for the bug, but it will be some time before that is available as part of an Arduino IDE build. Fortunately it is possible to workaround the bug by using different key names in your debug_custom.json file:

Original key Workaround key
armToolchainPath toolchainPath
configFiles serverConfiguration.scripts
serverpath serverPath
servertype server

:red_exclamation_mark: The workaround will stop working once the bug is fixed, so you should also leave the correct keys in your debug_custom.json file so that it will continue working even after you update Arduino IDE to a new version that has the fix.