FPGA Project: A UART Echo at 115200 Baud

A UART echo receives each byte from your computer and sends it straight back, so whatever you type appears in the terminal only if the FPGA is working. It reuses the receiver and transmitter from the UART project unchanged, with the clock divider set for each board: 868 clocks per bit at 100 MHz and 434 at 50 MHz for 115200 baud. One holding register covers the case where the next byte arrives a few clocks before the transmitter is free.

How this was checked

The design was simulated in Icarus Verilog 12 and linted with Verilator 5.036 (-Wall, no warnings) for every board's top level. The Basys 3 and Arty A7 versions were synthesized, placed and routed in Vivado 2025.2, met timing, and produced a bitstream. The DE10-Lite version was simulated and linted but not compiled, because Intel Quartus was not used here; its pin assignments come from Terasic's DE10-Lite System Builder file. None of the bitstreams has been loaded onto a board yet. If you build it and something doesn't behave as described, please tell us through the contact page. The Basys 3 and Arty A7 have a USB-UART chip on board; the DE10-Lite does not, so it needs a 3.3 V USB-to-serial adapter on its Arduino header.

The three boards

BoardFPGAClockTools
Digilent Basys 3AMD Artix-7 XC7A35T100 MHz, pin W5Vivado
Digilent Arty A7-35AMD Artix-7 XC7A35T100 MHz, pin E3Vivado
Terasic DE10-LiteIntel MAX 10 10M5050 MHz, pin P11Quartus Prime Lite
The echo pathThe receive line goes through uart_rx; each good byte is stored in a holding register, which uart_tx sends back when it is free. The last byte also drives the LEDs.uart_rxHoldingregisteruart_txbytewhen free
The holding register lets a byte wait if the transmitter is still finishing the previous one.

The Verilog

uart_echo.v
`timescale 1ns/1ps
// UART echo: every byte received is sent straight back, at 115200 baud 8N1.
// Uses the receiver and transmitter from the UART project unchanged.
module uart_echo #(parameter CLKS_PER_BIT = 868) (   // 100 MHz / 115200
  input  wire clk,
  input  wire rst,
  input  wire rx,
  output wire tx,
  output reg  [7:0] last      // the last byte, for LEDs
);
  wire [7:0] data;
  wire valid, frame_err, busy;
  uart_rx #(.CLKS_PER_BIT(CLKS_PER_BIT)) u_rx (.clk(clk), .rst(rst), .rx(rx), .data(data), .valid(valid), .frame_err(frame_err));
  // A byte normally arrives a whole frame after the last, as the transmitter
  // finishes; if the sender's clock is slightly fast it can arrive a few
  // clocks early, so one byte is held until the transmitter is free.
  reg [7:0] hold = 8'h00;
  reg       pending = 1'b0;
  wire      send = pending && !busy;
  always @(posedge clk) begin
    if (rst) pending <= 1'b0;
    else if (valid && !frame_err) begin hold <= data; pending <= 1'b1; end
    else if (send) pending <= 1'b0;
  end
  uart_tx #(.CLKS_PER_BIT(CLKS_PER_BIT)) u_tx (.clk(clk), .rst(rst), .start(send), .data(hold), .tx(tx), .busy(busy));
  initial last = 8'h00;
  always @(posedge clk) if (valid && !frame_err) last <= data;
endmodule

module top_echo_basys3 (input wire clk, input wire btnC, input wire RsRx, output wire RsTx, output wire [7:0] led);
  uart_echo #(.CLKS_PER_BIT(868)) u (.clk(clk), .rst(btnC), .rx(RsRx), .tx(RsTx), .last(led));
endmodule

// On the Arty the names are from the USB-UART chip's point of view:
// uart_txd_in is the FPGA's input, uart_rxd_out its output.
module top_echo_arty (input wire CLK100MHZ, input wire [0:0] btn, input wire uart_txd_in, output wire uart_rxd_out, output wire [3:0] led);
  /* verilator lint_off UNUSEDSIGNAL */
  wire [7:0] last;               // the low four bits are shown
  /* verilator lint_on UNUSEDSIGNAL */
  uart_echo #(.CLKS_PER_BIT(868)) u (.clk(CLK100MHZ), .rst(btn[0]), .rx(uart_txd_in), .tx(uart_rxd_out), .last(last));
  assign led = last[3:0];
endmodule

// The DE10-Lite has no USB-UART chip: wire a 3.3 V USB-to-serial adapter to
// ARDUINO_IO[0] (FPGA receives) and ARDUINO_IO[1] (FPGA sends), and ground.
module top_echo_de10lite (input wire MAX10_CLK1_50, input wire [0:0] KEY, inout wire [15:0] ARDUINO_IO, output wire [9:0] LEDR);
  wire [7:0] last;
  wire tx;
  uart_echo #(.CLKS_PER_BIT(434)) u (.clk(MAX10_CLK1_50), .rst(~KEY[0]), .rx(ARDUINO_IO[0]), .tx(tx), .last(last));
  assign ARDUINO_IO[1] = tx;
  assign ARDUINO_IO[0] = 1'bz;
  assign ARDUINO_IO[15:2] = 14'bz;
  assign LEDR = {2'b00, last};
endmodule

Why the holding register

A byte normally arrives a whole frame after the last, just as the transmitter finishes. But the receiver reports a byte in the middle of its stop bit, and a sender whose clock runs slightly fast can start the next byte a little early. In the testbench, three of five back-to-back bytes were sent with a stop bit one clock short; without somewhere to wait, such a byte would be dropped. With the holding register, all five came back in order.

Pins

BoardFPGA receives onFPGA sends onDivider
Basys 3RsRx, pin B18RsTx, pin A18868
Arty A7uart_txd_in, pin A9uart_rxd_out, pin D10868
DE10-LiteARDUINO_IO[0]ARDUINO_IO[1]434

The Arty A7's names are from the USB-UART chip's point of view: uart_txd_in is the chip's transmit output, which is the FPGA's input. On the DE10-Lite, connect the adapter's TX to ARDUINO_IO[0], its RX to ARDUINO_IO[1], and ground to ground, and use a 3.3 V adapter only.

Simulation and build results

The testbench sent 0x48, 0x69, 0x21, 0x0D, 0x0A back to back and received all five in order. In Vivado the Basys 3 design used 73 LUTs and 80 flip-flops with 5.753 ns of slack; the Arty A7 used 73 LUTs and 76 flip-flops with 6.058 ns.

Try it

  • Program the board, open a terminal such as PuTTY, screen or the Arduino serial monitor at 115200 baud, 8 data bits, no parity, 1 stop bit.
  • Type: each character should appear once, echoed by the FPGA. Turn off the terminal's local echo, or you'll see each character twice.
  • Watch the LEDs show the last character's bits: 'A' is 0x41, 0100 0001.

Common mistakes

  • Swapping TX and RX, especially with the Arty A7's naming.
  • A divider for the wrong clock: 434 on a 100 MHz board runs at 230400 baud.
  • A 5 V USB-serial adapter on the DE10-Lite, which can damage the FPGA.
  • Forgetting a common ground with an external adapter.

Check your understanding

  • Q1. What divider gives 115200 baud from 100 MHz, and what error results? Answer: 868, giving 115,207 baud, 0.006% fast.
  • Q2. Why might a byte arrive before the transmitter is free? Answer: the receiver reports it mid-stop-bit, and a slightly fast sender can start the next byte early.
  • Q3. Which Arty pin is the FPGA's output? Answer: uart_rxd_out, pin D10.

Beginner FPGA projects

Related

Sources

Last verified

Simulated, linted and built on 17 November 2026; the files are in the site's repository under scripts/fpga.