🛠 Activer I2C, SPI et UART sur le BPI-CM4 : env.txt ou 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
- BPI-CM4 + BPI-CM4IO carrier board
- Vendor image Debian 10 / Ubuntu 20.04 or Armbian bananapicm4io
- Optional: level shifter — the VDDIO_C rail of the GPIOX banks is configured for 1.8 V or 3.3 V depending on the setup; the wiki never guarantees 5 V
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
- Modifying
/boot/config.txtas on a Raspberry Pi: it does not exist here; it isenv.txt(vendor) orarmbianEnv.txt(Armbian). - Relying on Dangku's WiringPi under Armbian: it requires the 4.9 BSP kernel and fails on mainline.
- Hardcoding the
/dev/i2c-2number in a script: on mainline, the header bus is not aliased, so the number may change — always resolve it via/sys/class/i2c-dev/. - Confusing it with the carrier's internal buses: the
i2c0alias points to the camera controller,i2c1to the DSI touch bus — not to the header. - Connecting a 5 V module without checking the actual level of the GPIOX bank (VDDIO_C rail 1.8/3.3 V).
Other tutorials for this board
- Monter le module BPI-CM4 sur son carrier et réussir le premier boot
- Apprivoiser les LED et la touche ADC du carrier CM4IO
- Mesurer le stockage du BPI-CM4 : eMMC, microSD et le palier NVMe
- Brancher un capteur BME280 sur l'I2C1 du carrier (GPIOX_17/18)
- Déplacer le rootfs sur un SSD NVMe via le port mini-PCIe
- Exploiter le NPU 5 TOPS de l'A311D pour l'inférence embarquée
Code examples for this board
clignotante.pyPythonbouton-gpio.pyPythoncapteur-i2c.shBashsurveillance-temperature.shBashcapteur-dht11.pyPythonservo-pwm-sysfs.shBash