drivers: serial: implement stm32 uart async api

Add initial implementation of the uart async api
for stm32 mcus. This uses the dma controller
in normal mode for reception. In addition, to detect
reception of bytes we enable the idle line detection
interrupt.

Signed-off-by: Shlomi Vaknin <shlomi.39sd@gmail.com>
Signed-off-by: Jun Li <jun.r.li@intel.com>
Signed-off-by: Giancarlo Stasi <giancarlo.stasi.co@gmail.com>
This commit is contained in:
Shlomi Vaknin 2021-01-16 18:44:24 +02:00 committed by Carles Cufí
commit b4afd1aecf
3 changed files with 727 additions and 5 deletions

View file

@ -27,6 +27,26 @@ struct uart_stm32_config {
size_t pinctrl_list_size;
};
#ifdef CONFIG_UART_ASYNC_API
struct uart_dma_stream {
const char *dma_name;
uint32_t dma_channel;
struct dma_config dma_cfg;
uint8_t priority;
bool src_addr_increment;
bool dst_addr_increment;
int fifo_threshold;
struct dma_block_config blk_cfg;
uint8_t *buffer;
size_t buffer_length;
size_t offset;
volatile size_t counter;
int32_t timeout;
struct k_delayed_work timeout_work;
bool enabled;
};
#endif
/* driver data */
struct uart_stm32_data {
/* Baud rate */
@ -37,6 +57,18 @@ struct uart_stm32_data {
uart_irq_callback_user_data_t user_cb;
void *user_data;
#endif
#ifdef CONFIG_UART_ASYNC_API
const struct device *uart_dev;
const struct device *dev_dma_tx;
const struct device *dev_dma_rx;
uart_callback_t async_cb;
void *async_user_data;
struct uart_dma_stream dma_rx;
struct uart_dma_stream dma_tx;
uint8_t *rx_next_buffer;
size_t rx_next_buffer_len;
#endif
};
#endif /* ZEPHYR_DRIVERS_SERIAL_UART_STM32_H_ */