This tutorial will guide you through the configuration process for the Google Coral Edge TPU on a Raspberry Pi 5, including hardware settings and software installation.
Prerequisites
- A Raspberry Pi with Raspberry Pi OS installed.
- An internet connection.
- Basic knowledge of terminal commands.
Step 1: Configure Hardware Settings
First, you need to edit the Raspberry Pi configuration file to enable the necessary hardware settings for the Coral Edge TPU. Open the config file:
sudo nano /boot/firmware/config.txt
Add the following lines to the file:
[all]
# Enable the PCIe External connector.
dtparam=pciex1
kernel=kernel8.img
# Enable Pineboards Hat Ai
dtoverlay=pineboards-hat-ai
Save and close the file by pressing CTRL+X, then Y to confirm, and Enter to exit. Reboot your Raspberry Pi to apply these changes:
sudo reboot
Step 2: Update the Kernel
Kernel version 6.6.30 or higher is needed for the Pineboards Hat Ai overlay. To check your kernel version use this command:
uname -a
Expected output:
Linux coralpi 6.6.30-v8+ #1761 SMP PREEMPT Thu May 2 16:54:52 BST 2024 aarch64 GNU/Linux
Step 3: Install the PCIe Driver and Edge TPU Runtime
Update your package list:
sudo apt update
Add the Google Coral Edge TPU package repository:
echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
Import the repository GPG key:
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
Update your package list again:
sudo apt-get update
Install necessary packages:
sudo apt-get install cmake libedgetpu1-std devscripts debhelper dkms dh-dkms
Step 4: Install the Gasket Driver
Clone the Gasket driver repository:
git clone https://github.com/google/gasket-driver.git
Change into the directory and build the driver:
cd gasket-driversudo debuild -us -uc -tc -b
Go back to the parent directory and install the built package:
cd ..
sudo dpkg -i gasket-dkms_1.0-18_all.deb
Step 5: Set Up the udev Rule Add a udev rule to manage device permissions:
sudo sh -c "echo 'SUBSYSTEM==\"apex\", MODE=\"0660\", GROUP=\"apex\"' >> /etc/udev/rules.d/65-apex.rules"
Create a new group and add your user to it:
sudo groupadd apex
sudo adduser $USER apex
Reboot your Raspberry Pi to apply all changes:
sudo reboot
Verify if the driver is loaded using the following command:
sudo lspci -v
Expected output:
0000:01:00.0 System peripheral: Global Unichip Corp. Coral Edge TPU (prog-if ff)
Subsystem: Global Unichip Corp. Coral Edge TPU
Flags: bus master, fast devsel, latency 0, IRQ 39
Memory at 1800100000 (64-bit, prefetchable) [size=16K]
Memory at 1800000000 (64-bit, prefetchable) [size=1M]
Capabilities: [80] Express Endpoint, MSI 00
Capabilities: [d0] MSI-X: Enable+ Count=128 Masked-
Capabilities: [e0] MSI: Enable- Count=1/32 Maskable- 64bit+
Capabilities: [f8] Power Management version 3
Capabilities: [100] Vendor Specific Information: ID=1556 Rev=1 Len=008 <?>
Capabilities: [108] Latency Tolerance Reporting
Capabilities: [110] L1 PM Substates
Capabilities: [200] Advanced Error Reporting
Kernel driver in use: apex
Kernel modules: apex
Conclusion
Your Raspberry Pi is now configured to use the Coral Edge TPU. You can begin deploying machine learning models and running inference tasks with improved processing power.
2 comments
Hello Bret,
Very good work!
Thank you for this tutorial, it has enabled me to implement Coral’s TPU simply and clearly.
EG
Hi, Eric! Awesome, I’m really glad to hear that it helped 😄