Configure the UART sufficiently to actually get the message out.
This commit is contained in:
41
main.c
41
main.c
@@ -1,11 +1,43 @@
|
|||||||
|
|
||||||
#define U0THR (*((volatile unsigned char *) 0xE000C000)) /* UART0 transmitter holding register */
|
#define UARTBASE 0xE000C000
|
||||||
#define U0LSR (*((volatile unsigned char *) 0xE000C014)) /* UART0 line status register */
|
|
||||||
#define U0THRE ((U0LSR & (1<<5))) /* UART0 transmitter holding register is empty */
|
#define RBR 0x00
|
||||||
|
#define THR 0x00
|
||||||
|
#define DLL 0x00
|
||||||
|
#define DLM 0x04
|
||||||
|
#define IER 0x04
|
||||||
|
#define IIR 0x08
|
||||||
|
#define FCR 0x08
|
||||||
|
|
||||||
|
#define LCR 0x0c
|
||||||
|
#define LSR 0x14
|
||||||
|
#define SCR 0x1c
|
||||||
|
#define ACR 0x20
|
||||||
|
#define FDR 0x28
|
||||||
|
#define TER 0x30
|
||||||
|
|
||||||
|
#define REG(x) (((volatile unsigned char *)UARTBASE)[x])
|
||||||
|
|
||||||
|
#define U0THRE ((REG(LSR) & (1<<5))) /* UART0 transmitter holding register is empty */
|
||||||
|
|
||||||
|
#define PINSEL0 (*((volatile unsigned char *) 0xE002C000))
|
||||||
|
|
||||||
|
void init_uart(void)
|
||||||
|
{
|
||||||
|
REG(FDR) = 0x10; /* DivAddVal = 0, MulVal = 1 */
|
||||||
|
|
||||||
|
REG(LCR) = 0x80;
|
||||||
|
REG(DLM) = 0x00;
|
||||||
|
REG(DLL) = 0x08; /* 14745600 / (16*115200) */
|
||||||
|
REG(LCR) = 0x13;
|
||||||
|
REG(FCR) = 0x07;
|
||||||
|
|
||||||
|
PINSEL0 = 0x00000005; /* P0.0 and P0.1 assigned to UART */
|
||||||
|
}
|
||||||
|
|
||||||
void putch(char c) {
|
void putch(char c) {
|
||||||
while (!U0THRE);
|
while (!U0THRE);
|
||||||
U0THR = c;
|
REG(THR) = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void putstr(char *s) {
|
void putstr(char *s) {
|
||||||
@@ -13,6 +45,7 @@ void putstr(char *s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
|
init_uart();
|
||||||
putstr("Your entire life has been a mathematical error... a mathematical error I'm about to correct!\n");
|
putstr("Your entire life has been a mathematical error... a mathematical error I'm about to correct!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user