gpio-libgpiod.sh
libgpiod is the serious GPIO interface under Linux: gpiodetect, gpioinfo, gpioset. The script blinks a carrier-connector LED while documenting the line-release pitfall when gpioset exits.
Hardware
An Arduino Portenta X8 (ST STM32MP1 module: quad Cortex-A7 Linux + dual Cortex-M4 real-time core, 8 GB eMMC, 2 GB LPDDR4, on-board Wi-Fi/BT, optional LTE). 1 LED + 330 Ω resistor (pins are 1.8 V/3.3 V per the connector: check the schematic).
Wiring
LED on the chosen GPIO pin of the high-density connector (via carrier board), GND nearby. Some pins are below 3.3 V.
How it works
gpioset asks the kernel to drive the line; --mode=exit applies the value then exits. Depending on the kernel, add --mode=wait to hold it.
Running it
Linux side: SSH access (routed USB-C or network) on the Portenta Linux image, bash/Python scripts. Real-time side: Arduino IDE with the « Arduino Mbed OS Portenta X8 Boards » core, application M7 core, flashing via mboot from Linux.
Variants
Move to a Python daemon (python-gpio example) for fine control, or drive PWM via /sys/class/pwm.
gpio-libgpiod.sh
#!/bin/bash
# Clignotement LED via libgpiod (outils noyau standard).
# Installation : opkg/apt install gpiod (present sur l'image X8).
# Lister : gpiodetect ; broches du connecteur : gpioinfo.
CHIP="${1:-gpiochip0}" # verifier avec gpiodetect
LIGNE="${2:-27}" # GPIO du schema carrier (exemple)
echo "Puces GPIO :"
gpiodetect
echo "Clignotement $CHIP ligne $LIGNE (Ctrl-C pour arreter)"
while true; do
# --mode=exit applique puis rend la ligne ; selon le noyau,
# ajouter --mode=wait pour garder la ligne captive.
gpioset --mode=exit "$CHIP" "$LIGNE=1"
sleep 1
gpioset --mode=exit "$CHIP" "$LIGNE=0"
sleep 1
done