1.安装开发工具
- cmake
sh
brew install cmake
- openocd
sh
brew install openocd
- arm-none-eabi-gcc
用 brew 安装的版本会出现如下错误:
sh
arm-none-eabi-gcc: fatal error: cannot read spec file 'nosys.specs': No such file or directory
用 arm 官方的版本没有问题。
sh
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.xz
cd /opt
sudo tar xf ~/Downloads/arm-gnu-toolchain-13.3.rel1-darwin-arm64-arm-none-eabi.tar.xz
- arm-none-eabi-gdb
sh
brew install arm-none-eabi-gdb
- minicom
sh
sudo apt install minicom
2. 安装 pico-sdk
sh
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
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
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 烧录。
sh
PROGRAM=$1
if [ "$#" -eq 0 ]; then
echo "$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
sh
sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000"
- 启动 gdb
sh
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. 串口调试
sh
minicom -b 115200 -o -D /dev/tty.usbmodem1302