-1

I have been using a Raspberry Pi Pico for a project and everything works, but I want my program to remain on the Pico, even after it's been unplugged and plugged back in. At the moment, once the board loses power the program is wiped and I need to re-upload the code.

I am using the C++ SDK and using VSCode as my editor. I've read that for Python code to run on boot, you have to call the program main.py, but calling my program main.cpp doesnt seem to have the same affect.

Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
Dean
  • 63
  • 5
  • 5
    Uploading the source of a C++ program to the Pico won't do anything. You need to compile the C++ code and upload the binary to the Pico. [Here is a tutorial](https://circuitdigest.com/microcontroller-projects/how-to-program-raspberry-pi-pico-using-c) which shows how to do this. – Jan Schultke Jun 11 '23 at 18:51
  • 1
    @Jan Schultke I understand how to upload code to the pico, by compiling the code and the pressing the reset button for it to become a storage device and then dropping the .uf2 file on to the pico from the laptop. What I dont know is with the method of uploading the code if the power is cut from the pico the program is not retained, so when re plugged back in nothing will execute and you need to then reupload the code again – Dean Jun 11 '23 at 19:39
  • I couldn't instantly find any resource that explains this either. The Pico does have 2MB of flash storage, and this persists across power cycles. So if you store the binary in flash and execute the binary from flash, it should work. Maybe you need to look online for "Pi Pico store executable in flash memory" or so. – Jan Schultke Jun 11 '23 at 19:48
  • @Jan Schultke right ok no problem, is this potentially a use for programming via SWD or is that completely different – Dean Jun 11 '23 at 19:54

1 Answers1

1

Hi so I figured this out so I thought I would share it in case someone else had the same issue.

So pretty much all you have to do put the pico into mass storage by holding BOOTSEL as you plug it in. Then go to your build directory where your normal .uf2 file is and first upload the .bin file of your program and then upload the .uf2 file onto the pico.

After you upload the .uf2 file the code will start to execute and should now hold the program even after a power cycle.

If you dont have a .bin file in your build directory then you will need to add the pico_add_extra_outputs() line in your CMakeLists.txt file

Dean
  • 63
  • 5