0% found this document useful (0 votes)
76 views12 pages

qemu-uart

Uploaded by

lakituen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views12 pages

qemu-uart

Uploaded by

lakituen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

UART driver for Serial I/O on the Versatile

board

The ARM Versatile board supports four PL011 UART


devices for serial I/O .
Each UART device has a base address in the system
memory map.
The base addresses of the 4 UARTs are
UART0: 0x101F1000
UART1: 0x101F2000
UART2: 0x101F3000
UART3: 0x10090000
UART Functional diagram
UART driver for Serial I/O

Each UART has a number of registers, which are


byte offsets from the base address. The following
lists the most important UART registers.

0x00 UARTDR - Data register: for read/write chars


0x18 UARTFR - Flag register: TxEmpty, RxFull, etc.
0x24 UARIBRD - Baud rate register: set baud rate
0x2C UARTLCR - Line control register: bits per char,
parity, etc.
0x38 UARTIMIS - Interrupt mask register for TX and
RX interrupts
PL011 registers from technical Ref manual
Initialise the UART

(1) Write a divisor value to the baud rate register for


a desired baud rate.

The ARM PL011 technical reference manual lists the


following integer divisor values (based on 7.38 MHz
UART clock) for the commonly used baud rates:
0x4 = 1152000
OxC = 38400
Ox18 = 192000
0x20 = 14400
0x30 = 9600
Initialise the UART

(2). Write to Line Control register to specify the


number of bits per char and parity, e.g. 8 bits per
char with no parity.

(3). Write to Interrupt Mask register to


enable/disable RX and TX interrupts
Initialise the UART

When using the emulated ARM Versatilepb board, it


seems that QEMU automatically uses default values
for both baud rate and line control parameters,
making steps (1) and (2) either optional or
unnecessary.

For the emulated Versatilepb board, all we need to


do is to program the Interrupt Mask register (if
using interrupts) and check the Flag register during
serial 1/0.
UART Data register

0x00 UARTDR - Data register: for read/write chars

To begin with, we shall implement the UART I/O by


polling, which only checks the Flag status register.

We read from the data register when the flag


register indicates that there is data available

We write to the data register when the flag register


indicates that there is no to be trasmitted
Flag Register

7 6 5 4 3
TXFE RXFF TXFF RXFE BUSY

Where TXFE= Tx buffer empty


RXFF=Rx buffer full
TXFF=Tx buffer full
RXFE = Rx buffer empty
BUSY = device is busy
UART Flag register
Read a char from the uart Data Register

RXFE Receive FIFO empty


- the RXFE bit is set when the receive FIFO is empty.

int ugetc(UART *up)


{
// loop while the receive buffer is empty
while( (up->FR) & 0x10);

// read the char when the RXFE bit goes to 0


return (char)((up->DR) & 0xFF);
}
Write a char to UART Data Register

int uputc(UART *up, char c)


{
// loop while the transmit buffer is full
while((up->FR & 0x20));
// send the char
(up->DR) = (int)c;
}

You might also like