Gpio Q&A

Q1:How to control GPIO electrical level under Userspace?

  1. Use echo command to control IO, the example is to control GPIO4.

    echo 4 > /sys/class/gpio/export
    echo out > /sys/class/gpio/gpio4/direction
    echo 1 > /sys/class/gpio/gpio4/value    //Pull up
    echo 0 > /sys/class/gpio/gpio4/value    //Pull down
    
  2. Use riu_w to write register to control, you need to check GPIO_Mapping_Table, take GPIO4 as an example.

    Check kernel/drivers/sstar/include/infinity2m/gpio.h, GPIO1 corresponds to PAD_GPIO4, check GPIO_Mapping_Table, the RIU address corresponding to PAD_GPIO4 is 103C, and the 8BIT offset address is 0x08. Configure GPIO1 as Output, DRV>4mA, when OUT=low, Reg value = 0x00; when OUT=high, Reg value = 0x11.

    There are also gpio mode related register config instructions in kernel/drivers/sstar/gpio/infinity2m/gpio_table.c.

    The offset address of RIU under Userspace is calculated as 16BIT, so the reg address of PAD_GPIO4 is 0x103C04.

    ./riu_w 0x103C 0x04 0x00    //Pull down
    ./riu_w 0x103C 0x04 0x11    //Pull up
    
  3. Use mmap to map a physical address to a virtual address, and access the physical address by accessing the virtual address. The code implementation of riu_w in Method 2 is this way. Code implementation: reg_rw.c