6 /* baud rate: BAUDDIV = (UART_CLK / (16 * baud)) */
7 #define UART_CLK 3000000
9 void init_serial(int baud)
13 REG_CR = 0; /* disable UART */
15 /* disable pullups for GPIO 14 & 15 */
16 gpio_pullups(0xc000, 0, PUD_DISABLE);
17 /* select alt0 function for GPIO 14 & 15 */
18 gpio_fsel(14, FSEL_ALT0);
19 gpio_fsel(15, FSEL_ALT0);
21 REG_ICR = 0x7ff; /* clear pending interrupts */
23 /* calculate baud rate divisor */
24 bdiv_fp6 = (UART_CLK << 6) / (16 * baud);
25 REG_IBRD = 1;//(bdiv_fp6 >> 6) & 0xffff; /* 16 bits integer part */
26 REG_FBRD = 40;//bdiv_fp6 & 0x3f; /* 6 bits fractional precision */
28 /* line control: fifo enable, 8n1 */
29 REG_LCRH = LCRH_FIFOEN | LCRH_8BITS;
30 /* mask all interrupts */
31 REG_IMSC = I_CTS | I_RX | I_TX | I_RTIME | I_FRM | I_PAR | I_BRK | I_OVR;
33 /* enable UART RX&TX */
34 REG_CR = CR_UARTEN | CR_TXEN | CR_RXEN;
37 void ser_putchar(int c)
39 while(REG_FR & FR_TXFF);
45 while(REG_FR & FR_RXFE);
49 void ser_printstr(const char *s)