Skip to content

Commit

Permalink
platform: use new debug API
Browse files Browse the repository at this point in the history
Implement sketch debugging according to the official Arduino
Platform Debug Specification [1].

The biggest improvement is that now `launch.json` can be fully
customized by the core (including the type of each entry),
so there is no need to copy files in the sketch folder.
In particular, `debug_custom.json` is not used anymore.

[1] https://arduino.github.io/arduino-cli/0.35/platform-specification/#sketch-debugging-configuration
  • Loading branch information
pillo79 committed Dec 6, 2023
1 parent faecc65 commit 0e673fa
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 117 deletions.
15 changes: 12 additions & 3 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29741,9 +29741,21 @@ nano_nora.build.psram_type=opi
nano_nora.build.memory_type={build.boot}_{build.psram_type}
nano_nora.build.disable_pin_remap=

nano_nora.debug_config.nano_nora.cortex-debug.custom.name=Arduino on Nano ESP32
nano_nora.debug_config.nano_nora.cortex-debug.custom.overrideAttachCommands.0=set remote hardware-watchpoint-limit 2
nano_nora.debug_config.nano_nora.cortex-debug.custom.overrideAttachCommands.1=monitor reset halt
nano_nora.debug_config.nano_nora.cortex-debug.custom.overrideAttachCommands.2=monitor gdb_sync
nano_nora.debug_config.nano_nora.cortex-debug.custom.overrideAttachCommands.3=interrupt
nano_nora.debug_config.nano_nora.cortex-debug.custom.overrideRestartCommands.0=monitor reset halt
nano_nora.debug_config.nano_nora.cortex-debug.custom.overrideRestartCommands.1=monitor gdb_sync
nano_nora.debug_config.nano_nora.cortex-debug.custom.overrideRestartCommands.2=interrupt
nano_nora.debug.additional_config=debug_config.nano_nora

nano_nora.tools.esptool_py.program.pattern_args=--chip {build.mcu} --port "{serial.port}" --before default_reset --after hard_reset write_flash -z --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size {build.flash_size} {build.bootloader_addr} "{build.path}/{build.project_name}.bootloader.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0xf70000 "{build.variant.path}/extra/nora_recovery/nora_recovery.ino.bin" 0x10000 "{build.path}/{build.project_name}.bin"
nano_nora.tools.esptool_py.erase.pattern_args=--chip {build.mcu} --port "{serial.port}" --before default_reset --after hard_reset erase_flash

nano_nora.programmer.default=esptool

nano_nora.menu.PartitionScheme.default=With FAT partition (default)
nano_nora.menu.PartitionScheme.spiffs=With SPIFFS partition (advanced)
nano_nora.menu.PartitionScheme.spiffs.build.partitions=app3M_spiffs9M_fact512k_16MB
Expand All @@ -29755,8 +29767,5 @@ nano_nora.menu.PinNumbers.byGPIONumber.build.disable_pin_remap=-DBOARD_USES_HW_G
nano_nora.menu.USBMode.default=Normal mode (TinyUSB)
nano_nora.menu.USBMode.hwcdc=Debug mode (Hardware CDC)
nano_nora.menu.USBMode.hwcdc.build.usb_mode=1
nano_nora.menu.USBMode.hwcdc.build.copy_jtag_files=1
nano_nora.menu.USBMode.hwcdc.build.openocdscript=esp32s3-builtin.cfg
nano_nora.menu.USBMode.hwcdc.build.debugconfig=esp32s3-arduino.json

##############################################################
116 changes: 79 additions & 37 deletions platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ tools.xtensa-esp-elf-gdb.path={runtime.platform.path}/tools/xtensa-esp-elf-gdb
tools.riscv32-esp-elf-gcc.path={runtime.platform.path}/tools/riscv32-esp-elf
tools.riscv32-esp-elf-gdb.path={runtime.platform.path}/tools/riscv32-esp-elf-gdb

debug.server.openocd.path={runtime.platform.path}/tools/openocd-esp32/bin/openocd
debug.server.openocd.scripts_dir={runtime.platform.path}/tools/openocd-esp32/share/openocd/scripts/
debug.server.openocd.scripts_dir.windows={runtime.platform.path}\tools\openocd-esp32\share\openocd\scripts\

tools.esptool_py.path={runtime.platform.path}/tools/esptool
tools.esptool_py.cmd=esptool
tools.esptool_py.cmd.linux=esptool.py
Expand Down Expand Up @@ -105,19 +101,6 @@ build.extra_flags=-DARDUINO_HOST_OS="{runtime.os}" -DARDUINO_FQBN="{build.fqbn}"
build.extra_libs=
build.memory_type={build.boot}_qspi

# OpenOCD default configs
build.copy_jtag_files=0
build.openocdscript.esp32=esp32-wrover-kit-3.3v.cfg
build.openocdscript.esp32s2=esp32s2-kaluga-1.cfg
build.openocdscript.esp32s3=esp32s3-builtin.cfg
build.openocdscript.esp32c3=esp32c3-builtin.cfg
build.openocdscript.esp32c6=esp32c6-builtin.cfg
build.openocdscript.esp32c6=esp32h2-builtin.cfg
build.openocdscript={build.openocdscript.{build.mcu}}

# Debug plugin configuration
build.debugconfig={build.mcu}.json

# Custom build options
build.opt.name=build_opt.h
build.opt.path={build.path}/{build.opt.name}
Expand Down Expand Up @@ -154,18 +137,6 @@ recipe.hooks.prebuild.set_core_build_flag.pattern.windows=cmd /c type nul > "{fi
recipe.hooks.core.prebuild.set_core_build_flag.pattern.windows=cmd /c echo "-DARDUINO_CORE_BUILD" > "{file_opts.path}"
recipe.hooks.core.postbuild.set_core_build_flag.pattern.windows=cmd /c type nul > "{file_opts.path}"

# Generate debug.cfg (must be postbuild)
recipe.hooks.postbuild.1.pattern=/usr/bin/env bash -c "[ {build.copy_jtag_files} -eq 0 ] || cp -f "{debug.server.openocd.scripts_dir}"board/{build.openocdscript} "{build.source.path}"/debug.cfg"
recipe.hooks.postbuild.1.pattern.windows=cmd /c IF {build.copy_jtag_files}==1 COPY /y "{debug.server.openocd.scripts_dir}board\{build.openocdscript}" "{build.source.path}\debug.cfg"

# Generate debug_custom.json
recipe.hooks.postbuild.2.pattern=/usr/bin/env bash -c "[ {build.copy_jtag_files} -eq 0 ] || cp -f "{runtime.platform.path}"/tools/ide-debug/{build.debugconfig} "{build.source.path}"/debug_custom.json"
recipe.hooks.postbuild.2.pattern.windows=cmd /c IF {build.copy_jtag_files}==1 COPY /y "{runtime.platform.path}\tools\ide-debug\{build.debugconfig}" "{build.source.path}\debug_custom.json"

# Generate chip.svd
recipe.hooks.postbuild.3.pattern=/usr/bin/env bash -c "[ {build.copy_jtag_files} -eq 0 ] || cp -f "{runtime.platform.path}"/tools/ide-debug/svd/{build.mcu}.svd "{build.source.path}"/debug.svd"
recipe.hooks.postbuild.3.pattern.windows=cmd /c IF {build.copy_jtag_files}==1 COPY /y "{runtime.platform.path}\tools\ide-debug\svd\{build.mcu}.svd" "{build.source.path}\debug.svd"

## Compile c files
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.extra_flags} {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" -DARDUINO_VARIANT="{build.variant}" -DARDUINO_PARTITION_{build.partitions} {build.extra_flags} {compiler.cpreprocessor.flags} {includes} "@{build.opt.path}" "@{file_opts.path}" "{source_file}" -o "{object_file}"

Expand Down Expand Up @@ -217,16 +188,87 @@ pluggable_monitor.required.serial=builtin:serial-monitor
## Upload/Debug tools
## ------------------

# Debugger configuration (general options)
# ----------------------------------------
# EXPERIMENTAL feature:
# - this is alpha and may be subject to change without notice
debug.executable={build.path}/{build.project_name}.elf
# Debugger configuration
# ----------------------

# OS-specific paths
pathsep=/
pathsep.windows=\
binext=
binext.windows=.exe

# ESP32 debug configuration
debug_script.esp32=esp32-wrover-kit-3.3v.cfg
debug_config.esp32.cortex-debug.custom.name=Arduino on ESP32
debug_config.esp32.cortex-debug.custom.postAttachCommands.0=set remote hardware-watchpoint-limit 2
debug_config.esp32.cortex-debug.custom.postAttachCommands.1=monitor reset halt
debug_config.esp32.cortex-debug.custom.postAttachCommands.2=monitor gdb_sync
debug_config.esp32.cortex-debug.custom.postAttachCommands.3=thb setup
debug_config.esp32.cortex-debug.custom.postAttachCommands.4=c
debug_config.esp32.cortex-debug.custom.overrideRestartCommands.0=monitor reset halt
debug_config.esp32.cortex-debug.custom.overrideRestartCommands.1=monitor gdb_sync
debug_config.esp32.cortex-debug.custom.overrideRestartCommands.2=thb setup
debug_config.esp32.cortex-debug.custom.overrideRestartCommands.3=c

# ESP32-S2 debug configuration
debug_script.esp32s2=esp32s2-kaluga-1.cfg
debug_config.esp32s2.cortex-debug.custom.name=Arduino on ESP32-S2
debug_config.esp32s2.cortex-debug.custom.postAttachCommands.0=set remote hardware-watchpoint-limit 2
debug_config.esp32s2.cortex-debug.custom.postAttachCommands.1=monitor reset halt
debug_config.esp32s2.cortex-debug.custom.postAttachCommands.2=monitor gdb_sync
debug_config.esp32s2.cortex-debug.custom.postAttachCommands.3=thb setup
debug_config.esp32s2.cortex-debug.custom.postAttachCommands.4=c
debug_config.esp32s2.cortex-debug.custom.overrideRestartCommands.0=monitor reset halt
debug_config.esp32s2.cortex-debug.custom.overrideRestartCommands.1=monitor gdb_sync
debug_config.esp32s2.cortex-debug.custom.overrideRestartCommands.2=thb setup
debug_config.esp32s2.cortex-debug.custom.overrideRestartCommands.3=c

# ESP32-S3 debug configuration
debug_script.esp32s3=esp32s3-builtin.cfg
debug_config.esp32s3.cortex-debug.custom.name=Arduino on ESP32-S3
debug_config.esp32s3.cortex-debug.custom.overrideAttachCommands.0=set remote hardware-watchpoint-limit 2
debug_config.esp32s3.cortex-debug.custom.overrideAttachCommands.1=monitor reset halt
debug_config.esp32s3.cortex-debug.custom.overrideAttachCommands.2=monitor gdb_sync
debug_config.esp32s3.cortex-debug.custom.overrideAttachCommands.3=thb setup
debug_config.esp32s3.cortex-debug.custom.overrideAttachCommands.4=c
debug_config.esp32s3.cortex-debug.custom.overrideRestartCommands.0=monitor reset halt
debug_config.esp32s3.cortex-debug.custom.overrideRestartCommands.1=monitor gdb_sync

# ESP32-C3 debug configuration
debug_script.esp32c3=esp32c3-builtin.cfg
debug_config.esp32c3.cortex-debug.custom.name=Arduino on ESP32-C3
debug_config.esp32c3.cortex-debug.custom.serverArgs.0=-d3
debug_config.esp32c3.cortex-debug.custom.overrideAttachCommands.0=set remote hardware-watchpoint-limit 8
debug_config.esp32c3.cortex-debug.custom.overrideAttachCommands.1=monitor reset
debug_config.esp32c3.cortex-debug.custom.overrideAttachCommands.2=monitor halt
debug_config.esp32c3.cortex-debug.custom.overrideAttachCommands.3=monitor gdb_sync
debug_config.esp32c3.cortex-debug.custom.overrideAttachCommands.4=thb setup
debug_config.esp32c3.cortex-debug.custom.overrideRestartCommands.0=monitor reset
debug_config.esp32c3.cortex-debug.custom.overrideRestartCommands.1=monitor halt
debug_config.esp32c3.cortex-debug.custom.overrideRestartCommands.2=monitor gdb_sync
debug_config.esp32c3.cortex-debug.custom.overrideRestartCommands.3=thb setup

# ESP32-C6 debug configuration (TBD)
debug_script.esp32c6=esp32c6-builtin.cfg
debug_config.esp32c6=

# ESP32-H2 debug configuration (TBD)
debug_script.esp32h2=esp32h2-builtin.cfg
debug_config.esp32h2=

# Debug API variable definitions
debug.executable={build.path}{pathsep}{build.project_name}.elf
debug.toolchain=gcc
debug.toolchain.path={tools.{build.tarch}-esp-elf-gdb.path}/bin/
debug.toolchain.prefix={build.tarch}-{build.target}-elf-
debug.toolchain.path={tools.{build.tarch}-esp-elf-gdb.path}{pathsep}bin{pathsep}
debug.toolchain.prefix={build.tarch}-{build.target}-elf
debug.server=openocd
debug.server.openocd.script=debug.cfg
debug.server.openocd.path={runtime.platform.path}{pathsep}tools{pathsep}openocd-esp32{pathsep}bin{pathsep}openocd{binext}
debug.server.openocd.scripts_dir={runtime.platform.path}{pathsep}tools{pathsep}openocd-esp32{pathsep}share{pathsep}openocd{pathsep}scripts{pathsep}
debug.server.openocd.scripts.0=board{pathsep}{debug_script.{build.mcu}}
debug.svd_file={runtime.platform.path}{pathsep}tools{pathsep}ide-debug{pathsep}svd{pathsep}{build.mcu}.svd

debug.cortex-debug.custom.request=attach
debug.additional_config=debug_config.{build.mcu}

##
## ESPTool
Expand Down
19 changes: 0 additions & 19 deletions tools/ide-debug/esp32.json

This file was deleted.

22 changes: 0 additions & 22 deletions tools/ide-debug/esp32c3.json

This file was deleted.

19 changes: 0 additions & 19 deletions tools/ide-debug/esp32s2.json

This file was deleted.

17 changes: 0 additions & 17 deletions tools/ide-debug/esp32s3.json

This file was deleted.

0 comments on commit 0e673fa

Please sign in to comment.