Merge pull request #1839 from cesanta/stm32uart

Fix wrong reference to prescaler
This commit is contained in:
Sergey Lyubka 2022-11-09 09:24:24 +00:00 committed by GitHub
commit eed25f23f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -175,10 +175,9 @@ static inline void uart_init(struct uart *uart, unsigned long baud) {
gpio_init(tx, GPIO_MODE_AF, GPIO_OTYPE_PUSH_PULL, GPIO_SPEED_HIGH, 0, af);
gpio_init(rx, GPIO_MODE_AF, GPIO_OTYPE_PUSH_PULL, GPIO_SPEED_HIGH, 0, af);
uart->CR1 = 0; // Disable this UART
uart->BRR = FREQ / APB2_PRE / baud; // Baud rate x16 (with 4dp), "4" is APBx
// prescaler, different from APBx_PRE
// TODO(): make this configurable ?
uart->CR1 = 0; // Disable this UART
uart->BRR = FREQ / 4 / baud; // Baud rate, "4" is APBx prescaler, different from APBx_PRE
// TODO(): make this configurable ?
uart->CR1 |= BIT(13) | BIT(2) | BIT(3); // Set UE, RE, TE
}
static inline void uart_write_byte(struct uart *uart, uint8_t byte) {