Recent

Author Topic: Problems debugging STM32 blue pill with Lazarus [solved - with workarounds]  (Read 1969 times)

petex

  • Jr. Member
  • **
  • Posts: 69
hello,
I am attempting to get the GDB debugger to work with Lazarus.

I made a debug probe using a Raspberry PI and OpenOcd. The installation of the software went very well (several cups of coffee required!) with few snags. I also got the Ocd config file to work for this particular controller (STM32F103C8T6)

I connected the Pi to a STM32 blue pill card via the probe connector and a lashup of 4 wires, and arranged the PI (powered by USB) to supply 3.3v power to the STM32.

I was able to load and run the Blinky.bin program using a telnet link from my PC to the headless Pi using WiFi on my network.

I then ran the GDB debugger (arm-embedded-gdb.exe) supplied from the MBR package from git which I used previously. I was able to use this to connect to the GDB server on the PI and run the program using remote "Monitor" commands as follows:

Quote
C:\Windows\System32>C:\fpcupdeluxe-mbf\fpc\bin\x86_64-win64\arm-embedded-gdb.exe
C:\fpcupdeluxe-mbf\fpc\bin\x86_64-win64\gdbtest.exe: warning: Couldn't determine a path for the index cache directory.
GNU gdb (GDB) 10.1
Copyright (C) 2020 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".
(gdb) target remote 192.168.1.201:3333
Remote debugging using 192.168.1.201:3333
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
0x0800118a in ?? ()
(gdb) monitor program /home/pi/fileserver/temp/Blinky.bin 0x8000000
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08000e9c msp: 0x20005000
** Programming Started **
** Programming Finished **
(gdb) monitor reset
(gdb) monitor halt
target halted due to debug-request, current mode: Thread
xPSR: 0x81000000 pc: 0x0800118a msp: 0x20004f8c
(gdb)

I set up the debugger options in Lazarus to use the remote debugger. When I run the program from Lazarus, I get the following error and it shuts down.

Quote
warning: Couldn't determine a path for the index cache directory

Any ideas on how to proceed ?

Also (assuming it will work) will Lazarus load the program from PC to PI automatically, or do I have to load the program from the PI side before starting ?



ps - a working openocd.cfg file for a PI zero w......
Code: [Select]
source [find interface/raspberrypi-native.cfg]

transport select swd

set CHIPNAME stm32f103c8t6

source [find target/stm32f1x.cfg]

# did not yet manage to make a working setup using srst

#reset_config srst_only

reset_config  srst_nogate

adapter srst delay 100

adapter srst pulse_width 100

bcm2835gpio_swd_nums 25 24
bcm2835gpio_trst_num 7
bcm2835gpio_srst_num 18
bindto 0.0.0.0
init

targets

reset halt
« Last Edit: January 29, 2021, 09:47:22 pm by petex »

MiR

  • Full Member
  • ***
  • Posts: 225
Re: Problems debugging STM32 blue pill with Lazarus
« Reply #1 on: January 29, 2021, 02:14:39 pm »
Haven't seens that particular error you reported but can you please provide a screenshot of your debugger configuration in Lazarus?

And yes, the binary will get uploaded automagically from lazarus to thre device.

Michael

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 8095
  • Debugger - SynEdit - and more
    • wiki
Re: Problems debugging STM32 blue pill with Lazarus
« Reply #2 on: January 29, 2021, 02:20:50 pm »
Quote
warning: Couldn't determine a path for the index cache directory

At least Lazarus trunk should ignore this. I am not sure if it is in the current fixes branch. (Nor did you say which version you use?)

You can try to patch your Lazarus:
https://github.com/User4martin/lazarus/commit/739958972a81acb2e6acb53bbe49697523da3e1c
https://github.com/User4martin/lazarus/commit/739958972a81acb2e6acb53bbe49697523da3e1c.diff

petex

  • Jr. Member
  • **
  • Posts: 69
Re: Problems debugging STM32 blue pill with Lazarus
« Reply #3 on: January 29, 2021, 02:24:45 pm »
notice when i run from the windows comand line i get:-
C:\Windows\System32>C:\fpcupdeluxe-mbf\fpc\bin\x86_64-win64\arm-embedded-gdb.exe
C:\fpcupdeluxe-mbf\fpc\bin\x86_64-win64\gdbtest.exe: warning: Couldn't determine a path for the index cache directory.

MiR

  • Full Member
  • ***
  • Posts: 225
Re: Problems debugging STM32 blue pill with Lazarus
« Reply #4 on: January 29, 2021, 02:31:10 pm »
Set Debugger_Remote_DownloadExe to true, this will upload the binary....

You may (or may not) need to play arround with EncodeCurrentDirPath and EncodeExeFileName. The rest of the settings look good to me.

Also looks like you are using truk-lazarus, on release lazarus some of the options are missing.

petex

  • Jr. Member
  • **
  • Posts: 69
Re: Problems debugging STM32 blue pill with Lazarus
« Reply #5 on: January 29, 2021, 04:43:56 pm »
ok, so the first error message can be resolved by defining a windows environment variable HOME that points to the gdb exe path - see attached.

I now get another debugger failure - "failed to load application executable", clicking on more information specifies the missing file.
e.g. c:\blah blahblah\test, where "test" is my target name. i.e. I have compiled test.bin, .hex and .elf
If I rename the programs to just "test" i still get the same error.

on another point, when the debugger fails, it does not disconnect from the GDB server so I get connections exceeded error when I try again. I have to manually restart the GDB server on the PI.

petex

  • Jr. Member
  • **
  • Posts: 69
Re: Problems debugging STM32 blue pill with Lazarus
« Reply #6 on: January 29, 2021, 04:53:59 pm »
 EncodeCurrentDirPath
 EncodeExeFileName

changing these to "gdfeNone" has done something.

I have no errors and the debugger is showing the first break point i set at the first pascal code line.
So i'll see how it goes............

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 8095
  • Debugger - SynEdit - and more
    • wiki
Re: Problems debugging STM32 blue pill with Lazarus
« Reply #7 on: January 29, 2021, 04:56:20 pm »
In case of more issues.

Menu: View > Ide Internals > Debug Output

There you can see the raw communication between IDE and gdb. If you get errors from gdb, you may want to see what the IDE send. You can also copy this, if you enquire about it here.

MiR

  • Full Member
  • ***
  • Posts: 225
Re: Problems debugging STM32 blue pill with Lazarus
« Reply #8 on: January 29, 2021, 04:57:15 pm »
Thanks Martin, was just writing the same thing....

Please remember that debugging in Lazarus does not work perfect, use breakpoints (and delete them as soon as they are not used anymore), works better than single-stepping (for me)

petex

  • Jr. Member
  • **
  • Posts: 69
Re: Problems debugging STM32 blue pill with Lazarus
« Reply #9 on: January 29, 2021, 05:20:31 pm »
ok, I managed to get the program loaded and running with a single breakpoint in the blinky loop.

It seems that I need to:

1) Set a HOME environment variable to set a valid path on the PC

in Lazarus TOOLS//OPTIONS//Debugger ........
2) change "EncodeCurrentDirPath" and "EncodeExeFileName" to "gdfeNone"

3) check the "Debugger_remote_downloadexe" option

4) set GDB server IP address=PI address and port=3333

5) remove the ".elf" extension from the program file e.g. "Blinky.elf".


Sometimes I can get an error if the GDB server has more than one connection. In which case I have to restart the GDB server.


The GDB server also complains about multiple breakpoints, so it seems i will have to only have one active.

MiR

  • Full Member
  • ***
  • Posts: 225
Re: Problems debugging STM32 blue pill with Lazarus
« Reply #10 on: January 29, 2021, 05:28:05 pm »
You can disable the breakpoints in 'InternalExceptionBreakpoints' this will give you three more Breakpoints.

The Cortex.M3 only supports a total of 6 Hardware Breakpoints you cannot have more unless you buy a JLink Debug Probe which offers unlimited breakpoints.


 

TinyPortal © 2005-2018