0023 MP2.5GTPU(M.2 E) EN
Keywords
Raspberry Pi5, PCIe, Switch, RL8125, 2.5Gbps, Ethernet, iperf3 speed test, TPU, DTPU, Driver installation, Operation demonstration, AI, google, Coral, M.2 E key
I. Introduction
The Raspberry Pi 5 features a 16-pin PCIe interface, which we can use to expand a variety of peripheral devices. Now we utilize the PCIe interface, with one is an M.2 E key interface, which can connect to a TPU module with A+E Key. Another expands the Ethernet capability through the RTL8125 chip to 2.5Gbps. The 2.5G Ethernet on this expansion board is automatically recognized as eth1 in the Raspberry Pi OS without requiring any drivers upon power-up. If using the Ubuntu system, you need to install the RTL8125 driver first before it can be used. 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.
II. Hardware Resources
1. Use a 0.5mm 16-pin PCIe cable to connect to the PCIE interface of the Raspberry Pi 5.
2. One PCIe expansion for 2.5Gbps Ethernet.
3. One PCIe expansion for M.2 E-key interface, it used to connect to Google Coral Edge TPU, with the Raspberry Pi official OS loading the driver.
4. The 2.5Gbps Ethernet is driver-free in the Raspberry Pi OS and OpenWrt system, but requires driver installation in Ubuntu system.
5. Gold immersion PCB process, lead-free production, certified by UL, compliant with ROHS standards, and has a fire rating of 94V-0.
6. The board has four M2.5 mounting holes, with a recessed design on the top of the board to facilitate the use of the 40-Pin GPIO.
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
IV. Raspberry Pi OS operation demonstration
4.1 Internet test
The 2.5G Ethernet on the MP2.5GTPU expansion board is plug-and-play without requiring drivers in the Raspberry Pi OS. After the system starts, enter the command ifconfig -a
in the terminal, and the 2.5G Ethernet will be recognized as eth1:
Using the speed test website of USTC, we conducted a speed test for the 2.5G Ethernet connected to the internet (with a 200M connection), and the results are as follows:
Note: The speed test can be affected by the network environment and the testing method. Speeds should be considered based on actual results; this test is for reference only.
4.2 2.5G Ethernet test in local network
Install the network speed testing tool iperf3:
sudo apt install iperf3
Use iperf3 to perform a speed test between the Raspberry Pi OS and the PC via a 2.5G router.
The speed test results for eth1 are as follows:
When the Raspberry Pi OS acts as the client, the speed is about 2.35 Gbps:
When the Raspberry Pi OS acts as the server, the speed is about 1.82 Gbps:
Note: The speed test can be affected by the network environment and the testing method. Speeds should be considered based on actual results; this test is for reference only.
V. Ubuntu system operation demonstration
5.1 Install the RTL8125 driver for Ubuntu system
The 2.5G Ethernet on the MP2.5GTPU expansion board is not plug-and-play in Ubuntu systems and requires the installation of the RTL8125 driver.
Since the wireless network module of the Raspberry Pi 5 is plug-and-play in Ubuntu systems, we need to use it to connect to a wireless network.
We can also use an Ethernet cable to connect to the native Ethernet port on the Raspberry Pi 5.
The ifconfig tool is not installed by default in Ubuntu systems, so it needs to be installed manually:
sudo apt install net-tools
Enter ifconfig -a
, and we can see that the 2.5G Ethernet is not displayed at this time:
Then we will begin installing the RTL8125 driver.
First, we need to update the system:
sudo apt-get update
Then we need to prepare the compilation environment:
sudo apt-get install --reinstall linux-headers-$(uname -r) linux-headers-generic build-essential dkms
And install drivers:
sudo apt-get install r8125-dkms
After installation is complete, enter:
sudo modprobe r8125
Enter ifconfig -a
to see a network interface named enxxx, which indicates that the 2.5G Ethernet driver has been successfully installed.
5.2 Internet test
Using the speed test website of USTC, we conducted a speed test for the 2.5G Ethernet connected to the internet (with a 200M connection), and the results are as follows:
Note: The speed test can be affected by the network environment and the testing method. Speeds should be considered based on actual results; this test is for reference only.
如果使用Ubuntu内置的Firefox浏览器时运行速度很慢或者经常无响应,建议安装轻量浏览器Falkon:
sudo apt install falkon
5.3 2.5G内网测试
安装网络测速软件iperf3:
sudo apt install iperf3
利用iperf3,在Ubuntu系统与PC之间进行测速。
测速结果如下:
当Ubuntu系统作为client时,速度大约为2.35Gbps:
当Ubuntu系统作为server时,速度大约为1.85Gbps:
注意:网络测速受网络环境和测试方法影响,速度请以实际为准,本测试仅供参考。
六、OpenWrt系统操作演示
6.1 概述
MP2.5G扩展板在OpenWrt系统下,默认树莓派上的原生千兆网口为LAN口,我们可以把扩展板上的2.5G网口作为LAN口,而把树莓派5上的原生网口作为WAN口,这样就能利用2.5G网口在内网高速传输文件。
6.2 准备工作
本文档使用的OpenWrt系统为:openwrt-bcm27xx-bcm2712-rpi-5-squashfs-sysupgrade-linux-6.1.100-20240805.img.gz
烧写OpenWrt系统并上电启动后,我们将网线一端插在树莓派5的原生网口上,另一端插在PC上,待PC的网卡与树莓派5上的网口连接成功后,我们在Windows设置中找到网络和Internet,在以太网中打开连接的网络查看默认网关的IP地址,这个地址就是OpenWrt系统的后台配置页面地址,如图所示,本文测试的地址为192.168.198.1:
然后打开网页浏览器输入192.168.198.1进入OpenWrt系统。默认用户名为root
,默认密码为password
:
6.3 MP2.5G的2.5G网口的配置和应用
进入“系统 - TTYD终端”,输入ifconfig -a命令,可以看到有eth0和eth1两个网口,其中eth0为树莓派5的原生网口,eth1为扩展板的2.5G网口:
我们使用的宽带一般不会超过千兆,为了获得更好的内网性能,建议将树莓派5的原生千兆配置从默认的LAN配置为WAN,然后把扩展板的2.5G以太网口配置为LAN。
点击“网络 - 接口”,点击“修改”:
在“物理设置”中,把eth1选中,然后点击“保存&应用”按钮:
将网线从树莓派5的原生网口中拔出,插入2.5G网口,待PC的网卡与2.5G网口连接成功后,我们刷新管理页面,点击“网络 - 接口”,点击“修改”:
在“物理设置”中,把eth0前面的勾去掉,然后点击“保存”按钮:
回到“网络 - 接口”,点击“添加新接口”:
接口名称设置为WAN,接口协议选择DHCP客户端,接口选择eth0后点击“提交”按钮:
在防火墙设置中选择WAN口后点击“保存&应用”按钮:
把连接Internet网络的网线插到树莓派5的原生网口上,然后回到“网络 - 接口”,稍等片刻,就可以看见新建的WAN接口获取了IP地址,这样PC就可以通过连接2.5G网口进入内网上网了,此时网络结构为千兆网口(接Internet,树莓派上)进,2.5G网口(接内网,扩展板上)出:
我们在树莓派5的USB3.0接口上插入一个支持USB3.0的U盘或者移动硬盘,参考下面链接,将这个U盘或者移动硬盘配置为共享目录:
设置完毕后,我们在资源管理器中输入\\192.168.198.1
(地址为扩展板的地址,视实际情况而不同),就能看到所映射的共享目录了:
将任意文件拖拽到桌面进行读取速度测试:
将任意文件拖拽到SSD进行写入速度测试:
注意:网络测速受网络环境和测试方法影响,速度请以实际为准,本测试仅供参考。
6.4 其它应用
树莓派5的无线模块可以作为无线AP,也可以作为无线WAN口,关于这些应用的实现,请参考下列链接:
七、树莓派OS运行TPU模组
本章介绍如何在树莓派OS运行TPU模组。
Note: The operation requires a stable internet connection to the regions out of China (you may need to find your own method). Otherwise, many files may not download or may only partially download, which could ultimately lead to the code failing to run.
7.1 配置config.txt
系统启动后打开树莓派终端输入命令:
sudo nano /boot/firmware/config.txt
或者:
sudo mousepad /boot/firmware/config.txt
在文件最下方添加以下代码:
dtparam=pciex1
kernel=kernel8.img
dtoverlay=pineboards-hat-ai
代码添加成功后,保存并重启系统:
sudo reboot
7.2 确认软件环境
系统重启后打开打开树莓派终端输入命令:
uname -r
确保内核版本大于4.18后输入:
lsmod | grep apex
确保没有输出则可以开始安装TPU驱动。
7.3 安装必要软件
确保网络能连通外网(需自备方法)后,添加Google TPU软件库:
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 -
添加完成后更新软件列表:
sudo apt-get update
更新完成后安装必要的软件:
sudo apt-get install cmake libedgetpu1-std devscripts debhelper dkms dh-dkms
7.4 安装Gasket Driver
依次输入以下命令安装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
安装完成后输入以下命令确保驱动以及软件安装成功:
sudo apt-get install gasket-dkms libedgetpu1-std
接下来添加udev rule去获得设备操作权限:
sudo sh -c "echo 'SUBSYSTEM==\"apex\", MODE=\"0660\", GROUP=\"apex\"' >> /etc/udev/rules.d/65-apex.rules"
添加用户到apex:
sudo groupadd apex
sudo adduser $USER apex
设置完成后重启系统:
sudo reboot
7.5 验证模块检测以及驱动安装
系统启动后验证模块检测以及驱动安装:
lspci -nn | grep 089a
这里需要看到TPU模块,如下图所示(具体参数显示以实际为准):
ls /dev/apex_0
这里插了一个TPU模块,因此可以看到一个TPU模块。
输入sudo lspci -v
可以看到驱动加载,其中必须包括TPU驱动,如果插了SSD硬盘,还需要包括SSD模块,如下图所示:
7.6 代码运行环境配置
Google TPU模块代码运行需要在Python3.6-3.9之间,而树莓派最新系统的Python版本为3.11,因此我们需要使用Pyenv来下载老版本Python。
首先进行依赖安装:
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
依赖安装完成后进行pyenv的安装:
curl https://pyenv.run | bash
输入:
sudo nano ~/.bashrc
或者:
sudo mousepad ~/.bashrc
在文件最下面添加以下代码:
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
添加完成后保存退出并重新加载shell:
exec "$SHELL"
接下来我们可以利用pyenv安装老系统版本Python:
pyenv install -v 3.8.8
等待安装成功后我们将系统Python版本更改为3.8.8:
pyenv global 3.8.8
更改成功后可以查看当前Python使用版本为3.8.8:
pyenv versions
python3 -V
7.7 下载代码和运行模组
依次输入以下命令进行下载:
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
接下来下载代码运行模组
pip3 install numpy
pip3 install Pillow
pip3 install --extra-index-url https://google-coral.github.io/py-repo/ pycoral
7.8 运行代码
模组下载完成后返回 coral/pycoral路径下
cd ..
输入以下代码进行代码运行
注意:我们可以复制下列代码,但是请先粘贴到文本软件中,按照上图的格式,删除多余的回车符,再复制然后粘贴到终端中运行:
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
联系我们
电话:13957118045
如本页面有任何疏漏、错误或者侵权,请通过上述途径联系我们,谢谢!
Copyright 2004-2024 野芯科技