The SoCs used on the Raspberry Pis have two built-in UARTs, a PL011 and a mini UART. They are implemented using different hardware blocks, so they have slightly different characteristics. However, both are 3.3V devices, which means extra care must be taken when connecting up to an RS232 or other system that utilises different voltage levels. An adapter must be used to convert the voltage levels between the two protocols. Alternatively, 3.3V USB UART adapters can be purchased for very low prices. By default, on Raspberry Pis equipped with the wireless/Bluetooth module (Raspberry Pi 3 and Raspberry Pi Zero W), the PL011 UART is connected to the Bluetooth module, while the mini UART is used as the primary UART and will have a Linux console on it. On all other models, the PL011 is used as the primary UART. In Linux device terms, by default, /dev/ttyS0 refers to the mini UART, and /dev/ttyAMA0 refers to the PL011. The primary UART is the one assigned to the Linux console, which depends on the Raspberry Pi model as described above. There are also symlinks: /dev/serial0, which always refers to the primary UART (if enabled), and /dev/serial1, which similarly always refers to the secondary UART (if enabled). Mini UART and CPU core frequencyThe baud rate of the mini UART is linked to the core frequency of the VPU on the VC4 GPU. This means that, as the VPU frequency governor varies the core frequency, the baud rate of the UART also changes. This makes the UART of limited use in the default state. By default, if the mini UART is selected for use as the primary UART, it will be disabled. To enable it, add The default value of the Disabling Linux's use of console UARTIn a default install of Raspbian, the primary UART (serial0) is assigned to the Linux console. Using the serial port for other purposes requires this default behaviour to be changed. On startup, This can be done by using the raspi-config utility, or manually.
Select option 5, Interfacing options, then option P6, Serial, and select No. Exit raspi-config. To manually change the settings, edit the kernel command line with Reboot the Raspberry Pi for the change to take effect. UART output on GPIO pinsBy default, the UART transmit and receive pins are on GPIO 14 and GPIO 15 respectively, which are pins 8 and 10 on the GPIO header. UARTs and Device TreeVarious UART Device Tree Overlay definitions can be found in the kernel github tree. The two most useful overlays are
There are other UART-specific overlays in the folder. Refer to For full instructions on how to use Device Tree Overlays see this page. In brief, add a line to the
Relevant differences between PL011 and mini UARTThe mini UART has smaller FIFOs. Combined with the lack of flow control, this makes it more prone to losing characters at higher baudrates. It is also generally less capable than the PL011, mainly due to its baud rate link to the VPU clock speed. The particular deficiencies of the mini UART compared to the PL011 are :
Further documentation on the mini UART can be found in the SoC peripherals document here. |
|