Open main menu

DAVE Developer's Wiki β

Changes

DESK-XZ7-L/Peripherals/UART

5,534 bytes added, 26 January
Peripheral UART
!style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white"|Notes
|-
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#ededededf8fb; padding:5px; color:#000000"|20232024/01/23|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#ededededf8fb; padding:5px; color:#000000"|DESK-XZ7-L-1.0.1 release
|-
|}
<section begin=Body/>
== UART0 Peripheral UART ==
UART0 is a spare The Zynq-7000 second UART device available on the JP17 PMOD connector. This device (UART0) is routed through the PLand it is mapped to the <code>ttyPS1</code> device.This feature is available in the [[DESK-XZ7-L/Development/Creating_and_building_the_Vivado_project#CAN0_and_UART0_routing_example_project | Vivado project example]] using the TCL scripts here below:
{| * <code>recreate_prj_bora_BASE.tcl</code>* <code>recreate_prj_boralite_BASE.tcl</code>* <code>recreate_prj_boralite_NAND.tcl</code>* <code>recreate_prj_borax_BASE.tcl</code> ===Accessing the peripheral === ====Linux messages at boot time==== <pre class="workstation-terminal">...[ 0.198315] e0000000.serial: ttyPS1 at MMIO 0xe0000000 (irq = 34, base_baud = 3125000) is a xuartps[ 0.207202] e0001000.serial: ttyPS0 at MMIO 0xe0001000 (irq = 35, base_baud = 3125000) is a xuartps...</pre> ==== Usage with stty ===='''N.B.''' UART mapping respect to <code>ttyPSX</code> is the following one: UART0 (RS232) <-> ttyPS1 UART1 (Serial Port) <-> ttyPS0 <pre class="wikitableworkstation-terminal">|root@bora:~# stty -F /dev/ttyPS1 115200 -echoroot@bora:~# cat /dev/ttyPS1 &[1] 297root@bora:~# echo "Test loopback" > /dev/ttyPS1root@bora:~# Test loopback</pre> ==== Helloworld from UART0 ==== On target we need to loopback pin <code>6</code> and <code>7</code> of <code>PMOD A</code>.  Here below an example on C code for initializing and using UART0 through FPGA: <pre class="c">#include <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>#include <fcntl.h> #include <termios.h> int set_interface_attribs (int fd, int speed, int parity){ struct termios tty; memset (&tty, 0, sizeof tty); if (tcgetattr (fd, &tty) ! Physical device !! Processor's resource !! Connector !! Type !! Linux device file !! Notes= 0) { printf("error %d from tcgetattr", errno); return -1; }  cfsetospeed (&tty, speed); cfsetispeed (&tty, speed);  tty.c_cflag = (tty.c_cflag & ~CSIZE) |CS8; // 8-bit chars // disable IGNBRK for mismatched speed tests; otherwise receive break // as \000 chars tty.c_iflag &= ~IGNBRK; // disable break processing tty.c_lflag = 0; // no signaling chars, no echo, // no canonical processing tty.c_oflag = 0; // no remapping, no delays tty.c_cc[VMIN] = 0; // read doesn't block tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout  tty.c_iflag &= ~(IXON | Boot Console IXOFF |IXANY); // shut off xon/xoff ctrl  tty.c_cflag | UART0 = (CLOCAL |CREAD);// ignore modem controls, // enable reading tty.c_cflag &= ~(PARENB | JP17 PARODD); // shut off parity tty.c_cflag || 2= parity; tty.c_cflag &= ~CSTOPB; tty.c_cflag &= ~CRTSCTS;  if (tcsetattr (fd, TCSANOW, &tty) != 0) { printf("error %d from tcsetattr", errno); return -wire LVTTL 1; } return 0;}   int main(){ int fd; char *portname = "/dev/ttyPS1";  char msg[] = "Hello World from BELK (FPGA PS0 UART )!\n\r";  fd = open(portname, O_RDWR |O_NOCTTY | O_SYNC); if (fd <code0) { printf("error %d opening %s: %s", errno, portname, strerror (errno)); exit(1); } printf("%s", msg);  set_interface_attribs (fd, B115200, 0); // set speed to 115,200 bps, 8n1 (no parity) write(fd, msg, strlen(msg));  exit(0);} </pre> For compile it, please use the following instruction: <pre class="workstation-terminal">dvdk@vagrant:~$ wget https://mirror.dave.eu/desk-xz-l/desk-xz7-l-1.0.1/desk-xz7-l-1.0.1_bora_sdk.sh--2024-01-26 11:57:04-- https://mirror.dave.eu/desk-xz-l/desk-xz7-l-1.0.1/desk-xz7-l-1.0.1_bora_sdk.shResolving mirror.dave.eu (mirror.dave.eu)... 84.46.251.143Connecting to mirror.dave.eu (mirror.dave.eu)|84.46.251.143|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 998591008 (952M) [text/x-sh]Saving to: ‘desk-xz7-l-1.0.1_bora_sdk.sh’ desk-xz7-l-1.0.1_bora_sdk.sh 100%[====================================================================================================>] 952.33M 10.8MB/s in 1m 40s  2024-01-26 11:58:43 (9.57 MB/s) - ‘desk-xz7-l-1.0.1_bora_sdk.sh’ saved [998591008/998591008] dvdk@vagrant:~$ chmod 755 desk-xz7-l-1.0.1_bora_sdk.sh dvdk@vagrant:~$ ./desk-xz7-l-1.0.1_bora_sdk.sh PetaLinux SDK installer version 2021.2======================================Enter target directory for SDK (default: /opt/petalinux/2021.2): You are about to install the SDK to "/devopt/petalinux/2021.2". Proceed [Y/n]? yExtracting SDK.......................................................................................................................................................................................................................doneSetting it up...doneSDK 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/2021.2/environment-setup-cortexa9t2hf-neon-xilinx-linux-gnueabidvdk@vagrant:~$ source /opt/petalinux/2021.2/environment-setup-cortexa9t2hf-neon-xilinx-linux-gnueabi dvdk@vagrant:~$ vi hello_UART0.cdvdk@vagrant:~$ $CC -O hello_UART0.c -o hello_UART0</ttyPS1pre> Copy <code>hello_UART0</code> ||on target and perform the following command: |<pre class="workstation-terminal">root@bora:~# chmod u+x hello_UART0root@bora:~# ./hello_UART0Hello World from BELK (FPGA PS0 UART)!</pre> |}=== Additional information ===Serial ports can be used through the standard serial programming API. For detailed information, please refer to the Serial Programming HOWTO at [http://tldp.org/HOWTO/Serial-Programming-HOWTO/index.html Serial-Programming-HOWTO]
<section end=Body/>
---- [[Category:BORA]] [[Category:BORA Xpress]] [[Category:BORA Lite]]
8,286
edits