You are on page 1of 4

UART Controller with FIFO Buffer Function Based

on APB Bus

Jiajing Li1, Lixin Yang2, Xi Feng2, Yanhui Xing1, Zhijie Chen1, Peiyuan Wan1*
1
Beijing Embedded System Key Lab, College of Microelectronics, Faculty of Information Technology
2022 IEEE 16th International Conference on Anti-counterfeiting, Security, and Identification (ASID) | 978-1-6654-9067-2/22/$31.00 ©2022 IEEE | DOI: 10.1109/ASID56930.2022.9996035

Beijing University of Technology, Beijing, China


2
Beijing Smart-chip Microelectronics Technology Co., Ltd. Beijing 100192, China
*
wanpy@bjut.edu.cn

Abstract—This paper proposes a UART communication long-distance communication interface, UART has been
interface based on APB bus with asynchronous FIFO buffer. widely used in digital systems and is a very important module.
Based on this design, the UART controller can be flexibly The modules of the UART are designed with a modular
configured through the AMBA bus to support baud rate approach, including the APB bus interface module, the
modification, transmission bits, configurability of parity mode register management module, the synchronization module, and
and other functions. And the asynchronous FIFO buffer function the clock control module, as well as FIFO control module,
is added for communication between high-speed devices and low- filter module, sending and receiving module, etc. This paper
speed UART devices. During data transmission, the FIFO can firstly introduces the UART transmission protocol and divides
buffer the data and the situation that the UART device occupies
the internal structure of the UART module in detail according
the APB bus and the processor for a long time can be avoided,
improving the data transmission efficiency. The design is based
to the protocol. Then the registers and SPI state machine of the
on the UART transmission protocol. the finite state machine interface module are designed in detail. Finally, through RTL
method is used to control the the transmission timing of UART simulation and FPGA verification, the UART communication
interface, and RTL simulation and FPGA verification are carried can be implemented correctly.
out, showing good flexibility of this design.
II. DESIGN SCHEME
Keywords—UART; APB bus; FIFO; Configurable; FPGA
A. UART and APB Transmission Process
I. INTRODUCTION The UART has one line for receiving data and the other
UART is a universal asynchronous transceiver for serial line for sending data. When the signal line is idle and does not
data communication and is used for asynchronous transmit data, it is in a high-level logic “1” state, indicating that
communication. The bus has bidirectional communication, there is no data transmission on the current line. Then the
which can realize full-duplex transmission and reception. It master device first sends a logic “0” signal, indicating the
can receive data from peripheral devices and convert between beginning of the transmission character. Then send data bits,
serial communication and parallel communication. Compared which can be 5~8 logical “0” or “1”. Such as ASCII code (7
with IIC and SPI communication protocols, UART can realize bits), extended BCD code (8 bits) in most cases using little
full-duplex asynchronous transmission with only two wires, endian transmission. Then the data bit will be followed by a
which is more resource-saving and good at long-distance parity bit. After the data bit is added with this bit, the number
transmission [1,2]. It is currently widely used in MCU multi- of digits of “1” should be an even number (even parity) or an
computer communication and various external modules for odd number (odd parity). Finally, the stop bit is sent, which is
cache data transmission. The UART protocol stipulates that the end of a character data such as 1-bit, 1.5-bit, 2-bit high
both receiving and sending data should be transmitted on a level. The data transmission timing of the UART transmission
separate line, without the need for a clock line. The protocol is shown in Fig.1.
transmission rate needs to be determined by the baud rate, but
the existing UART design functions are not comprehensive
enough. The baud rate and frame length of some UART 0 1 1
interfaces cannot be flexibly configured, and the application
1 LSB Idle
scenario is single. Therefore, in order to provide the maximum MSB Parity Stop
Start bit bit bit
flexibility for SOC design and FPGA development, the bit
DATA
configurable UART interface based on APB interface
proposed in this paper solves the above problems. In order to
improve the efficiency of sending and receiving transmission,
a data buffer is provided and a FIFO module is added. As a Figure 1. UART transmission timing

___________________________________
978-1-6654-7735-2/22/$31.00 ©2022 IEEE
1
Authorized licensed use limited to: Institut Teknologi Sepuluh Nopember. Downloaded on March 09,2023 at 01:44:42 UTC from IEEE Xplore. Restrictions apply.
difference is that PWRITE changes to low level during the
T1 T2 T3 T4 T5 SETUP cycle at the beginning of the transfer, indicating the
read transfer state. Secondly, during the ENABLE cycle, the
PCLK slave peripherals must provide valid data in advance to ensure
that the rising edge of the clock at the end of the ENABLE
PADDR ADDR
cycle can be captured, so that the master can read the correct
data [3,4].
PWRITE
B. Block Diagram
PSEL According to the transmission process and related
requirements of the UART protocol, the internal structure
PENABLE
design of the interface module is shown in Fig.4. The APB bus
controls the read/write of the entire UART internal registers.
PWDATA DATA The APB slave is the connection bridge between the UART
interface and the APB bus, and it is responsible for exchanging
Figure 2. APB write transfer data with the CPU through the APB bus [5]. The output of the
APB slave includes FIFO read and write signals and data
stream signals, which are responsible for writing the data from
T1 T2 T3 T4 T5 the APB bus into the FIFO and reading data from the FIFO to
the processor. The register control module is responsible for
PCLK latching the address on the APB and controlling the
configuration baud rate and other information. At the same
PADDR ADDR time, the CPU can operate the corresponding control register
and status register through the APB bus. Serial reception or
PWRITE transmission of data is realized by the receive shift register
RX_shifter or the transmit shift register TX_shifter. A filter is a
PSEL filter circuit module for the input signal. When data is input to
the UART port, glitches may appear. If data is not filtered, the
received signal may appear metastable. If data is used directly,
PENABLE
it may cause errors in data transmission results [6].
PRDATA DATA

APB Tx_FIFO Tx_Shifter TXD


Figure 3. APB read transfer

The basic transfer timing of APB bus write operation is Slave


shown in Fig.2. The rising edge of the clock PCLK during
write transfer is valid. The first cycle of T1~T2 is idle state; the CPU
Baud Rate Control Filter RXD
second cycle of T2~T3 is PSEL=1 and PENABLE=0 is the
SETUP state cycle; the third cycle of T3~T4 is PSEL=1 and
PENABLE=1 is the ENABLE state cycle, In the fourth cycle
of T4~T5, PSEL=0 and PENABLE=0 return to IDLE state. At
Rx_FIFO Rx_Shifter
the beginning of the write transfer, in other words, after the
rising edge of T2 in the figure, the write signal PWRITE, the
write address PADDR, the write data PWDATA and the chip Regilter
select signal PSEL all change to valid states. When the rising Control
edge of the next cycle comes, that is, T3 in the figure, the
Figure 4. UART architecture diagram
enable signal PENABLE Valid, and during the entire ENABLE
cycle, PADDR, PWRITE, PWDATA and PSEL remain stable
C. UART Register
and unchanged. Write transfer is performed during this cycle.
After this cycle ends, PENABLE is invalid, and a write transfer TABLE I. THE UART STATUS REGISTER DESCRIPTION
is completed. After the transmission is completed, if the device
does not continue to transmit, the PSEL becomes invalid, and Name Width Distribution
PADDR, PWRITE and PWDATA have no effect on the 2’b00:115200 bit/s
system transmission in the IDLE state, remaining unchanged BAUD_SEL 2bit
2’b01:9800 bit/s
until the next transmission in order to reduce power 2’b10:4800 bit/s
2’b11:2400 bit/s
consumption. The basic transfer timing of the APB bus read
operation is shown in Fig.3, and the read transfer process clock 2’b00:NO PARITY
is also triggered by the rising edge. In the process of APB read PARITY_MODE 2bit 2’b01:ODD PARITY
2’b10:EVEN PARITY
operation, the timings of PADDR, PWRITE, PSEL, and
PENABLE are similar to the timing of write operations. The

2
Authorized licensed use limited to: Institut Teknologi Sepuluh Nopember. Downloaded on March 09,2023 at 01:44:42 UTC from IEEE Xplore. Restrictions apply.
Name Width Distribution D. Design of State Machine
2’b00:5bit The UART module designed in this paper sends and
2’b01:6bit
DATA_LENGTH 2bit
2’b10:7bit
receives data through the state machine. When the UART
2’b11:8bit module sends data, the state machine is shown in Fig.5. After
Number of stop bit the circuit is reset, it first enters the IDLE state. When the
STOP_BIT 1bit 0:one stop bit UART starts to work, APB SLAVE will configure the
1:two stop bits corresponding working mode, such as the size of the baud rate,
Start bit of data transmission the mode selection of parity, the length of the data frame and
MSB_SEL 1bit 0:MSB stop bit, and the start bit of data transmission – MSB or LSB.
1:LSB When it is detected that the FIFO transmit data buffer is not
High indicates that the transmission empty, it goes to the START state. When the master sends a
TX_FIFO_FULL 1bit
buffer is full
low-level start bit, it enters the WAIT state, and then starts to
High indicates that the transmission send valid data bits. After different time intervals according to
TX_FIFO_EMPTY 1bit
buffer is empty the selection of the baud rate, it enters the SHIFT state,
High indicates that the receive sending a shift signal, and then enters the next WAIT state
RX_FIFO_FULL 1bit
buffer is full
again, sending the next data bit. According to the configured
High indicates that the receive
RX_FIFO_EMPTY 1bit
buffer is empty
data frame length, the data bits to send can be decided. After
the valid data is sent, it enters the PARITY state, sending the
parity bit according to the configured mode, and finally switch
to the STOP state, sending Stop bit, and thus completing the
IDLE transmission process of a data frame [7]. If it is detected that
the FIFO transmission data buffer is not empty at this time, it
will jump from the STOP state to the START state, otherwise
STOP it will jump to the IDLE state.
START When the UART module receives data, the state machine
is shown in Fig.6. Similar to the sending operation, the
corresponding working mode needs to be configured first. The
default is the IDLE state. When a low-level signal is detected,
PARITY it will switch to the START state. According to the baud rate
WAIT setting, when counting to the middle of the received bit unit, if
it is detected to be at a low level, it will be determined as a
start bit, and the state machine alternately enters the WAIT
state and the SAMPLE state to receive the corresponding valid
SHIFT data bits; then enters the PARITY state to receive the parity bit;
and finally enters the STOP state to receive the stop bit to
complete the entire receiving process.
Figure 5. UART sending state machine III. SIMULATION AND VERIFICATION
This design is implemented in Verilog HDL and uses RTL
simulation and FPGA to verify the design. In the RTL
IDLE simulation, the UART module registers are configured by
writing Testbench, which is the work of the UART module.
According to the simulation results of the IIC module, the
STOP
correctness of the IIC module can be verified. Logic function
START verification only verifies the logic implemented by the
hardware description language, and does not indicate whether
the actual circuit is correct. Therefore, after the RTL-level
verification is completed, in order to ensure that the functions
PARITY of the described circuit are completely correct, we adopt the
FPGA verification method. In the FPGA verification, the
WAIT designed UART is imported into the FPGA and verified with
an external UART device to verify the correctness of the
SAMPLE design [8-11].
A. RTL Simulation Verification
Figure 6. UART receive state machine After completing the RTL design of the UART module,
RTL simulation is performedfor the UART module design.

3
Authorized licensed use limited to: Institut Teknologi Sepuluh Nopember. Downloaded on March 09,2023 at 01:44:42 UTC from IEEE Xplore. Restrictions apply.
configured, and the communication between the high-speed
device and the low-speed UART device can be realized
through the FIFO buffer. During data transmission, the FIFO
can buffer the data synchronously, and at the same time, the
situation that UART device occupies the APB bus and the
processor for a long time can be avoided, improving the data
transmission efficiency. This design adopts finite state
machine design method and Verilog HDL for logic
implementation. Finally, through RTL simulation and FPGA
verification, the designed UART can communicate correctly
with other UART devices.
Figure 7. UART transmission simulation waveform
ACKNOWLEDGMENT
This paper is funded by the project of the State Grid
Corporation of China in 2020,: Research on cache data
consistency technology of main control chip in intelligent
distribution terminal under Grant 5700-202041395A-0-0-00.
REFERENCES
[1] S. Harutyunyan, T. Kaplanyan, A. Kirakosyan and A. Momjyan, "Design
and verification of autoconfigurable UART controller," 2020 IEEE
40th International Conference on Electronics and Nanotechnology
(ELNANO), pp. 347-350, 2020.
[2] U. Nanda and S. K. Pattnaik, "Universal asynchronous receiver and
transmitter (UART)," 2016 3rd International Conference on Advanced
Computing and Communication Systems (ICACCS), pp. 1-5, 2016.
[3] A. Paunikar, R. Gavankar, N. Umarikar and K. Sivasankaran, "Design
and implementation of area efficient, low power AMBA-APB Bridge for
SoC," 2014 International Conference on Green Computing
Communication and Electrical Engineering (ICGCCEE), pp. 1-6, 2014.
[4] M. Roopa, R. M. Vani and P. V. Hunagund, "UART controller as
AMBA APB slave," National Conference on Challenges in Research &
Technology in the Coming Decades (CRT 2013), pp. 1-6, 2013.
Figure 8. UART FPGA verification diagram
[5] Y. Liu et al., "Design and verification of UART circuit of SoC based on
AMBA bus," 2020 7th International Conference on Information Science
By adding a testbench to the UART module, including and Control Engineering (ICISCE), pp. 2370-2374, 2020.
setting the UART baud rate, data frame length and parity [6] N. Anand, G. Joseph, S. S. Oommen and R. Dhanabal, "Design and
check mode, etc, the IIC module can realize the normal implementation of a high speed serial peripheral interface," 2014
communication function, shown in Fig.7, including the International Conference on Advances in Electrical Engineering
transmission start signal, the transmission of valid data bits, (ICAEE), pp. 1-3, 2014.
parity bits and stop bits. It proves the correctness of the [7] B. Qu and D.W. Fan, "Design of remote data monitoring and
function of the UART module. recording system based on ARM," 2010 2nd International Conference
on Industrial and Information Systems, pp. 252-255, 2010.
B. FPGA Verification [8] A. Roychoudhury, T. Mitra and S. R. Karri, "Using formal techniques to
debug the AMBA system-on-chip bus protocol," 2003 Design,
The design is verified by FPGA. The RTL is imported into Automation and Test in Europe Conference and Exhibition, pp. 828-833,
ISE for processing, and the generated BIT file is imported into 2003.
the FPGA test board. The output pins of the FPGA is tested, [9] B. Jeevan, P. Sahithi, P. Samskruthi and K. Sivani, "Simulation and
and the results are captured by an oscilloscope as shown in synthesis of UART through FPGA Zedboard for IoT applications," 2022
Fig.8, indicating that the UART module designed in this paper International Conference on Advances in Computing, Communication
functions normally. and Applied Informatics (ACCAI), pp. 1-7, 2022.
[10] P. S. Mutha and Y. M. Vaidya, "FPGA reconfiguration using UART and
IV. CONCLUSION SPI flash," 2017 International Conference on Trends in Electronics and
Informatics (ICEI), pp. 59-63, 2017.
This paper designs and implements a UART [11] A. K. Gupta, A. Raman, N. Kumar and R. Ranjan, "Design and
communication protocol equipped with FIFO buffer function implementation of high-speed universal asynchronous receiver and
based on APB bus. Through the configuration register, the transmitter (UART)," 2020 7th International Conference on Signal
baud rate, frame length and parity mode can be flexibly Processing and Integrated Networks (SPIN), pp. 295-300, 2020.

4
Authorized licensed use limited to: Institut Teknologi Sepuluh Nopember. Downloaded on March 09,2023 at 01:44:42 UTC from IEEE Xplore. Restrictions apply.

You might also like