How do I realize serial communication between fpga and PC on PL? PYNQ-Z2

Hello, I have encountered a question. I implemented the transceiver on pl side of fpga. I want to realize serial communication between computer and fpga through pl serial port. How can I realize this function? Is it via GPIO pin? Is there a corresponding tutorial?
i use a pynq-z2 board and vivado 2018.2

Can you please explain in more detail 1) what you need - what your requirements are, and 2) what you are trying to do (what PL serial port, and what connection on the PC do you have)?

Cathal

Sorry I didn’t describe it clearly before.

Board PYNQ-Z2

Our project

Now I’m going to reproduce a project of polar code decoder. In this project, a receiver, a transmitter and a decoder are implemented on FPGA PL. On the PC side, the project generates coded information through matlab and sends it to the receiver of FPGA through COM port. (Actually, we have a USB to TTL converter) After receiving the signal, FPGA decodes it, and then sends the result back to the PC side through the transmitter.

What are my requirements

I want to know how to use the GPIO pins or other pins on the fpga PL to realize information transmittion between PC and Rx&Tx on FPGA?
I tried to use GPIO pin, but the receiver didn’t respond. Obviously, no signal was received.

What to do

I want to know how to realize serial data transmission between PC and FPGA PL, and how to use pins. Is there any tutorial or file?

Other Details

Tx and Rx

//////////////////////////////////////////////////////////////////////
// File Downloaded from http://www.nandland.com
//////////////////////////////////////////////////////////////////////
// This file contains the UART Receiver.  This receiver is able to
// receive 8 bits of serial data, one start bit, one stop bit,
// and no parity bit.  When receive is complete o_rx_dv will be
// driven high for one clock cycle.
// 
// Set Parameter CLKS_PER_BIT as follows:
// CLKS_PER_BIT = (Frequency of i_Clock)/(Frequency of UART)
// Example: 10 MHz Clock, 115200 baud UART
// (10000000)/(115200) = 87
//CLKS_PER_BIT = 10417: BAUD RATE=9600
module uart_rx 
  #(parameter CLKS_PER_BIT = 868)
  (
   input        i_Clock,         
   input        i_Rx_Serial,
   output       o_Rx_DV,
   output [7:0] o_Rx_Byte
   );

/////////////////////////////////////////////////////////////////////
// File Downloaded from http://www.nandland.com
//////////////////////////////////////////////////////////////////////
// This file contains the UART Transmitter. This transmitter is able
// to transmit 8 bits of serial data, one start bit, one stop bit,
// and no parity bit. When transmit is complete o_Tx_done will be
// driven high for one clock cycle.
//
// Set Parameter CLKS_PER_BIT as follows:
// CLKS_PER_BIT = (Frequency of i_Clock)/(Frequency of UART)
// Example: 10 MHz Clock, 115200 baud UART
// (10000000)/(115200) = 87

module uart_tx
#(parameter CLKS_PER_BIT = 868)
(
input i_Clock,
input i_Tx_DV,
input [7:0] i_Tx_Byte,
output o_Tx_Active,
output reg o_Tx_Serial,
output o_Tx_Done
);

1 Like

If you were using PS GPIO from Python, it probably won’t be able to generate the correct timing for the UART.

Are you doing something like this in Matlab?:
https://uk.mathworks.com/help/matlab/ref/serialport.html?

You could use an IOP or PYNQ microblaze and write an application to read/write to UART. It would need to have access to your sensor data. https://pynq.readthedocs.io/en/v2.6.1/pynq_libraries.html#iops

You could build your own MicroBlaze to manage your system.

You could add a UART to your PL design. There is a UART IP in Vivado. You woudl then need to figure out how to get data from your other PL IP (sensors?) and write it to the UART, and receive commands (?) from the UART an write to your IP.
PYNQ won’t really help you do this unless you want to use PYNQ to read your sensors, and then use PYNQ to write back to the UART. i.e. all the communication would be going through the PS.

I’d suggest a couple of things. Does communication have to be over serial port? Could you use a socket connection from Matlab?
https://uk.mathworks.com/help/instrument/udpport.html?searchHighlight=connect%20to%20sockets&s_tid=srchtitle_connect%20to%20sockets_1
This would put the communication over Ethernet (or WiFi is you have a dongle). If you search you can probably find a TCP/IP way to do it.

If this doesn’t work, could you connect Matlab to the COM port the micro USB is connected to? This would push the communication through the PS, so you would need to read/write from stdin/out.

Cathal

1 Like

Hi…

  1. You add it by your own, and keep your code as a module.

  2. Bundle your module as a custom ip and utilize the format given by Xilinx.

By and by, I will presumably go with the subsequent choice. Furthermore, that is on the grounds that, the format is obviously composed and remarked. Inside this format there is a state machine that gives you admittance to several registers.Trough these registers you can pass information from PL to PS side. After you have your own IP, you can add it into a square plan and interface it box the AXI Interconnect. On this stage your IP will have it’s own location into the location supervisor. With that, you can get to box the light interface every individual register.