1.安装开发工具
- cmake
brew install cmake
- openocd
brew install openocd
- arm-none-eabi-gcc
用 brew 安装的版本会出现如下错误:
arm-none-eabi-gcc: fatal error: cannot read spec file 'nosys.specs': No such file or directory
用 arm 官方的版本没有问题。
cd ~/Downloads
wget https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-darwin-arm64-arm-none-eabi.tar.xzcd /opt
sudo tar xf ~/Downloads/arm-gnu-toolchain-13.3.rel1-darwin-arm64-arm-none-eabi.tar.xz
- arm-none-eabi-gdb
brew install arm-none-eabi-gdb
- minicom
sudo apt install minicom
2. 安装 pico-sdk
mkdir -p ~/work/lab/pico
cd ~/work/lab/pico
git clone --recursive https://github.com/raspberrypi/pico-sdk.git
git clone --recursive https://github.com/raspberrypi/pico-examples.git
3.编译
build_rp2040.sh
cd pico-examples
rm -rf build_rp2040
mkdir -p build_rp2040
cd build_rp2040
export PICO_SDK_PATH="../../pico-sdk"
export PICO_TOOLCHAIN_PATH="/opt/arm-gnu-toolchain-13.3.rel1-darwin-arm64-arm-none-eabi/bin"
cmake ../ -DPICO_PLATFORM="rp2040" -DPICO_BOARD="pico" -DCMAKE_BUILD_TYPE=Debug
make -j4
build_rp2350.sh
cd pico-examples
rm -rf build_rp2350
mkdir -p build_rp2350
cd build_rp2350
export PICO_SDK_PATH="../../pico-sdk"
export PICO_TOOLCHAIN_PATH="/opt/arm-gnu-toolchain-13.3.rel1-darwin-arm64-arm-none-eabi/bin"
cmake ../ -DPICO_PLATFORM="rp2350" -DPICO_BOARD="pico2" -DCMAKE_BUILD_TYPE=Debug
make -j4
4. 烧录
-
方法1
按住按钮,插上电源。 会加载分区 /Volumes/RP2350,把固件拷贝到 /Volumes/RP2350。完成后,会自动重启。
RP2350换成实际的设备名称。
- 方法2
使用 openocd 烧录。
upload.sh
PROGRAM=$1if [ "$#" -eq 0 ]; thenecho "$0 program"echo "ex: $0 ./pico-examples/build_rp2040/blink/blink.elf"
else sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" -c "program $PROGRAM verify reset exit"
fi
5. 调试
- 启动 openocd
sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000"
- 启动 gdb
arm-none-eabi-gdb pico-examples/build_rp2040/blink/blink.elf
target remote localhost:3333
monitor reset init
continue
sleep_us/sleep_ms在调试时会挂起,需要修改rp2040.cfg,只是用一个核心。
文件位置(视不同版本而定):~/.pico-sdk/openocd/0.12.0+dev/scripts/target/rp2040.cfg
set _USE_CORE { 0 }
6. 串口调试
minicom -b 115200 -o -D /dev/tty.usbmodem1302
参考
- https://www.raspberrypi.com/documentation/microcontrollers/debug-probe.html
- https://www.hackster.io/whitney-knitter/raspbery-pi-pico-development-on-m2-mac-103609
- https://www.waveshare.net/wiki/Pico-ResTouch-LCD-3.5
- https://github.com/raspberrypi/pico-sdk/issues/1528