37#include "mcu_periph/uart_arch.h"
46#ifndef UART_THREAD_STACK_SIZE
47#define UART_THREAD_STACK_SIZE 512
60#define SERIAL_INIT_NULL { NULL, NULL, NULL, NULL, NULL, 0, 0 }
74 p->rx_buf[
p->rx_insert_idx] = c;
76 if (temp !=
p->rx_extract_idx) {
77 p->rx_insert_idx = temp;
94 while (
p->tx_insert_idx !=
p->tx_extract_idx) {
95#if USE_UART_SOFT_FLOW_CONTROL
96 if (init_struct->cts_port != 0) {
98 while (
gpio_get(init_struct->cts_port, init_struct->cts_pin) == 1) ;
101 uint8_t data =
p->tx_buf[
p->tx_extract_idx];
107#if USE_UART_SOFT_FLOW_CONTROL
108 if (init_struct->cts_port != 0) {
114 p->tx_running =
false;
120#define UART1_BAUD SERIAL_DEFAULT_BITRATE
125#define USE_UART1_TX TRUE
128#define USE_UART1_RX TRUE
136#define UART1_CR2 USART_CR2_STOP1_BITS
191#if USE_UART1_TX && defined UART1_GPIO_PORT_TX
194#if USE_UART1_RX && defined UART1_GPIO_PORT_RX
225#define UART2_BAUD SERIAL_DEFAULT_BITRATE
230#define USE_UART2_TX TRUE
233#define USE_UART2_RX TRUE
238#ifndef UART2_HW_FLOW_CONTROL
239#define UART2_HW_FLOW_CONTROL FALSE
242#if UART2_HW_FLOW_CONTROL && defined(UART2_CR3)
243#warning "UART2_CR3 reset to your value, HW flow control not enabled! You may want to set USART_CR3_CTSE | USART_CR3_RTSE yourself."
251#define UART2_CR2 USART_CR2_STOP1_BITS
255#if UART2_HW_FLOW_CONTROL
256#define UART2_CR3 USART_CR3_CTSE | USART_CR3_RTSE
310#if USE_UART2_TX && defined UART2_GPIO_PORT_TX
313#if USE_UART2_RX && defined UART2_GPIO_PORT_RX
343#define UART3_BAUD SERIAL_DEFAULT_BITRATE
348#define USE_UART3_TX TRUE
351#define USE_UART3_RX TRUE
359#define UART3_CR2 USART_CR2_STOP1_BITS
414#if USE_UART3_TX && defined UART3_GPIO_PORT_TX
417#if USE_UART3_RX && defined UART3_GPIO_PORT_RX
447#define UART4_BAUD SERIAL_DEFAULT_BITRATE
452#define USE_UART4_TX TRUE
455#define USE_UART4_RX TRUE
463#define UART4_CR2 USART_CR2_STOP1_BITS
518#if USE_UART4_TX && defined UART4_GPIO_PORT_TX
521#if USE_UART4_RX && defined UART4_GPIO_PORT_RX
551#define UART5_BAUD SERIAL_DEFAULT_BITRATE
556#define USE_UART5_TX TRUE
559#define USE_UART5_RX TRUE
567#define UART5_CR2 USART_CR2_STOP1_BITS
622#if USE_UART5_TX && defined UART5_GPIO_PORT_TX
625#if USE_UART5_RX && defined UART5_GPIO_PORT_RX
655#define UART6_BAUD SERIAL_DEFAULT_BITRATE
660#define USE_UART6_TX TRUE
663#define USE_UART6_RX TRUE
671#define UART6_CR2 USART_CR2_STOP1_BITS
726#if USE_UART6_TX && defined UART6_GPIO_PORT_TX
729#if USE_UART6_RX && defined UART6_GPIO_PORT_RX
753#if defined UART6_GPIO_CTS && defined UART6_GPIO_PORT_CTS
764#define UART7_BAUD SERIAL_DEFAULT_BITRATE
769#define USE_UART7_TX TRUE
772#define USE_UART7_RX TRUE
780#define UART7_CR2 USART_CR2_STOP1_BITS
835#if USE_UART7_TX && defined UART7_GPIO_PORT_TX
838#if USE_UART7_RX && defined UART7_GPIO_PORT_RX
868#define UART8_BAUD SERIAL_DEFAULT_BITRATE
873#define USE_UART8_TX TRUE
876#define USE_UART8_RX TRUE
884#define UART8_CR2 USART_CR2_STOP1_BITS
939#if USE_UART8_TX && defined UART8_GPIO_PORT_TX
942#if USE_UART8_RX && defined UART8_GPIO_PORT_RX
1003#if defined(STM32H7XX)
1004#define __USART_CR1_M USART_CR1_M0
1005#elif defined(STM32F7XX)
1006#define __USART_CR1_M USART_CR1_M_0
1007#elif defined(STM32F1XX) || defined (STM32F3XX) || defined(STM32F4XX)
1008#define __USART_CR1_M USART_CR1_M
1010#error Unsupported board
1055#if defined(STM32F7XX) || defined(STM32H7XX)
1083 int space =
p->tx_extract_idx -
p->tx_insert_idx - 1;
1105 if (temp ==
p->tx_extract_idx) {
1109 p->tx_buf[
p->tx_insert_idx] = data;
1110 p->tx_insert_idx = temp;
1117 p->tx_buf[
p->tx_insert_idx] = data;
1143 for (i = 0; i < len; i++) {
1144 p->tx_buf[
p->tx_insert_idx] = data[i];
#define UART4_GPIO_PORT_RX
#define UART1_GPIO_PORT_TX
#define UART6_GPIO_PORT_RX
#define UART2_GPIO_PORT_RX
#define UART1_GPIO_PORT_RX
#define UART6_GPIO_PORT_TX
#define UART4_GPIO_PORT_TX
#define UART3_GPIO_PORT_TX
#define UART3_GPIO_PORT_RX
void gpio_setup_pin_af(ioportid_t port, uint16_t pin, uint8_t af, bool is_output)
Setup a gpio for input or output with alternate function.
static uint8_t gpio_get(ioportid_t port, uint16_t pin)
Get level of a gpio.
static THD_WORKING_AREA(wa_thd_spi1, SPI_THREAD_STACK_SIZE)
static MUTEX_DECL(sys_time_mtx)
#define UART8_GPIO_PORT_RX
#define UART7_GPIO_PORT_RX
#define UART8_GPIO_PORT_TX
#define UART2_GPIO_PORT_TX
UART2 (with optional flow control activated by default)
#define UART1_GPIO_AF
UART defines.
#define UART6_GPIO_PORT_CTS
#define UART5_GPIO_PORT_TX
#define UART5_GPIO_PORT_RX
Some architecture independent helper functions for GPIOs.
void uart_put_byte(struct uart_periph *periph, long fd, uint8_t data)
void uart_periph_set_bits_stop_parity(struct uart_periph *periph, uint8_t bits, uint8_t stop, uint8_t parity)
uint8_t uart_getch(struct uart_periph *p)
void uart_periph_set_baudrate(struct uart_periph *periph, uint32_t baud)
#define UART_TX_BUFFER_SIZE
#define UART_RX_BUFFER_SIZE
#define UART7_GPIO_PORT_TX
UART7 (Modem with optional flow control disabled by default)
void uart_periph_set_mode(struct uart_periph *p, bool tx_enabled, bool rx_enabled, bool hw_flow_control)
void WEAK uart_send_message(struct uart_periph *p, long fd)
void uart_periph_init(struct uart_periph *p)
void WEAK uart_put_buffer(struct uart_periph *p, long fd, const uint8_t *data, uint16_t len)
void WEAK uart_periph_invert_data_logic(struct uart_periph *p, bool invert_rx, bool invert_tx)
int WEAK uart_check_free_space(struct uart_periph *p, long *fd, uint16_t len)
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
static SEMAPHORE_DECL(we_ukf_sem, 0)