GPIO Q&A

Q: How to control GPIO level in Userspace?

  1. Use echo command to control IO.

Take controlling GPIO1 as an example.

    echo 1 > /sys/class/gpio/export
    echo out > /sys/class/gpio/gpio1/direction
    echo 1 > /sys/class/gpio/gpio1/value    //Pull up the level
    echo 0 > /sys/class/gpio/gpio1/value    //Pull down the level
  1. To use riu_w to write register control level, you need to check GPIO_Mapping_Table.

    Take GPIO1 as an example.

    By checking kernel/drivers/sstar/pioneer3/gpio.h, we can see that GPIO1 corresponds to PAD_SR_IO01. By checking GPIO_Mapping_Table, we can see that the RIU address corresponding to PAD_SR_IO01 is 103E, and the 8BIT offset address is 0x02. Configure them as Output, LeakHi, DRV=1→8mA, when OUT=low, Reg value = 0x58; when OUT=high, Reg value = 0x5B.

    The offset address of the RIU under Userspace takes 16BIT as a unit, so the reg address of PAD_SR_IO01 is 0x103E01.

    ./riu_w 0x103E 0x01 0x58    //Pull up the level
    ./riu_w 0x103E 0x01 0x5B    //Pull down the level
    
  2. Use mmap to map a physical address to a virtual address, and access the physical address by accessing the virtual address.

    Code: reg_rw.c

...