DESK-XZU-L/Peripherals/UART

From DAVE Developer's Wiki
Jump to: navigation, search
History
Issue Date Notes
2026/08/27 DESK-XZU-L 2.2.0 release


Peripheral UART[edit | edit source]

The Zynq Ultrascale second UART device (UART0) is routed through the PL and it is mapped to the ttyPS1 device

Accessing the peripheral[edit | edit source]

Linux messages at boot time[edit | edit source]

...
[    2.473625] ff000000.serial: ttyPS1 at MMIO 0xff000000 (irq = 24, base_baud = 6249999) is a xuartps
[    2.477759] ff010000.serial: ttyPS0 at MMIO 0xff010000 (irq = 25, base_baud = 6249999) is a xuartps
...

Usage with stty[edit | edit source]

N.B. UART mapping respect to ttyPSX is the following one:

UART0 (RS232) <-> ttyPS1
UART1 (Serial Port) <-> ttyPS0
root@onda:~# stty -F /dev/ttyPS1 115200 -echo
root@onda:~# cat /dev/ttyPS1 &
[1] 915
root@onda:~# echo "Test loopback" > /dev/ttyPS1
root@onda:~# Test loopback

Helloworld from UART0[edit | edit source]

On target we need to loopback pin 1 and 2 of PMOD A.

Here below an example on C code for initializing and using UART0 through FPGA:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>

int main()
{
	int fd;
	char *portname = "/dev/ttyPS1";
	int numchar;

	char msg[] = "Hello World from DESK-XZU-L-2.2.0 (FPGA PS0 UART)!\r";

	fd = open(portname, O_RDWR | O_NOCTTY | O_SYNC);
	if (fd < 0)
	{
        	printf("error %d opening %s: %s", errno, portname, strerror (errno));
	        exit(1);
	}

	numchar = write(fd, msg, strlen(msg));

	exit(errno);
}

For compile it, please use the following instruction:

dvdk@vagrant:~$ wget https://mirror.dave.eu/desk-xz-l/desk-xzu-l-2.0.0/Petalinux/onda_eg_sdk.sh
--2025-06-13 09:27:27--  https://mirror.dave.eu/desk-xz-l/desk-xzu-l-2.0.0/Petalinux/onda_eg_sdk.sh
Resolving mirror.dave.eu (mirror.dave.eu)... 84.46.251.143
Connecting to mirror.dave.eu (mirror.dave.eu)|84.46.251.143|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 963331875 (919M) [text/x-sh]
Saving to: ‘onda_eg_sdk.sh’

onda_eg_sdk.sh                                     100%[====================================================================================================>] 918.70M   236KB/s    in 27m 56s 

2025-06-13 09:55:23 (561 KB/s) - ‘onda_eg_sdk.sh’ saved [963331875/963331875]

dvdk@vagrant:~$ chmod 755 onda_eg_sdk.sh 
dvdk@vagrant:~$ ./onda_eg_sdk.sh 
PetaLinux SDK installer version 2024.2
======================================
Enter target directory for SDK (default: /opt/petalinux/2024.2): 
You are about to install the SDK to "/opt/petalinux/2024.2". Proceed [Y/n]? 
Extracting SDK.......................................................................................................................................................................................................................done
Setting it up...done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
 $ . /opt/petalinux/2024.2/environment-setup-cortexa72-cortexa53-xilinx-linux
dvdk@vagrant:~$ source /opt/petalinux/2024.2/environment-setup-cortexa9t2hf-neon-xilinx-linux-gnueabi 
dvdk@vagrant:~$ vi hello_UART0.c
dvdk@vagrant:~$ $CC -O hello_UART0.c -o hello_UART0
dvdk@vagrant:~$ file hello_UART0
hello_UART0: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=e8feb62d81503033073cc8c39086b20db1c154ca, for GNU/Linux 5.15.0, with debug_info, not stripped
dvdk@vagrant:~$ 

Copy hello_UART0 on target and perform the following command:

root@onda:~# ./hello_UART0
root@onda:~# Hello World from DESK-XZ7-L-2.2.0 (FPGA PS0 UART)!

Additional information[edit | edit source]

Serial ports can be used through the standard serial programming API.

For detailed information, please refer to the Serial Programming HOWTO at Serial-Programming-HOWTO