Skip to content

[U(S)ART] hardware flow control support #1634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion libraries/SrcWrapper/src/stm32/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ void uart_init(serial_t *obj, uint32_t baudrate, uint32_t databits, uint32_t par
/* Determine the U(S)ART peripheral to use (USART1, USART2, ...) */
USART_TypeDef *uart_tx = pinmap_peripheral(obj->pin_tx, PinMap_UART_TX);
USART_TypeDef *uart_rx = pinmap_peripheral(obj->pin_rx, PinMap_UART_RX);
USART_TypeDef *uart_rts = pinmap_peripheral(obj->pin_rts, PinMap_UART_RTS);
USART_TypeDef *uart_cts = pinmap_peripheral(obj->pin_cts, PinMap_UART_CTS);

/* Pin Tx must not be NP */
if (uart_tx == NP) {
Expand Down Expand Up @@ -290,6 +292,17 @@ void uart_init(serial_t *obj, uint32_t baudrate, uint32_t databits, uint32_t par
pinmap_pinout(obj->pin_rx, PinMap_UART_RX);
}

/* Configure flow control */
uint32_t flow_control = UART_HWCONTROL_NONE;
if (uart_rts != NP) {
flow_control |= UART_HWCONTROL_RTS;
pinmap_pinout(obj->pin_rts, PinMap_UART_RTS);
}
if (uart_cts != NP) {
flow_control |= UART_HWCONTROL_CTS;
pinmap_pinout(obj->pin_cts, PinMap_UART_CTS);
}

/* Configure uart */
uart_handlers[obj->index] = huart;
huart->Instance = (USART_TypeDef *)(obj->uart);
Expand All @@ -298,7 +311,7 @@ void uart_init(serial_t *obj, uint32_t baudrate, uint32_t databits, uint32_t par
huart->Init.StopBits = stopbits;
huart->Init.Parity = parity;
huart->Init.Mode = UART_MODE_TX_RX;
huart->Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart->Init.HwFlowCtl = flow_control;
huart->Init.OverSampling = UART_OVERSAMPLING_16;
#if !defined(STM32F1xx) && !defined(STM32F2xx) && !defined(STM32F4xx)\
&& !defined(STM32L1xx)
Expand Down