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

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...

Is the same error that you have?

Tomorrow I will try with another PC (with Kubuntu 22.04) with an STM32F407 and another dongle.
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 »

No. It's failed earlier with unknown fqbn
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Arduino IDE 2 & Debug feature

Post by ag123 »

I've not yet tried this out, but I'm thinking about it and just some 2 cents suggestions.

I'd think it is probably adequate for the IDE to start arm-none-eabi-gdb
so that it probably does a
(gdb) target remote :3333
gdb has to locate the local elf file with all the symbols and source.

this is so that gdbserver (e.g. openocd) is started manually by the user. say using a script. openocd can be started by the user manually beforehand.
that is probably simpler as an implementation.

I think, stm32cubeprogrammer, stm32cube IDE also has a gdbserver in it, so by keeping the 2 separate, e.g. that the ide runs basically arm-none-eabi-gdb, and the gdbserver started separately, it'd probably be easier to integrate the different gdbserver implementations.
openocd is also rather tricky as there are some configuration files to select for different dongles (e.g. st-link vs others) and mcu series, e.g. F4 series, vs F3 series etc.
i'm not too sure about the differences if after all the configurations are different.

edit:
A article i stumbled into with some google searches:
http://pacinispace.blogspot.com/2020/02 ... linux.html

personally i used openocd too, in OpenSuse, but that i've not yet tried debugging in Arduino IDE 2
luca_stm32
Posts: 19
Joined: Tue Feb 18, 2020 3:37 pm

Re: Arduino IDE 2 & Debug feature

Post by luca_stm32 »

Ok, I can debug again.
I changed dongle programmer: the dongle I'm using now has idVendor=0483, idProduct=3748.

Now gdb-server console is:
[2023-02-16T20:19:38.042Z] 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
Info : STLINK v2 JTAG v30 API v2 SWIM v7 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.180666
Info : STM32F103.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 50000 for gdb connections
Info : accepting 'gdb' connection on tcp/50000
target halted due to debug-request, current mode: Thread
xPSR: 0x81000000 pc: 0x08003848 msp: 0x20004fe0
Info : device id = 0x20036410
Info : flash size = 64kbytes
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08004b04 msp: 0x20005000
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08004b04 msp: 0x20005000
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000003a msp: 0x20005000
Warn : keep_alive() was not invoked in the 1000ms timelimit. GDB alive packet not sent! (1097). Workaround: increase "set remotetimeout" in GDB
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08004b04 msp: 0x20005000
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08004b04 msp: 0x20005000
Info : halted: PC: 0x0800015c

and Debug console is:

void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);

}

Note: automatically using hardware breakpoints for read-only addresses.
Breakpoint 1, loop () at /home/luca/Arduino/Blink/Blink.ino:14
14 digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
halted: PC: 0x0800015c
halted: PC: 0x08004e00
halted: PC: 0x08004c20
halted: PC: 0x08000158
Breakpoint 1, loop () at /home/luca/Arduino/Blink/Blink.ino:14
14 digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
halted: PC: 0x0800015c
halted: PC: 0x0800015e
halted: PC: 0x08004d58
halted: PC: 0x08000166
halted: PC: 0x08004de0
halted: PC: 0x0800016c
halted: PC: 0x0800016e
halted: PC: 0x08004d58
halted: PC: 0x08000176
halted: PC: 0x08004de0
halted: PC: 0x08004c24
halted: PC: 0x08004e00
halted: PC: 0x08004c20
halted: PC: 0x08000158
Breakpoint 1, loop () at /home/luca/Arduino/Blink/Blink.ino:14
14 digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
luca_stm32
Posts: 19
Joined: Tue Feb 18, 2020 3:37 pm

Re: Arduino IDE 2 & Debug feature

Post by luca_stm32 »

Can you compile the sketch?
If yes, can you program the device?
User avatar
Vassilis
Posts: 23
Joined: Wed Dec 18, 2019 3:04 pm
Location: Thessaloniki, Greece
Contact:

Re: Arduino IDE 2 & Debug feature

Post by Vassilis »

Debugging works fine on Windows 10, Arduino IDE 2.0.3, STM32F303
Arduino_IDE_Debugging.jpg
Arduino_IDE_Debugging.jpg (79.35 KiB) Viewed 5659 times
Vassilis Serasidis
https://www.serasidis.gr
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 »

Hum. Very strange. We are not able to debug and I've no idea what goes wrong. Is someone could create patch of all changes made, please?
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Arduino IDE 2 & Debug feature

Post by ag123 »

openocd (at least on linux) is quite tricky, it runs as a server and has its own console.
Hence, I'd normally start openocd separately in its own terminal session, normally driven by a script.

Then from the IDE, i start gdb or more correctly arm-none-eabi-gdb.
The key is arm-none-eabi-gdb
1 - needs to be able to locate its elf file and source where the symbols are generated and located. I'm not too sure if the object files are required.
2 - then in gdb it does a "target remote :3333"
which is probably followed by run, etc.

The main thing is openocd works as a gdbserver, in this example at port 3333.
Access to the openocd console is not required from gdb, rather the openocd console is separate and provides the user an alternate means and commands to interact with the mcu.

once gdb (arm-none-eabi-gdb) connects to gdbserver, say at port 3333. the remote debugging session would be started and normally the IDE should be able to stop at breakpoints and trace source codes.

as openocd has its own configuration requirements which varies between dongles (e.g. st-link) and the mcu (e.g. F3, F4 etc).
I'd suggest from the IDE, we'd basically take care of that "target remote :3333", which would allow it to connect to the gdbserver.

And that the gdbserver, can be started manually by the user, e.g. openocd. This would simplify things and untie dependencies.
Subsequent to that, the instructions for the gdbserver (e.g. openocd, or stm32cube ide etc) can be documented separately.

The part for connecting the IDE (i.e. gdb, or arm-none-eabi-gdb) to gdbserver is normally nearly always the same. which requires the hostname or address and port in which the gdbserver is running.
And possibly the location of the object files, elf, symbols, map, source etc.

quite often, i establish connection first from within openocd to the mcu, this is normally done from the openocd startup script.
e.g. i've a script that looks like such

Code: Select all

#!/bin/bash
openocd \
-f /usr/share/openocd/scripts/interface/stlink-v2.cfg \
-f /usr/share/openocd/scripts/target/stm32f4x.cfg 
# "connect under reset"
#-c "init; reset init"
this script starts openocd and connect to the mcu.

Then i start gdb e.g. from the IDE which in turns connect to openocd.
This in a way 'untie' the dependencies between the IDE and openocd, so that the configurations can be separate.

I think openocd also needs to be built properly with the required modules appropriately built. I've been using that shipped with my distribution, but things could have changed since.
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 @ag123 .
I know how to run openOCD. My point is to be able to launch the debug from Arduino IDE 2 by simply clicking on the debug button. ;)
User avatar
Vassilis
Posts: 23
Joined: Wed Dec 18, 2019 3:04 pm
Location: Thessaloniki, Greece
Contact:

Re: Arduino IDE 2 & Debug feature

Post by Vassilis »

@fpiSTM
I will write a simple guide on how to install and use the STM32 debugger on Windows

[EDIT] I think it's better, to send you a GitHub pull request with the necessary changes
Vassilis Serasidis
https://www.serasidis.gr
Post Reply

Return to “IDE's”