🛠 GPIO and Industrial I/O Control on BPI-5202

BPI-5202 Loongson 2K1000LAi Embedded Single Board Industrial Computer · avance · Maîtrisez l'accès bas niveau aux GPIO et aux modules d'extension du BPI-5202 pour l'automatisation industrielle.

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

É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.

  1. 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.

  1. 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.

  1. 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.

  1. 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.

  1. 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.

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials