Skip to content

Commit aec60f9

Browse files
committed
New revision of Simple UART for FPGA
1 parent a0473ef commit aec60f9

File tree

10 files changed

+732
-977
lines changed

10 files changed

+732
-977
lines changed

README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22

33
Simple UART (Universal Asynchronous Receiver & Transmitter) module for serial communication with an FPGA. The UART module was implemented using VHDL.
44

5-
**The default settings are 115200 baud rate, 8 data bits, 1 stop bit, no parity, disable input data FIFO, 50 MHz system clock.**
5+
**Simple UART for FPGA requires: 1 start bit, 8 data bits, 1 stop bit!**
66

7-
The UART module was tested in hardware. In the near future it will be implemented generic support settings of stop bits. Stay tuned!
7+
The UART module was simulated and tested in hardware.
88

99
**Synthesis resource usage summary:**
1010

11-
Parity | Input FIFO | LE (LUT) | FF | BRAM
12-
--- | --- | --- | --- | ---
13-
none | disable | 72 | 46 | 0
14-
none | enable | 110 | 63 | 1
15-
even/odd | disable | 82 | 49 | 0
16-
even/odd | enable | 121 | 66 | 1
17-
mark/space | disable | 77 | 49 | 0
18-
mark/space | enable | 115 | 66 | 1
11+
Parity | LE (LUT) | FF | BRAM
12+
--- | --- | --- | ---
13+
none | 80 | 55 | 0
14+
even/odd | 91 | 58 | 0
15+
mark/space | 84 | 58 | 0
1916

20-
*Synthesis was performed using Quartus II 64-Bit Version 13.0.1 with default settings for FPGA Altera Cyclone II.*
17+
*Synthesis was performed using Quartus II 64-Bit Version 13.0.1 for FPGA Altera Cyclone II with these settings: 115200 baud rate and 50 MHz system clock .*

example/uart_loopback.vhd

Lines changed: 27 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,67 @@
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
1+
--------------------------------------------------------------------------------
2+
-- PROJECT: SIMPLE UART FOR FPGA
3+
--------------------------------------------------------------------------------
4+
-- MODULE: UART LOOPBACK EXAMPLE TOP MODULE
5+
-- AUTHORS: Jakub Cabal <[email protected]>
6+
-- lICENSE: The MIT License (MIT)
7+
-- WEBSITE: https://github.com/jakubcabal/uart_for_fpga
248
--------------------------------------------------------------------------------
259

2610
library IEEE;
2711
use IEEE.STD_LOGIC_1164.ALL;
2812
use IEEE.NUMERIC_STD.ALL;
29-
13+
14+
-- UART FOR FPGA REQUIRES: 1 START BIT, 8 DATA BITS, 1 STOP BIT!!!
15+
-- OTHER PARAMETERS CAN BE SET USING GENERICS.
16+
3017
entity UART_LOOPBACK is
3118
Generic (
32-
BAUD_RATE : integer := 115200; -- baud rate value
33-
DATA_BITS : integer := 8; -- legal values: 5,6,7,8
34-
PARITY_BIT : string := "none"; -- legal values: "none", "even", "odd", "mark", "space"
3519
CLK_FREQ : integer := 50e6; -- set system clock frequency in Hz
36-
INPUT_FIFO : boolean := True; -- enable input data FIFO
37-
FIFO_DEPTH : integer := 256 -- set depth of input data FIFO
20+
BAUD_RATE : integer := 115200; -- baud rate value
21+
PARITY_BIT : string := "none" -- legal values: "none", "even", "odd", "mark", "space"
3822
);
3923
Port (
4024
CLK : in std_logic; -- system clock
4125
RST_N : in std_logic; -- low active synchronous reset
4226
-- UART INTERFACE
43-
TX_UART : out std_logic;
44-
RX_UART : in std_logic;
27+
UART_TXD : out std_logic;
28+
UART_RXD : in std_logic;
4529
-- DEBUG INTERFACE
4630
BUSY : out std_logic;
47-
FRAME_ERR : out std_logic;
48-
DATA_VLD : out std_logic
31+
FRAME_ERR : out std_logic
4932
);
5033
end UART_LOOPBACK;
5134

5235
architecture FULL of UART_LOOPBACK is
5336

54-
signal data : std_logic_vector(DATA_BITS-1 downto 0);
55-
signal valid : std_logic;
56-
signal reset : std_logic;
57-
signal frame_error : std_logic;
58-
signal send : std_logic;
37+
signal data : std_logic_vector(7 downto 0);
38+
signal valid : std_logic;
39+
signal reset : std_logic;
5940

6041
begin
6142

6243
reset <= not RST_N;
63-
send <= valid WHEN (frame_error = '0') ELSE '0';
64-
44+
6545
uart_i: entity work.UART
6646
generic map (
67-
BAUD_RATE => BAUD_RATE,
68-
DATA_BITS => DATA_BITS,
69-
PARITY_BIT => PARITY_BIT,
7047
CLK_FREQ => CLK_FREQ,
71-
INPUT_FIFO => INPUT_FIFO,
72-
FIFO_DEPTH => FIFO_DEPTH
48+
BAUD_RATE => BAUD_RATE,
49+
PARITY_BIT => PARITY_BIT
7350
)
7451
port map (
7552
CLK => CLK,
7653
RST => reset,
7754
-- UART INTERFACE
78-
TX_UART => TX_UART,
79-
RX_UART => RX_UART,
55+
UART_TXD => UART_TXD,
56+
UART_RXD => UART_RXD,
8057
-- USER DATA OUTPUT INTERFACE
8158
DATA_OUT => data,
8259
DATA_VLD => valid,
83-
FRAME_ERROR => frame_error,
60+
FRAME_ERROR => FRAME_ERR,
8461
-- USER DATA INPUT INTERFACE
8562
DATA_IN => data,
86-
DATA_SEND => send,
63+
DATA_SEND => valid,
8764
BUSY => BUSY
8865
);
8966

90-
frame_err_gen : process (CLK)
91-
begin
92-
if (rising_edge(CLK)) then
93-
if (reset = '1') then
94-
FRAME_ERR <= '0';
95-
elsif (valid = '1') then
96-
FRAME_ERR <= frame_error;
97-
end if;
98-
end if;
99-
end process;
100-
101-
DATA_VLD <= valid;
102-
103-
end FULL;
67+
end FULL;

example/uart_loopback_tb.vhd

Lines changed: 38 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,50 @@
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
1+
--------------------------------------------------------------------------------
2+
-- PROJECT: SIMPLE UART FOR FPGA
3+
--------------------------------------------------------------------------------
4+
-- MODULE: TESTBANCH OF UART LOOPBACK EXAMPLE TOP MODULE
5+
-- AUTHORS: Jakub Cabal <[email protected]>
6+
-- lICENSE: The MIT License (MIT)
7+
-- WEBSITE: https://github.com/jakubcabal/uart_for_fpga
248
--------------------------------------------------------------------------------
259

2610
library IEEE;
2711
use IEEE.STD_LOGIC_1164.ALL;
2812
use IEEE.NUMERIC_STD.ALL;
29-
13+
3014
entity UART_LOOPBACK_TB is
3115
end UART_LOOPBACK_TB;
32-
33-
architecture FULL of UART_LOOPBACK_TB is
34-
35-
signal CLK : std_logic := '0';
36-
signal RST_N : std_logic := '0';
37-
signal tx_uart : std_logic;
38-
signal rx_uart : std_logic := '1';
39-
signal data_vld : std_logic;
40-
signal frame_error : std_logic;
41-
signal busy : std_logic;
42-
43-
constant clk_period : time := 20 ns;
44-
constant uart_period : time := 8696 ns;
16+
17+
architecture FULL of UART_LOOPBACK_TB is
18+
19+
signal CLK : std_logic := '0';
20+
signal RST_N : std_logic := '0';
21+
signal tx_uart : std_logic;
22+
signal rx_uart : std_logic := '1';
23+
signal busy : std_logic;
24+
signal frame_error : std_logic;
25+
26+
constant clk_period : time := 20 ns;
27+
constant uart_period : time := 8680.56 ns;
4528
constant data_value : std_logic_vector(7 downto 0) := "10100111";
4629
constant data_value2 : std_logic_vector(7 downto 0) := "00110110";
47-
30+
4831
begin
49-
32+
5033
utt: entity work.UART_LOOPBACK
5134
generic map (
52-
BAUD_RATE => 115200,
53-
DATA_BITS => 8,
54-
PARITY_BIT => "none",
5535
CLK_FREQ => 50e6,
56-
INPUT_FIFO => True,
57-
FIFO_DEPTH => 256
36+
BAUD_RATE => 115200,
37+
PARITY_BIT => "none"
5838
)
5939
port map (
6040
CLK => CLK,
6141
RST_N => RST_N,
62-
-- UART RS232 INTERFACE
63-
TX_UART => tx_uart,
64-
RX_UART => rx_uart,
42+
-- UART INTERFACE
43+
UART_TXD => tx_uart,
44+
UART_RXD => rx_uart,
6545
-- DEBUG INTERFACE
6646
BUSY => busy,
67-
FRAME_ERR => frame_error,
68-
DATA_VLD => data_vld
47+
FRAME_ERR => frame_error
6948
);
7049

7150
clk_process : process
@@ -81,16 +60,16 @@ begin
8160
rx_uart <= '1';
8261
RST_N <= '0';
8362
wait for 100 ns;
84-
RST_N <= '1';
63+
RST_N <= '1';
8564

8665
wait for uart_period;
8766

8867
rx_uart <= '0'; -- start bit
8968
wait for uart_period;
9069

91-
for i in 0 to 7 loop
92-
rx_uart <= data_value(i); -- data bits
93-
wait for uart_period;
70+
for i in 0 to (data_value'LENGTH-1) loop
71+
rx_uart <= data_value(i); -- data bits
72+
wait for uart_period;
9473
end loop;
9574

9675
rx_uart <= '1'; -- stop bit
@@ -99,9 +78,9 @@ begin
9978
rx_uart <= '0'; -- start bit
10079
wait for uart_period;
10180

102-
for i in 0 to 7 loop
103-
rx_uart <= data_value2(i); -- data bits
104-
wait for uart_period;
81+
for i in 0 to (data_value2'LENGTH-1) loop
82+
rx_uart <= data_value2(i); -- data bits
83+
wait for uart_period;
10584
end loop;
10685

10786
rx_uart <= '1'; -- stop bit
@@ -110,7 +89,7 @@ begin
11089
rx_uart <= '0'; -- start bit
11190
wait for uart_period;
11291

113-
for i in 0 to 7 loop
92+
for i in 0 to (data_value'LENGTH-1) loop
11493
rx_uart <= data_value(i); -- data bits
11594
wait for uart_period;
11695
end loop;
@@ -121,7 +100,7 @@ begin
121100
rx_uart <= '0'; -- start bit
122101
wait for uart_period;
123102

124-
for i in 0 to 7 loop
103+
for i in 0 to (data_value2'LENGTH-1) loop
125104
rx_uart <= data_value2(i); -- data bits
126105
wait for uart_period;
127106
end loop;
@@ -133,4 +112,4 @@ begin
133112

134113
end process;
135114

136-
end FULL;
115+
end FULL;

0 commit comments

Comments
 (0)