1 /*
2  * Copyright (c) 2016 Open-RnD Sp. z o.o.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @brief Driver for UART port on STM32 family processor.
9  *
10  */
11 
12 #ifndef ZEPHYR_DRIVERS_SERIAL_UART_STM32_H_
13 #define ZEPHYR_DRIVERS_SERIAL_UART_STM32_H_
14 
15 #include <drivers/pinmux.h>
16 
17 /* device config */
18 struct uart_stm32_config {
19 	struct uart_device_config uconf;
20 	/* clock subsystem driving this peripheral */
21 	struct stm32_pclken pclken;
22 	/* initial hardware flow control, 1 for RTS/CTS */
23 	bool hw_flow_control;
24 	/* initial parity, 0 for none, 1 for odd, 2 for even */
25 	int  parity;
26 	const struct soc_gpio_pinctrl *pinctrl_list;
27 	size_t pinctrl_list_size;
28 #if defined(CONFIG_PM) \
29 	&& !defined(CONFIG_UART_INTERRUPT_DRIVEN) \
30 	&& !defined(CONFIG_UART_ASYNC_API)
31 	uart_irq_config_func_t irq_config_func;
32 #endif
33 };
34 
35 #ifdef CONFIG_UART_ASYNC_API
36 struct uart_dma_stream {
37 	const struct device *dma_dev;
38 	uint32_t dma_channel;
39 	struct dma_config dma_cfg;
40 	uint8_t priority;
41 	bool src_addr_increment;
42 	bool dst_addr_increment;
43 	int fifo_threshold;
44 	struct dma_block_config blk_cfg;
45 	uint8_t *buffer;
46 	size_t buffer_length;
47 	size_t offset;
48 	volatile size_t counter;
49 	int32_t timeout;
50 	struct k_work_delayable timeout_work;
51 	bool enabled;
52 };
53 #endif
54 
55 /* driver data */
56 struct uart_stm32_data {
57 	/* Baud rate */
58 	uint32_t baud_rate;
59 	/* clock device */
60 	const struct device *clock;
61 #ifdef CONFIG_UART_INTERRUPT_DRIVEN
62 	uart_irq_callback_user_data_t user_cb;
63 	void *user_data;
64 #endif
65 
66 #ifdef CONFIG_UART_ASYNC_API
67 	const struct device *uart_dev;
68 	uart_callback_t async_cb;
69 	void *async_user_data;
70 	struct uart_dma_stream dma_rx;
71 	struct uart_dma_stream dma_tx;
72 	uint8_t *rx_next_buffer;
73 	size_t rx_next_buffer_len;
74 #endif
75 #ifdef CONFIG_PM
76 	bool tx_poll_stream_on;
77 	bool tx_int_stream_on;
78 	bool pm_constraint_on;
79 #endif
80 };
81 
82 #endif	/* ZEPHYR_DRIVERS_SERIAL_UART_STM32_H_ */
83