====== GPIO ======
[[..:bpi-r2:gpio|BPI-R2-GPIO]]
===== pin-define =====
{{http://wiki.banana-pi.org/images/1/1d/R64_gpio_40.jpg|}}
^ 2nd function ^ main function ^ pin# ^ xxxxxxxxxxxxxxxxxxxxx ^ pin# ^ main function ^ 2nd function ^
| | | | {{ :bpi-r2:gpio_farbig.png?nolink |}} | | | |
| | +3V3 | 1 | ::: | 2 | +5V | |
| GPIO 56 # | I2C1_SDA | 3 | ::: | 4 | +5V | |
| GPIO 55 # | I2C1_SCL | 5 | ::: | 6 | GND | |
| GPIO101 | PWM 7 | 7 | ::: | 8 | UART0-TX | GPIO 59 # |
| | GND | 9 | ::: | 10 | UART0-RX | GPIO 60 # |
| GPIO 51 # | PWM1 / UART1-TX | 11 | ::: | 12 | | |
| GPIO 52 # | PWM2 / UART1-RX | 13 | ::: | 14 | GND | |
| GPIO 98 # | | 15 | ::: | 16 | | GPIO 61 # |
| | +3V3 | 17 | ::: | 18 | | GPIO 62 # |
| GPIO 68 # | PWM5 / SPI1 MOSI | 19 | ::: | 20 | GND | |
| GPIO 69 | PWM6 / SPI1 MISO | 21 | ::: | 22 | SPI0 CLK | GPIO 63 |
| GPIO 67 | PWM4 / SPI1 CLK | 23 | ::: | 24 | SPI1 CS | GPIO 70 |
| | GND | 25 | ::: | 26 | SPI0 CS | GPIO 66 |
| GPIO 58 | I2C2 SDA | 27 | ::: | 28 | I2C2 SCL | GPIO 57 |
| GPIO 85 | | 29 | ::: | 30 | GND | |
| GPIO 82 | SPI0 MOSI| 31 | ::: | 32 | SPI0 MOSI | GPIO 64 |
| | | 33 | ::: | 34 | GND | |
| | | 35 | ::: | 36 | SPI0 MISO | GPIO 65 |
| GPIO 86 | | 37 | ::: | 38 | I2S IN | |
| | GND | 39 | ::: | 40 | I2S OUT | |
| | | ::: | | | |
(# verified gpio working, 101 is blocked by pwm)
* uart0 (dts) => Debug-Uart
* uart1 (dts) => undefined => mt7622_uart2_2_tx_rx_pins (59/60)
* uart2 (dts) => uart1 (gpio) => mt7622_uart2_1_tx_rx_pins (51/52)
===== Kernel 4.19 =====
root@bpi-iot-ros-ai:~# cat /sys/kernel/debug/pinctrl/10211000.pinctrl-pinctrl_mt7622/gpio-ranges
GPIO ranges handled:
0: pinctrl_mt7622 GPIOS [409 - 511] PINS [0 - 102]
root@bpi-iot-ros-ai:~# GPIO_NO=$((409+56))
root@bpi-iot-ros-ai:~# echo $GPIO_NO
465
root@bpi-iot-ros-ai:~# echo $GPIO_NO > /sys/class/gpio/export
-bash: echo: write error: Invalid argument => blocked by i2c1
#if i2c1 is disabled in dts:
root@bpi-r64:~# echo $GPIO_NO > /sys/class/gpio/export
root@bpi-r64:~# echo out > /sys/class/gpio/gpio${GPIO_NO}/direction
root@bpi-r64:~# echo 1 > /sys/class/gpio/gpio${GPIO_NO}/value #led goes on
root@bpi-r64:~# echo 0 > /sys/class/gpio/gpio${GPIO_NO}/value #led goes off
The sysfs interface (/sys/class/gpio/...) needs kernel-option CONFIG_GPIO_SYSFS
==== uart ====
debug-Uart is uart0 in DTS, uart2 seems to be uart1 of gpio header...uart1 is currently not defined in dts.
==== on-board LEDs ====
needs LEDS_GPIO [=y]
there is only red and green, red seems not working
echo 1 > /sys/class/leds/bpi-r64\:pio\:green/brightness
===== pwm =====
in linux numbering begins at 0 where on bpi documentation/gpio-header pwms starting at 1...
* pwm1 pin 11 (GPIO 51)
* pwm2 pin 13 (GPIO 52)
* pwm3 fan,inverted - seems not working correctly
* pwm4 pin 23 (GPIO 67)
* pwm5 pin 19 (GPIO 68)
* pwm6 pin 21 (GPIO 69)
* pwm7 pin7 (GPIO101) - seems not working
pwm working except 3 (2) and 7 (6) in my [[https://github.com/frank-w/BPI-R2-4.14/commits/5.7-pwm|5.7-pwm branch]]
root@bpi-r64:~# cd /sys/class/pwm/pwmchip0
root@bpi-r64:/sys/class/pwm/pwmchip0# echo 0 > export
root@bpi-r64:/sys/class/pwm/pwmchip0# cd pwm0
root@bpi-r64:/sys/class/pwm/pwmchip0/pwm0# echo 10000 > period
root@bpi-r64:/sys/class/pwm/pwmchip0/pwm0# echo 5000 > duty_cycle
root@bpi-r64:/sys/class/pwm/pwmchip0/pwm0# echo 1 > enable
==== pwm in uboot ====
pwm-patches from sam are merged in 2020-07, but to use them there is cmd_pwm needed
http://forum.banana-pi.org/t/bpi-r64-current-u-boot-support/10077/74
both Available in [[https://github.com/frank-w/u-boot/commits/2020-04-bpi-pwm|2020-04-bpi-pwm branch]]
here pwm1 (0) is defined in dts