🛠 GPIO and Industrial I/O Control on BPI-5202
Objectifs
This advanced tutorial aims to configure and control digital I/O on the BPI-5202. We will leverage the 20-pin GPIO port and extension modules (DI/DO) via the internal bus. The goal is to implement a simple control loop: reading a logical state (sensor) and commanding an actuator (LED or relay), using LoongArch hardware support.
Matériel nécessaire
- BPI-5202 board powered by DC 24V.
- Loongnix or LoongOS operating system installed.
- GPIO extension module or sensor/actuator connected to the 20-pin header (2.54 mm pitch).
- Serial console interface (isolated RS232) or SSH for terminal access.
- Multimeter for voltage level verification (optional).
Étapes
Log in via terminal. Check if the kernel has detected the LoongArch-specific GPIO controller. Use dmesg | grep gpio to confirm driver initialization. Note the base numbers assigned to physical ports.
- Hardware Detection Verification
In Linux, GPIOs are exposed via sysfs. Assuming physical GPIO 1 maps to system GPIO 100. Create the link if necessary: ``bash echo 100 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio100/direction ` For an input (sensor), replace out with in`. Ensure pull-up/down resistors are configured if the module allows, or rely on DI/DO module characteristics.
- Input/Output Mode Configuration
To set the output high (3.3V or 5V depending on the module): ``bash echo 1 > /sys/class/gpio/gpio100/value ` To read the state of an input configured in in mode: `bash cat /sys/class/gpio/gpio101/value `` Write a simple Bash script to toggle the state every second to test responsiveness.
- Control and Reading
If using a DI/DO module connected to the internal bus, GPIOs may be grouped. Consult module documentation for address offsets. The internal bus handles logic, but Linux exposure remains standard via sysfs or /dev/gpiochipX with libgpiod.
- Using Extension Modules
For critical applications, avoid rapid state changes via sysfs (too slow). Use direct ioctl interface or configure the kernel for direct memory access to 2K1000LA GPIO registers, respecting physical addresses defined in the Device Tree.
- Real-Time Optimization
Vérification
Use a multimeter to measure voltage on the relevant pin: it should be near 0V (low state) or reference voltage (high state). For inputs, short the pin to ground to verify that the cat command returns 0.
Pour aller plus loin
Explore libgpiod for more robust GPIO event handling. Integrate these I/Os into a lightweight SCADA system or use CAN2.0 ports for distributed industrial network communication.