Brian Silverman | aa9183a | 2013-12-08 10:33:47 -0800 | [diff] [blame^] | 1 | #include "cape/uart_common.h" |
| 2 | #include "cape/uart_common_private.h" |
| 3 | |
| 4 | #define FPCLK 60000000 |
| 5 | |
| 6 | void 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 | } |