|
|
(One intermediate revision by one other user not shown) |
Line 1: |
Line 1: |
− | {{rockpi4_header}}
| + | #redirect [[Rock4/hardware/gpio]] |
− | {{Languages|rockpi4/hardware/gpio}}
| + | |
− | | + | |
− | [[rockpi4 | ROCK Pi 4]] > [[rockpi4/hardware | Hardware]] > [[rockpi4/hardware/gpio | GPIO]]
| + | |
− | | + | |
− | <div class="col-md-12 ">
| + | |
− | <div class="panel panel-midnight-white">
| + | |
− | <div class="panel-heading"><h3>Hardware</h3></div>
| + | |
− | <div class="panel-body">
| + | |
− | === <span id="gpio">'''Rock Pi 4A / 4A Plus / 4B / 4B Plus / 4C / 4C Plus(>=V1.2)''' general purpose input-output (GPIO) connector</span> ===
| + | |
− | ROCK Pi 4 has a 40-pin expansion header. Each pin is distinguished by color.
| + | |
− | {| class="wikitable"
| + | |
− | ! GPIO number || Function2 || Function1 || GPIO || Pin# || || Pin# || GPIO || Function1 || Function2 || GPIO number
| + | |
− | |-
| + | |
− | | || || +3.3V || || style="background:yellow"| 1 || ||style="background:red"| 2 || || +5.0V || ||
| + | |
− | |-
| + | |
− | | 71 || || I2C7_SDA || GPIO2_A7 || style="background:green; color:white"| 3 || || style="background:red"| 4 || || +5.0V || ||
| + | |
− | |-
| + | |
− | | 72 || || I2C7_SCL || GPIO2_B0 || style="background:green; color:white"| 5 || || style="background:black; color:white"| 6 || || GND || ||
| + | |
− | |-
| + | |
− | | 75 || || SPI2_CLK || GPIO2_B3 || style="background:green; color:white"| 7 || || style="background:green; color:white"| 8 || GPIO4_C4 || style="background:orange"|UART2_TXD || || 148
| + | |
− | |-
| + | |
− | | || || GND || || style="background:black; color:white"| 9 || || style="background:green; color:white"|10 || GPIO4_C3 || style="background:orange"|UART2_RXD || || 147
| + | |
− | |-
| + | |
− | |146 || || PWM0 || GPIO4_C2 || style="background:green; color:white"|11 || || style="background:green; color:white"|12 || GPIO4_A3 || I2S1_SCLK || || 131
| + | |
− | |-
| + | |
− | | 150 || || PWM1 || GPIO4_C6 || style="background:green; color:white"|13 || || style="background:black; color:white"|14 || || GND || ||
| + | |
− | |-
| + | |
− | | 149 || || SPDIF_TX || GPIO4_C5 || style="background:green; color:white"|15 || || style="background:green; color:white"|16 || GPIO4_D2 || || || 154
| + | |
− | |-
| + | |
− | | || || +3.3V || || style="background:yellow"|17 || || style="background:green; color:white"|18 || GPIO4_D4 || || || 156
| + | |
− | |-
| + | |
− | |40 || UART4_TXD || style="background:orange"|SPI1_TXD || GPIO1_B0 || style="background:green; color:white"|19 || ||style="background:black; color:white"|20 || || GND || ||
| + | |
− | |-
| + | |
− | |39 || UART4_RXD || style="background:orange"|SPI1_RXD || GPIO1_A7 || style="background:green; color:white"|21 || || style="background:green; color:white"|22 || GPIO4_D5 || || || 157
| + | |
− | |-
| + | |
− | |41 || || style="background:orange"|SPI1_CLK || GPIO1_B1 || style="background:green; color:white"|23 || || style="background:green; color:white"|24 || GPIO1_B2 || style="background:orange"|SPI1_CSn || || 42
| + | |
− | |-
| + | |
− | | || || GND || || style="background:black; color:white"|25 || || style="background:green; color:white"|26 || || ADC_IN0 || ||
| + | |
− | |-
| + | |
− | | 64 || || I2C2_SDA || GPIO2_A0 || style="background:blue; color:white"|27 || || style="background:blue; color:white"|28 || GPIO2_A1 || I2C2_CLK || || 65
| + | |
− | |-
| + | |
− | | 74 || I2C6_SCL || SPI2_TXD || GPIO2_B2 || style="background:green; color:white"|29 || || style="background:black; color:white"|30 || || GND || ||
| + | |
− | |-
| + | |
− | | 73 || I2C6_SDA || SPI2_RXD || GPIO2_B1 || style="background:green; color:white"|31 || || style="background:green; color:white"|32 || GPIO3_C0 || SPDIF_TX || UART3_CTSn || 112
| + | |
− | |-
| + | |
− | | 76 || || SPI2_CSn || GPIO2_B4 || style="background:green; color:white"|33 || || style="background:black; color:white"|34 || || GND || ||
| + | |
− | |-
| + | |
− | | 133 || || I2S1_LRCK_TX || GPIO4_A5 || style="background:green; color:white"|35 || || style="background:green; color:white"|36 || GPIO4_A4 || I2S1_LRCK_RX || || 132
| + | |
− | |-
| + | |
− | | 158 || || || GPIO4_D6 || style="background:green; color:white"|37 || || style="background:green; color:white"|38 || GPIO4_A6 || I2S1_SDI || || 134
| + | |
− | |-
| + | |
− | | || || GND || || style="background:black; color:white"|39 || ||style="background:green; color:white"|40 || GPIO4_A7 || I2S1_SDO || || 135
| + | |
− | |}
| + | |
− | | + | |
− | <div class="toccolours mw-collapsible mw-collapsed" style="overflow:auto;">
| + | |
− | | + | |
− | === <span id="rockpi4c+gpio">'''ROCK Pi 4C Plus V1.0/V1.1''' general purpose input-output (GPIO) connector</span> ===
| + | |
− | | + | |
− | ROCK Pi 4C Plus has a 40-pin expansion header. Each pin is distinguished by color.
| + | |
− | {| class="wikitable"
| + | |
− | ! GPIO number || Function2 || Function1 || GPIO || Pin# || || Pin# || GPIO || Function1 || Function2 || GPIO number
| + | |
− | |-
| + | |
− | | || || +3.3V || || style="background:yellow"| 1 || ||style="background:red"| 2 || || +5.0V || ||
| + | |
− | |-
| + | |
− | | 71 || || I2C7_SDA || GPIO2_A7 || style="background:green; color:white"| 3 || || style="background:red"| 4 || || +5.0V || ||
| + | |
− | |-
| + | |
− | | 72 || || I2C7_SCL || GPIO2_B0 || style="background:green; color:white"| 5 || || style="background:black; color:white"| 6 || || GND || ||
| + | |
− | |-
| + | |
− | | 75 || || SPI2_CLK || GPIO2_B3 || style="background:green; color:white"| 7 || || style="background:green; color:white"| 8 || GPIO4_C4 || style="background:orange"|UART2_TXD || || 148
| + | |
− | |-
| + | |
− | | || || GND || || style="background:black; color:white"| 9 || || style="background:green; color:white"|10 || GPIO4_C3 || style="background:orange"|UART2_RXD || || 147
| + | |
− | |-
| + | |
− | |146 || || PWM0 || GPIO4_C2 || style="background:green; color:white"|11 || || style="background:green; color:white"|12 || GPIO2_D3 || || || 91
| + | |
− | |-
| + | |
− | | 33 || || || GPIO1_A1 || style="background:green; color:white"|13 || || style="background:black; color:white"|14 || || GND || ||
| + | |
− | |-
| + | |
− | | 149 || || SPDIF_TX || GPIO4_C5 || style="background:green; color:white"|15 || || style="background:green; color:white"|16 || GPIO4_D2 || || || 154
| + | |
− | |-
| + | |
− | | || || +3.3V || || style="background:yellow"|17 || || style="background:green; color:white"|18 || GPIO4_D4 || || || 156
| + | |
− | |-
| + | |
− | |40 || UART4_TXD || style="background:orange"|SPI1_TXD || GPIO1_B0 || style="background:green; color:white"|19 || ||style="background:black; color:white"|20 || || GND || ||
| + | |
− | |-
| + | |
− | |39 || UART4_RXD || style="background:orange"|SPI1_RXD || GPIO1_A7 || style="background:green; color:white"|21 || || style="background:green; color:white"|22 || GPIO4_D5 || || || 157
| + | |
− | |-
| + | |
− | |41 || || style="background:orange"|SPI1_CLK || GPIO1_B1 || style="background:green; color:white"|23 || || style="background:green; color:white"|24 || GPIO1_B2 || style="background:orange"|SPI1_CSn || || 42
| + | |
− | |-
| + | |
− | | || || GND || || style="background:black; color:white"|25 || || style="background:green; color:white"|26 || || ADC_IN0 || ||
| + | |
− | |-
| + | |
− | | 64 || || I2C2_SDA || GPIO2_A0 || style="background:blue; color:white"|27 || || style="background:blue; color:white"|28 || GPIO2_A1 || I2C2_CLK || || 65
| + | |
− | |-
| + | |
− | | 74 || I2C6_SCL || SPI2_TXD || GPIO2_B2 || style="background:green; color:white"|29 || || style="background:black; color:white"|30 || || GND || ||
| + | |
− | |-
| + | |
− | | 73 || I2C6_SDA || SPI2_RXD || GPIO2_B1 || style="background:green; color:white"|31 || || style="background:green; color:white"|32 || GPIO3_C0 || SPDIF_TX || UART3_CTSn || 112
| + | |
− | |-
| + | |
− | | 76 || || SPI2_CSn || GPIO2_B4 || style="background:green; color:white"|33 || || style="background:black; color:white"|34 || || GND || ||
| + | |
− | |-
| + | |
− | | 133 || || I2S1_LRCK_TX || GPIO4_A5 || style="background:green; color:white"|35 || || style="background:green; color:white"|36 || GPIO2_D4 || || || 92
| + | |
− | |-
| + | |
− | | 158 || || || GPIO4_D6 || style="background:green; color:white"|37 || || style="background:green; color:white"|38 || GPIO1_A4 || || || 36
| + | |
− | |-
| + | |
− | | || || GND || || style="background:black; color:white"|39 || ||style="background:green; color:white"|40 || GPIO1_C4 || || || 52
| + | |
− | |}
| + | |
− | | + | |
− | ==== More details about 40-pin Header ====
| + | |
− | * Function marked with color orange is the default function of this pin.
| + | |
− | * Except Pins for power supply, all pins are laid out directly to Soc RK3399.
| + | |
− | * For pin 3, 5, 27, 28, 29 and 31, each pin is connected to the 3.0V supply through a 4.7K pull-up resistor.
| + | |
− | * Pin 19, 21, 23, 24 are laid out directly to the pins of SPI device on board.
| + | |
− | * Pin 7 is laid out directly to the pin of MIPI CSI on board.
| + | |
− | * UART
| + | |
− | ** UART2 is enabled as U-boot and Linux serial console by default. Check [[Rockpi4/dev/serial-console]] to use. Check [[Rockpi4/hardware/devtree_overlays]] to disable serial console on UART2.
| + | |
− | ** UART2 & UART4 support a wide range of baud rate. It includes but not is not limited to the following baud rates. For instance, 115200bps. 500000bps, 1500000bps and so on.
| + | |
− | ** For v1.4 and later hardware, on board SPI flash is soldered, UART4 PINs are used as SPI function.
| + | |
− | * For I2C-2 and I2C-7
| + | |
− | ** We have do the test using the i2c device e2prom. We need to open the i2c device file, and then do the read or write operation.
| + | |
− | | + | |
− | </div>
| + | |
− | | + | |
− | === IO Voltage ===
| + | |
− | RK3399 have three IO voltages, 1.8V/3.0V/3.3V. For ROCK Pi 4, below is the default voltage:
| + | |
− | | + | |
− | <pre>
| + | |
− | | GPIO | Voltage Level | Tolerance |
| + | |
− | | ---------- | ------------- | --------- |
| + | |
− | | GPIO3_C0 | 3.3V | 3.465V |
| + | |
− | | ADC_IN0 | 1.8V | 1.98V |
| + | |
− | | Other GPIO | 3.0V | 3.14V |
| + | |
− | | + | |
− | | + | |
− | </pre>
| + | |
− | | + | |
− | | + | |
− | === GPIO number ===
| + | |
− | Rockchip RK3399 GPIO has 5 banks, GPIO0 to GPIO4, each bank has 32pins, naming as below:
| + | |
− | | + | |
− | GPIO0_A0 ~ A7
| + | |
− | GPIO0_B0 ~ B7
| + | |
− | GPIO0_C0 ~ C7
| + | |
− | GPIO0_D0 ~ D7
| + | |
− |
| + | |
− | GPIO1_A0 ~ A7
| + | |
− | ....
| + | |
− | GPIO1_D0 ~ D7
| + | |
− | | + | |
− | For Rockchip 4.4 kernel, the GPIO number can be calculated as below, take GPIO4_D5 (PIN22 on 40PIN GPIO) as an example:
| + | |
− | | + | |
− | GPIO4_D5 = 4*32 + 3*8 + 5 = 157
| + | |
− | (A=0, B=1, C=2, D=3)
| + | |
− | | + | |
− | [[File:Gpio_number.png]]
| + | |
− | | + | |
− | To set GPIO4_D5 output
| + | |
− | | + | |
− | cd /sys/class/gpio
| + | |
− | echo 157 > export
| + | |
− | cd gpio157
| + | |
− | echo out > direction
| + | |
− | echo 1 > value # output high
| + | |
− | echo 0 > value # output low
| + | |
− | | + | |
− | === GPIO Libraries/API ===
| + | |
− | ====Install [[Rockpi4/dev/libmraa | Libmraa]] ====
| + | |