Difference between revisions of "ARM Embedded Tutorial - Raspberry Pi Pico Debugging the onboard LED"

From Lazarus wiki
Jump to navigationJump to search
Line 40: Line 40:
 
You will most likely also have to set EncodeCurrentPath to gdfeNone, when this field is set wrong you cannot download your code to the pico.
 
You will most likely also have to set EncodeCurrentPath to gdfeNone, when this field is set wrong you cannot download your code to the pico.
  
The last setting is to set all InternalExceptionBreakpoints to 'False'. ""This setting is very important"", the pico has only 4 Hardware Breakpoints and when you waste three of them for this setting then it will be close to impossible to debug even a simple program because you run out of breakpoints.
+
The last setting is to set all InternalExceptionBreakpoints to 'False'. '''This setting is very important''', the pico has only 4 Hardware Breakpoints and when you waste three of them for this setting then it will be close to impossible to debug even a simple program because you run out of breakpoints.
  
 
Last Step is to go back to the top of the dialog and set the Name field to 'OpenOCD'.
 
Last Step is to go back to the top of the dialog and set the Name field to 'OpenOCD'.

Revision as of 01:23, 1 March 2021

Introduction

In this chapter we will learn how to debug a pico with thre help of another pico and openocd-rp2040.

If you did not yet read the introduction on how to set up openocd on your computer take a look at this page:

ARM Embedded Tutorial - Raspberry Pi Pico Setting up for Development

Here's a schematic on how to connect the two Pico's needed for this chapter on a breadboard:

pico-debug.png

the picoprobe is the device on the left, the pico that runs our program is on the right side.


Load the demo project into lazarus

Open the blinky/blinky-raspi_pico.lpi project in Lazarus.

First thing to do is to configure the debugger, to do this open the IDE options Page and go to 'Debugger Backend'

pico-setup-debugger.png


First select 'GNU remote debugger (gdbserver)' and then select the gdb to use.

Here you have two choices, both are provided by FPCUPdeluxe in the installation directory.

First choice is to use gdb-multiarch for your platform, this allows you to debug arm or avr boards without the need to change the debugger.

The alternative is to use a gdb that is specific to arm-none-eabi, it is located in the fpcbootstrap/gdb/arm-embedded/ directory. On Windows this directory is pre-selected when you first open up the Debugger Backend Page.

Depending on your choice you either put 'auto' in the Architecture field, when you decide to use the debugger in the fpcbootrap directory leave the field empty.

Then set the 'Debugger_Remote_DownloadExe' entry to true and set Debugger_Remote_Hostname to localhost

Enter 3333 in the Debugger_Remote_Port field (the OpenOCD default port for debugging)

You will most likely also have to set EncodeCurrentPath to gdfeNone, when this field is set wrong you cannot download your code to the pico.

The last setting is to set all InternalExceptionBreakpoints to 'False'. This setting is very important, the pico has only 4 Hardware Breakpoints and when you waste three of them for this setting then it will be close to impossible to debug even a simple program because you run out of breakpoints.

Last Step is to go back to the top of the dialog and set the Name field to 'OpenOCD'.

Hit OK to close the IDE Options, you are now ready to debug!

Start Debugging

Open a cmd window or a Unix shell and start openocd-rp2040:

 ~/fpcupdeluxe/ccr/develtools4fpc/bin/openocd-rp2040 -f board/pico.cfg

or

 C:\fpcupdeluxe\ccr\develtools4fpc\bin\openocd-rp2040.exe -f board/pico.cfg


(Exchange fpcupdeluxe with the name of the directory where you put your FPCUPdeluxe installation....)

Click 'Build' to build the project, then set a breakpoint on the first line of code and then hit 'Run' to start debugging:

pico-lazarus-debugging.png

Play around with single stepping, debugging works quite good but not perfect.... I usually set breakpoints where I need them and use 'Run' to reach them.

Always keep an eye on the list of used breakpoints, when things go crazy you have likely exceeded your 4 hardware breakpoints which makes debugging impossible. Delete unneeded breakponits and start again!

Back to main Pico Page



Back to main Pico Page