en:bpi-r2:gpio
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
en:bpi-r2:gpio [2018/04/17 14:08] – [on-board LEDs] frank | en:bpi-r2:gpio [2020/08/29 17:14] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== GPIO ====== | ||
+ | ===== Basics ===== | ||
+ | https:// | ||
+ | |||
+ | ===== Pin define ===== | ||
+ | |||
+ | {{: | ||
+ | image taken from bpi-r2 schematics | ||
+ | |||
+ | ^ Sparefunction ^ Mainfunction ^ pin# ^ xxxxxxxxxxxxxxxxxxxxx ^ pin# ^ Mainfunction | ||
+ | | | | | {{ : | ||
+ | | - | 3V3 | ||
+ | | I2C_SDA0 | ||
+ | | I2C SCL0 | GPIO 76 | ||
+ | | PWM3 | GPIO 206 | | ||
+ | | - | GND | ||
+ | | UART0 TX | GPIO 80 | ||
+ | | UART0 RX | GPIO 79 | ||
+ | | PWM2 | GPIO 205 | 15 | ::: | 16 | GPIO 25 / INT3 | URTS1 | | ||
+ | | - | 3V3 | ||
+ | | SPI0_MO | ||
+ | | SPI0_MI | ||
+ | | SPI0_CK | ||
+ | | - | GND | ||
+ | | I2C_SDA1 | ||
+ | | | GPIO 126 | 29 | ::: | 30 | GND | - | | ||
+ | | I2S0_BCK | ||
+ | | I2S0_LRCK | ||
+ | | I2S0_DATA | ||
+ | | SPDIF_IN1 | ||
+ | | - | GND | ||
+ | | | | | ::: | | | | | ||
+ | |||
+ | < | ||
+ | | ^ main ^ spare ^ | ||
+ | ^ Pin 1 | 3V3 | - | | ||
+ | ^ Pin 2 | 5V | - | | ||
+ | ^ Pin 3 | GPIO 75 | I2C_SDA0 | | ||
+ | ^ Pin 4 | 5V | - | | ||
+ | ^ Pin 5 | GPIO 76 | I2C SCL0 | | ||
+ | ^ Pin 6 | GND | - | | ||
+ | ^ Pin 7 | GPIO 206 | PWM3 | | ||
+ | ^ Pin 8 | GPIO 82 | UART1 TX | | ||
+ | ^ Pin 9 | GND | - | | ||
+ | ^ Pin 10 | GPIO 81 | UART1 RX | | ||
+ | ^ Pin 11 | GPIO 80 | UART0 TX | | ||
+ | ^ Pin 12 | Int2 | GPIO 24 (*) / UCTS1 | | ||
+ | ^ Pin 13 | GPIO 79 | UART0 RX | | ||
+ | ^ Pin 14 | GND | - | | ||
+ | ^ Pin 15 | GPIO 205 | PWM2 | | ||
+ | ^ Pin 16 | GPIO 25 / Int3 | URTS1 | | ||
+ | ^ Pin 17 | 3V3 | - | | ||
+ | ^ Pin 18 | GPIO 21 | PCM_TX | | ||
+ | ^ Pin 19 | GPIO 56 | SPI0_MO | | ||
+ | ^ Pin 20 | GND | - | | ||
+ | ^ Pin 21 | GPIO 55 | SPI0_MI | | ||
+ | ^ Pin 22 | GPIO 18 | PCM_CLK | | ||
+ | ^ Pin 23 | GPIO 54 | SPI0_CK | | ||
+ | ^ Pin 24 | GPIO 53 | SPI0_CSN | | ||
+ | ^ Pin 25 | GND | - | | ||
+ | ^ Pin 26 | GPIO 20 | PCM_RX | | ||
+ | ^ Pin 27 | GPIO 57 | I2C_SDA1 | | ||
+ | ^ Pin 28 | GPIO 58 | I2C_SCL1 | | ||
+ | ^ Pin 29 | GPIO 126 | I2S0_MCLK | ||
+ | ^ Pin 30 | GND | - | | ||
+ | ^ Pin 31 | GPIO 74 | I2S0_BCK | | ||
+ | ^ Pin 32 | GPIO 72 | I2S0_DATA_IN | | ||
+ | ^ Pin 33 | GPIO 73 (?) | I2S0_LRCK | | ||
+ | ^ Pin 34 | GND | - | | ||
+ | ^ Pin 35 | GPIO 49 (M) | I2S0_DATA | | ||
+ | ^ Pin 36 | GPIO 19 | PCM_SYNC | | ||
+ | ^ Pin 37 | GPIO 202 | SPDIF_IN1 | | ||
+ | ^ Pin 38 | INT0 | GPIO 22 (*) / PCM_RST_IN | | ||
+ | ^ Pin 39 | GND | - | | ||
+ | ^ Pin 40 | GPIO 200 | SPDIF_OUT | | ||
+ | </ | ||
+ | (*) special GPIO need memory-patch and mode-set in 4.4.70 | ||
+ | (?) currently not working | ||
+ | (M) mode-setting needed | ||
+ | |||
+ | ===== Kernel 4.4.70 ===== | ||
+ | |||
+ | ==== Access standard GPIO ==== | ||
+ | <code bash> | ||
+ | root@bpi-r2: | ||
+ | root@bpi-r2: | ||
+ | root@bpi-r2: | ||
+ | root@bpi-r2: | ||
+ | </ | ||
+ | works with LED on Pin 14 (-) and Pin 16 (+), incl. resistor (220 Ohm) | ||
+ | |||
+ | ==== Access special GPIO ==== | ||
+ | for the GPIOs 22/ | ||
+ | |||
+ | <code bash> | ||
+ | root@bpi-r2: | ||
+ | ./mwrite offset : 10005b10, val : 00000038 | ||
+ | b6f03b10 | ||
+ | root@bpi-r2: | ||
+ | root@bpi-r2: | ||
+ | root@bpi-r2: | ||
+ | root@bpi-r2: | ||
+ | </ | ||
+ | for GPIO24 (pin 12) i have to set mode to 0 | ||
+ | |||
+ | ===== Kernel 4.14 ===== | ||
+ | GPIO_SYSFS and CONFIG_DEBUG_GPIO must be set in Kernel-Config (.config) | ||
+ | |||
+ | ==== Access standard GPIO ==== | ||
+ | |||
+ | <code bash> | ||
+ | root@bpi-r2# | ||
+ | root@bpi-r2# | ||
+ | GPIO ranges handled: | ||
+ | 0: 1000b000.pinctrl GPIOS [232 - 511] PINS [0 - 279] #base=232, first value of GPIOS | ||
+ | root@bpi-r2# | ||
+ | root@bpi-r2# | ||
+ | 257 | ||
+ | root@bpi-r2# | ||
+ | </ | ||
+ | |||
+ | Pin 14=GND/ | ||
+ | |||
+ | === GPIO as Output === | ||
+ | <code bash> | ||
+ | root@bpi-r2# | ||
+ | root@bpi-r2# | ||
+ | root@bpi-r2# | ||
+ | </ | ||
+ | |||
+ | used for LED+resistor (220 Ohm) on Pin 14=GND/ | ||
+ | |||
+ | === GPIO as Input === | ||
+ | |||
+ | now try with high-active button-circuit on GPIO 200 (pin 40 between button and resistor, using pin 39 as GND [resistor] and pin 17 as 3v3-vcc) | ||
+ | |||
+ | <code bash> | ||
+ | [10:54] root@bpi-r2: | ||
+ | [10:56] root@bpi-r2: | ||
+ | 0 #button not pressed | ||
+ | [10:56] root@bpi-r2: | ||
+ | 1 #button pressed | ||
+ | [10:56] root@bpi-r2: | ||
+ | 0 #button not pressed | ||
+ | #check every 1/4s | ||
+ | watch -n 0.25 cat / | ||
+ | </ | ||
+ | ==== Special GPIO ==== | ||
+ | |||
+ | memory-hack (like in 4.4.70) not needed | ||
+ | |||
+ | here example for GPIO24 (pin12): | ||
+ | |||
+ | <code bash> | ||
+ | root@bpi-r2# | ||
+ | root@bpi-r2# | ||
+ | root@bpi-r2# | ||
+ | root@bpi-r2# | ||
+ | </ | ||
+ | |||
+ | LED becomes on :) | ||
+ | |||
+ | ==== on-board LEDs ==== | ||
+ | |||
+ | on-board leds used here are near the power-socket (not next to gpio) | ||
+ | |||
+ | http:// | ||
+ | |||
+ | on => | ||
+ | |||
+ | echo 1 > / | ||
+ | |||
+ | off => | ||
+ | |||
+ | echo 0 > / | ||
+ | |||
+ | blink (creates delay_on/ | ||
+ | |||
+ | echo timer > / | ||
+ | |||
+ | change blink frequency (on and off time in ms) => | ||
+ | |||
+ | echo 100 > / | ||
+ | echo 100 > / | ||
+ | |||
+ | |||
+ | in my tests, green is blinking by default (red+blue are simply on/off), i don't know how to disable blinking of green led | ||
+ | |||
+ | < | ||
+ | echo 0 > $L: | ||
+ | echo 1 > $L: | ||
+ | echo 0 > $L: | ||
+ | echo 1 > $L: | ||
+ | ===== UART ===== | ||
+ | |||
+ | ==== change DTS(i) ==== | ||
+ | |||
+ | with Kernel 4.4.x the DeviceTree-sections are missing, these can be copied from a newer Kernel (dtsi). in the *bpi*.dts or *bananapi*.dts set state to enabled | ||
+ | |||
+ | definitions in the mt7623.dtsi: | ||
+ | |||
+ | now in bananapi.dts set " | ||
+ | |||
+ | notice that in mt7623.dtsi first must come uart2 then the others, else after uboot-message " | ||
+ | |||
+ | Uart3 can be [[http:// | ||
+ | |||
+ | ==== port preferences ==== | ||
+ | |||
+ | <code bash> | ||
+ | #show preferences of serial port (replace ttyS2 with your port or ttyUSB0 if a USB2serial-adapter is used): | ||
+ | stty -F /dev/ttyS2 -a | ||
+ | |||
+ | #set speed to 9600 baud, 8 bits, 1 stop bit, no parity: | ||
+ | stty -F /dev/ttyS2 9600 cs8 -cstopb -parenb | ||
+ | |||
+ | #deactivate processing (character conversion, | ||
+ | stty -F /dev/ttyS2 -opost | ||
+ | |||
+ | #raw Modus | ||
+ | stty -F /dev/ttyS2 raw | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Usage ==== | ||
+ | |||
+ | pin 8/10 = uart1 (tx/rx) = 11003000 | ||
+ | pin 11/13 = uart0 (tx/rx) = 11002000 | ||
+ | |||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | DEV=/ | ||
+ | #stty -F ${DEV} sane | ||
+ | #stty -F ${DEV} 9600 cs8 -cstopb -parenb -crtscts -echo | ||
+ | stty -F ${DEV} 9600 cs8 -cstopb -parenb raw -echo | ||
+ | |||
+ | dmesg | grep " | ||
+ | |||
+ | echo " | ||
+ | echo " | ||
+ | |||
+ | echo "using $DEV" | ||
+ | echo "send data using \"echo \" | ||
+ | |||
+ | while read line; do | ||
+ | # if [[ -n " | ||
+ | echo " | ||
+ | # fi | ||
+ | done < <(cat $DEV) | ||
+ | </ | ||
+ | <code bash> | ||
+ | echo " | ||
+ | </ | ||
+ | |||
+ | |||
+ | {{ : | ||
+ | |||
+ | {{: | ||
+ | {{: | ||
+ | {{: | ||
+ | |||
+ | < | ||
+ | PI | ||
+ | 1 (3V3) ------- | ||
+ | 6 (GND) --------- | ||
+ | 8 (TX) | ||
+ | 10 (RX) ------- LV1 HV1 -------- TX | ||
+ | </ | ||
+ | ===== PWM ===== | ||
+ | |||
+ | kernel-option PWM_MEDIATEK must be set (module possible), depends on PWM(=y) | ||
+ | |||
+ | using gpio 206 (pin 7) as pwm3 | ||
+ | < | ||
+ | echo 3 >/ | ||
+ | echo 200000 >/ | ||
+ | echo 100000 >/ | ||
+ | echo 1 >/ | ||
+ | </ | ||
+ | |||
+ | [[https:// | ||
+ | < | ||
+ | period The total period of the PWM signal (read/ | ||
+ | duty_cycle The active time of the PWM signal (read/ | ||
+ | </ | ||
+ | < | ||
+ | period=200000ns=200ms=5kHz | ||
+ | duty_cycle=100000ns=1/ | ||
+ | </ | ||
+ | |||
+ | currently output has the wrong frequency (1kHz instead of 5kHz) see [[http:// | ||
+ | |||
+ | 2018-03-02: frequency is now right: [[https:// | ||
+ | ===== SPI ===== | ||
+ | http:// | ||
+ | ===== I2C ===== | ||
+ | [[http:// | ||
+ | |||
+ | < | ||
+ | in ubuntu 18.4 you need to add universe to / | ||
+ | |||
+ | < | ||
+ | [17:13] root@bpi-r2: | ||
+ | [17:14] root@bpi-r2: | ||
+ | </ | ||
+ | |||
+ | added an rtc ds1307 (with removed pullups) to i2c0 (I2C_SDA0=pin3, | ||
+ | |||
+ | < | ||
+ | #!/bin/bash | ||
+ | modprobe i2c-dev | ||
+ | modprobe rtc-ds1307 | ||
+ | echo ds1307 0x68 > / | ||
+ | #cat / | ||
+ | #read rtc | ||
+ | hwclock -r | ||
+ | #set system-clock to rtc-value | ||
+ | #hwclock -s | ||
+ | #set rtc to system-time | ||
+ | #hwclock -w | ||
+ | </ | ||
+ | |||
+ | ===== 1Wire ===== | ||
+ | thanks to user [[http:// | ||
+ | |||
+ | To enable w1-gpio on GPIO 19 add the following to the main node of mt7623n-bananapi-bpi-r2.dts | ||
+ | |||
+ | < | ||
+ | w1 { | ||
+ | | ||
+ | | ||
+ | gpios = <& | ||
+ | | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | add settings to kernel config | ||
+ | |||
+ | CONFIG_W1=m | ||
+ | CONFIG_W1_MASTER_GPIO=m | ||
+ | CONFIG_W1_SLAVE_THERM=m | ||
+ | |||
+ | and recompile the kernel | ||
+ | |||
+ | Your devices should now show up at / | ||
+ | |||
+ | ===== GPS-PPS ===== | ||
+ | |||
+ | http:// | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | adding this to main-section of mt7623n-bananapi-bpi-r2.dts: | ||
+ | |||
+ | < | ||
+ | pps { | ||
+ | | ||
+ | | ||
+ | gpios = <& | ||
+ | | ||
+ | }; | ||
+ | </ | ||
+ | {{ : | ||
+ | |||
+ | and add this options in the kernel-config for GPIO PPS support: | ||
+ | |||
+ | CONFIG_PPS=m | ||
+ | CONFIG_PPS_CLIENT_LDISC=m | ||
+ | CONFIG_PPS_CLIENT_GPIO=m | ||
+ | |||
+ | ===== thermal ===== | ||
+ | not really gpio, but i wont spend an own page | ||
+ | |||
+ | cat / | ||
+ | |||
+ | http:// |
en/bpi-r2/gpio.txt · Last modified: 2023/06/08 17:06 by 127.0.0.1