文章目录
- SHELL中microPython命令行
- SHELL中基于microPython的控制代码
- Hello Pico 代码
- SHELL中简单点灯代码
- SHELL中循环亮灯代码
- 基于pico sdk开发环境搭建及点灯代码
- 必备开发工具
- Mingw-w64:著名C/C++编译器GCC
- arm-none-eabi:交叉编译工具
- Git:开源的分布式版本控制系统
- cmake:生成makefile
- python:需要3.7.0以上。
- 安装及设置环境变量
- git必要的仓库
- 编译准备
- 正式编译
- 以blink(点灯例程)为例,生成文件结构如下:
- 点灯测试
- Tips:查看gcc涉及到的所有include文件目录
SHELL中microPython命令行
SHELL中基于microPython的控制代码
Tips:一般采用Thonny进行控制,可参考博文:
如果是采用其他串口软件进行控制,采用的波特率是115200。
Hello Pico 代码
在 Shell 中输入以下命令,Pico 会显示
Hello, Pico!
print("Hello, Pico!")
SHELL中简单点灯代码
在 Shell 中输入以下命令
from machine import Pin #导入Pin控制库
led = Pin(25, Pin.OUT) #初始化led
led.value(1) # 亮灯
led.value(0) # 灭灯
SHELL中循环亮灯代码
Pico 将执行三次亮灯灭灯循环,最后输出 Loop End
from machine import Pin
import utime
LED=Pin(25,Pin.OUT)
v = 1
while v < 4:
LED(1)
utime.sleep(1)
LED(0)
utime.sleep(1)
v += 1
LED(1)
utime.sleep(1)
LED(0)
utime.sleep(1)
v += 1
LED(1)
utime.sleep(1)
LED(0)
utime.sleep(1)
v += 1
print('LED closed!') # 输出结束语句
基于pico sdk开发环境搭建及点灯代码
必备开发工具
Mingw-w64:著名C/C++编译器GCC
下载地址:https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/
安装:mingw-w64-v11.0.0.zip,解压后将bin目录加入系统path即可。
测试命令:mingw32-make -v
正确安装返回值:
GNU Make 4.2.1
Built for x86_64-w64-mingw32
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
arm-none-eabi:交叉编译工具
下载地址:https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads
安装:安装时选择将bin路径加入系统path。
为避免兼容问题,本机采用2019-q4-major版本,最新版本为:gcc-arm-none-eabi-10.3-2021.10-win32。
测试命令:arm-none-eabi-gcc -v
正确安装返回值:
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=f:/dev/gnu\ tools\ arm\ embedded/9\ 2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/lto-wrapper.exe
Target: arm-none-eabi
Configured with: /mnt/workspace/workspace/GCC-9-pipeline/jenkins-GCC-9-pipeline-100_20191030_1572397542/src/gcc/configure --build=x86_64-linux-gnu --host=i686-w64-mingw32 --target=arm-none-eabi --prefix=/mnt/workspace/workspace/GCC-9-pipeline/jenkins-GCC-9-pipeline-100_20191030_1572397542/install-mingw --libexecdir=/mnt/workspace/workspace/GCC-9-pipeline/jenkins-GCC-9-pipeline-100_20191030_1572397542/install-mingw/lib --infodir=/mnt/workspace/workspace/GCC-9-pipeline/jenkins-GCC-9-pipeline-100_20191030_1572397542/install-mingw/share/doc/gcc-arm-none-eabi/info --mandir=/mnt/workspace/workspace/GCC-9-pipeline/jenkins-GCC-9-pipeline-100_20191030_1572397542/install-mingw/share/doc/gcc-arm-none-eabi/man --htmldir=/mnt/workspace/workspace/GCC-9-pipeline/jenkins-GCC-9-pipeline-100_20191030_1572397542/install-mingw/share/doc/gcc-arm-none-eabi/html --pdfdir=/mnt/workspace/workspace/GCC-9-pipeline/jenkins-GCC-9-pipeline-100_20191030_1572397542/install-mingw/share/doc/gcc-arm-none-eabi/pdf --enable-languages=c,c++ --enable-mingw-wildcard --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-headers=yes --with-newlib --with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/mnt/workspace/workspace/GCC-9-pipeline/jenkins-GCC-9-pipeline-100_20191030_1572397542/install-mingw/arm-none-eabi --with-libiconv-prefix=/mnt/workspace/workspace/GCC-9-pipeline/jenkins-GCC-9-pipeline-100_20191030_1572397542/build-mingw/host-libs/usr --with-gmp=/mnt/workspace/workspace/GCC-9-pipeline/jenkins-GCC-9-pipeline-100_20191030_1572397542/build-mingw/host-libs/usr --with-mpfr=/mnt/workspace/workspace/GCC-9-pipeline/jenkins-GCC-9-pipeline-100_20191030_1572397542/build-mingw/host-libs/usr --with-mpc=/mnt/workspace/workspace/GCC-9-pipeline/jenkins-GCC-9-pipeline-100_20191030_1572397542/build-mingw/host-libs/usr --with-isl=/mnt/workspace/workspace/GCC-9-pipeline/jenkins-GCC-9-pipeline-100_20191030_1572397542/build-mingw/host-libs/usr --with-libelf=/mnt/workspace/workspace/GCC-9-pipeline/jenkins-GCC-9-pipeline-100_20191030_1572397542/build-mingw/host-libs/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='GNU Tools for Arm Embedded Processors 9-2019-q4-major' --with-multilib-list=rmprofile
Thread model: single
gcc version 9.2.1 20191025 (release) [ARM/arm-9-branch revision 277599] (GNU Tools for Arm Embedded Processors 9-2019-q4-major)
Git:开源的分布式版本控制系统
测试命令:git --version
正确安装返回值:
git version 2.23.0.windows.1
cmake:生成makefile
下载地址:https://cmake.org/download/
安装:cmake-3.26.4-windows-x86_64,将bin路径加入系统path。
测试命令:cmake -h
正确安装返回值:
Usage
cmake [options] <path-to-source>
cmake [options] <path-to-existing-build>
cmake [options] -S <path-to-source> -B <path-to-build>
Specify a source directory to (re-)generate a build system for it in the
current working directory. Specify an existing build directory to
re-generate its build system.
Options
-S <path-to-source> = Explicitly specify a source directory.
-B <path-to-build> = Explicitly specify a build directory.
-C <initial-cache> = Pre-load a script to populate the cache.
-D <var>[:<type>]=<value> = Create or update a cmake cache entry.
-U <globbing_expr> = Remove matching entries from CMake cache.
-G <generator-name> = Specify a build system generator.
-T <toolset-name> = Specify toolset name if supported by
generator.
-A <platform-name> = Specify platform name if supported by
generator.
python:需要3.7.0以上。
安装及设置环境变量
git必要的仓库
必备库:pico-sdk和pico-examples
执行命令:
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
建议clone到本地的模板生成库(介绍可参考官方文档):
git clone https://github.com/raspberrypi/pico-project-generator.git
编译准备
首先添加pico环境变量:
将pico-sdk的根目录路径添加到新建PICO_SDK_PATH中,如:
执行CMD,并将当前目录变更为进入pico-examples根目录,并在其中新建build子文件夹。
进入build文件夹:
在当前目录下执行:
cmake -G "MinGW Makefiles" ..
执行结果为:
PICO_SDK_PATH is E:/pico/pico-sdk
PICO platform is rp2040.
Build type is Release
PICO target board is pico.
Using board configuration from E:/pico/pico-sdk/src/boards/include/boards/pico.h
CMake Warning at E:/pico/pico-sdk/src/rp2_common/tinyusb/CMakeLists.txt:10 (message):
TinyUSB submodule has not been initialized; USB support will be unavailable
hint: try 'git submodule update --init' from your SDK directory
(E:/pico/pico-sdk).
CMake Warning at hello_world/usb/CMakeLists.txt:19 (message):
not building hello_usb because TinyUSB submodule is not initialized in the
SDK
Skipping TinyUSB device examples as TinyUSB is unavailable
Skipping TinyUSB host examples as TinyUSB is unavailable
Skipping TinyUSB dual examples, as TinyUSB hw/mcu/raspberry_pi/Pico-PIO-USB submodule unavailable
-- Configuring done
-- Generating done
-- Build files have been written to: E:/pico/pico-examples/build
按提示执行:git submodule update --init,没有效果,该warn待查。
正式编译
mingw32-make -j8
-j4 -j8的表示用4个或8个线程编译,加快编译速度,可选参数。
编译显示:
E:\pico\pico-examples\build>mingw32-make -j8
Scanning dependencies of target bs2_default
[ 0%] Performing build step for 'ELF2UF2Build'
[ 0%] Performing build step for 'PioasmBuild'
[ 0%] Built target bs2_default
[ 0%] Built target bs2_default_padded_checksummed_asm
Consolidate compiler generated dependencies of target elf2uf2
Consolidate compiler generated dependencies of target pioasm
[100%] Built target elf2uf2
[100%] Built target pioasm
[ 0%] No install step for 'ELF2UF2Build'
[ 0%] No install step for 'PioasmBuild'
[ 0%] Completed 'ELF2UF2Build'
[ 0%] Completed 'PioasmBuild'
[ 0%] Built target ELF2UF2Build
[ 0%] Built target PioasmBuild
编译完成:
Scanning dependencies of target pio_ws2812
Scanning dependencies of target adc_dma_capture
Scanning dependencies of target pio_ir_loopback
Consolidate compiler generated dependencies of target pio_st7789_lcd
Consolidate compiler generated dependencies of target pio_uart_rx_intr
Consolidate compiler generated dependencies of target pio_ws2812_parallel
Consolidate compiler generated dependencies of target pio_uart_tx
Consolidate compiler generated dependencies of target pio_uart_rx
Consolidate compiler generated dependencies of target pio_ws2812
Consolidate compiler generated dependencies of target pio_ir_loopback
Consolidate compiler generated dependencies of target adc_dma_capture
[ 93%] Built target pio_uart_rx_intr
[ 94%] Built target pio_uart_tx
[ 95%] Built target pio_st7789_lcd
[ 96%] Built target pio_ws2812_parallel
[ 97%] Built target pio_uart_rx
[ 98%] Built target pio_ws2812
[ 99%] Built target pio_ir_loopback
[100%] Built target adc_dma_capture
以blink(点灯例程)为例,生成文件结构如下:
名称 大小 修改日期
CMakeFiles/ 2023/6/27 14:15:24
elf2uf2/ 2023/6/27 11:23:21
blink.bin 8.6 kB 2023/6/27 11:26:22
blink.dis 158 kB 2023/6/27 11:26:22
blink.elf 30.4 kB 2023/6/27 11:26:21
blink.elf.map 155 kB 2023/6/27 11:26:21
blink.hex 24.2 kB 2023/6/27 11:26:22
blink.uf2 17.5 kB 2023/6/27 11:26:22
cmake_install.cmake 1.2 kB 2023/6/27 11:23:46
Makefile 73.3 kB 2023/6/27 11:23:46
点灯测试
按住BOOT键后上电,电脑弹出虚拟U盘,将.uf2文件拖拽或发送至树莓pico的虚拟U盘中,自动重启并运行下载后的程序。
Tips:查看gcc涉及到的所有include文件目录
以F:\dev\mingw-w64\bin下的gcc.exe作为编译器为例(已加入系统path),
要查看gcc涉及到的所有include文件目录的命令为:
gcc.exe -v -E -x c++ -
E:\pico\pico-examples\build>gcc.exe -v -E -x c++ -
Using built-in specs.
COLLECT_GCC=gcc.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-8.1.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw810/x86_64-810-win32-seh-rt_v6-rev0/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=win32 --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-win32-seh-rev0, Built by MinGW-W64 project' --with-bugurl=https://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-win32-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-win32-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=' -I/c/mingw810/x86_64-810-win32-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw810/x86_64-810-win32-seh-rt_v6-rev0/mingw64/opt/lib -L/c/mingw810/prerequisites/x86_64-zlib-static/lib -L/c/mingw810/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: win32
gcc version 8.1.0 (x86_64-win32-seh-rev0, Built by MinGW-W64 project)
COLLECT_GCC_OPTIONS='-v' '-E' '-mtune=core2' '-march=nocona'
F:/dev/mingw-w64/bin/../libexec/gcc/x86_64-w64-mingw32/8.1.0/cc1plus.exe -E -quiet -v -iprefix F:/dev/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/ -U_REENTRANT - -mtune=core2 -march=nocona
ignoring duplicate directory "F:/dev/mingw-w64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++"
ignoring duplicate directory "F:/dev/mingw-w64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32"
ignoring duplicate directory "F:/dev/mingw-w64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward"
ignoring duplicate directory "F:/dev/mingw-w64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/8.1.0/include"
ignoring nonexistent directory "C:/mingw810/x86_64-810-win32-seh-rt_v6-rev0/mingw64C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../include"
ignoring duplicate directory "F:/dev/mingw-w64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed"
ignoring duplicate directory "F:/dev/mingw-w64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
ignoring nonexistent directory "C:/mingw810/x86_64-810-win32-seh-rt_v6-rev0/mingw64/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
F:/dev/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++
F:/dev/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32
F:/dev/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward
F:/dev/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include
F:/dev/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed
F:/dev/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include
End of search list.