How to Debug the Raspberry Pi Pico Using Another Pico! - Picoprobe and VSCode Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video i'm going to cover how to debug the raspberry pi pico using another raspberry pi pico now whilst this might sound a little odd one of the picos acts as a debugger and is essentially a usb to serial wire debug converter and allows us to program and debug the target pico we can also use the pico probe to monitor the uart output of the target pico so this tutorial will tell you the basics of getting the pico probe and required tool chain working and some basic debugging to show you how it works so as a kind of prerequisite to this video i'm assuming that you already have vs code set up in such a way that you can build programs for the pico already if not i have a video covering that topic in the cards above so to start with i'll run through a few things that we need in order to get started debugging the raspberry pi pico firstly in terms of hardware we're going to need two picos a breadboard to put them on and some jumper cables then in terms of software we need openocd and gdb you will already have gdb from when you set up the vs code c tool chain for programming the rp2040 we will also need the lib usb win32 usb driver and finally we're going to need the picoprobe uf2 file which is provided by the raspberry pi foundation so let's start with openocd on my website i have provided a zip file with a pre-built version of openocd it is already configured for debugging pico and there is no need to tinker with it to get it working all you have to do is extract it somewhere sensible and in my case i've extracted it next to where i keep the pico sdk now for those a bit apprehensive about downloading a zip file from the internet i completely understand that and it is possible for you to build your own version of open ocd my folder is simply intended as a time saver you can build your own by downloading the msys2 tool collection from their website and then following the steps outlined in appendix a of the raspi pico getting skated guide you will need to find the lib usb 1.0 dll file from the lib usb drivers and paste that into your open ocd folder now we need to install the usb drivers download zadig from the website linked in the description open the file and select the pico probe interface 2 option from the drop down if you don't see it then in the options menu select show all devices and then you should be able to see it from the drop down now in the driver box select the lib usb win32 driver and press install on mine it says reinstall but that's because i've already done this process to get this guide going now let's flash the picoprobe firmware onto one of the picots download the uf2 file from the raspberry pi pico website and program the pico by pressing the reset button and connecting it over usb then dragging and dropping the uf2 file over the pico should now reboot and the onboard led should be solid green now we must wire up the two picots place them both in the breadboard and then wire them up according to the diagram shown in appendix a of the pico getting started guide firstly i'm going to power the target picot using the v sys and ground pins on both picots then wire the ground pin on the swd connectors to the ground pin connected to the pico pro then wire the uart 1 port which is gpio pins four and five on the pico probe to the uart zero port gpio pin 0 and 1 on the target pico note that tx connects to rx and vice versa then we connect the picoprobes gpio pin 2 to the swclk pin on the target picot and finally we connect the gpio pin 3 to the swd i o pin on the target picot the picoprobe is now ready to use you only have to power the pico probe over usb and it will provide power to the target pico we can also use the pico probe as a simple uart serial device to monitor the serial output of the target pico now in the next couple of steps we're going to test the tool chain we set up earlier and this will be a command line interface but don't worry shortly we will be moving into vs code open two command prompts in one of them navigate to where your openocd.exe application is in my case it is c pico openocd folder then use the following command open ocd f interface picoprobe.cfg f target rp2040.cfg s tcl you should see the following output it is important that you keep this command prompt open in the other prompt navigate to a project that you know builds and functions correctly i'm going to pick one of the pico examples the hello world serial program to be specific make sure an elf file is present then use the following command arm none e a b i gdb then the name of the elf file in my case hello serial.elf once gdb has launched use the following series of commands target remote localhost 3333 load then use monitor reset init and then continue and your program should now be programmed to the target pico and operating normally to test this and in this case the uart functionality of the pico probe i will open putty and point it to the com port that the pico probe is connected to we choose a baud rate of 115 200 and you can see in the window that opens that the target pico is operating as intended you can close the two command prompt windows now now let's get vs code set up you will need the following plugins cortex debug cmake tools and c plus tools you should already have the last two installed so you probably will only have to install the cortex debug plugin after doing that open vs code settings and open the settings.json file using the button in the top right of the page highlighted in red now add the following two lines of code to the editor you can find these lines of code from my website linked in the description ensure that the open ocd path is the file path of where you downloaded open ocd to including the openocd.exe application you can now save and close this file next open a project that you want to debug in my case for the simplicity of this this video i'm simply going to debug a basic led blink program actually it's the program we wrote in one of my earliest pico videos once open in the dot vs code folder in the project explorer create a json file called launch if there isn't already copy and paste the boilerplate template from my website into the launch json file and adjusting the paths of the last two lines and the path to the build elf file the search directory path should be pointed to the tcl folder in the open ocd folder the rp2040 svd file is found in the pico sdk so point it to where you downloaded the pico sdk more specifically the svd file itself you can now save the launch.json file now open the debug and run tab on the left hand side of vs code you should see cortex debug selected in the top left drop down it is important that you build your program before attempting to debug as in my experience debugging it first will sometimes cause an error or you'll be debugging using an older version of your program so i'll build my blink led code now ensure that the probe is plugged in and powered on press the green play button next to the cortex debug drop down it will take a few seconds but soon the blue bar will turn orange indicating that we are now debugging your target pico has been programmed with your code it will always pause at the start of the main function but once you press the continue button on the top toolbar your program will start operating in my case as you can see the leds are blinking on and off you can set a break point before or during debugging by pressing the red dot next to the line number the next time the program reaches this point it will pause and you can simply resume it with the continue button from the top toolbar you can remove a breakpoint by simply pressing the red button and it will disappear on the left hand side the left hand toolbar we have the registers and peripheral devices where we can poke around and take a look into what values the registers currently have above this we have the variables tab which contains the values that each variable has in your code which is a little higher level than the registers note that this only shows up when the debugger is paused at a break point so to stop debugging simply use the stop button on the top of the toolbar do remember that if you change your code you must rebuild it before debugging otherwise you'll be debugging an old version of your code so this video covered how to get started debugging the raspberry pi pico i realized i didn't cover too much in depth regarding how to properly debug your programs as that's the topic for a much more in-depth video perhaps a part two let me know if you'd like a video like that if this video has helped you then please like and subscribe let me know if you have any questions or feedback in the comments below thank you and have a nice day
Info
Channel: Learn Embedded Systems
Views: 43,658
Rating: undefined out of 5
Keywords:
Id: 0i2gLeBal9Y
Channel Id: undefined
Length: 10min 55sec (655 seconds)
Published: Sun Mar 07 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.