Raspberry Pi / serial console

Serial console on a Raspberry Pi with FreeBSD

When Wi-Fi is not up yet, or a boot hangs, the serial line is the only way in. The Pi 4 and Zero 2 W need one USB serial adapter on the header. The Pi 5 needs its own cable, or two adapters over USB.

A green Raspberry Pi board with a small raspberry imp sitting on the SD card slot.

Settings on every board: 115200 baud, 8 data bits, no parity, 1 stop bit, no flow control (115200 8N1). All signals are 3.3 V. A 5 V adapter can damage the board; on an adapter with a voltage jumper, set it to 3.3 V. Never connect the adapter's VCC pin.

The adapters used here are plain USB serial adapters. FreeBSD drives the common chips with uchcom(4) (CH340), uftdi(4) (FT232), uplcom(4) (PL2303) and uslcom(4) (CP210x).

What to have

BoardConsole with boot and kernel messagesLogin only, after boot
Pi 4 Model Bone USB serial adapter on the GPIO headersame
Zero 2 Wone USB serial adapter on the GPIO headersame
Pi 5 Model Ba cable for the 3-pin UART connectortwo USB serial adapters, over USB

Pi 4 and Zero 2 W: the GPIO header

  1. Wire the adapter to the header. Transmit goes to receive:

    AdapterHeader pin
    GND6 (GND)
    RX8 (GPIO14, TXD)
    TX10 (GPIO15, RXD)

    Wiring diagram: the adapter's GND goes to header pin 6, its RX to pin 8 (TXD) and its TX to pin 10 (RXD). VCC stays free.

  2. Nothing to set on the board. The config.txt of the FreeBSD image has dtoverlay=disable-bt, so the PL011 UART sits on pins 8 and 10, and the kernel uses it as its console: dmesg shows uart0: console (115200,n,8,1). /etc/ttys starts a login on ttyu0 because it is the console (onifconsole).

  3. Open the line on the computer. On FreeBSD:

    cu -l /dev/cuaU0 -s 115200
    

    ~. at the start of a line closes cu. On other systems any terminal program set to 115200 8N1 works. Power the board on: the loader, the kernel messages and then the login prompt appear.

The Bluetooth radio of these boards also needs this UART. Taking it for Bluetooth means losing the console here; moving the console to the mini UART stopped a Zero 2 W at boot in 3 boots out of 3 (see Bluetooth).

Pi 5, option 1: the 3-pin UART connector

The Pi 5 boots FreeBSD through UEFI firmware. Its GPIO header UARTs live on the RP1 chip, which FreeBSD 15.1 GENERIC does not drive, so pins 8 and 10 stay silent at boot. The rp1uart module attaches them once loaded, with transmit measured and receive not tested; it does not give a boot console. The console is the separate 3-pin UART connector between the two micro HDMI ports. The test board reports it as:

uart0: <PrimeCell UART (PL011)> iomem 0x107d001000-0x107d0011ff irq 0 on acpi0
uart0: console (115200,n,8,1)

Wiring diagram: a cable from the 3-pin UART connector between the two micro HDMI ports of the Pi 5 to a USB serial adapter, and a USB lead to the computer running cu at 115200.

That connector takes a cable with a 3-pin JST SH plug (1.0 mm pitch), with a USB serial adapter at the other end. Check the pin order printed on the board or in its documentation before wiring loose leads. This is the only way to see the loader, kernel messages and a panic on a Pi 5. The config.txt there has enable_uart=1 and dtparam=uart0_console.

Pi 5, option 2: two USB serial adapters over USB

Without that cable, two USB serial adapters give a login, but only after FreeBSD has booted.

  1. Plug adapter A into a USB port of the Pi 5 and adapter B into the computer. Wire them to each other, transmit to receive:

    Adapter A (Pi 5)Adapter B (computer)
    TXRX
    RXTX
    GNDGND

    Wiring diagram: adapter A in a USB port of the Pi 5, where a getty runs on cuaU0, and adapter B in the computer. TX of each goes to RX of the other, GND to GND. Login after boot only, no loader and no kernel messages.

  2. On the Pi 5, adapter A shows up as cuaU0 (for a CH340: uchcom0: CH340 detected). Add a login on it to /etc/ttys:

    cuaU0	"/usr/libexec/getty 3wire.115200"	vt100	onifexists secure
    

    onifexists starts the login whenever the adapter is there at boot. After plugging it in later, kill -HUP 1 makes init read the file again.

  3. Open adapter B on the computer at 115200 8N1 and press Enter for the login prompt.

What this cannot show: the loader, kernel messages, and a hang or panic. Over the same adapter, kernel messages after boot need conscontrol add ucom; the loader tunable hw.usb.ucom.cons_unit alone does not do it. For a board that stops during boot, option 1 is needed.

When the line stays silent

  • Swap TX and RX: the most common mistake.
  • Check GND: without a common ground the characters come out as garbage or not at all.
  • Wrong speed shows as garbage too; everything here is 115200.
  • On the computer, dmesg | tail after plugging the adapter in shows its device name.
  • Day-to-day access is easier over the network: ssh once Wi-Fi is up (what to install). Keep the serial line as the fallback.

Built with ssg