🛠 Override du device tree : OTG en gadget, UART2, et l'Euler bus oublié
Objectives
The mainline device tree for the PINE A64 (sun50i-a64-pine64.dts, compatible pine64,pine64) makes pragmatic choices that can be challenged: the OTG port is hardcoded as host (usb_otg dr_mode = "host"), the UART2 on the Pi-2 connector is disabled, and the Euler 2×17 bus — the board's true originality, featuring additional UARTs, SPI, SPDIF, and CAN — is not utilized by any default image. This advanced tutorial covers: understanding the DTS structure, writing an overlay, and taking ownership of the board's silent peripherals.
Hardware
- 1 × PINE A64/A64+ running Armbian mainline (
apt install device-tree-compiler) - Micro-USB cable to a host PC (gadget test)
- The official "Pine A64 Pin Assignment" PDF at hand for Pi-2/Euler pinout
- Optionally, the RTL8723BS Wi-Fi/BT module on its SDIO 3.0 connector
Complete Code
/* pine64-otg-peripheral.dts — overlay : rendre l'OTG périphérique */
/dts-v1/;
/plugin/;
&usb_otg {
dr_mode = "peripheral"; /* le mainline impose "host" */
status = "okay";
};
&uart2 {
status = "okay"; /* PB0/PB1 = broches UART2 du connecteur Pi-2 */
};
# Compiler l'overlay :
dtc -@ -I dts -O dtb -o pine64-otg-peripheral.dtbo pine64-otg-peripheral.dts
sudo cp pine64-otg-peripheral.dtbo /boot/dtb/allwinner/overlay/
# Déclarer l'overlay (Armbian : /boot/armbianEnv.txt, ligne : overlays=...)
# reboot, puis vérifier côté PC hôte : lsusb voit apparaître la carte (gadget).
# Inventaire des contrôleurs présents mais désactivés :
ls /sys/firmware/devicetree/base/soc/ | head -40
grep -rl '"disabled"' /sys/firmware/devicetree/base/ 2>/dev/null | head
# Les banques GPIO exposées (PB..PH) et leur numérotation bank*32+pin :
# PD16 -> 112 PH2 -> 226 (pinctrl-sun50i-a64.c)
gpioinfo gpiochip0 | grep -E 'PD|PH'
Expected Verification
After rebooting with the overlay, the micro-USB OTG port is seen as a device from the host PC (lsusb on the PC, dmesg | grep -i gadget on the board) — proof that the dr_mode in the mainline DTS was indeed the lock. The enabled UART2 appears (ls /dev/ttyS* or ttySN depending on numbering order) on pins PB0/PB1 of the Pi-2 connector. For the Euler bus (2×17 pins: additional UARTs, SPI, SPDIF, CAN), the path is the same: enable the relevant controllers in an overlay and wire according to the official pinout PDF — the board offers more connectors than its default image activates.
Common Errors
- Editing the compiled .dtb instead of using an overlay: Armbian images support overlays (
/boot/armbianEnv.txt) — a manually edited .dtb will be overwritten during the next kernel package update. - Forgetting that changing the OTG mode breaks FEL boot once the kernel is loaded: FEL lives in the BROM before the kernel, but a port in gadget mode is surprising when you want to plug in a USB drive — document the return to the mainline state.
- Pinning UART2 "like on an RPi": PB0/PB1 correspond to physical pins 11/12 of the Pi-2 connector (comment "On Pi-2 connector" in the DTS) — not to the Raspberry Pi's UART pins. >
- Enabling a controller whose pins are in conflict: pinctrl groups are shared (PB, PC, PD, PE, PF, PG, PH) — a CAN and a UART may target the same pin; check the pinout PDF beforehand.
- Expecting Bluetooth from the RTL8723BS without caution: mainline BT support for the SDIO module is widely reported as unstable. >
- Confusing GPIO offsets and physical pins: tools refer to offsets as bank×32+pin (PH2 = 226), never as connector row numbers.
Other tutorials for this board
- Premier boot d'Armbian sur la PINE A64 (microSD, console série, rootfs)
- PINE A64 ou PINE A64+ ? Le pièg du réseau gigabit dès le premier regard
- Faire clignoter une LED avec libgpiod (numérotation GPIO du A64 : PB0 = 32)
- Benchmark Ethernet iperf3 : mesurer le piège 10/100 vs gigabit
- Lire un capteur I²C (BME280) sur le bus i2c-1 du connecteur Pi-2
- Un serveur maison qui consomme 2,5 W : Docker léger sur la PINE A64
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash