Cornell University ECE4760
Programming the chip from VSCode
Pi Pico RP2040
You can always put the rp2040 into program-load mode by cycling the power while holding down the program button.
This gets tedious, is hard on connectors, and when you build the Pico into a device may not even be possible.
After you have set up VScode according to Hunter's directions, there are at least two ways to program the chip:
- The first is an easy fix for cycling the power which requires minimal software and hardware additions.
After you do this, you can compile in VScode, double-click the program button you will install, then click
run in VScode to download the prodgram.
See also the Runtime Infrastructure section of the SDK docs.
Software:
Add the line:
pico_bootsel_via_double_reset
to the
target_link_libraries list in every cmakelists.txt file
That's all!
Hardware:
Refer to the Pi Pico pinout diagram and identify pin 30, the RUN signal. Note that pin 28 is ground.
The button you will add shorts the RUN pin to ground when you push it. The official Pi page uses more
wires and a bigger button.
-- Straighten the leads on the switch using small pliers so that they make better contact
in the solderless board and to make the lead spacing closer to 0.2 inch (2 rows apart on board).
![](button_bent.jpg)
![](button_unbent.jpg)
-- Connect button leads to pins 28 and 30.
(click image to expand).
I find it easier to hold the button with pliers when pushing it into the solderless board.
![](board_small.jpg)
Using the button:
-- Use power cycling programming once to insert the new loader code you just added to cmakelist.txt
--
Push the button once to reset the program to re-start.
--Push the button twice, quickly (within 0.5 second), to enter program mode, then click run in VScode.
No more power cycling or unplugging!
- The second method uses openOCD (which should have been intalled during the VScode download) to push
the elf file through the debug port. You do not have to touch the Pico, or push any buttons!
The debug probe must be connected!
Bruce has tested this only on a Windows machine.
You should be able to program by
- Starting a PowerShell in windows or a console on the Mac.
- Changing the current directory in the shell window to your current build diectory.
- Make sure the debugger is stopped. VScode Menu item: Run->stop debugging
- Issue this command (with the name of your executable elf file)
openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program yourfile.elf verify reset exit"
- The target board should get the new code, then reset and start.
You can find out more about openOCD here.
Copyright Cornell University
February 1, 2025