Skip to content

Arduino IDE 2.x Debug feature support #1896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
N0rbert opened this issue Dec 10, 2022 · 4 comments · Fixed by #1976
Closed

Arduino IDE 2.x Debug feature support #1896

N0rbert opened this issue Dec 10, 2022 · 4 comments · Fixed by #1976
Assignees
Labels
Milestone

Comments

@N0rbert
Copy link
Contributor

N0rbert commented Dec 10, 2022

Is your feature request/improvement related to a problem? Please describe.

Yes, it is related to debugging problem. I'm unable to debug simple Blink.ino program on Nucleo F446RE board. Arduino IDE 2.0.3 says "Debugging is not supported by 'Nucleo-64'".

Steps to reproduce:

  1. Download latest Arduino IDE 2.0.3, extract and launch it.
  2. In Arduino IDE go to FilePreferences and set https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json as additional board URL for stm32duino.
  3. In Boards Manager add STM32 MCU based boards by STMicroelectronics.
  4. Select Nucleo-64 board and set Tools → Board part number to Nucleo F446RE.
  5. Set Tools → Debug symbols and core logs to Symbols Enabled (-g).
  6. Set Tools → Optimize to Debug (-Og).
  7. Try to debug the program.

blink-debug

Pressing Debug → Start Debugging open empty template for launch.json instead of normally preconfigured and reproducible file.

debug-start_debugging

It is unclear what user should write in the fields on launch.json file

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  "version": "0.2.0",
  "configurations": [
  {
    "cwd": "${workspaceRoot}",
    "executable": "./bin/executable.elf",
    "name": "Debug with OpenOCD",
    "request": "launch",
    "type": "cortex-debug",
    "servertype": "openocd",
    "configFiles": [],
    "searchDir": [],
    "runToEntryPoint": "main",
    "showDevDebugOutput": "none"
  }
  ]
}

to get OpenOCD working with STM32.

Describe the solution you'd like

Arduino IDE 2.x detects preconfigured launch.json for well known and mature stm32duino framework.
Debugging is possible using OpenOCD software and embedded ST-Link hardware.

Describe alternatives you've considered

The debugging of STM32F446RE on Nucleo-64 F446RE is actually possible using VSCode with vscode-arduino, cortex-debug and marus25.cortex-debug-dp-stm32f4 extensions by openocd from Debian repository and STM32F446x.svd file from marus25.cortex-debug-dp-stm32f4 extension.

Additional context

The current behavior was observed using latest Arduino IDE
(Version: 2.0.3 ; Date: 2022-12-05T09:27:52.215Z ; CLI Version: 0.29.0 [76251df9] ) and stm32duino 2.3.0.

This issue was originally filed at arduino/arduino-ide#1760 .

@N0rbert
Copy link
Contributor Author

N0rbert commented Dec 10, 2022

I have just found this interesting thread - https://www.stm32duino.com/viewtopic.php?f=18&p=10740 by @luca_stm32 .

I adapted this method to my Nucleo F446RE as follows on the same Debian 11 system:

sudo apt-get install openocd
sudo usermod -a -G dialout $USER

In Arduino IDE 2.0.3 at first I have installed Arduino SAMD Boards (32-bits ARM Cortex-M0+) from Board Manager.
Then I hacked needed files:

cp -v /usr/share/openocd/scripts/board/st_nucleo_f4.cfg ~/.arduino15/packages/STMicroelectronics/hardware/stm32/2.3.0/variants/STM32F0xx/F030R8T/\{build.openocdscript\}
# ^^ note: I do not know why openocd needs above MCU and path! But this works!

cat <<EOF > /tmp/platform.txt.patch
--- /home/d/.arduino15/packages/STMicroelectronics/hardware/stm32/2.3.0/platform.txt
+++ /home/d/.arduino15-hack/packages/STMicroelectronics/hardware/stm32/2.3.0/platform.txt
@@ -215,3 +215,42 @@
 tools.remoteproc_gen.upload.params.verbose=
 tools.remoteproc_gen.upload.params.quiet=
 tools.remoteproc_gen.upload.pattern="{busybox}" sh "{path}/{script}" generate "{build.path}/{build.project_name}.elf" "{build.path}/run_arduino_{build.project_name}.sh"
+
+# 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
+debug.toolchain=gcc
+debug.toolchain.path={runtime.tools.xpack-arm-none-eabi-gcc-10.3.1-2.3.path}/bin/
+debug.toolchain.prefix=arm-none-eabi-
+debug.server=openocd
+debug.server.openocd.path={runtime.tools.openocd-0.10.0-arduino7.path}/bin/openocd
+debug.server.openocd.scripts_dir={runtime.tools.openocd-0.10.0-arduino7.path}/share/openocd/scripts/
+debug.server.openocd.script={runtime.platform.path}/variants/{build.variant}/{build.openocdscript}
+
+#
+# OpenOCD sketch upload - version with configurable bootloader size
+# FIXME: this programmer is a workaround for default options being overwritten by uploadUsingPreferences
+#
+
+tools.openocd-withbootsize.path={runtime.tools.openocd-0.10.0-arduino7.path}
+tools.openocd-withbootsize.cmd=bin/openocd
+tools.openocd-withbootsize.cmd.windows=bin/openocd.exe
+
+tools.openocd-withbootsize.upload.params.verbose=-d2
+tools.openocd-withbootsize.upload.params.quiet=-d0
+tools.openocd-withbootsize.upload.pattern="{path}/{cmd}" {upload.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.bin} verify reset {bootloader.size}; shutdown"
+
+# Program flashes the binary at 0x0000, so use the linker script without_bootloader
+tools.openocd-withbootsize.program.params.verbose=-d2
+tools.openocd-withbootsize.program.params.quiet=-d0
+tools.openocd-withbootsize.program.pattern="{path}/{cmd}" {program.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; program {{build.path}/{build.project_name}.elf} verify reset; shutdown"
+
+tools.openocd-withbootsize.erase.params.verbose=-d3
+tools.openocd-withbootsize.erase.params.quiet=-d0
+tools.openocd-withbootsize.erase.pattern=
+
+tools.openocd-withbootsize.bootloader.params.verbose=-d2
+tools.openocd-withbootsize.bootloader.params.quiet=-d0
+tools.openocd-withbootsize.bootloader.pattern="{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{runtime.platform.path}/bootloaders/{bootloader.file}} verify reset; shutdown"

EOF

patch -p1 ~/.arduino15/packages/STMicroelectronics/hardware/stm32/2.3.0/platform.txt < /tmp/platform.txt.patch

And as the result I can debug the program:

f446re-debug

@fpistm
Copy link
Member

fpistm commented Dec 12, 2022

Hi @N0rbert
We are aware of this and commented on the post you referred:
https://www.stm32duino.com/viewtopic.php?p=10740&sid=4664002bf596b3872fb0170d9f3d69a5#p10740
This will probably come.

@fpistm fpistm changed the title Preconfigured launch.json and other debug settings are needed for modern Arduino IDE 2.x Arduino IDE 2.x Debug feature support Dec 12, 2022
@fpistm
Copy link
Member

fpistm commented Feb 15, 2023

Unfortunately, we do not succeed to reproduce the setup. My guess is the update of arduino-cli prevent to have it working.
Could you confirm it always work on your side with Arduino 2.0.3, please ?

@fpistm fpistm added this to the 2.5.0 milestone Mar 6, 2023
@gautierg-st gautierg-st mentioned this issue Mar 15, 2023
4 tasks
@fpistm fpistm added enhancement New feature or request and removed New feature labels Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants