Arduino IDE 2 & Debug feature

Development environment specific, Arduino, Eclipse, VS2013, Em::Blocks etc
luca_stm32
Posts: 19
Joined: Tue Feb 18, 2020 3:37 pm

Arduino IDE 2 & Debug feature

Post by luca_stm32 »

Hi.
Last week Arduino released IDE 2 (IDE 1.8.X is now "legacy"). As described here https://docs.arduino.cc/software/ide-v2 ... 2-debugger, Arduino IDE 2 has the debug functionality!

Searching on google, I found this link https://forum.arduino.cc/t/update-on-ar ... g/980363/3: it seems to me that platform.txt should be modified in order to add this feature (see https://github.com/arduino/ArduinoCore- ... #L129-L140).

Is the implementation of this feature in the STM32duino core roadmap?

Thanks for all your great job.
Regards.
Luca
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Arduino IDE 2 & Debug feature

Post by fpiSTM »

Hi,

we probably test this.
Anyway any help are welcome. If you succeed to configure it properly do not hesitate to share feedback or do a a PR.

Note that the ide 2.0.0 has some issue. I use it since 1 week and saw several small issues.
luca_stm32
Posts: 19
Joined: Tue Feb 18, 2020 3:37 pm

Re: Arduino IDE 2 & Debug feature

Post by luca_stm32 »

Hi.
In this days, I made some tests in order to make the debugger work with Arduino IDE 2.
I'm on Linux and I used a STlink chinese clone as programmer/debugger.
I tried with a Bluepill board.
I use Arduino IDE 2 AppImage.

First of all, I installed Arduino SAMD board package (ver 1.8.13) in order to have openocd installed.
Then I modified platform.txt and boards.txt as follow:
In platform platform.txt I added the following lines:

# 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"

In boards.txt, I added only last line to Generic F1 section

################################################################################
# Generic F1
GenF1.name=Generic STM32F1 series

GenF1.build.core=arduino
GenF1.build.board=GenF1
GenF1.build.mcu=cortex-m3
GenF1.build.series=STM32F1xx
GenF1.build.cmsis_lib_gcc=arm_cortexM3l_math
GenF1.build.st_extra_flags=-D{build.product_line} {build.enable_usb} {build.xSerial} {build.bootloader_flags}
GenF1.build.openocdscript=openocd_scripts/stm32F103.cfg

Then I added two folder under /.arduino15/packages/STMicroelectronics/hardware/stm32/2.3.0/variants/STM32F1xx/F103C4T_F103C6(T-U)/
debug_scripts and openocd_scripts (I don't know why Bluepill variants point to F103C4T_F103C6(T_U) directory).
In debug_scripts I added the file variant.gdb
#
# STM32F103 OpenOCD script.
#
# Copyright (c) 2014-2015 Arduino LLC. All right reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#

# Define 'reset' command
define reset

info reg

break main

# End of 'reset' command
end

target remote | openocd -c "interface cmsis-dap" -c "set CHIPNAME at91samd21g18" -f target/stm32f1x.cfg -c "gdb_port pipe; log_output openocd.log"

and under openocd_script I added the file stm32F103.cfg

#
# STM32F103 OpenOCD script.
#
# Copyright (c) 2014-2015 Arduino LLC. All right reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#

source [find interface/stlink.cfg]

# chip name
set CHIPNAME STM32F103
set ENDIAN little

# choose a port here
set telnet_port 0

source [find target/stm32f1x.cfg]


With this configuration I can debug the code.
I hope I have not forgot something.
I hope this could help.

Regards.
Luca
luca_stm32
Posts: 19
Joined: Tue Feb 18, 2020 3:37 pm

Re: Arduino IDE 2 & Debug feature

Post by luca_stm32 »

Hi.
With 2.0.3 Arduino IDE release I can load SD files too! In this way, I can see also the Cortex Peripheral Register (older Arduino 2 IDE versions doesn't work).

In the sketch folder, I added the file debug_custom.json:

Code: Select all

{
    "svdFile": "path_where_SVD_file_is_located/STM32SVD_File.svd"
}
Hope this could help.
Best regards.
Luca
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Arduino IDE 2 & Debug feature

Post by fpiSTM »

Thanks @luca_stm32

Related issue on GitHub:
https://github.com/stm32duino/Arduino_C ... ssues/1896
Dougl
Posts: 1
Joined: Sat Dec 17, 2022 3:27 am

Re: Arduino IDE 2 & Debug feature

Post by Dougl »

@fpiSTM and @luca_stm32 just wanted to say that I followed the instructions on Kubuntu 20.04 running Arduino IDE v2.0.3 appImage and was able to do in-circuit debugging using ST-Link and an STM32 bluepill( stm32f103 ). Your instructions were very concise. Thank you.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Arduino IDE 2 & Debug feature

Post by fpiSTM »

Hi @luca_stm32 and @Dougl
we tried to reproduce your setup to debug, unfortunately it does not work.
I think the arduino-cli update since you have tested avoid to have it functional.
Just to be sure about your setup, you run it under which OS ?
luca_stm32
Posts: 19
Joined: Tue Feb 18, 2020 3:37 pm

Re: Arduino IDE 2 & Debug feature

Post by luca_stm32 »

Hi fpiSTM
I'm on Kubuntu 22.04.
I use Arduino IDE 2.0.3 and STM32Duino 2.3.0 core (modified as described above).
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Arduino IDE 2 & Debug feature

Post by fpiSTM »

@luca_stm32
Thanks. Did you test recently?
luca_stm32
Posts: 19
Joined: Tue Feb 18, 2020 3:37 pm

Re: Arduino IDE 2 & Debug feature

Post by luca_stm32 »

This evening I tied again and I have an error (STM32F013C8T6 and STLink V2.1 chinese clone running Blink.ino example):

[2023-02-16T19:20:02.397Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session connected. You can switch to "DEBUG CONSOLE" to see GDB interactions.
/home/luca/.arduino15/packages/arduino/tools/openocd/0.10.0-arduino7/bin/openocd -c "gdb_port 50000" -c "tcl_port 50001" -c "telnet_port 50002" -s /home/luca/Arduino/Blink -f /home/luca/Programmi/arduino-ide_2.0.3_Linux_64bit/resources/app/plugins/cortex-debug/extension/support/openocd-helpers.tcl -f "/home/luca/.arduino15/packages/STMicroelectronics/hardware/stm32/2.3.0/variants/STM32F1xx/F103C4T_F103C6(T-U)/openocd_scripts/stm32F103.cfg"
Open On-Chip Debugger 0.10.0+dev-gf0767a31 (2018-06-11-13:40)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
CDRTOSConfigure
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
Info : Listening on port 50001 for tcl connections
Info : Listening on port 50002 for telnet connections
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Error: open failed
in procedure 'init'
in procedure 'ocd_bouncer'

[2023-02-16T19:20:02.425Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session closed
GDB server session ended. This terminal will be reused, waiting for next session to start...

Tomorrow I will try with another PC (with Kubuntu 22.04) with an STM32F407 and another dongle.
Post Reply

Return to “IDE's”