单片机/MCU论坛
直播中

Monody_4fc

3年用户 29经验值
擅长:模拟技术 嵌入式技术 MEMS/传感技术
私信 关注
[文章]

ubuntu上交叉编译rp2040

以ubuntu20.04为例,server版/桌面版也可以

记录下踩坑

1.安装ssh 可选(桌面版不需要这一步,server版方便用vscode开发)

安装ssh服务端

sudo apt install openssh-server

获取ssh状态

sudo systemctl status sshd

如果是running表示可以使用

如果不是需要开启ssh

sudo service sshd start

获取本机IP 用以后面vscode连接

ip addr

vscode连接ssh的参数

用户名@ip

2.安装openocd

调试器配置

这里需要注意 ,我使用daplink无法连接到rp2040 ,所以使用另一块pico作为调试器,需要给pico调试器下载固件,也就是picoprobe

地址

https://github.com/Wiz-IO/tool-pico-openocd/blob/main/picoprobe.uf2

在window下使用picoprobe调试器,需要安装zadig-2.7.exe 安装 USB 驱动的程序

编译openocd源码

实际上有编译好的openocd,但是它好像不支持picoprobe.所以需要自己编译

https://xpack-dev-tools.github.io/openocd-xpack/

总结就是:编译好的openocd 支持daplink 不支持picoprobe,而daplink是无法连接到rp2040

自己编译的opneocd支持picoprobe,picoprobe可以连接到rp2040

克隆源码

git clone https://github.com/raspberrypi/openocd.git --branch picoprobe --depth=1 --no-sing

安装依赖

sudo apt install automake autoconf build-essential texinfo libtool libftdi-dev libusb-1.
cd openocd/
./bootstrap 
./configure --enable-picoprobe# 使能picoprobe

编译

make -j4 #使用4个线程编译 加快编译速度

安装

sudo make install

验证安装

openocd -v#显示安装的版本

验证是否是否识别到picoprobe

sudo openocd -f interface/picoprobe.cfg

如下

Open On-Chip `Debugger `0.11.0-g8e3c38f-dirty (2024-08-14-05:39)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
adapter speed: 5000 kHz
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 5000 kHz
Warn : gdb services need one or more targets defined

验证是否是否识别到rp2040

Open On-Chip Debugger 0.11.0-g8e3c38f-dirty (2024-08-14-05:39)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'swd'
adapter speed: 5000 kHz

Info : Hardware thread awareness created
Info : Hardware thread awareness created
Info : RP2040 Flash Bank Command
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 5000 kHz
Info : SWD DPIDR 0x0bc12477
Info : SWD DLPIDR 0x00000001
Info : SWD DPIDR 0x0bc12477
Info : SWD DLPIDR 0x10000001
Info : rp2040.core0: hardware has 4 breakpoints, 2 watchpoints
Info : rp2040.core1: hardware has 4 breakpoints, 2 watchpoints
Info : starting gdb server for rp2040.core0 on 3333
Info : Listening on port 3333 for gdb connections

3.安装交叉编译工具链

sudo apt install cmake gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib

这里可能会遇到一个问题就是在编译pico代码时,默认安装的cmake版本太低

需要升级cmake

打开cmake下载的官网:https://cmake.org/files/

这里我们选择最高的子版本cmake-3.30.0-linux-x86_64.sh

升级cmake

sudo bash cmake-3.20.6-inux-x86_64.sh --skip-licence --prefix=/usr
安装过程中遇到:

第一个选择时,输入y!!!

Do you accept the license? [yn]:

输入 y

第二个选择时,输入n!!!

By default the CMake will be installed in:
 "/usr/cmake-3.23.0-linux-x86_64"
Do you want to include the subdirectory cmake-3.23.0-linux-x86_64?
Saying no will install in: "/usr"

原文链接https://blog.csdn.net/weixin_42156097/article/details/126932003

查看cmake版本

cmake --version
cmake version 3.20.6

4.下载rp2040的sdk和example,配置sdk路径

下载源码到/home/用户名/rp2040目录下,没有就新建一个

git clone https://github.com/raspberrypi/pico-sdk.git
git clone https://github.com/raspberrypi/pico-examples.git

设置picosdk的路径

在/home/用户名 目录下 打开

sudo nano .bashrc

编辑.bashrc文件

添加

export PICO_SDK_PATH="/home/sxl/rp2040/pico-sdk"

5.编译,烧录

在/home/sxl/rp2040/pico-examples目录下,新建build文件夹

mkdir build
ccd build

执行cmake ..生成makefile文件 ,要有网络

进入build目录下的blink执行makef

cd blink
make -j2

烧录

jlink

sudo openocd -f interface/jlink.cfg -c "adapter speed 1000" -c "transport select swd" -f target/rp2040.cfg -c "program /home/sx/rp2040/pico-examples/build/blink/blink.elf  verify reset exit"
sudo openocd -f interface/jlink.cfg -c "adapter speed 1000" -c "transport select swd" -f target/rp2040.cfg -c "program /home/sx/rp2040/pico-examples/build/blink/blink.elf  verify reset exit"

picoprobe

sudo openocd -f interface/picoprobe.cfg -f target/rp2040.cfg -c "program /home/sxl/rp2040/pico-examples/build/blink/blink.elf  verify reset exit"
-f interface/picoprobe.cfg 告诉openocd使用picoprobe的配置来访问SWD接口

 -f target/rp2040.cfg 告诉openocd我们要访问基于RP2040的芯片的板子

 -c "program /home/sxl/rp2040/pico-examples/build/blink/blink.elf  verify reset exit"  
  告诉openocd执行命令,分别为编程(烧写)elf固件,
 路径必须是绝对路径或者相对路径、验证、复位、退出

ubuntusever

sudo openocd -f interface/picoprobe.cfg -f target/rp2040.cfg -c "program /home/sxl/rp2040/pico-examples/build/blink/blink.elf  verify reset exit"
sudo openocd -f interface/jlink.cfg -c "adapter speed 1000" -c "transport select swd" -f target/rp2040.cfg -c "program /home/sxl/rp2040/pico-examples/build/blink/blink.elf  verify reset exit"

更多回帖

发帖
×
20
完善资料,
赚取积分