
Raspberry-Pi-PICO系列--第三篇 开发环境搭建-Ubuntu系统
一、目的上一篇《Raspberry-Pi-PICO系列--第二篇 开发环境搭建-Mac系统》中我们介绍了如何在Mac上搭建raspberry pi picoC/C++ SDK开发环境,本篇我们介绍Uuntu系统上的环境搭建二、准备三、实战...
一、目的
在上一篇《Raspberry-Pi-PICO系列--第二篇 开发环境搭建-Mac系统》中我们介绍了如何在Mac上搭建raspberry pi pico C/C++ SDK开发环境,本篇我们介绍Ubuntu 16.04系统上的环境搭建过程。
二、准备
系统环境
如果是windows的同学可以通过虚拟机安装Ubuntu环境(具体安装过程请参考网上相关资料)
Ubuntu 16.04
fire@fire-pd:~$ uname -a
Linux fire-pd 4.15.0-112-generic #113~16.04.1-Ubuntu SMP Fri Jul 10 04:37:08 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
那么首先让我们打开一个terminal
1、安装vim
$ sudo apt-get install vim
2、安装cmake
$ sudo apt-get install cmake
查看cmake版本
$ cmake --version
cmake version 3.5.1
如果版本低于3.12.0则需要更新cmake(通过cmake源码编译升级)
具体方法如下:
编译cmake的过程中依赖一些package,通过以下命令安装一下
$ sudo apt-get install libncurses-dev
$ sudo apt-get install libssl-dev
下载cmake源码、解压、配置、编译、安装
$ wget https://cmake.org/files/v3.22/cmake-3.22.0.tar.gz
$ tar -zxvf cmake-3.22.0.tar.gz
$ cd cmake-3.22.0/
$ ./configure
$ make
$ sudo make install
$ sudo update-alternatives --install /usr/bin/cmake cmake /usr/local/bin/cmake 1 --force
$ cmake --version
3、安装git
$ sudo apt-get install git
4、创建工作目录,专门存放跟raspberry_pi_pico有关的内容
$ mkdir -p ~/workspace/third/raspberry_pi_pico
5、进入工作目录
$ cd ~/workspace/third/raspberry_pi_pico
6、下载代码仓库
$ git clone -b master https://github.com/raspberrypi/pico-sdk.git
$ cd pico-sdk/
$ git submodule update --init
$ cd ..
$ git clone -b master https://github.com/raspberrypi/pico-examples.git
$ git clone -b master https://github.com/raspberrypi/pico-extras.git
$ git clone -b master https://github.com/raspberrypi/pico-playground.git
注意git submodule update --init一定要执行,因为pico-sdk里面要用到tinyUSB,否则sdk里面的USB功能就都无法使用
其中最重要的两个仓库,一个是pico-sdk,一个是pico-examples;其他仓库都是一些高级应用。
7、下载linux版本的交叉编译工具链,地址如下
8、解压工具链到特定目录
你的用户名@你的PC名:~/workspace/third/raspberry_pi_pico$ pwd
$ /home/你的用户名/workspace/third/raspberry_pi_pico
$ mkdir toolchain
$ cd toolchain/
$ cp ~/Downloads/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 .
$ tar -jxvf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2
验证一下工具链可用,我们可以执行一下命令
$ cd ~/workspace/third/raspberry_pi_pico/toolchain/gcc-arm-none-eabi-10.3-2021.10/bin/
$ ./arm-none-eabi-gcc -v
屏幕输出内容
Using built-in specs.
COLLECT_GCC=./arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/home/你的用户名/workspace/third/raspberry_pi_pico/toolchain/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/lto-wrapper
Target: arm-none-eabi
Configured with: /mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/src/gcc/configure --target=arm-none-eabi --prefix=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-native --libexecdir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-native/lib --infodir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-native/share/doc/gcc-arm-none-eabi/info --mandir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-native/share/doc/gcc-arm-none-eabi/man --htmldir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-native/share/doc/gcc-arm-none-eabi/html --pdfdir=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-native/share/doc/gcc-arm-none-eabi/pdf --enable-languages=c,c++ --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-newlib --with-headers=yes --with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/install-native/arm-none-eabi --build=x86_64-linux-gnu --host=x86_64-linux-gnu --with-gmp=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-native/host-libs/usr --with-mpfr=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-native/host-libs/usr --with-mpc=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-native/host-libs/usr --with-isl=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-native/host-libs/usr --with-libelf=/mnt/workspace/workspace/GCC-10-pipeline/jenkins-GCC-10-pipeline-338_20211018_1634516203/build-native/host-libs/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='GNU Arm Embedded Toolchain 10.3-2021.10' --with-multilib-list=rmprofile,aprofile
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 10.3.1 20210824 (release) (GNU Arm Embedded Toolchain 10.3-2021.10)
9、设置环境变量PICO_SDK_PATH/PICO_TOOLCHAIN_PATH
为了避免每次都要重新设置,我们将这两个环境变量设置到profile文件,这样每次打开一个新的terminal时,这些环境变量已经设置好了。
$ vim ~/.bashrc
在文件的末尾添加如下
export PICO_SDK_PATH="/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk"
export PICO_TOOLCHAIN_PATH="/home/你的用户名/workspace/third/raspberry_pi_pico/toolchain/gcc-arm-none-eabi-10.3-2021.10"
设置完成后重新打开一个terminal,输入
$ env | grep PICO
如果能看到如下内容说明设置成功
PICO_TOOLCHAIN_PATH=/home/你的用户名/workspace/third/raspberry_pi_pico/toolchain/gcc-arm-none-eabi-10.3-2021.10
PICO_SDK_PATH=/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk
由于在实际编译中发现本机的GCC版本过低会导致编译elf2uf2失败,故需要执行以下命令对GCC/G++进行升级(建议可以先跳过这一步,后面发现本机编译elf2uf2失败的时候再执行以下步骤)
编译elf2uf2工具的目的是将elf格式的固件转换成uf2格式并通过USB下载
$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
$ sudo apt-get update
$ sudo apt-get install gcc-7
$ sudo apt-get install g++-7
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 100
$ sudo update-alternatives --config gcc
$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 100
$ sudo update-alternatives --config g++
$ gcc --version
$ g++ --version
三、实战--编译工程并烧写运行
$ cd ~/workspace/third/raspberry_pi_pico/pico-examples
$ mkdir build
$ cd build
$ cmake ..
如果之前都正确配置的话,你应该可以看到如下结果
Using PICO_SDK_PATH from environment ('/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk')
PICO_SDK_PATH is /home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk
Defaulting PICO_PLATFORM to rp2040 since not specified.
Defaulting PICO platform compiler to pico_arm_gcc since not specified.
-- Defaulting build type to 'Release' since not specified.
PICO compiler is pico_arm_gcc
-- The C compiler identification is GNU 10.3.1
-- The CXX compiler identification is GNU 10.3.1
-- The ASM compiler identification is GNU
-- Found assembler: /home/你的用户名/workspace/third/raspberry_pi_pico/toolchain/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc
Defaulting PICO target board to pico since not specified.
Using board configuration from /home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/boards/include/boards/pico.h
-- Found Python3: /usr/bin/python3.5 (found version "3.5.2") found components: Interpreter
TinyUSB available at /home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/lib/tinyusb/src/portable/raspberrypi/rp2040; enabling build support for USB.
-- Configuring done
-- Generating done
-- Build files have been written to: /home/你的用户名/workspace/third/raspberry_pi_pico/pico-examples/build
编译blink工程
$ cd ~/workspace/third/raspberry_pi_pico/pico-examples/build/blink
$ make
编译成功时屏幕输出
Creating directories for 'ELF2UF2Build'
No download step for 'ELF2UF2Build'
No update step for 'ELF2UF2Build'
No patch step for 'ELF2UF2Build'
Performing configure step for 'ELF2UF2Build'
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/你的用户名/workspace/third/raspberry_pi_pico/pico-examples/build/elf2uf2
Performing build step for 'ELF2UF2Build'
[ 50%] Building CXX object CMakeFiles/elf2uf2.dir/main.cpp.o
[100%] Linking CXX executable elf2uf2
[100%] Built target elf2uf2
No install step for 'ELF2UF2Build'
Completed 'ELF2UF2Build'
Built target ELF2UF2Build
Scanning dependencies of target bs2_default
Building ASM object pico-sdk/src/rp2_common/boot_stage2/CMakeFiles/bs2_default.dir/compile_time_choice.S.obj
Linking ASM executable bs2_default.elf
Built target bs2_default
Generating bs2_default.bin
Generating bs2_default_padded_checksummed.S
Built target bs2_default_padded_checksummed_asm
Scanning dependencies of target blink
Building C object blink/CMakeFiles/blink.dir/blink.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_stdlib/stdlib.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/hardware_gpio/gpio.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/hardware_claim/claim.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_platform/platform.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/hardware_sync/sync.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/hardware_uart/uart.c.obj
Building ASM object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/hardware_divider/divider.S.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/common/pico_time/time.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/common/pico_time/timeout_helper.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/hardware_timer/timer.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/common/pico_sync/sem.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/common/pico_sync/lock_core.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/common/pico_sync/mutex.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/common/pico_sync/critical_section.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/common/pico_util/datetime.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/common/pico_util/pheap.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/common/pico_util/queue.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_runtime/runtime.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/hardware_clocks/clocks.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/hardware_irq/irq.c.obj
Building ASM object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/hardware_irq/irq_handler_chain.S.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/hardware_pll/pll.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/hardware_vreg/vreg.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/hardware_watchdog/watchdog.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/hardware_xosc/xosc.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_printf/printf.c.obj
Building ASM object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_bit_ops/bit_ops_aeabi.S.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_bootrom/bootrom.c.obj
Building ASM object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_divider/divider.S.obj
Building ASM object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_double/double_aeabi.S.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_double/double_init_rom.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_double/double_math.c.obj
Building ASM object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_double/double_v1_rom_shim.S.obj
Building ASM object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_int64_ops/pico_int64_ops_aeabi.S.obj
Building ASM object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_float/float_aeabi.S.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_float/float_init_rom.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_float/float_math.c.obj
Building ASM object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_float/float_v1_rom_shim.S.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_malloc/pico_malloc.c.obj
Building ASM object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_mem_ops/mem_ops_aeabi.S.obj
Building ASM object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_standard_link/crt0.S.obj
Building CXX object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_standard_link/new_delete.cpp.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_standard_link/binary_info.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_stdio/stdio.c.obj
Building C object blink/CMakeFiles/blink.dir/home/你的用户名/workspace/third/raspberry_pi_pico/pico-sdk/src/rp2_common/pico_stdio_uart/stdio_uart.c.obj
Linking CXX executable blink.elf
Built target blink
并且在目录下有文件blink.uf2、blink.elf、blink.bin,分别对应不同烧写方式用的文件。
.uf2格式可以直接通过板载USB下载
.elf格式可以通过SWD接口下载
.bin格式可以直接flash烧写器烧写到flash中
如果编译出错的原因是编译elf2uf2出错(并且是C++语法错误)查看一下GCC版本更新一下再重新编译一下(如果还有问题,可以留言)
烧写
将开发板上的白色按钮按住,然后将USB线接在开发板上,此时PC上会识别出U盘,如图
将blink.uf2文件拷贝到此目录下,设备就会自动重启,并且板载LED开始闪烁。
至此,我们完成了Ubuntu上开发环境的搭建。
下篇我们将介绍如何在Windows上面搭建开发环境。
更多推荐
所有评论(0)