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;
93 while (
p->tx_insert_idx !=
p->tx_extract_idx) {
94#if USE_UART_SOFT_FLOW_CONTROL
95 if (init_struct->cts_port != 0) {
97 while (
gpio_get(init_struct->cts_port, init_struct->cts_pin) == 1) ;
99 uint8_t data =
p->tx_buf[
p->tx_extract_idx];
105 if (init_struct->cts_port != 0) {
111 if (
p->tx_insert_idx >
p->tx_extract_idx) {
118 p->tx_extract_idx =
p->tx_insert_idx;
122 p->tx_running =
false;
128#define UART1_BAUD SERIAL_DEFAULT_BITRATE
133#define USE_UART1_TX TRUE
136#define USE_UART1_RX TRUE
144#define UART1_CR2 USART_CR2_STOP1_BITS
199#if USE_UART1_TX && defined UART1_GPIO_PORT_TX
202#if USE_UART1_RX && defined UART1_GPIO_PORT_RX
233#define UART2_BAUD SERIAL_DEFAULT_BITRATE
238#define USE_UART2_TX TRUE
241#define USE_UART2_RX TRUE
246#ifndef UART2_HW_FLOW_CONTROL
247#define UART2_HW_FLOW_CONTROL FALSE
250#if UART2_HW_FLOW_CONTROL && defined(UART2_CR3)
251#warning "UART2_CR3 reset to your value, HW flow control not enabled! You may want to set USART_CR3_CTSE | USART_CR3_RTSE yourself."
259#define UART2_CR2 USART_CR2_STOP1_BITS
263#if UART2_HW_FLOW_CONTROL
264#define UART2_CR3 USART_CR3_CTSE | USART_CR3_RTSE
318#if USE_UART2_TX && defined UART2_GPIO_PORT_TX
321#if USE_UART2_RX && defined UART2_GPIO_PORT_RX
351#define UART3_BAUD SERIAL_DEFAULT_BITRATE
356#define USE_UART3_TX TRUE
359#define USE_UART3_RX TRUE
367#define UART3_CR2 USART_CR2_STOP1_BITS
422#if USE_UART3_TX && defined UART3_GPIO_PORT_TX
425#if USE_UART3_RX && defined UART3_GPIO_PORT_RX
455#define UART4_BAUD SERIAL_DEFAULT_BITRATE
460#define USE_UART4_TX TRUE
463#define USE_UART4_RX TRUE
471#define UART4_CR2 USART_CR2_STOP1_BITS
526#if USE_UART4_TX && defined UART4_GPIO_PORT_TX
529#if USE_UART4_RX && defined UART4_GPIO_PORT_RX
559#define UART5_BAUD SERIAL_DEFAULT_BITRATE
564#define USE_UART5_TX TRUE
567#define USE_UART5_RX TRUE
575#define UART5_CR2 USART_CR2_STOP1_BITS
630#if USE_UART5_TX && defined UART5_GPIO_PORT_TX
633#if USE_UART5_RX && defined UART5_GPIO_PORT_RX
663#define UART6_BAUD SERIAL_DEFAULT_BITRATE
668#define USE_UART6_TX TRUE
671#define USE_UART6_RX TRUE
679#define UART6_CR2 USART_CR2_STOP1_BITS
734#if USE_UART6_TX && defined UART6_GPIO_PORT_TX
737#if USE_UART6_RX && defined UART6_GPIO_PORT_RX
761#if defined UART6_GPIO_CTS && defined UART6_GPIO_PORT_CTS
772#define UART7_BAUD SERIAL_DEFAULT_BITRATE
777#define USE_UART7_TX TRUE
780#define USE_UART7_RX TRUE
788#define UART7_CR2 USART_CR2_STOP1_BITS
843#if USE_UART7_TX && defined UART7_GPIO_PORT_TX
846#if USE_UART7_RX && defined UART7_GPIO_PORT_RX
876#define UART8_BAUD SERIAL_DEFAULT_BITRATE
881#define USE_UART8_TX TRUE
884#define USE_UART8_RX TRUE
892#define UART8_CR2 USART_CR2_STOP1_BITS
947#if USE_UART8_TX && defined UART8_GPIO_PORT_TX
950#if USE_UART8_RX && defined UART8_GPIO_PORT_RX
1011#if defined(STM32H7XX)
1012#define __USART_CR1_M USART_CR1_M0
1013#elif defined(STM32F7XX)
1014#define __USART_CR1_M USART_CR1_M_0
1015#elif defined(STM32F1XX) || defined (STM32F3XX) || defined(STM32F4XX)
1016#define __USART_CR1_M USART_CR1_M
1018#error Unsupported board
1063#if defined(STM32F7XX) || defined(STM32H7XX)
1091 int space =
p->tx_extract_idx -
p->tx_insert_idx - 1;
1113 if (temp ==
p->tx_extract_idx) {
1117 p->tx_buf[
p->tx_insert_idx] = data;
1118 p->tx_insert_idx = temp;
1125 p->tx_buf[
p->tx_insert_idx] = data;
1151 for (i = 0; i < len; i++) {
1152 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)