0006 MPTPU(M.2 E) EN:修订间差异

来自Mcuzone Wiki
无编辑摘要
第1行: 第1行:
== '''Keywords''' ==
== '''Keywords''' ==
Raspberry Pi5, PCIe, TPU, DTPU, Driver installation, Operation demonstration, AI, google, Coral
Raspberry Pi5, PCIe, TPU, DTPU, Driver installation, Operation demonstration, AI, Google, Coral


== '''Ⅰ、Introduction''' ==
== '''Ⅰ、Introduction''' ==
MPTPU is a TPU expansion board specifically designed for the Raspberry Pi 5, driven by a Coral TPU module through PCIe 1x Gen2. TPU module on the Raspberry Pi system requires the installation of drivers and configuration of the operating environment. This document is based on the MPTPU expansion board (single TPU), and the driver installation is also applicable for dual TPU setups.
MPTPU is a TPU expansion board specifically designed for the Raspberry Pi 5, driven by a Coral TPU module through PCIe 1x Gen2. TPU module on the Raspberry Pi system requires the installation of drivers and configuration of the operating environment. This document is based on the MPTPU expansion board (single TPU), and the driver installation is also applicable for dual TPU setups.


'''''Note:  The operation requires a stable internet connection to the regions out of China. Otherwise, many files may not download or may only partially download, which could ultimately lead to the code failing to run.'''''
'''''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.'''''


== '''Ⅱ、Hardware Resources''' ==
== '''Ⅱ、Hardware Resources''' ==
第16行: 第16行:
2.4 An onboard power indicator LED ("PWR").
2.4 An onboard power indicator LED ("PWR").


2.5 Adopts high-quality electronic components, lead-free production, immersion gold process; the PCB board is UL certified and ROHS compliant.
2.5 Adopts high-quality electronic components, lead-free production, immersion gold process; the PCB board is UL certified and RoHS compliant.


2.6 The board has four M2.5G mounting holes, with a recessed design on the top of the board to facilitate the use of the 40-pin GPIO without affecting the use of the Raspberry Pi 5's 40-pin GPIO.
2.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 without affecting the use of the Raspberry Pi 5's 40-Pin GPIO.
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_33.jpg
http://www.mcuzone.com/wiki/0006_MPW7_TPU/0006_MPW7_TPU_33.jpg


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


3.2 Use Imager or balenaEtcher to flash the OS image in TF card. [[0005_MPS2242_2280%EF%BC%88%E5%8D%95SSD%E6%89%A9%E5%B1%95%E6%9D%BF%EF%BC%89#3.2_%E4%BB%8ETF%E5%8D%A1%E5%90%AF%E5%8A%A8|Click here to read the instructions for System flashing]]
3.2 Use Imager or balenaEtcher to flash the OS image in TF card. [[0005 MPS2242 2280(单SSD扩展板)#3.2 从TF卡启动|Click here to read the instructions for System flashing]]


== '''四、驱动安装与配置''' ==
== '''Ⅳ、Driver installation and configuration''' ==


=== 4.1 配置config.txt ===
=== 4.1 Config config.txt ===
系统启动后打开树莓派终端输入命令:
After the system starts, open the Raspberry Pi terminal and enter the command:


<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>
第57行: 第57行:
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>
第83行: 第83行:
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>
第89行: 第89行:
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>
第97行: 第97行:
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:
依次输入以下命令安装Gasket Driver:



2024年8月14日 (三) 09:43的版本

Keywords

Raspberry Pi5, PCIe, TPU, DTPU, Driver installation, Operation demonstration, AI, Google, Coral

Ⅰ、Introduction

MPTPU is a TPU expansion board specifically designed for the Raspberry Pi 5, driven by a Coral TPU module through PCIe 1x Gen2. TPU module on the Raspberry Pi system requires the installation of drivers and configuration of the operating environment. This document is based on the MPTPU expansion board (single TPU), and the driver installation is also applicable for dual TPU setups.

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.

Ⅱ、Hardware Resources

2.1 Specifically designed for the PCIe interface of the Raspberry Pi 5.

2.2 Support M.2 E-KEY PCIe and Google coral Edge TPU.

2.3 CSI/DSI slots: Supports 0.5mm pitch 22-pin cables and 1mm pitch 15-pin cables.

2.4 An onboard power indicator LED ("PWR").

2.5 Adopts high-quality electronic components, lead-free production, immersion gold process; the PCB board is UL certified and RoHS compliant.

2.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 without affecting the use of the Raspberry Pi 5's 40-Pin GPIO. 0006_MPW7_TPU_33.jpg

0006_MPW7_TPU_34.jpg

0006_MPW7_TPU_35.jpg

Ⅲ、System flashing

3.1 The Raspberry Pi OS used in this document is: 2024-07-04-raspios-bookworm-armhf.img.xz(Raspberry Pi OS with desktop)。

You can download it in:

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

3.2 Use Imager or balenaEtcher to flash the OS image in TF card. Click here to read the instructions for System flashing

Ⅳ、Driver installation and configuration

4.1 Config config.txt

After the system starts, 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

依次输入以下命令安装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

安装完成后输入以下命令确保驱动以及软件安装成功:

sudo apt-get install gasket-dkms libedgetpu1-std

0006_MPW7_TPU_12.jpg

接下来添加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

0006_MPW7_TPU_13.jpg

设置完成后重启系统:

sudo reboot

4.5 验证模块检测以及驱动安装

系统启动后验证模块检测以及驱动安装:

lspci -nn | grep 089a

ls /dev/apex_0

0006_MPW7_TPU_14.jpg

这里板载单TPU,因此可以看到一个TPU模块。

输入sudo lspci -v可以看到驱动加载:

0006_MPW7_TPU_15.jpg

4.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

0006_MPW7_TPU_17.jpg

0006_MPW7_TPU_18.jpg

依赖安装完成后进行pyenv的安装:

curl https://pyenv.run | bash

0006_MPW7_TPU_19.jpg

输入:

sudo nano ~/.bashrc

或者:

sudo mousepad ~/.bashrc

在文件最下面添加以下代码:

export PYENV_ROOT="$HOME/.pyenv"

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

eval "$(pyenv init -)"

0006_MPW7_TPU_20.jpg

0006_MPW7_TPU_21.jpg

添加完成后保存退出并重新加载shell:

exec "$SHELL"

0006_MPW7_TPU_22.jpg

接下来我们可以利用pyenv安装老系统版本Python:

pyenv install -v 3.8.8

0006_MPW7_TPU_23.jpg

0006_MPW7_TPU_24.jpg

等待安装成功后我们将系统Python版本更改为3.8.8:

pyenv global 3.8.8

更改成功后可以查看当前Python使用版本为3.8.8:

pyenv versions

python3 -V

0006_MPW7_TPU_25.jpg

五、下载和运行演示代码

5.1 下载代码和运行模组

依次输入以下命令进行下载:

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

接下来下载代码运行模组

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

5.2 运行代码

模组下载完成后返回 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

0006_MPW7_TPU_31.jpg

鉴于本开发板的测试需要在外网下载大量数据,为了方便用户进行测试,用户在购买本开发板后,可以联系我司获取已经配置完毕的树莓派OS镜像。

联系我们

4f7e81daf8791971.jpg 79c020da7ad0af9b.jpg 2851e01a0549e6f7.gif 0003_bb.jpg 0005_qq.jpg QQ:8204136

邮件:mcuzone@vip.qq.com

电话:13957118045

如本页面有任何疏漏、错误或者侵权,请通过上述途径联系我们,谢谢!

Copyright 2004-2024 野芯科技