diff --git a/ion/src/device/console.cpp b/ion/src/device/console.cpp index c18b033fb..c53e3f811 100644 --- a/ion/src/device/console.cpp +++ b/ion/src/device/console.cpp @@ -27,7 +27,7 @@ namespace Console { namespace Device { void init() { - RCC.APB2ENR()->setUSART1EN(true); + RCC.APB1ENR()->setUSART3EN(true); for(const GPIOPin & g : Pins) { g.group().MODER()->setMode(g.pin(), GPIO::MODER::Mode::AlternateFunction); @@ -39,17 +39,17 @@ void init() { UARTPort.CR1()->setRE(true); /* We need to set the baud rate of the UART port. - * This is set relative to the APB2 clock, which runs at 96 MHz. + * This is set relative to the APB1 clock, which runs at 48 MHz. * * The baud rate is set by the following equation: - * BaudRate = fAPB2/(16*USARTDIV), where USARTDIV is a divider. - * In other words, USARDFIV = fAPB2/(16*BaudRate). All frequencies in Hz. + * BaudRate = fAPB1/(16*USARTDIV), where USARTDIV is a divider. + * In other words, USARDFIV = fAPB1/(16*BaudRate). All frequencies in Hz. * - * In our case, fAPB2 = 96 MHz, so USARTDIV = 52.08333 - * DIV_MANTISSA = 52 - * DIV_FRAC = 16*0.083333 = 1.33 = 1 + * In our case, fAPB1 = 48 MHz, so USARTDIV = 26.0416667 + * DIV_MANTISSA = 26 + * DIV_FRAC = 16*0.0416667 = 1 */ - UARTPort.BRR()->setDIV_MANTISSA(52); + UARTPort.BRR()->setDIV_MANTISSA(26); UARTPort.BRR()->setDIV_FRAC(1); } diff --git a/ion/src/device/console.h b/ion/src/device/console.h index 7e0942d01..ece212142 100644 --- a/ion/src/device/console.h +++ b/ion/src/device/console.h @@ -10,18 +10,15 @@ namespace Device { /* Pin | Role | Mode * -----+-------------------+-------------------- - * PC11 | UART1 RX | Alternate Function - * PD8 | UART1 TX | Alternate Function + * PC11 | UART3 RX | Alternate Function + * PD8 | UART3 TX | Alternate Function */ void init(); void shutdown(); -//constexpr USART UARTPort = USART(3); -//constexpr static GPIOPin Pins[] = { GPIOPin(GPIOC, 11), GPIOPin(GPIOD, 8) }; - -constexpr USART UARTPort = USART(1); -constexpr static GPIOPin Pins[] = { GPIOPin(GPIOB, 3), GPIOPin(GPIOB, 6) }; +constexpr USART UARTPort = USART(3); +constexpr static GPIOPin Pins[] = { GPIOPin(GPIOC, 11), GPIOPin(GPIOD, 8) }; void sendChar(char c); char recvChar(); diff --git a/ion/src/device/regs/rcc.h b/ion/src/device/regs/rcc.h index 04eb49f8d..5db37c773 100644 --- a/ion/src/device/regs/rcc.h +++ b/ion/src/device/regs/rcc.h @@ -75,6 +75,7 @@ public: public: REGS_BOOL_FIELD(TIM3EN, 1); REGS_BOOL_FIELD(SPI3EN, 15); + REGS_BOOL_FIELD(USART3EN, 18); REGS_BOOL_FIELD(PWREN, 28); };