树莓派(Raspberry Pi)picotool-安装

直接安装

在archlinux上,使用yay直接安装

yay -S picotool

从源码安装

安装libusb

sudo pacman -S libusb

下载 pico-sdk

git clone https://github.com/raspberrypi/pico-sdk.git --branch master
cd pico-sdk
git submodule update --init
cd ..

下载 picotool 编译构建

git clone https://github.com/raspberrypi/picotool.git
cd picotool
mkdir build
cd build
export PICO_SDK_PATH=../../pico-sdk
cmake ../
make

工具介绍

$picotool help
PICOTOOL:
    Tool for interacting with RP2040/RP2350 device(s) in BOOTSEL mode, or with an RP2040/RP2350 binary

SYNOPSIS:
    picotool info [-b] [-p] [-d] [--debug]  [-l] [-a] [device-selection]
    picotool info [-b] [-p] [-d] [--debug]  [-l] [-a] <filename> [-t <type>]
    picotool config [-s <key> <value>] [-g  <group>] [device-selection]
    picotool config [-s <key> <value>] [-g  <group>] <filename> [-t <type>]
    picotool load [--ignore-partitions] [--family <family_id>] [-p <partition>] [-n] [-N] [-u] [-v] [-x] <filename> [-t <type>] [-o <offset>] [device-selection]
    picotool encrypt [--quiet] [--verbose]  [--hash] [--sign] <infile> [-t <type>] [-o <offset>] <outfile> [-t <type>] <aes_key> [-t <type>] [<signing_key>] [-t <type>]
    picotool seal [--quiet] [--verbose] [--hash] [--sign] [--clear] <infile> [-t <type>] [-o <offset>] <outfile> [-t <type>] [<key>] [-t <type>] [<otp>] [-t <type>] [--major <major>] [--minor  <minor>] [--rollback <rollback>  [<rows>..]]
    picotool link [--quiet] [--verbose]     <outfile> [-t <type>] <infile1> [-t<type>] <infile2> [-t   <type>] [<infile3>] [-t   <type>] [-p] <pad>
    picotool save [-p] [device-selection]
    picotool save -a [device-selection]
    picotool save -r <from> <to>    [device-selection]
    picotool verify [device-selection]
    picotool reboot [-a] [-u] [-g   <partition>] [-c <cpu>]   [device-selection]
    picotool otp list|get|set|load|dump|    permissions|white-label
    picotool partition info|create
    picotool uf2 info|convert
    picotool version [-s] [<version>]
    picotool coprodis [--quiet] [--verbose]     <infile> [-t <type>] <outfile> [-t <type>]
    picotool help [<cmd>]

COMMANDS:
    info          Display information from    the target device(s) or file.
                  Without any arguments, this     will display basic  information for all connected RP2040    devices in BOOTSEL mode
    config        Display or change program   configuration settings from the target device(s) or file.
    load          Load the program / memory   range stored in a file onto the device.
    encrypt       Encrypt the program.
    seal          Add final metadata to a     binary, optionally including a hash and/or signature.
    link          Link multiple binaries into     one block loop.
    save          Save the program / memory   stored in flash on the device to a file.
    verify        Check that the device   contents match those in the file.
    reboot        Reboot the device
    otp           Commands related to the     RP2350 OTP (One-Time-Programmable) Memory
    partition     Commands related to RP2350  Partition Tables
    uf2           Commands related to UF2     creation and status
    version       Display picotool version
    coprodis      Post-process coprocessor    instructions in disassembly files.
    help          Show general help or help   for a specific command

Use "picotool help <cmd>" for more info
说明
大部分命令都要求将树莓派微控制器设备连接到开发设备上,并处于 BOOTSEL 模式下。
重点
如果打印错误消息 No accessible RP2040/RP2350 devices in BOOTSEL mode were found,并且伴有类似这样的提示: Device at bus 1, address 7 appears to be a RP2040 device in BOOTSEL mode, but picotool was unable to connect,这表明已连接了一个 Pico 系列设备,但是执行命令的权限不够,这时可以使用 sudo 来运行 picotool
sudo picotool info -a
如果使用的是 Windows 系统,则需要安装一个驱动程序。
下载并运行 Zadig,从下拉框中选择 RP2 Boot(Interface 1),并选择 WinUSB 作为驱动程序,然后点击 “安装驱动程序” 按钮。

picotool 的 1.1 版本开始,支持与未处于 BOOTSEL 模式的树莓派微控制器进行交互,使用 picotool-f 参数使用SDK 的USB 标准输入输出(stdio)进行交互。

显示信息

当前版本的SDK支持二进制信息,能够存储目标设备或者文件的精简信息。info 命令用于读取此类信息。

这些信息既可以从一个或多个处于 BOOTSEL 模式的已连接树莓派微控制器中读取,也可以从一个文件中读取。该文件可以是可执行与可链接格式(ELF)文件、通用闪存存储格式(UF2)文件或二进制(BIN)文件。

$picotool help info
INFO:
    Display information from the target device(s) or file.
    Without any arguments, this will display basic information for all connected
    RP2040 devices in BOOTSEL mode

SYNOPSIS:
    picotool info [-b] [-p] [-d] [--debug] [-l] [-a] [device-selection]
    picotool info [-b] [-p] [-d] [--debug] [-l] [-a] <filename> [-t <type>]

OPTIONS:
    Information to display
        -b, --basic
            Include basic information. This is the default
        -p, --pins
            Include pin information
        -d, --device
            Include device information
        --debug
            Include device debug information
        -l, --build
            Include build attributes
        -a, --all
            Include all information

TARGET SELECTION:
    To target one or more connected RP2040 device(s) in BOOTSEL mode (the default)
        --bus <bus>
            Filter devices by USB bus number
        --address <addr>
            Filter devices by USB device address
        --vid <vid>
            Filter by vendor id
        --pid <pid>
            Filter by product id
        --ser <ser>
            Filter by serial number
        -f, --force
            Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be rebooted back to application mode
        -F, --force-no-reboot
            Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but without the RPI-RP2 drive mounted
    To target a file
        <filename>
            The file name
        -t <type>
            Specify file type (uf2 | elf | bin) explicitly, ignoring file extension

例如,在将Pico系列设备插入 USB 接口之前,按住 BOOTSEL 按钮,使其以大容量存储模式连接到计算机。然后打开一个终端窗口并输入:

$sudo picotool info
Program Information
    name: hello_world
    features: stdout to UART

或者

$sudo picotool info -a
Program Information
    name:         hello_world
    features:     stdout to UART
    binary start: 0x10000000
    binary end:   0x1000606c

Fixed Pin Information
    20: UART1 TX
    21: UART1 RX

Build Information
    build date:       Dec 31 2020
    build attributes: Debug build

Device Information
    flash size:  2048K
    ROM version: 2

也可以通过如下的命令获取引脚信息。

$ sudo picotool info -bp
Program Information
    name:     hello_world
    features: stdout to UART

Fixed Pin Information
    20: UART1 TX
    21: UART1 RX

也可以查询二进制文件的信息。

$ picotool info -a lcd_1602_i2c.uf2
File lcd_1602_i2c.uf2:
Program Information
    name:         lcd_1602_i2c
    web site:     https://github.com/raspberrypi/pico-examples/tree/HEAD/i2c/lcd_1602_i2c
    binary start: 0x10000000
    binary end:   0x10003c1c

Fixed Pin Information
    4: I2C0 SDA
    5: I2C0 SCL

Build Information
    build date: Dec 31 2020

保存程序

“保存”功能支持将设备中的一段内存、一个程序或整个闪存内容保存到一个二进制(BIN)文件或通用闪存存储格式(UF2)文件中。

$ picotool help save
SAVE:
    Save the program / memory stored in flash on the device to a file.

SYNOPSIS:
    picotool save [-p] [--bus <bus>] [--address <addr>] [-f] [-F] <filename> [-t <type>]
    picotool save -a [--bus <bus>] [--address <addr>] [-f] [-F] <filename> [-t <type>]
    picotool save -r <from> <to> [--bus <bus>] [--address <addr>] [-f] [-F] <filename> [-t <type>]

OPTIONS:
    Selection of data to save
        -p, --program
            Save the installed program only. This is the default
        -a, --all
            Save all of flash memory
        -r, --range
            Save a range of memory. Note that UF2s always store complete 256 byte-aligned blocks of 256 bytes, and the range is expanded accordingly
        <from>
            The lower address bound in hex
        <to>
            The upper address bound in hex
    Source device selection
        --bus <bus>
            Filter devices by USB bus number
        --address <addr>
            Filter devices by USB device address
        -f, --force
            Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be rebooted back to application mode
        -F, --force-no-reboot
            Force a device not in BOOTSEL mode but running compatible code to reset so the command can be executed. After executing the command (unless the command itself is a 'reboot') the device will be left connected and accessible to picotool, but  without the RPI-RP2 drive mounted 
    File to save to
        <filename>
            The file name
        -t <type>
            Specify file type (uf2 | elf | bin) explicitly, ignoring file extension

比如:

$ sudo picotool info
Program Information
name:     lcd_1602_i2c
web site: https://github.com/raspberrypi/pico-examples/tree/HEAD/i2c/lcd_1602_i2c
$ picotool save spoon.uf2
Saving file: [==============================] 100%
Wrote 51200 bytes to spoon.uf2
$ picotool info spoon.uf2
File spoon.uf2:
Program Information
name:     lcd_1602_i2c
web site: https://github.com/raspberrypi/pico-examples/tree/HEAD/i2c/lcd_1602_i2c

二进制信息

二进制信息是在构建时嵌入到二进制文件中的、可由机器定位且能被机器读取的信息。

基本信息

当拿到一个 Pico 系列设备但不知道里面有什么内容时,这些信息就非常有用了!
基本信息包括:
- 程序名称
- 程序描述
- 程序版本字符串
- 程序构建日期
- 程序网址
- 程序结束地址
- 程序特性,这是一个根据二进制文件中的各个字符串构建的列表,在 SDK 中可以显示出来(例如,我们会有一个针对通用异步收发传输器(UART)标准输入输出(stdio)的特性,以及一个针对通用串行总线(USB)标准输入输出(stdio)的特性)。
- 构建属性,及与二进制文件本身相关的内容(例如,调试构建)

引脚

当忘记可执行文件是为基于树莓派微控制器的哪种电路板构建的时,可使用picotool info --pins获取文件的引脚信息。

$ picotool info --pins sprite_demo.elf
File sprite_demo.elf:

Fixed  Pin Information
0-4:   Red 0-4
6-10:  Green 0-4
11-15: Blue 0-4
16:    HSync
17:    VSync
18:    Display Enable
19:    Pixel Clock
20:    UART1 TX
21:    UART1 RX

完整信息

使用 -a 选项可获取完整信息。

$ picotool info -a i2c_bus_scan.elf
File i2c_bus_scan.elf:

Program Information
    name:         i2c_bus_scan
    web site:     https://github.com/raspberrypi/pico-examples/tree/HEAD/i2c/bus_scan
    features:     UART stdin / stdout
    binary start: 0x10000000
    binary end:   0x10004c74

Fixed Pin Information
    0: UART0 TX
    1: UART0 RX
    4: I2C0 SDA
    5: I2C0 SCL

Build Information
    sdk version:      2.0.0-develop
    pico_board:       pico
    build date:       Aug 1 2024
    build attributes: Debug
上一篇:【Java】SpringBoot模拟流式输出,前端使用流式接收数据并打印


下一篇:YashanDB 23.2.3安装过程,并使用DBeaver进行连接