blob: 3b70764df14416688931c2e0876e7465d6855db8 [file] [log] [blame]
Brian Silvermanaa9183a2013-12-08 10:33:47 -08001#include "cape/uart_common.h"
2#include "cape/uart_common_private.h"
3
4#define FPCLK 60000000
5
6void uart_common_configure(int baud) {
7 // baud = 60MHz / (8 * (2 - OVER8) * (mantissa / fraction))
8 int fraction = 8; // the biggest it can be with OVER8=0
9 int mantissa = FPCLK * (16 /* 8 * (2 - OVER8) */ / fraction) / baud;
10 UART->BRR = (mantissa << 4) | fraction;
11 UART->CR1 = USART_CR1_UE /* enable it */ |
12 USART_CR1_M /* 9th bit for the parity */ |
13 USART_CR1_PCE /* enable parity (even by default) */;
14}