Configuring UART
This section explains how to configure UART for the following:
Raspberry Pi 4
The Raspberry Pi 4 has six available UARTs. By default, only UART1 (used by the debug serial console) is enabled. Note that UART1 uses a different driver than the other UARTs.
Don't repurpose UART1 until you assign another UART to work as the debug console, unless you don't need a console.
If you want to connect your Raspberry Pi 4 with a UART serial peripheral (e.g., a GPS module, lidar module, NFC reader, etc.), then you need to manually enable a UART interface and serial port for the device. To enable UART2 on GPIOs 0 and 1:
Set the GPIO pin mode to connect the UART2 hardware block to the GPIO pins:
gpio-bcm2711 set 0,1 a4Start the serial driver. The address and IRQ are specific for this UART interface:
devc-serpl011 -b115200 -v -c50000000 -e -F -u2 0xfe201400,153Optionally, configure the serial port settings:
stty baud=115200 par=none bits=8 stopb=1 < /dev/ser2
You can now try sending data to the serial port with:
echo “Hello World” > /dev/ser2You can read from the serial port with:
cat /dev/ser2Earlier releases of the Quick Start Target Image (QSTI) for the Raspberry Pi 4 don't include the devc-serpl011 driver. If your image doesn’t have the driver, you can find it in either the com.qnx.qnx800.target.connectivity.devc package in the QNX Software Center (QSC), or as part of the Raspberry Pi 4 BSP software package.
Additional addresses and IRQs
Use the following table to substitute the appropriate values for the following commands. The filesystem exposes the UART at /dev/ser<Ser#>:
gpio-rp1 set <GPIO #> <GPIO Mode>
devc-serpl011 -b115200 -c50000000 -e -F -u<Ser#> <Address>,<IRQ>If you also need hardware flow-control (CTS/RTS, i.e., clear to send/request to send), configure those GPIO pins with the second pair of pins listed below for each UART. You can do this at the same time as configuring the TX/RX pins if they use the same alternate mode, or in a separate call to gpio-bcm2711. For example:
# Configure GPIOs for UART0
gpio-bcm2711 set 14,15 a0
gpio-bcm2711 set 16,17 a3
# Configure GPIOs for UART3
gpio-bcm2711 set 4-7 a4| UART | Driver | GPIO configuration | Address | IRQ | |
|---|---|---|---|---|---|
| GPIO # (TX/RX, CTS/RTS) | Mode | ||||
| UART0 | devc-serpl011 |
14, 15 | a0 | 0xfe201000 |
153 |
| 16, 17 | a3 | ||||
| UART1 | devc-serminiuart |
14, 15 | a5 | 0xfe215000 |
125 |
| 16, 17 | |||||
| UART2 | devc-serpl011 |
0, 1 | a4 | 0xfe201400 |
153 |
| 2, 3 | |||||
| UART3 | devc-serpl011 |
4, 5 | a4 | 0xfe201600 |
153 |
| 6, 7 | |||||
| UART4 | devc-serpl011 |
8, 9 | a4 | 0xfe201800 |
153 |
| 10, 11 | |||||
| UART5 | devc-serpl011 |
12, 13 | a4 | 0xfe201A00 |
153 |
| 14, 15 | |||||
Raspberry Pi 5
To connect your Raspberry Pi 5 with a UART serial peripheral (e.g., a GPS module, lidar module, NFC reader, etc.), you need to manually enable a UART interface and serial port for the device. These instructions explain how to enable UART0 (GPIO pins 14 and 15) on a Raspberry Pi 5:
This example refers to UART0 on the GPIO header, not to be confused with the Pi 5’s built-in serial debug port, which isn't exposed at all on the GPIO header
Enable the RP1 MSIX UART0 interrupt:
msix-rp1 -m set 25lSet the GPIO pin mode to connect the UART0 hardware block to GPIO pins 14 and 15:
gpio-rp1 set 14,15 a4Start the serial driver. The address and IRQ are specific for this UART interface:
devc-serpl011-rpi5 -b115200 -v -c50000000 -e -F -u1 0x1f00030000,185Note:The
-u1option establishes the serial port resource at /dev/ser1 . The-u0option isn't supported, which is why UART0 is exposed as /dev/ser1 in the filesystem.Optionally, configure the serial port settings:
stty baud=115200 par=none bits=8 stopb=1 < /dev/ser1
You can now try sending data to the serial port with:
echo “Hello World” > /dev/ser1You can read from the serial port with:
cat /dev/ser1Additional addresses and IRQs
Use the following table to substitute the appropriate values for the following commands. The filesystem exposes the UART at /dev/ser<Ser#>:
msix-rp1 -m set <MSIX Interrupt>l
gpio-rp1 set <GPIO #> <GPIO Mode>
devc-serpl011-rpi5 -b115200 -c50000000 -e -F -u<Ser#> <Address>,<IRQ>There is a trailing l (el) in the msix-rp1 command line. It's easy to miss but is required for correct configuration.
If you also need hardware flow-control (CTS/RTS), configure those GPIO pins with the second pair of pins listed below for each UART. You can do this at the same time as configuring the TX/RX pins, or in a separate call to gpio-rp1. For example, to configure UART0 for hardware flow-control, do one of the following:
gpio-rp1 set 14-17 a4gpio-rp1 set 14,15 a4
gpio-rp1 set 16,17 a4| UART | MSIX Interrupt | GPIO configuration | Address | IRQ | |
|---|---|---|---|---|---|
| GPIO # (TX/RX, CTS/RTS) | Mode | ||||
| UART0 | 25 | 14, 15 | a4 | 0x1f00030000 |
185 |
| 16, 17 | |||||
| UART1 | 42 | 0, 1 | a2 | 0x1f00034000 |
202 |
| 2, 3 | |||||
| UART2 | 43 | 4, 5 | a2 | 0x1f00038000 |
203 |
| 6, 7 | |||||
| UART3 | 44 | 8, 9 | a2 | 0x1f0003C000 |
204 |
| 10, 11 | |||||
| UART4 | 45 | 12, 13 | a2 | 0x1f00040000 |
205 |
| 14, 15 | |||||
