stm32duino / Arduino_Core_STM32

STM32 core support for Arduino

Home Page:https://github.com/stm32duino/Arduino_Core_STM32/wiki

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cannot debug with openOCD in sloeber/eclipse

PerennialNovice opened this issue · comments

Describe the bug
I am trying to activate debugging capabilities for STM32duino using sloeber, the arduino eclipse IDE.
I have latest sloeber 4.4.3 and latest STM32duino 2.7.1

I found that the instructions on the wiki are not quite up to date

As described below, I got the OCD server running and working somehow.
But, when I run the debug configuration, I get a lot of output and on start, the source code doeas not appear, but instead a window with a button to open disassembly.

image

Clearly, that is not what I expected...

the complete openOCD output:

xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:04)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
WARNING: interface/stlink-v2-1.cfg is deprecated, please switch to interface/stlink.cfg
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
Started by GNU MCU Eclipse
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 500 kHz
Info : STLINK V2J40M27 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.237100
Info : [stm32l4x.cpu] Cortex-M4 r0p1 processor detected
Info : [stm32l4x.cpu] target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32l4x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : accepting 'gdb' connection on tcp/3333
[stm32l4x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x21000000 pc: 0x080087e2 msp: 0x2009ffd8
Info : device idcode = 0x10036470 (STM32L4R/L4Sxx - Rev Y : 0x1003)
Info : RDP level 0 (0xAA)
Info : flash size = 2048 KiB
Info : flash mode : dual-bank
Info : device idcode = 0x10036470 (STM32L4R/L4Sxx - Rev Y : 0x1003)
Info : RDP level 0 (0xAA)
Info : OTP size is 1024 bytes, base address is 0x1fff7000
Warn : Prefer GDB command "target extended-remote :3333" instead of "target remote :3333"
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
[stm32l4x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08008484 msp: 0x200a0000
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
[stm32l4x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08008484 msp: 0x200a0000, semihosting
Info : Padding image section 0 at 0x080001bc with 4 bytes
Info : Padding image section 1 at 0x0800dd0c with 4 bytes
Info : Padding image section 2 at 0x0800f32c with 4 bytes (bank write end alignment)
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
[stm32l4x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08008484 msp: 0x200a0000, semihosting
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
[stm32l4x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08008484 msp: 0x200a0000, semihosting
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
[stm32l4x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08008484 msp: 0x200a0000, semihosting
Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
[stm32l4x.cpu] halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08008484 msp: 0x200a0000, semihosting

manually set breakpoints get never hit

To Reproduce

I installed the GNU MCU plugin, though I was not able to deselect things as suggested in 1.1.1. Install OpenOCD from the GNU MCU Eclipse plug-ins
Following the instructions (blink example sketch, ...), i found that ${openocd_path} had not been set at all.
I searched my system and the only openocd.exe I found was stored in

C:\Sloeber443\arduinoPlugin\packages\STMicroelectronics\tools\xpack-openocd\0.12.0-1\bin

, so I used this path and set it in Window -> Preferences -> MCU -> Global OpenOCD Path
Next difference to the wiki is, that I have a Nucleo-L4R5ZI, so I changed the config options to

-s "${openocd_path}/../scripts" -f interface/stlink-v2-1.cfg -f target/stm32l4x.cfg

As for the executable name, ${A.COMPILER.PATH}/arm-none-eabi-gdb did not give a path, so I looked at the environment variables and found that ${A.COMPILER.PATH} does not exist in my installation.
But I found another environment variable named ${compiler.path}, so I used that.

I set a breakpoint in the setup() function
image

Sloeber does not show the favourites menu, so I didn't bother activationg the buttons but run the debug session by right-clicking the project -> Debug As -> Debug configurations -> blink Release
image

when I now resume (F8) the breakpoint gets never reached or it is not active.

clicking suspend halts the target, but does not show code
some more lines appear under thread #1
image

I can stop & resume at will, but never get to see code, and the only change is that some more lines appear under Thread #1
image

And in the open OCd Debugger Console some messages appear on each halt
image

complete debugger console output:

Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-w64-mingw32 --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Note: automatically using hardware breakpoints for read-only addresses.
No source file named C:\\Users\\xxxxxx\\Documents\\sloeber-workspace\\blink\\Blink.ino.

Temporary breakpoint 1, 0x0800851e in main ()
No breakpoint number 3.

Program received signal SIGINT, Interrupt.
0x080087e2 in delay ()

Program received signal SIGINT, Interrupt.
0x08001072 in getCurrentMillis ()

Program received signal SIGINT, Interrupt.
0x0800107a in getCurrentMillis ()

Program received signal SIGINT, Interrupt.
0x08002f50 in HAL_GetTick ()

Program received signal SIGINT, Interrupt.
0x08008840 in yield ()

Program received signal SIGINT, Interrupt.
0x080087e2 in delay ()```


**Desktop (please complete the following information):**
 - OS: Windows
 - Sloeber IDE version: 4.4.3
 - STM32 core version: 2.7.1
 - Tools menu settings if not the default:
<img width="417" alt="image" src="https://github.com/stm32duino/Arduino_Core_STM32/assets/85557472/69c9381f-0384-4074-840f-3936ca1baf45">

 - Upload method: SWD

**Board (please complete the following information):**
 - Name: Nucleo-L4R5ZI
 - Hardware Revision: MB1312 A-01 A220300861

Hi @MasteringTheMess
As stated in the wiki, only the Arduino IDE is supported.
This wiki was added for information and was tested one time. Since this date no more test was done. I guess several change we made on Sloeber sinde and on Arduino core.

Since this, the official way to debug is Arduino IDE 2 which support debug.

Thanks for clarifying

Made some progress on this and thought I'd share my findings - even though Sloeber is not officially supported
maybe someone bothers changing the wiki ??

  • I started with a fresh install of Sloeber 4.4.3 product

  • then added STM32 platform from

    https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json

  • then go to Help -> Install New Software and search for openOCD which yields exactly one result which I installed

  • create blink example for STM32 (Nucleo-L412KB in my case) with debug options enabled
    Optimize on Debug (-Og) and Debug symbols and core logs set to Core logs and Symbols enabled(-g)

  • build project by hitting Ctrl-R (takes an awful lot of time on Windows - blessed are the Lunix-users ;) )

  • Then create a run/debug configuration by right-click on the project -> Debug as -> Debug configurations -> double-click on GDB OpenOCD Debugging

  • leave Main unchanged and go to Debugger-tab and follow the link to the global preferences for the openOCD path and set it to

    "SLOEBER_HOME"\arduinoPlugin\packages\STMicroelectronics\tools\xpack-openocd\0.12.0-1\bin (for Windows)

  • set config options to

    -s "${openocd_path}/../scripts" -f interface/stlink-v2-1.cfg -f target/stm32l4x.cfg

  • set the GDB exectuable name to

    ${compiler.path}/arm-none-eabi-gdb

  • on the Startup tab, set Pre-run/Restart reset commands to

    monitor reset halt
    monitor reset init

  • click apply and the debug

Now, all should run without error, but no source is shown!
Instead the source not found window appears stating that main() could not be found

This is essentially what I described when starting this discussion here.

Now, go to Project -> Properties -> Sloeber -> Compile Options and add -ggdb to append to C and C++ and run the freshly created Debug Configuration again (which takes an awful lot of time on windows because a complete build has to be done)

The binary is downloaded to the µC and execution halts at the beginning of main() AND the corresponding source file is shown in the editor !
Using the debug controls in the toolbar you now can jump in/over/out of functions at will and set some breakpoints, watch expressions, etc...

Happy debugging :)

Credits go to Zach Wilcox over there on the Eclipse Forums for finding this back in 2018