Access Official Technical PDF

Share Summary:LinkedInEmail

Getting a SAMA5D2 UART working under Linux involves more than connecting serial wires. The hardware pins must be routed to the UART peripheral, the device tree must enable the interface, and the application must open the correct Linux device node with matching serial settings. On the SAMA5D27 SOM1 Evaluation Kit, UART4 is available through mikroBUS1 and, in the described Buildroot configuration, is exposed to applications as /dev/ttyS1.

This walkthrough covers the connection, Linux configuration layers, and two ways to verify serial communication: a small C program and the microcom utility.

SAMA5D2 UART hardware and wiring

The example uses a PC, a SAMA5D27 SOM1 Evaluation Kit, an SD card, and a TTL-level USB-to-serial cable. UART4 is connected to the board’s mikroBUS1 interface. Its receive and transmit signals are routed through pins PB3 and PB4:

  • URXD4 is assigned to PB3 and connected to RX_mBUS1.
  • UTXD4 is assigned to PB4 and connected to TX_mBUS1.

Connect the board to the USB-to-serial adapter with the transmit and receive lines crossed: J25 pin 3 (RX_mBUS1) to the adapter’s TXD, and J25 pin 4 (TX_mBUS1) to the adapter’s RXD. Connect J25 pin 8 to ground. The adapter must use TTL-level signaling, as specified for this setup.

Correct wiring is essential: the board’s receive input must connect to the adapter’s transmit output, and vice versa. For pin-multiplexing details, consult the SAMA5D2 data sheet.

How Linux exposes UART4

Linux handles this UART through the TTY framework. That framework provides the character-device interface used by applications, including standard operations such as opening, reading, and writing a device file. UART devices are registered with names such as ttySx, where the number depends on the platform’s device configuration.

In the referenced AT91 Buildroot configuration, the device-tree aliases assign serial0 to UART1 (the DBGU) and serial1 to UART4. As a result, UART4 is registered as /dev/ttyS1. The device node is the interface an application uses; the device tree and kernel driver provide the configuration beneath it.

Device-tree and kernel configuration

The example Buildroot configuration is atmel_sama5d27_som1_ek_mmc_dev_defconfig. With that configuration, the application note indicates that no device-tree or kernel changes are required to use UART4.

The device-tree sources describe the UART controller’s address, interrupt, clock, DMA channels, and pin assignments. The SoC-level definition includes UART4, while the board-level device tree enables it, assigns its pins to PB3 and PB4, and enables DMA for transmit and receive. Its status is set to “okay” so Linux can use the peripheral.

The AT91 USART driver is provided by the Linux kernel. If you need to inspect the relevant settings, the application note points to the AT91 USART driver and AT91 on-chip serial port support in kernel configuration. The driver source is located at drivers/tty/serial/atmel_serial.c. For the specified default setup, these settings are already in place.

Opening and configuring the serial port

A Linux application opens /dev/ttyS1 and configures the port using the TTY interface, commonly through the termios API. The example program opens the device for reading and writing, then configures 115200 baud, eight data bits, no parity, and one stop bit (8N1). It also disables canonical input processing and echo, and sets a read timeout using VTIME and VMIN.

These settings must match the serial device at the other end of the cable. After applying the configuration, the program repeatedly reads available input and writes the string “Hello World!” to the port. Build it with the ARM Buildroot cross-compiler provided in the development environment, then copy the executable to the target board.

Testing UART communication with microcom

For a quick interactive check, Buildroot’s BusyBox configuration can include microcom. On the target board, start a session at 115200 baud with:

microcom -s 115200 /dev/ttyS1

With UART4 connected to the PC’s USB-to-serial adapter, characters entered at either end can be used to check the link. Press Ctrl+X to exit microcom. This offers a direct way to test the port without first developing an application.

The C program provides a complementary test: run it on the target and observe the UART waveform on the mikroBUS1 connection while monitoring the PC’s serial port. Together, the utility and application help distinguish basic wiring and port-access checks from testing within custom software.

Practical takeaways

For this SAMA5D27 SOM1 setup, UART4 is available on mikroBUS1 and appears to Linux applications as /dev/ttyS1. The key steps are to use TTL-level serial hardware, cross TXD and RXD, share ground, and configure both ends for the same serial format. The default Buildroot device tree and kernel configuration already support the interface, so initial testing can focus on wiring, the correct device node, and matching port settings.

Once communication is confirmed with microcom or a simple C program, the same TTY device interface can be used as the starting point for application-specific serial communication.

Access Official Technical PDF

About The Author