(2 << SYSCTL_RCC2_SYSDIV2_S);
SYSCTL_RCC2_R = rcc2;
+ // Enable UART and GPIO Port A clocks
+ SYSCTL_RCGCUART_R = 0x1;
+ SYSCTL_RCGCGPIO_R |= 0x1;
+
+ // Choose UART for PA[1:0], and set PA1 to source current
+ GPIO_PORTA_AFSEL_R = 0x03;
+ GPIO_PORTA_DR2R_R = 0x03;
+ GPIO_PORTA_PCTL_R = 0x11;
+
+ // Set 115200bps
+ UART0_IBRD_R = 43;
+ UART0_FBRD_R = 26;
+ UART0_LCRH_R = UART_LCRH_WLEN_8;
+
+ // Enable interrupts
+ UART0_IM_R |= UART_IM_RXIM;
+ NVIC_EN0_R = NVIC_EN0_INT5;
+
+ // Go!
+ UART0_CTL_R |= UART_CTL_UARTEN;
+
// infinite loop
for (;;) {
asm("wfi");
asm("");
}
}
+
+__attribute__((isr))
+void uart0_isr() {
+ // Receive data, increment by 1 and send it back through the UART
+ int data = UART0_DR_R & 0xFF;
+ data = (data + 1) & 0xFF;
+ UART0_DR_R = data;
+}