Skip to content

Commit 3e490cf

Browse files
committed
Add UART loopback example
1 parent 3f89283 commit 3e490cf

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

example/uart_loopback.vhd

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
-- The MIT License (MIT)
2+
--
3+
-- Copyright (c) 2015 Jakub Cabal
4+
--
5+
-- Permission is hereby granted, free of charge, to any person obtaining a copy
6+
-- of this software and associated documentation files (the "Software"), to deal
7+
-- in the Software without restriction, including without limitation the rights
8+
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
-- copies of the Software, and to permit persons to whom the Software is
10+
-- furnished to do so, subject to the following conditions:
11+
--
12+
-- The above copyright notice and this permission notice shall be included in
13+
-- all copies or substantial portions of the Software.
14+
--
15+
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
-- SOFTWARE.
22+
--
23+
-- Website: https://github.com/jakubcabal/uart_for_fpga
24+
--------------------------------------------------------------------------------
25+
26+
library IEEE;
27+
use IEEE.STD_LOGIC_1164.ALL;
28+
use IEEE.NUMERIC_STD.ALL;
29+
30+
entity UART_LOOPBACK is
31+
Generic (
32+
BAUD_RATE : integer := 9600;
33+
DATA_BITS : integer := 8;
34+
CLK_FREQ : integer := 50e6;
35+
INPUT_FIFO : boolean := True;
36+
FIFO_DEPTH : integer := 256
37+
);
38+
Port (
39+
CLK : in std_logic; -- system clock
40+
RST_N : in std_logic; -- low active synchronous reset
41+
-- UART INTERFACE
42+
TX_UART : out std_logic;
43+
RX_UART : in std_logic
44+
);
45+
end UART_LOOPBACK;
46+
47+
architecture FULL of UART_LOOPBACK is
48+
49+
-- signals
50+
signal data : std_logic_vector(DATA_BITS-1 downto 0);
51+
signal valid : std_logic;
52+
signal reset : std_logic;
53+
54+
begin
55+
56+
reset <= not RST_N;
57+
58+
uart_i: entity work.UART
59+
generic map (
60+
BAUD_RATE => BAUD_RATE, -- baud rate value, default is 9600
61+
DATA_BITS => DATA_BITS, -- legal values: 5,6,7,8, default is 8 dat bits
62+
CLK_FREQ => CLK_FREQ, -- set system clock frequency in Hz, default is 50 MHz
63+
INPUT_FIFO => INPUT_FIFO, -- enable input data FIFO, default is disable
64+
FIFO_DEPTH => FIFO_DEPTH -- set depth of input data FIFO, default is 256 items
65+
)
66+
port map (
67+
CLK => CLK, -- system clock
68+
RST => reset, -- high active synchronous reset
69+
-- UART INTERFACE
70+
TX_UART => TX_UART,
71+
RX_UART => RX_UART,
72+
-- USER DATA OUTPUT INTERFACE
73+
DATA_OUT => data,
74+
DATA_VLD => valid, -- when DATA_VLD = 1, data on DATA_OUT are valid
75+
-- USER DATA INPUT INTERFACE
76+
DATA_IN => data,
77+
DATA_SEND => valid, -- when DATA_SEND = 1, data on DATA_IN will be transmit
78+
BUSY => open -- when BUSY = 1, you must not set DATA_SEND to 1
79+
);
80+
81+
end FULL;

0 commit comments

Comments
 (0)