英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论