如何将一个C++程序上传到Pi Pico,使其在电源循环中持续存在。

huangapple go评论82阅读模式
英文:

How to upload a C++ program to Pi Pico which persists across power cycles

问题

我一直在使用树莓派 Pico 进行项目,一切正常,但我希望我的程序即使在拔插电源后仍然保留在 Pico 上。目前,一旦板子失去电源,程序就会被擦除,我需要重新上传代码。

我正在使用 C++ SDK,并使用 VSCode 作为我的编辑器。我已经了解到,要让 Python 代码在启动时运行,必须将程序命名为 main.py,但将我的程序命名为 main.cpp 似乎没有相同的效果。

英文:

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.

答案1

得分: 1

你只需按住BOOTSEL键插入Pico,将其设置为大容量存储,然后前往构建目录,在那里找到你的普通.uf2文件,首先上传程序的.bin文件,然后上传.uf2文件到Pico。上传.uf2文件后,代码将开始执行,并即使断电后应该仍能保留程序。如果你的构建目录中没有.bin文件,那么你需要在CMakeLists.txt文件中添加pico_add_extra_outputs()这行代码。

英文:

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

huangapple
  • 本文由 发表于 2023年6月12日 02:22:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76451924.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定