Hi @gmacario,
The Arduino Nicla Sense ME exposes a native CMSIS-DAP over USB, i.e., using the USB port connection, you can use any CMSIS-DAP-compatible debugging system to debug the Nicla Sense ME.
A simple, barebone procedure to get started is the following:
- Connect to the board with OpenOCD
- Use GDB to debug the board via OpenOCD.
You can use OpenOCD from the Arduino distribution or install version 0.11.0 from the official repository. The one pre-installed with Arduino can be found at
> $ARDUINO15/packages/arduino/tools/openocd/0.11.0-arduino2/bin/openocd
To connect to the Nicla Sense ME you can use the following command line:
> $ARDUINO15/packages/arduino/tools/openocd/0.11.0-arduino2/bin/openocd -s $ARDUINO15/packages/arduino/tools/openocd/0.11.0-arduino2/share/openocd/scripts/ -f interface/cmsis-dap.cfg -f target/nrf52.cfg -c "telnet_port disabled; init; reset init; halt; adapter speed 10000;"
Open On-Chip Debugger 0.11.0+dev-gab95bac57-dirty (2021-05-11-10:57)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : CMSIS-DAP: SWD Supported
Info : CMSIS-DAP: FW Version = v1.0
Info : CMSIS-DAP: Serial# = 27D35979
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : nrf52.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for nrf52.cpu on 3333
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x00006dd0 msp: 0x20010000
adapter speed: 10000 kHz
Info : Listening on port 6666 for tcl connections
Info : telnet server disabled
From this point, you can connect any GDB-enabled debugger to the Nicla Sense ME.
For example, you can install the ARM GCC Tools from the official repository or use the one distributed with Arduino:
> $ARDUINO15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-gdb --ex 'target extended-remote :3333'
GNU gdb (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 8.0.50.20171128-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-apple-darwin10 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Remote debugging using :3333
warning: No executable has been specified and target does not support
determining executable automatically. Try using the "file" command.
0x00006dd0 in ?? ()
(gdb)
And from here, you can start your debugging session.
Currently, the Arduino IDE 2.0 (2.0.2) doesn't support debugging boards based on ArduinoCore-mbed. Still, the same tools and methodology can be used inside PlatformIO, Visual Studio Code with Cortex Debug extension, Eclipse, etc.
As a reference, the following is an example configuration for Cortex-Debug to be included in .vscode/launch.json
to configurations
:
{
"cwd": "${workspaceRoot}",
"executable": "./build/arduino.mbed_nicla.nicla_sense/OneWireSimpleNiclaSense.ino.elf",
"name": "Debug with OpenOCD",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"openOCDLaunchCommands": [
"telnet_port disabled",
"init",
"reset init",
"halt",
"adapter speed 10000"
],
"device": "nRF5233",
"configFiles": [
"interface/cmsis-dap.cfg",
"target/nrf52.cfg"
],
"searchDir": [],
"runToEntryPoint": "main",
"showDevDebugOutput": "none",
"svdFile": ".vscode/nrf52833.svd"
}
Also, remember to compile the sketch with the "Optimize for Debugging" option enabled in the Arduino IDEs or the CLI (compile --optimize-for-debugging
) and that you can create and .elf
file for debugging purposes using the "Export Compiled Binary" from the IDE or CLI (compile --optimize-for-debugging -e
).