🛠 Activer I2C, SPI et UART sur le BPI-CM4 : env.txt ou armbianEnv.txt

Banana Pi BPI-CM4 (Amlogic A311D, Raspberry Pi CM4 form factor) · intermediaire · Schéma : IMG-bananapi-cm4-intermediaire-1-overlays-bus-banapi-cm4.svg — header 26 broches du carrier BPI-CM4IO avec les fonctions surlignées : I2C1 (GPIOX_17/18, broches 3/5), UART_B (GPIOX_6/7, broches 8/10), SPI_A (GPIOX_8 à 11, broches 19/21/23/24) ; à côté, une carte SD dont la partition boot affiche env.txt et armbianEnv.txt.

Objectives

On the BPI-CM4, not all buses on the 26-pin header are active by default, and the mechanism depends on the image: vendor images (BSP 4.9) use /boot/env.txt with an overlays="..." line and .dtbo files in /boot/overlays/, while Armbian (mainline kernel ≥ 6.4) uses /boot/armbianEnv.txt and armbian-config. You will enable I2C1 (GPIOX_17/18), SPI_A (GPIOX_8 to 11), and UART_B (GPIOX_6/7), then verify each bus. Note: the vendor's WiringPi/RPi.GPIO fork only works on the BSP; on mainline, you work with i2c-tools, spidev, and libgpiod.

Hardware

Complete Code

# --- Image vendor BSP (noyau 4.9) ---
sudo sed -i 's/^overlays=.*/overlays="i2c2 spi0 uart1 wifi_bt_rtl8822cs"/' /boot/env.txt
ls /boot/overlays/          # vérifier les noms de .dtbo disponibles
sudo reboot

# --- Armbian (mainline) ---
grep -E '^(overlay_prefix|overlays)' /boot/armbianEnv.txt
sudo armbian-config         # System > Hardware > cocher i2c / spi / uart
sudo reboot

# --- Vérification des trois bus ---
sudo apt install -y i2c-tools gpiod
i2cdetect -l                          # lister les contrôleurs
ls -l /sys/class/i2c-dev/ | cat       # mapper /dev/i2c-N -> nom du contrôleur
ls /dev/spidev* 2>/dev/null
gpioinfo | grep -i -e spi -e uart     # broches revendiquées par un pilote

Expected Verification

After reboot: one additional /dev/i2c-N corresponding to the header controller (on mainline, the &i2c2 controller for pins GPIOX_17/18 has no alias — its number depends on enumeration, hence reading /sys/class/i2c-dev/), a /dev/spidevX.Y for SPI_A, and UART_B available on a ttyAMLx/ttySx. The pins used by a bus appear as "used" in gpioinfo.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials