0013 MPSTPU(M.2 E) EN:修订间差异

来自Mcuzone Wiki
(创建页面,内容为“== '''关键词''' == 树莓派5、PCIe、TPU、DTPU、驱动安装、操作演示、AI、google、Coral、2230、2242、2280、NVMe SSD、固态硬盘 X1 == '''一、简介''' == Coral M.2加速器是一款M.2尺寸的模组,可以通过PCIE接口为树莓派等平台扩展边缘TPU协处理器。我司的MPSTPU扩展板通过PCIe Switch扩展出了两路PCIe接口,其中一路为M.2 E key接口,可外接A+E Key接口的TPU模组;另一路为M.2 M key…”)
 
 
(未显示同一用户的12个中间版本)
第1行: 第1行:
== '''关键词''' ==
[[0013 MPSTPU(M.2 E)|切换语言为中文]]
树莓派5、PCIe、TPU、DTPU、驱动安装、操作演示、AI、google、Coral、2230、2242、2280、NVMe SSD、固态硬盘 X1


== '''一、简介''' ==
== '''Keywords''' ==
Coral M.2加速器是一款M.2尺寸的模组,可以通过PCIE接口为树莓派等平台扩展边缘TPU协处理器。我司的MPSTPU扩展板通过PCIe Switch扩展出了两路PCIe接口,其中一路为M.2 E key接口,可外接A+E Key接口的TPU模组;另一路为M.2 M key接口,可外接NVMe SSD固态硬盘。MPSTPU扩展板可在加入TPU边缘计算能力的同时为系统提供SSD海量存储。
Raspberry Pi 5, PCIe, TPU, DTPU, Driver installation, Operation demonstration, AI, google, Coral, 2230, 2242, 2280, NVMe SSD, SSD X1


== '''二、硬件资源''' ==
== '''I. Introduction''' ==
1. 基于树莓派5设计,采用16Pin FPC和树莓派5的PCle接口连接;
The Coral M.2 Accelerator is an M.2 sized module that can expand edge TPU coprocessing capabilities via the PCIE interface for platforms such as the Raspberry Pi. Our MPSTPU expansion board adds two PCIe interfaces via a PCIe Switch, One is an M.2 E key interface, which can be used to connect a TPU module with an A+E Key interface, the other is an M.2 M key interface, which can be used to connect an NVMe SSD. The MPSTPU expansion board can provide the system with massive SSD storage while adding TPU edge computing capabilities.


2. 扩展板通过PCIe Switch进行一扩二;
== '''II. Hardware Resources''' ==
1. Designed for the Raspberry Pi 5, it uses a 16-pin FPC to connect to the Raspberry Pi 5's PCIe interface.


3. 一路PICe扩M.2 E key接口,用于接Google coral Edge TPU,树莓派官方OS加载驱动;
2. The MPSTPU expansion board adds two PCIe interfaces via a PCIe Switch.


4. 一路PCIe扩展M.2 M接口,接NVMe SSD(PCIe X1,仅支持Gen2模式),支持2230/2242/2280尺寸(默认焊接2280铜柱);
3. One PCIe extension M.2 E key interface, used for connecting the Google Coral Edge TPU, with the official Raspberry Pi OS loading the driver.


5. SSD可用于存储数据和系统启动;从SSD启动时,需树莓派官方固件是2024.5.13以后的版本;
4. One PCIe expanded M.2 M key slot, for connecting NVMe SSD (PCIe X1, Gen2 mode only). Supports 2230/2242/2280 size SSDs (defaulting to welded mounting posts for 2280 size). It does not support SSDs that use NGFF and SATA protocols.


6. 40Pin GPIO部分采用开窗设计,可通过杜邦线连接,不影响树莓派5自身GPIO引脚使用;
5. The SSD can be used for data storage and system booting. When booting from the SSD, the Raspberry Pi official firmware needs to be version 2024.5.13 or later.


7. PCB板沉金工艺,无铅生产,且通过UL认证,符合ROHS标准,防火等级94V-0。
6. The 40-pin GPIO section adopts an unobstructed design on the top. It can be connected via DuPont cable, without affecting the use of the Raspberry Pi 5's own GPIO pins.
 
7. Gold immersion PCB process, lead-free production, certified by UL, compliant with ROHS standards, and has a fire rating of 94V-0.
 
8. It uses four M2.5 mounting holes that align with the Raspberry Pi 5 mounting holes and is compatible with an optional aluminum alloy enclosure.


http://www.mcuzone.com/wiki/0013_MPTPU_M/0013_MPTPU_M_03.jpg
http://www.mcuzone.com/wiki/0013_MPTPU_M/0013_MPTPU_M_03.jpg


注意:
Note:
 
1. After the Raspberry Pi 5 firmware update, the settings cannot be modified, or else the firmware will automatically revert to the old version.


1. 树莓派5固件更新后,不能修改设置,不然固件会自动退回至老版本;
2. Due to the limitations of the switch, PCIe only supports X1 Gen2, with SSD speeds of approximately 400 MB/s.


2. 受限于Switch,PClIE仅支持X1Gen2,SSD速度约400MB/s。
== '''III. System flashing and setting''' ==


== '''三、系统烧写及设置''' ==
=== 3.1 Overview ===
This document uses the Raspberry Pi OS, Ubuntu system and OpenWrt system for testing.


=== 3.1 概述 ===
The version of the Raspberry Pi OS is: 2024-07-04-raspios-bookworm-arm64.img.xz
本文档采用树莓派OS、Ubuntu系统和OpenWrt系统进行测试。


树莓派OS的版本为2024-07-04-raspios-bookworm-arm64.img.xz,树莓派OS下载地址:
You can download the Raspberry Pi OS in:


https://www.raspberrypi.com/software/operating-systems/#raspberry-pi-os-64-bit
https://www.raspberrypi.com/software/operating-systems/#raspberry-pi-os-64-bit


Ubuntu系统的版本为ubuntu-24.04-preinstalled-desktop-arm64+raspi.img.xz,Ubuntu OS下载地址:
'''''Note: If you want to run the TPU module under Raspberry Pi OS, the TF card used for flashing the system should have a space of at least 16GB, otherwise, it will display space errors during the installation and configuration process!'''''
 
The version of the Ubuntu system is: ubuntu-24.04-preinstalled-desktop-arm64+raspi.img.xz
 
You can download the Ubuntu system in:


https://ubuntu.com/download/raspberry-pi
https://ubuntu.com/download/raspberry-pi


OpenWrt系统版本:
The version of the OpenWrt system is: openwrt-bcm27xx-bcm2712-rpi-5-squashfs-sysupgrade-linux-6.1.100-20240805.img.gz


openwrt-bcm27xx-bcm2712-rpi-5-squashfs-sysupgrade-linux-6.1.100-20240805.img.gz
=== 3.2 System flashed onto the SD (TF) card ===
[[0005 MPS2242 2280 2280P(Single SSD Expansion Board)#3.2 Boot from TF card|Click here to read the instructions for System flashing]]


=== 3.2 系统烧写在SD(TF)卡上 ===
=== 3.3 System flashed onto the SSD ===
[[0005 MPS2242 2280(单SSD扩展板)#3.2 从TF卡启动|点击直达烧写方法说明]]
[[0005 MPS2242 2280 2280P(Single SSD Expansion Board)#3.3 Boot from SSD|Click here to read the instructions for System flashing]]


=== 3.3 系统烧写在SSD硬盘上 ===
== '''IV. Raspberry Pi OS operation demonstration''' ==
[[0005 MPS2242 2280(单SSD扩展板)#3.3 从SSD硬盘启动|点击直达烧写方法说明]]。
This chapter introduces how to run the TPU module on the Raspberry Pi OS.


== '''四、运行TPU模组''' ==
The steps in this chapter apply to both systems booting from TF card and from SSD.
本章介绍如何在树莓派OS运行TPU模组。


本章的操作步骤同时适用于系统从TF卡启动和从SSD硬盘启动。
=== 4.1 Config config.txt ===
 
After the system boots, open the Raspberry Pi terminal and enter the command:
=== 4.1 配置config.txt ===
系统启动后打开树莓派终端输入命令:


<code>sudo nano /boot/firmware/config.txt</code>
<code>sudo nano /boot/firmware/config.txt</code>


或者:
Or:


<code>sudo mousepad /boot/firmware/config.txt</code>
<code>sudo mousepad /boot/firmware/config.txt</code>


在文件最下方添加以下代码:
Add the codes in the ending of this file:


<code>dtparam=pciex1</code>
<code>dtparam=pciex1</code>
第77行: 第85行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_02.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_02.jpg


代码添加成功后,保存并重启系统:
Then, save the file and reboot the system:


<code>sudo reboot</code>
<code>sudo reboot</code>


=== 4.2 确认软件环境 ===
=== 4.2 Ensuring software environment ===
系统重启后打开打开树莓派终端输入命令:
After reboot the system, open the Raspberry Pi terminal and enter the command:


<code>uname -r</code>
<code>uname -r</code>


确保内核版本大于4.18后输入:
After ensuring the kernel version is greater than 4.18, enter:


<code>lsmod | grep apex</code>
<code>lsmod | grep apex</code>


确保没有输出则可以开始安装TPU驱动。
Ensure there is no output, then you can begin installing the TPU driver.http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_03.jpg
 
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_03.jpg


=== 4.3 安装必要软件 ===
=== 4.3 Install necessary software ===
确保网络能连通外网(需自备方法)后,添加Google TPU软件库:
Ensure the network is connected to internet connection to the regions out of China (you may need to find your own method), and then add the Google TPU software library:


<code>echo "deb <nowiki>https://packages.cloud.google.com/apt</nowiki> coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list</code>
<code>echo "deb <nowiki>https://packages.cloud.google.com/apt</nowiki> coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list</code>
第103行: 第109行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_04.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_04.jpg


添加完成后更新软件列表:
Update the software list after adding:


<code>sudo apt-get update</code>
<code>sudo apt-get update</code>
第109行: 第115行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_06.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_06.jpg


更新完成后安装必要的软件:
Install the necessary software after the update is completed:


<code>sudo apt-get install cmake libedgetpu1-std devscripts debhelper dkms dh-dkms</code>
<code>sudo apt-get install cmake libedgetpu1-std devscripts debhelper dkms dh-dkms</code>
第117行: 第123行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_08.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_08.jpg


=== 4.4 安装Gasket Driver ===
=== 4.4 Install Gasket Driver ===
依次输入以下命令安装Gasket Driver:
Enter the following commands in sequence to install the Gasket Driver:


<code>git clone <nowiki>https://github.com/google/gasket-driver.git</nowiki></code>
<code>git clone <nowiki>https://github.com/google/gasket-driver.git</nowiki></code>
第136行: 第142行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_11.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_11.jpg


安装完成后输入以下命令确保驱动以及软件安装成功:
After the installation is complete, enter the following command to ensure that the driver and software were installed successfully:


<code>sudo apt-get install gasket-dkms libedgetpu1-std</code>
<code>sudo apt-get install gasket-dkms libedgetpu1-std</code>
第142行: 第148行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_12.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_12.jpg


接下来添加udev rule去获得设备操作权限:
Then, add a udev rule to obtain device operation permissions:


<code>sudo sh -c "echo 'SUBSYSTEM==\"apex\", MODE=\"0660\", GROUP=\"apex\"' >> /etc/udev/rules.d/65-apex.rules"</code>
<code>sudo sh -c "echo 'SUBSYSTEM==\"apex\", MODE=\"0660\", GROUP=\"apex\"' >> /etc/udev/rules.d/65-apex.rules"</code>


添加用户到apex:
Add user to apex:


<code>sudo groupadd apex</code>
<code>sudo groupadd apex</code>
第154行: 第160行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_13.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_13.jpg


设置完成后重启系统:
Reboot the system after the setup is complete:


<code>sudo reboot</code>
<code>sudo reboot</code>


=== 4.5 验证模块检测以及驱动安装 ===
=== 4.5 Verification module testing and driver installation ===
系统启动后验证模块检测以及驱动安装:
After system starting, verification module testing and driver installation:


<code>lspci -nn | grep 089a</code>
<code>lspci -nn | grep 089a</code>


这里需要看到TPU模块,如下图所示(具体参数显示以实际为准):
Here, you need to see the TPU module, as shown in the following figure (specific parameter display is subject to the actual device):


<code>ls /dev/apex_0</code>
<code>ls /dev/apex_0</code>
第169行: 第175行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_14.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_14.jpg


这里插了一个TPU模块,因此可以看到一个TPU模块。
This board has a single TPU onboard, so you can see a TPU module:


输入<code>sudo lspci -v</code>可以看到驱动加载,其中必须包括TPU驱动,如果插了SSD硬盘,还需要包括SSD模块,如下图所示:
By entering <code>sudo lspci -v</code>, you can see the driver loading, this must include the TPU driver, and if an SSD is inserted, it also needs to include the SSD module, as shown in the following figure:


http://www.mcuzone.com/wiki/0013_MPTPU_M/0013_MPTPU_M_01.jpg
http://www.mcuzone.com/wiki/0013_MPTPU_M/0013_MPTPU_M_01.jpg


=== 4.6 代码运行环境配置 ===
=== 4.6 Configuration of the Code Execution Environment ===
Google TPU模块代码运行需要在Python3.6-3.9之间,而树莓派最新系统的Python版本为3.11,因此我们需要使用Pyenv来下载老版本Python。
Running Google TPU module code requires Python versions between 3.6 and 3.9, while the latest Raspberry Pi system is Python 3.11. Therefore, we need to use Pyenv to download an older version of Python.


首先进行依赖安装:
First, install the depends:


<code>sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python3-openssl</code>
<code>sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python3-openssl</code>
第186行: 第192行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_18.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_18.jpg


依赖安装完成后进行pyenv的安装:
Install pyenv after the depends are installed:


<code>curl <nowiki>https://pyenv.run</nowiki> | bash</code>
<code>curl <nowiki>https://pyenv.run</nowiki> | bash</code>
第192行: 第198行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_19.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_19.jpg


输入:
Enter the command:


<code>sudo nano ~/.bashrc</code>
<code>sudo nano ~/.bashrc</code>


或者:
Or:


<code>sudo mousepad ~/.bashrc</code>
<code>sudo mousepad ~/.bashrc</code>


在文件最下面添加以下代码:
Add the codes in the ending of this file:


<code>export PYENV_ROOT="$HOME/.pyenv"</code>
<code>export PYENV_ROOT="$HOME/.pyenv"</code>
第212行: 第218行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_21.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_21.jpg


添加完成后保存退出并重新加载shell:
Save and exit after adding, then reload the shell:


<code>exec "$SHELL"</code>
<code>exec "$SHELL"</code>
第218行: 第224行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_22.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_22.jpg


接下来我们可以利用pyenv安装老系统版本Python:
Then, we can use pyenv to install an older version of Python:


<code>pyenv install -v 3.8.8</code>
<code>pyenv install -v 3.8.8</code>
第226行: 第232行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_24.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_24.jpg


等待安装成功后我们将系统Python版本更改为3.8.8:
After the installation is successful, we will change the system Python version to 3.8.8:


<code>pyenv global 3.8.8</code>
<code>pyenv global 3.8.8</code>


更改成功后可以查看当前Python使用版本为3.8.8:
After the change is successful, you can check the current Python version is 3.8.8:


<code>pyenv versions</code>
<code>pyenv versions</code>
第238行: 第244行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_25.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_25.jpg


=== 4.7 下载代码和运行模组 ===
=== 4.7 Download the code and run the module ===
依次输入以下命令进行下载:
Enter the following commands in sequence to download:


<code>mkdir coral && cd coral</code>
<code>mkdir coral && cd coral</code>
第255行: 第261行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_27.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_27.jpg


接下来下载代码运行模组
Then, download the code and run the module:


<code>pip3 install numpy</code>
<code>pip3 install numpy</code>
第269行: 第275行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_30.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_30.jpg


=== 4.8 运行代码 ===
=== 4.8 Run the code ===
模组下载完成后返回 coral/pycoral路径下
After the module download is complete, back to the coral/pycoral path:


<code>cd ..</code>
<code>cd ..</code>


输入以下代码进行代码运行
Enter the following code to run it:


http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_39.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_39.jpg


注意:我们可以复制下列代码,但是请先粘贴到文本软件中,按照上图的格式,删除多余的回车符,再复制然后粘贴到终端中运行:
Note: You can copy the following code, but please paste it into a text editor first. Then, following the format shown above, remove any extra enter. After that, copy it again and paste it into the terminal to run.


<code>python3 examples/classify_image.py \</code>
<code>python3 examples/classify_image.py \</code>
第290行: 第296行:
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_31.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_31.jpg


== '''五、树莓派系统下使用SSD硬盘''' ==
== '''V. Using SSD in the Raspberry Pi OS''' ==
关于对SSD硬盘的基本操作,我们可以参考以下链接:
For basic operations on the SSD, we can refer to the following link:


[[0005 MPS2242 2280(单SSD扩展板)#4.1 SSD用作存储扩展|SSD用作存储扩展(树莓派OS下)]]
[[0005 MPS2242 2280 2280P(Single SSD Expansion Board)#4.1 Use the SSD for storage expansion|Use the SSD for storage expansion (Raspberry Pi OS)]]


[[0005 MPS2242 2280(单SSD扩展板)#六、对SSD进行分区等操作|对SSD进行分区等操作]]
[[0005 MPS2242 2280 2280P(Single SSD Expansion Board)#VI. Perform partitioning and other operations on the SSD|Perform partitioning and other operations on the SSD]]


[[0005 MPS2242 2280(单SSD扩展板)#cite ref-1|调整外设启动顺序]]
[[0005 MPS2242 2280 2280P(Single SSD Expansion Board)#cite ref-1|Adjust the peripheral boot order]]


[[0005 MPS2242 2280(单SSD扩展板)#7.2 在PCIe Gen2下测试硬盘速度|安装硬盘测速软件hdparm]]
[[0005 MPS2242 2280 2280P(Single SSD Expansion Board)#7.2 Test the SSD speed in PCIe Gen2 mode|Install the SSD speed testing software hdparm]]


关于如何测试SSD硬盘,我们可以参考以下链接:
For how to test the SSD, we can refer to the following link:


[[0008 MPS2.5G(SSD和2.5G以太网)#4.2 SSD硬盘测试|SSD硬盘测试(树莓派OS下)]]
[[0008 MPS2.5G(SSD和2.5G以太网)#4.2 SSD硬盘测试|SSD硬盘测试(树莓派OS下)]]


== '''六、Ubuntu系统下使用SSD硬盘''' ==
== '''VI. Using SSD in the Ubuntu system''' ==
关于对SSD硬盘的基本操作,我们可以参考以下链接,除了SSD用作存储扩展中与树莓派OS下操作略有不同,其余部分基本相同:
For basic operations on the SSD, we can refer to the following link, apart from the SSD being used for storage expansion, which operates slightly differently under Raspberry Pi OS, the rest is basically the same.


[[0005 MPS2242 2280(单SSD扩展板)#5.1 SSD用作存储扩展|SSD用作存储扩展(Ubuntu系统下)]]
[[0005 MPS2242 2280 2280P(Single SSD Expansion Board)#5.1 Use the SSD for storage expansion|Use the SSD for storage expansion(Ubuntu system)]]


[[0005 MPS2242 2280(单SSD扩展板)#六、对SSD进行分区等操作|对SSD进行分区等操作]]
[[0005 MPS2242 2280 2280P(Single SSD Expansion Board)#VI. Perform partitioning and other operations on the SSD|Perform partitioning and other operations on the SSD]]


[[0005 MPS2242 2280(单SSD扩展板)#cite ref-1|调整外设启动顺序]]
[[0005 MPS2242 2280 2280P(Single SSD Expansion Board)#cite ref-1|Adjust the peripheral boot order]]


[[0005 MPS2242 2280(单SSD扩展板)#7.2 在PCIe Gen2下测试硬盘速度|安装硬盘测速软件hdparm]]
[[0005 MPS2242 2280 2280P(Single SSD Expansion Board)#7.2 Test the SSD speed in PCIe Gen2 mode|Install the SSD speed testing software hdparm]]


关于如何测试SSD硬盘,我们可以参考以下链接:
For how to test the SSD, we can refer to the following link:


[[0008 MPS2.5G(SSD和2.5G以太网)#5.2 SSD硬盘测试|SSD硬盘测试(Ubuntu系统下)]]
[[0008 MPS2.5G(SSD和2.5G以太网)#5.2 SSD硬盘测试|SSD硬盘测试(Ubuntu系统下)]]


== '''七、OpenWrt系统下使用SSD硬盘''' ==
== '''VII. Using SSD in the OpenWrt system''' ==
关于如何在OpenWrt系统下使用SSD硬盘,我们可以参考以下链接:
For how to use the SSD in the OpenWrt system, we can refer to the following link:


[[2001 CM4 Ultra(CM4核心板的扩展板)#5.5 SSD硬盘测试|SSD硬盘测试(OpenWrt系统下)]]
[[2001 CM4 Ultra(CM4核心板的扩展板)#5.5 SSD硬盘测试|SSD硬盘测试(OpenWrt系统下)]]


{{联系我们_图标}}
{{Contact_Us_icon}}

2024年9月4日 (三) 15:44的最新版本

切换语言为中文

Keywords

Raspberry Pi 5, PCIe, TPU, DTPU, Driver installation, Operation demonstration, AI, google, Coral, 2230, 2242, 2280, NVMe SSD, SSD X1

I. Introduction

The Coral M.2 Accelerator is an M.2 sized module that can expand edge TPU coprocessing capabilities via the PCIE interface for platforms such as the Raspberry Pi. Our MPSTPU expansion board adds two PCIe interfaces via a PCIe Switch, One is an M.2 E key interface, which can be used to connect a TPU module with an A+E Key interface, the other is an M.2 M key interface, which can be used to connect an NVMe SSD. The MPSTPU expansion board can provide the system with massive SSD storage while adding TPU edge computing capabilities.

II. Hardware Resources

1. Designed for the Raspberry Pi 5, it uses a 16-pin FPC to connect to the Raspberry Pi 5's PCIe interface.

2. The MPSTPU expansion board adds two PCIe interfaces via a PCIe Switch.

3. One PCIe extension M.2 E key interface, used for connecting the Google Coral Edge TPU, with the official Raspberry Pi OS loading the driver.

4. One PCIe expanded M.2 M key slot, for connecting NVMe SSD (PCIe X1, Gen2 mode only). Supports 2230/2242/2280 size SSDs (defaulting to welded mounting posts for 2280 size). It does not support SSDs that use NGFF and SATA protocols.

5. The SSD can be used for data storage and system booting. When booting from the SSD, the Raspberry Pi official firmware needs to be version 2024.5.13 or later.

6. The 40-pin GPIO section adopts an unobstructed design on the top. It can be connected via DuPont cable, without affecting the use of the Raspberry Pi 5's own GPIO pins.

7. Gold immersion PCB process, lead-free production, certified by UL, compliant with ROHS standards, and has a fire rating of 94V-0.

8. It uses four M2.5 mounting holes that align with the Raspberry Pi 5 mounting holes and is compatible with an optional aluminum alloy enclosure.

0013_MPTPU_M_03.jpg

Note:

1. After the Raspberry Pi 5 firmware update, the settings cannot be modified, or else the firmware will automatically revert to the old version.

2. Due to the limitations of the switch, PCIe only supports X1 Gen2, with SSD speeds of approximately 400 MB/s.

III. System flashing and setting

3.1 Overview

This document uses the Raspberry Pi OS, Ubuntu system and OpenWrt system for testing.

The version of the Raspberry Pi OS is: 2024-07-04-raspios-bookworm-arm64.img.xz

You can download the Raspberry Pi OS in:

https://www.raspberrypi.com/software/operating-systems/#raspberry-pi-os-64-bit

Note: If you want to run the TPU module under Raspberry Pi OS, the TF card used for flashing the system should have a space of at least 16GB, otherwise, it will display space errors during the installation and configuration process!

The version of the Ubuntu system is: ubuntu-24.04-preinstalled-desktop-arm64+raspi.img.xz

You can download the Ubuntu system in:

https://ubuntu.com/download/raspberry-pi

The version of the OpenWrt system is: openwrt-bcm27xx-bcm2712-rpi-5-squashfs-sysupgrade-linux-6.1.100-20240805.img.gz

3.2 System flashed onto the SD (TF) card

Click here to read the instructions for System flashing

3.3 System flashed onto the SSD

Click here to read the instructions for System flashing

IV. Raspberry Pi OS operation demonstration

This chapter introduces how to run the TPU module on the Raspberry Pi OS.

The steps in this chapter apply to both systems booting from TF card and from SSD.

4.1 Config config.txt

After the system boots, open the Raspberry Pi terminal and enter the command:

sudo nano /boot/firmware/config.txt

Or:

sudo mousepad /boot/firmware/config.txt

Add the codes in the ending of this file:

dtparam=pciex1

kernel=kernel8.img

dtoverlay=pineboards-hat-ai

0006_MPW7_TPU_01.jpg

0006_MPW7_TPU_02.jpg

Then, save the file and reboot the system:

sudo reboot

4.2 Ensuring software environment

After reboot the system, open the Raspberry Pi terminal and enter the command:

uname -r

After ensuring the kernel version is greater than 4.18, enter:

lsmod | grep apex

Ensure there is no output, then you can begin installing the TPU driver.0006_MPW7_TPU_03.jpg

4.3 Install necessary software

Ensure the network is connected to internet connection to the regions out of China (you may need to find your own method), and then add the Google TPU software library:

echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list

curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

0006_MPW7_TPU_04.jpg

Update the software list after adding:

sudo apt-get update

0006_MPW7_TPU_06.jpg

Install the necessary software after the update is completed:

sudo apt-get install cmake libedgetpu1-std devscripts debhelper dkms dh-dkms

0006_MPW7_TPU_07.jpg

0006_MPW7_TPU_08.jpg

4.4 Install Gasket Driver

Enter the following commands in sequence to install the Gasket Driver:

git clone https://github.com/google/gasket-driver.git

cd gasket-driver

sudo debuild -us -uc -tc -b

cd ..

sudo dpkg -i gasket-dkms_1.0-18_all.deb

0006_MPW7_TPU_09.jpg

0006_MPW7_TPU_10.jpg

0006_MPW7_TPU_11.jpg

After the installation is complete, enter the following command to ensure that the driver and software were installed successfully:

sudo apt-get install gasket-dkms libedgetpu1-std

0006_MPW7_TPU_12.jpg

Then, add a udev rule to obtain device operation permissions:

sudo sh -c "echo 'SUBSYSTEM==\"apex\", MODE=\"0660\", GROUP=\"apex\"' >> /etc/udev/rules.d/65-apex.rules"

Add user to apex:

sudo groupadd apex

sudo adduser $USER apex

0006_MPW7_TPU_13.jpg

Reboot the system after the setup is complete:

sudo reboot

4.5 Verification module testing and driver installation

After system starting, verification module testing and driver installation:

lspci -nn | grep 089a

Here, you need to see the TPU module, as shown in the following figure (specific parameter display is subject to the actual device):

ls /dev/apex_0

0006_MPW7_TPU_14.jpg

This board has a single TPU onboard, so you can see a TPU module:

By entering sudo lspci -v, you can see the driver loading, this must include the TPU driver, and if an SSD is inserted, it also needs to include the SSD module, as shown in the following figure:

0013_MPTPU_M_01.jpg

4.6 Configuration of the Code Execution Environment

Running Google TPU module code requires Python versions between 3.6 and 3.9, while the latest Raspberry Pi system is Python 3.11. Therefore, we need to use Pyenv to download an older version of Python.

First, install the depends:

sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python3-openssl

0006_MPW7_TPU_17.jpg

0006_MPW7_TPU_18.jpg

Install pyenv after the depends are installed:

curl https://pyenv.run | bash

0006_MPW7_TPU_19.jpg

Enter the command:

sudo nano ~/.bashrc

Or:

sudo mousepad ~/.bashrc

Add the codes in the ending of this file:

export PYENV_ROOT="$HOME/.pyenv"

[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"

eval "$(pyenv init -)"

0006_MPW7_TPU_36.jpg

0006_MPW7_TPU_21.jpg

Save and exit after adding, then reload the shell:

exec "$SHELL"

0006_MPW7_TPU_22.jpg

Then, we can use pyenv to install an older version of Python:

pyenv install -v 3.8.8

0006_MPW7_TPU_23.jpg

0006_MPW7_TPU_24.jpg

After the installation is successful, we will change the system Python version to 3.8.8:

pyenv global 3.8.8

After the change is successful, you can check the current Python version is 3.8.8:

pyenv versions

python3 -V

0006_MPW7_TPU_25.jpg

4.7 Download the code and run the module

Enter the following commands in sequence to download:

mkdir coral && cd coral

git clone https://github.com/google-coral/pycoral.git

cd pycoral

cd test_data

git clone https://github.com/google-coral/test_data.git

0006_MPW7_TPU_26.jpg

0006_MPW7_TPU_27.jpg

Then, download the code and run the module:

pip3 install numpy

0006_MPW7_TPU_28.jpg

pip3 install Pillow

0006_MPW7_TPU_29.jpg

pip3 install --extra-index-url https://google-coral.github.io/py-repo/ pycoral

0006_MPW7_TPU_30.jpg

4.8 Run the code

After the module download is complete, back to the coral/pycoral path:

cd ..

Enter the following code to run it:

0006_MPW7_TPU_39.jpg

Note: You can copy the following code, but please paste it into a text editor first. Then, following the format shown above, remove any extra enter. After that, copy it again and paste it into the terminal to run.

python3 examples/classify_image.py \

--model test_data/test_data/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \

--labels test_data/test_data/inat_bird_labels.txt \

--input test_data/test_data/parrot.jpg

0006_MPW7_TPU_31.jpg

V. Using SSD in the Raspberry Pi OS

For basic operations on the SSD, we can refer to the following link:

Use the SSD for storage expansion (Raspberry Pi OS)

Perform partitioning and other operations on the SSD

Adjust the peripheral boot order

Install the SSD speed testing software hdparm

For how to test the SSD, we can refer to the following link:

SSD硬盘测试(树莓派OS下)

VI. Using SSD in the Ubuntu system

For basic operations on the SSD, we can refer to the following link, apart from the SSD being used for storage expansion, which operates slightly differently under Raspberry Pi OS, the rest is basically the same.

Use the SSD for storage expansion(Ubuntu system)

Perform partitioning and other operations on the SSD

Adjust the peripheral boot order

Install the SSD speed testing software hdparm

For how to test the SSD, we can refer to the following link:

SSD硬盘测试(Ubuntu系统下)

VII. Using SSD in the OpenWrt system

For how to use the SSD in the OpenWrt system, we can refer to the following link:

SSD硬盘测试(OpenWrt系统下)

Contact Us

0001_x.jpg 0002_fb.jpg 0004_ytb.jpg 0003_bb.jpg 0005_qq.jpg QQ:8204136

Email: mcuzone@vip.qq.com

Tel: +86(0)13957118045

If there are any omissions, errors, or infringements on this page, please contact us through the above methods. Thank you!

Copyright 2004-2024 Wildchip