From 7d1dd858bbb395b592d8f96ab4179dbb12c7662c Mon Sep 17 00:00:00 2001 From: Luca Burelli Date: Wed, 30 Aug 2023 09:54:31 +0200 Subject: [PATCH] Nano ESP32: add debug support (#8567) * Nano ESP32: fix previous merge issues * platform: remove previous build options if file is missing "touch" would create the file if not present, but not delete its contents if a previous run left the file in the build dir. * platform: make debug_custom.json file customizable by board * platform: fix default debug prefix "debug.toolchain.prefix" must end with a dash, since only the tool name is appended to this string. The reason this is not a major issue is that the "debug_custom.json" file (copied in the sketch directory when debugging is enabled) forces its own prefix. And to make things more interesting, the "toolchainPrefix" entry in that file should _not_ end with a dash. * Nano ESP32: add debugging support --- boards.txt | 9 ++++++--- platform.txt | 11 +++++++---- tools/ide-debug/esp32s3-arduino.json | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 tools/ide-debug/esp32s3-arduino.json diff --git a/boards.txt b/boards.txt index 077c46452..54f16e019 100644 --- a/boards.txt +++ b/boards.txt @@ -25673,8 +25673,11 @@ nano_nora.menu.PinNumbers.default=By Arduino pin (default) nano_nora.menu.PinNumbers.byGPIONumber=By GPIO number (legacy) nano_nora.menu.PinNumbers.byGPIONumber.build.disable_pin_remap=-DBOARD_USES_HW_GPIO_NUMBERS -nano_nora.menu.PinNumbers.default=By Arduino pin (default) -nano_nora.menu.PinNumbers.byGPIONumber=By GPIO number (legacy) -nano_nora.menu.PinNumbers.byGPIONumber.build.disable_pin_remap=-DBOARD_USES_HW_GPIO_NUMBERS +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 ############################################################## diff --git a/platform.txt b/platform.txt index 970107849..dcd24c540 100644 --- a/platform.txt +++ b/platform.txt @@ -160,6 +160,9 @@ build.openocdscript.esp32s3=esp32s3-builtin.cfg build.openocdscript.esp32c3=esp32c3-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} @@ -181,7 +184,7 @@ recipe.hooks.prebuild.4.pattern.windows=cmd /c IF EXIST "{build.source.path}\boo # Check if custom build options exist in the sketch folder recipe.hooks.prebuild.5.pattern=bash -c "[ ! -f "{build.source.path}"/build_opt.h ] || cp -f "{build.source.path}"/build_opt.h "{build.path}"/build_opt.h" -recipe.hooks.prebuild.6.pattern=bash -c "[ -f "{build.path}"/build_opt.h ] || touch "{build.path}"/build_opt.h" +recipe.hooks.prebuild.6.pattern=bash -c "[ -f "{build.path}"/build_opt.h ] || : > "{build.path}"/build_opt.h" recipe.hooks.prebuild.5.pattern.windows=cmd /c if exist "{build.source.path}\build_opt.h" COPY /y "{build.source.path}\build_opt.h" "{build.path}\build_opt.h" recipe.hooks.prebuild.6.pattern.windows=cmd /c if not exist "{build.path}\build_opt.h" type nul > "{build.path}\build_opt.h" @@ -201,8 +204,8 @@ recipe.hooks.postbuild.1.pattern=bash -c "[ {build.copy_jtag_files} -eq 0 ] || c 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=bash -c "[ {build.copy_jtag_files} -eq 0 ] || cp -f "{runtime.platform.path}"/tools/ide-debug/{build.mcu}.json "{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.mcu}.json" "{build.source.path}\debug_custom.json" +recipe.hooks.postbuild.2.pattern=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=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" @@ -263,7 +266,7 @@ pluggable_monitor.required.serial=builtin:serial-monitor debug.executable={build.path}/{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.prefix={build.tarch}-{build.target}-elf- debug.server=openocd debug.server.openocd.script=debug.cfg diff --git a/tools/ide-debug/esp32s3-arduino.json b/tools/ide-debug/esp32s3-arduino.json new file mode 100644 index 000000000..559d2878c --- /dev/null +++ b/tools/ide-debug/esp32s3-arduino.json @@ -0,0 +1,18 @@ +{ + "name":"Arduino on ESP32-S3", + "toolchainPrefix":"xtensa-esp32s3-elf", + "svdFile":"debug.svd", + "request":"attach", + "overrideAttachCommands":[ + "set remote hardware-watchpoint-limit 2", + "monitor reset halt", + "monitor gdb_sync", + "thb setup", + "interrupt" + ], + "overrideRestartCommands":[ + "monitor reset halt", + "monitor gdb_sync", + "interrupt" + ] +}