基于以下环境
Ubuntu 20.04.4 LTS
WSL2
VSCODE
上述环境的安装网上搜索即可,不再赘述。
下载脚本
git clone https://github.com/raspberrypi/pico-setup.git
cd pico-setup/
./pico_setup.sh
如下提示
lhj@lhj:~/pico-setup$ ./pico_setup.sh
Not running on a Raspberry Pi. Use at your own risk!
Installing Dependencies
[sudo] password for lhj:
输入密码自动安装相关工具
相关环境安装在当前目录下pico
lhj@lhj:~/pico-setup$ ls pico
pico-examples pico-extras pico-playground pico-sdk
其中
pico-examples是例程
pico-sdk是sdk包
sdk如果有子仓库没有同步可以
cd pico-sdk
git submodule update --init
cd pico-examples/build
export PICO_SDK_PATH="/home/lhj/pico-setup/pico/pico-sdk" && cmake ..
make hello_usb
编译的程序位于hello_world/usb/下
lhj@lhj:~/pico-setup/pico/pico-examples/build$ ls hello_world/usb/
CMakeFiles cmake_install.cmake hello_usb.dis hello_usb.elf.map hello_usb.uf2
Makefile hello_usb.bin hello_usb.elf hello_usb.hex
将hello_usb.uf2复制到windows下
cp hello_world/usb/hello_usb.uf2 /mnt/d
下载到开发板即可
接上USB线,可以看到串口打印信息如下
下载示例程序
https://www.waveshare.net/w/upload/9/9d/RP2040-LCD-1.28.zip
vscode打开\RP2040-LCD-1.28\c文件夹
在wsl中打开该文件夹
新建终端
cd build
export PICO_SDK_PATH="/home/lhj/pico-setup/pico/pico-sdk" && cmake ..
make
生成的程序位于当前目录下main.uf2
将其复制到windows下,下载到开发板
参考https://github.com/raspberrypi/pico-sdk
在指定工作目录创建工程目录
mkdir test
cd teset
复制pico_sdk_import.cmake到工程目录
cp /home/lhj/pico-setup/pico/pico-sdk/external/pico_sdk_import.cmake .
设置环境变量PICO_SDK_PATH为SDK路径/home/lhj/pico-setup/pico/pico-sdk/,也可以在编译时在export指定或者-DPICO_SDK_PATH=指定。
新建文件CMakeLists.txt内容如下
cmake_minimum_required(VERSION 3.13)
# initialize the SDK based on PICO_SDK_PATH
# note: this must happen before project()
include(pico_sdk_import.cmake)
project(my_project)
# initialize the Raspberry Pi Pico SDK
pico_sdk_init()
# rest of your project
添加源码
hello_usb.c
#include <stdio.h>
#include "pico/stdlib.h"
int main() {
stdio_init_all();
while (true) {
printf("Hello, world!\n");
sleep_ms(1000);
}
return 0;
}
添加如下内容到CMakeLists.txt
if (TARGET tinyusb_device)
add_executable(hello_usb
hello_usb.c
)
# pull in common dependencies
target_link_libraries(hello_usb pico_stdlib)
# enable usb output, disable uart output
pico_enable_stdio_usb(hello_usb 1)
pico_enable_stdio_uart(hello_usb 0)
# create map/bin/hex/uf2 file etc.
pico_add_extra_outputs(hello_usb)
# add url via pico_set_program_url
# example_auto_set_url(hello_usb)
elseif(PICO_ON_DEVICE)
message(WARNING "not building hello_usb because TinyUSB submodule is not initialized in the SDK")
endif()
编译
mkdir build
cd build
export PICO_SDK_PATH="/home/lhj/pico-setup/pico/pico-sdk" && cmake ..
make
生成的程序位于当前路径下
hello_usb.uf2
下载到开发板即可
开发环境推荐使用WSL+Ubuntu,避免了安装虚拟机的繁琐,也避免了纯Windows下安装开发环境的麻烦。WSL的Ubuntu就相当于Windows下的一个应用程序,下载脚本一键就可以安装开发环境,而其他操作都是熟悉的在windows下。
https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf
https://www.waveshare.net/w/upload/5/5f/Pico_c_sdk.pdf
https://github.com/raspberrypi/pico-examples/
https://github.com/raspberrypi/pico-sdk