DESK-XZ7-L/Peripherals/UART

From DAVE Developer's Wiki
Jump to: navigation, search
History
Issue Date Notes

2024/01/23

DESK-XZ7-L-1.0.1 release
2024/06/12 DESK-XZ7-L-1.1.0 release

2025/03/04

Update HelloWorld from UART0
2025/06/12 DESK-XZ7-L 2.x.x release


Peripheral UART[edit | edit source]

The Zynq-7000 second UART device (UART0) is routed through the PL and it is mapped to the ttyPS1 device. This feature is available in the Vivado project example using the TCL scripts here below:

  • recreate_prj_bora_BASE.tcl
  • recreate_prj_bora_ETH1.tcl
  • recreate_prj_boralite_BASE.tcl
  • recreate_prj_boralite_ETH1.tcl
  • recreate_prj_boralite_NAND.tcl
  • recreate_prj_borax_BASE.tcl
  • recreate_prj_borax_ETH1.tcl

Accessing the peripheral[edit | edit source]

Linux messages at boot time[edit | edit source]

...
[    0.306574] e0000000.serial: ttyPS1 at MMIO 0xe0000000 (irq = 26, base_baud = 3125000) is a xuartps
[    0.315743] e0001000.serial: ttyPS0 at MMIO 0xe0001000 (irq = 27, base_baud = 3125000) 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@bora:~# stty -F /dev/ttyPS1 115200 -echo
root@bora:~# cat /dev/ttyPS1 &
[1] 722
root@bora:~# echo "Test loopback" > /dev/ttyPS1
root@bora:~# Test loopback

Helloworld from UART0[edit | edit source]

On target we need to loopback pin 4 and 6 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-XZ7-L-2.0.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-xz7-l-2.0.0/Petalinux/bora_sdk.sh
--2025-06-13 09:27:27--  https://mirror.dave.eu/desk-xz-l/desk-xz7-l-2.0.0/Petalinux/bora_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: ‘bora_sdk.sh’

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

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

dvdk@vagrant:~$ chmod 755 bora_sdk.sh 
dvdk@vagrant:~$ ./bora_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-cortexa9t2hf-neon-xilinx-linux-gnueabi
dvdk@vagrant:~$ 
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 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, BuildID[sha1]=3bf1e4927e775fe0a2afb1474737d77bfd391789, for GNU/Linux 5.15.0, with debug_info, not stripped

Copy hello_UART0 on target and perform the following command:

root@bora:~# ./hello_UART0
root@bora:~# Hello World from DESK-XZ7-L-2.0.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