Skip to content

Commit 04da64d

Browse files
Georgij CernysiovBenichou34
authored andcommitted
drivers: serial: stm32: dts binding, and fixup for flow control
Allows to enable initial RTS/CTS hardware flow control in the dts. Co-authored-by: Benoit Leforestier <[email protected]> Signed-off-by: Georgij Cernysiov <[email protected]>
1 parent 3f0f617 commit 04da64d

File tree

13 files changed

+63
-0
lines changed

13 files changed

+63
-0
lines changed

drivers/serial/uart_stm32.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,10 @@ static int uart_stm32_init(struct device *dev)
722722
LL_USART_PARITY_NONE,
723723
LL_USART_STOPBITS_1);
724724

725+
if (config->hw_flow_control) {
726+
uart_stm32_set_hwctrl(dev, LL_USART_HWCONTROL_RTS_CTS);
727+
}
728+
725729
/* Set the default baudrate */
726730
uart_stm32_set_baudrate(dev, data->baud_rate);
727731

@@ -777,6 +781,7 @@ static const struct uart_stm32_config uart_stm32_cfg_##name = { \
777781
.pclken = { .bus = DT_UART_STM32_##name##_CLOCK_BUS, \
778782
.enr = DT_UART_STM32_##name##_CLOCK_BITS \
779783
}, \
784+
.hw_flow_control = DT_UART_STM32_##name##_HW_FLOW_CONTROL \
780785
}; \
781786
\
782787
static struct uart_stm32_data uart_stm32_data_##name = { \

drivers/serial/uart_stm32.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ struct uart_stm32_config {
1717
struct uart_device_config uconf;
1818
/* clock subsystem driving this peripheral */
1919
struct stm32_pclken pclken;
20+
/* initial hardware flow control, 1 for RTS/CTS */
21+
bool hw_flow_control;
2022
};
2123

2224
/* driver data */

dts/bindings/serial/st,stm32-lpuart.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,10 @@ properties:
2929
category: required
3030
description: Clock gate information
3131
generation: define
32+
33+
hw-flow-control:
34+
type: boolean
35+
category: optional
36+
description: Set to enable RTS/CTS flow control at boot time
37+
generation: define
3238
...

dts/bindings/serial/st,stm32-uart.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ properties:
2323
category: required
2424
description: required interrupts
2525
generation: define
26+
27+
hw-flow-control:
28+
type: boolean
29+
category: optional
30+
description: Set to enable RTS/CTS flow control at boot time
31+
generation: define
2632
...

dts/bindings/serial/st,stm32-usart.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ properties:
2323
category: required
2424
description: required interrupts
2525
generation: define
26+
27+
hw-flow-control:
28+
type: boolean
29+
category: optional
30+
description: Set to enable RTS/CTS flow control at boot time
31+
generation: define
2632
...

soc/arm/st_stm32/stm32f0/dts_fixup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#define DT_USART_1_IRQ DT_ST_STM32_USART_40013800_IRQ_0
6666
#define DT_UART_STM32_USART_1_CLOCK_BITS DT_ST_STM32_USART_40013800_CLOCK_BITS
6767
#define DT_UART_STM32_USART_1_CLOCK_BUS DT_ST_STM32_USART_40013800_CLOCK_BUS
68+
#define DT_UART_STM32_USART_1_HW_FLOW_CONTROL DT_ST_STM32_USART_40013800_HW_FLOW_CONTROL
6869

6970
#define DT_UART_STM32_USART_2_BASE_ADDRESS DT_ST_STM32_USART_40004400_BASE_ADDRESS
7071
#define DT_UART_STM32_USART_2_BAUD_RATE DT_ST_STM32_USART_40004400_CURRENT_SPEED
@@ -73,6 +74,7 @@
7374
#define DT_USART_2_IRQ DT_ST_STM32_USART_40004400_IRQ_0
7475
#define DT_UART_STM32_USART_2_CLOCK_BITS DT_ST_STM32_USART_40004400_CLOCK_BITS
7576
#define DT_UART_STM32_USART_2_CLOCK_BUS DT_ST_STM32_USART_40004400_CLOCK_BUS
77+
#define DT_UART_STM32_USART_2_HW_FLOW_CONTROL DT_ST_STM32_USART_40004400_HW_FLOW_CONTROL
7678

7779
#define DT_I2C_1_BASE_ADDRESS DT_ST_STM32_I2C_V2_40005400_BASE_ADDRESS
7880
#define DT_I2C_1_COMBINED_IRQ_PRI DT_ST_STM32_I2C_V2_40005400_IRQ_COMBINED_PRIORITY

soc/arm/st_stm32/stm32f1/dts_fixup.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
#define DT_USART_1_IRQ DT_ST_STM32_USART_40013800_IRQ_0
7575
#define DT_UART_STM32_USART_1_CLOCK_BITS DT_ST_STM32_USART_40013800_CLOCK_BITS
7676
#define DT_UART_STM32_USART_1_CLOCK_BUS DT_ST_STM32_USART_40013800_CLOCK_BUS
77+
#define DT_UART_STM32_USART_1_HW_FLOW_CONTROL DT_ST_STM32_USART_40013800_HW_FLOW_CONTROL
7778

7879
#define DT_UART_STM32_USART_2_BASE_ADDRESS DT_ST_STM32_USART_40004400_BASE_ADDRESS
7980
#define DT_UART_STM32_USART_2_BAUD_RATE DT_ST_STM32_USART_40004400_CURRENT_SPEED
@@ -82,6 +83,7 @@
8283
#define DT_USART_2_IRQ DT_ST_STM32_USART_40004400_IRQ_0
8384
#define DT_UART_STM32_USART_2_CLOCK_BITS DT_ST_STM32_USART_40004400_CLOCK_BITS
8485
#define DT_UART_STM32_USART_2_CLOCK_BUS DT_ST_STM32_USART_40004400_CLOCK_BUS
86+
#define DT_UART_STM32_USART_2_HW_FLOW_CONTROL DT_ST_STM32_USART_40004400_HW_FLOW_CONTROL
8587

8688
#define DT_UART_STM32_USART_3_BASE_ADDRESS DT_ST_STM32_USART_40004800_BASE_ADDRESS
8789
#define DT_UART_STM32_USART_3_BAUD_RATE DT_ST_STM32_USART_40004800_CURRENT_SPEED
@@ -90,6 +92,7 @@
9092
#define DT_USART_3_IRQ DT_ST_STM32_USART_40004800_IRQ_0
9193
#define DT_UART_STM32_USART_3_CLOCK_BITS DT_ST_STM32_USART_40004800_CLOCK_BITS
9294
#define DT_UART_STM32_USART_3_CLOCK_BUS DT_ST_STM32_USART_40004800_CLOCK_BUS
95+
#define DT_UART_STM32_USART_3_HW_FLOW_CONTROL DT_ST_STM32_USART_40004800_HW_FLOW_CONTROL
9396

9497
#define DT_UART_STM32_UART_4_BASE_ADDRESS DT_ST_STM32_UART_40004C00_BASE_ADDRESS
9598
#define DT_UART_STM32_UART_4_BAUD_RATE DT_ST_STM32_UART_40004C00_CURRENT_SPEED
@@ -98,6 +101,7 @@
98101
#define DT_UART_4_IRQ DT_ST_STM32_UART_40004C00_IRQ_0
99102
#define DT_UART_STM32_UART_4_CLOCK_BITS DT_ST_STM32_UART_40004C00_CLOCK_BITS
100103
#define DT_UART_STM32_UART_4_CLOCK_BUS DT_ST_STM32_UART_40004C00_CLOCK_BUS
104+
#define DT_UART_STM32_UART_4_HW_FLOW_CONTROL DT_ST_STM32_UART_40004C00_HW_FLOW_CONTROL
101105

102106
#define DT_UART_STM32_UART_5_BASE_ADDRESS DT_ST_STM32_UART_40005000_BASE_ADDRESS
103107
#define DT_UART_STM32_UART_5_BAUD_RATE DT_ST_STM32_UART_40005000_CURRENT_SPEED
@@ -106,6 +110,7 @@
106110
#define DT_UART_5_IRQ DT_ST_STM32_UART_40005000_IRQ_0
107111
#define DT_UART_STM32_UART_5_CLOCK_BITS DT_ST_STM32_UART_40005000_CLOCK_BITS
108112
#define DT_UART_STM32_UART_5_CLOCK_BUS DT_ST_STM32_UART_40005000_CLOCK_BUS
113+
#define DT_UART_STM32_UART_5_HW_FLOW_CONTROL DT_ST_STM32_UART_40005000_HW_FLOW_CONTROL
109114

110115
#define DT_I2C_1_BASE_ADDRESS DT_ST_STM32_I2C_V1_40005400_BASE_ADDRESS
111116
#define DT_I2C_1_EVENT_IRQ_PRI DT_ST_STM32_I2C_V1_40005400_IRQ_EVENT_PRIORITY

soc/arm/st_stm32/stm32f2/dts_fixup.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#define DT_USART_1_IRQ DT_ST_STM32_USART_40011000_IRQ_0
9393
#define DT_UART_STM32_USART_1_CLOCK_BITS DT_ST_STM32_USART_40011000_CLOCK_BITS
9494
#define DT_UART_STM32_USART_1_CLOCK_BUS DT_ST_STM32_USART_40011000_CLOCK_BUS
95+
#define DT_UART_STM32_USART_1_HW_FLOW_CONTROL DT_ST_STM32_USART_40011000_HW_FLOW_CONTROL
9596

9697
#define DT_UART_STM32_USART_2_BASE_ADDRESS DT_ST_STM32_USART_40004400_BASE_ADDRESS
9798
#define DT_UART_STM32_USART_2_BAUD_RATE DT_ST_STM32_USART_40004400_CURRENT_SPEED
@@ -100,6 +101,7 @@
100101
#define DT_USART_2_IRQ DT_ST_STM32_USART_40004400_IRQ_0
101102
#define DT_UART_STM32_USART_2_CLOCK_BITS DT_ST_STM32_USART_40004400_CLOCK_BITS
102103
#define DT_UART_STM32_USART_2_CLOCK_BUS DT_ST_STM32_USART_40004400_CLOCK_BUS
104+
#define DT_UART_STM32_USART_2_HW_FLOW_CONTROL DT_ST_STM32_USART_40004400_HW_FLOW_CONTROL
103105

104106
#define DT_UART_STM32_USART_3_BASE_ADDRESS DT_ST_STM32_USART_40004800_BASE_ADDRESS
105107
#define DT_UART_STM32_USART_3_BAUD_RATE DT_ST_STM32_USART_40004800_CURRENT_SPEED
@@ -108,6 +110,7 @@
108110
#define DT_USART_3_IRQ DT_ST_STM32_USART_40004800_IRQ_0
109111
#define DT_UART_STM32_USART_3_CLOCK_BITS DT_ST_STM32_USART_40004800_CLOCK_BITS
110112
#define DT_UART_STM32_USART_3_CLOCK_BUS DT_ST_STM32_USART_40004800_CLOCK_BUS
113+
#define DT_UART_STM32_USART_3_HW_FLOW_CONTROL DT_ST_STM32_USART_40004800_HW_FLOW_CONTROL
111114

112115
#define DT_UART_STM32_USART_6_NAME DT_ST_STM32_USART_40011400_LABEL
113116
#define DT_UART_STM32_USART_6_BASE_ADDRESS DT_ST_STM32_USART_40011400_BASE_ADDRESS
@@ -116,6 +119,7 @@
116119
#define DT_USART_6_IRQ DT_ST_STM32_USART_40011400_IRQ_0
117120
#define DT_UART_STM32_USART_6_CLOCK_BITS DT_ST_STM32_USART_40011400_CLOCK_BITS
118121
#define DT_UART_STM32_USART_6_CLOCK_BUS DT_ST_STM32_USART_40011400_CLOCK_BUS
122+
#define DT_UART_STM32_USART_6_HW_FLOW_CONTROL DT_ST_STM32_USART_40011400_HW_FLOW_CONTROL
119123

120124
#define DT_UART_STM32_UART_4_NAME DT_ST_STM32_UART_40004C00_LABEL
121125
#define DT_UART_STM32_UART_4_BASE_ADDRESS DT_ST_STM32_UART_40004C00_BASE_ADDRESS
@@ -124,6 +128,7 @@
124128
#define DT_UART_4_IRQ DT_ST_STM32_UART_40004C00_IRQ_0
125129
#define DT_UART_STM32_UART_4_CLOCK_BITS DT_ST_STM32_UART_40004C00_CLOCK_BITS
126130
#define DT_UART_STM32_UART_4_CLOCK_BUS DT_ST_STM32_UART_40004C00_CLOCK_BUS
131+
#define DT_UART_STM32_UART_4_HW_FLOW_CONTROL DT_ST_STM32_UART_40004C00_HW_FLOW_CONTROL
127132

128133
#define DT_UART_STM32_UART_5_NAME DT_ST_STM32_UART_40005000_LABEL
129134
#define DT_UART_STM32_UART_5_BASE_ADDRESS DT_ST_STM32_UART_40005000_BASE_ADDRESS
@@ -132,6 +137,7 @@
132137
#define DT_UART_5_IRQ DT_ST_STM32_UART_40005000_IRQ_0
133138
#define DT_UART_STM32_UART_5_CLOCK_BITS DT_ST_STM32_UART_40005000_CLOCK_BITS
134139
#define DT_UART_STM32_UART_5_CLOCK_BUS DT_ST_STM32_UART_40005000_CLOCK_BUS
140+
#define DT_UART_STM32_UART_5_HW_FLOW_CONTROL DT_ST_STM32_UART_40005000_HW_FLOW_CONTROL
135141

136142
#define DT_USB_BASE_ADDRESS DT_ST_STM32_OTGFS_50000000_BASE_ADDRESS
137143
#define DT_USB_IRQ DT_ST_STM32_OTGFS_50000000_IRQ_OTGFS

soc/arm/st_stm32/stm32f3/dts_fixup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#define DT_USART_1_IRQ DT_ST_STM32_USART_40013800_IRQ_0
6666
#define DT_UART_STM32_USART_1_CLOCK_BITS DT_ST_STM32_USART_40013800_CLOCK_BITS
6767
#define DT_UART_STM32_USART_1_CLOCK_BUS DT_ST_STM32_USART_40013800_CLOCK_BUS
68+
#define DT_UART_STM32_USART_1_HW_FLOW_CONTROL DT_ST_STM32_USART_40013800_HW_FLOW_CONTROL
6869

6970
#define DT_UART_STM32_USART_2_BASE_ADDRESS DT_ST_STM32_USART_40004400_BASE_ADDRESS
7071
#define DT_UART_STM32_USART_2_BAUD_RATE DT_ST_STM32_USART_40004400_CURRENT_SPEED
@@ -73,6 +74,7 @@
7374
#define DT_USART_2_IRQ DT_ST_STM32_USART_40004400_IRQ_0
7475
#define DT_UART_STM32_USART_2_CLOCK_BITS DT_ST_STM32_USART_40004400_CLOCK_BITS
7576
#define DT_UART_STM32_USART_2_CLOCK_BUS DT_ST_STM32_USART_40004400_CLOCK_BUS
77+
#define DT_UART_STM32_USART_2_HW_FLOW_CONTROL DT_ST_STM32_USART_40004400_HW_FLOW_CONTROL
7678

7779
#define DT_UART_STM32_USART_3_BASE_ADDRESS DT_ST_STM32_USART_40004800_BASE_ADDRESS
7880
#define DT_UART_STM32_USART_3_BAUD_RATE DT_ST_STM32_USART_40004800_CURRENT_SPEED
@@ -81,6 +83,7 @@
8183
#define DT_USART_3_IRQ DT_ST_STM32_USART_40004800_IRQ_0
8284
#define DT_UART_STM32_USART_3_CLOCK_BITS DT_ST_STM32_USART_40004800_CLOCK_BITS
8385
#define DT_UART_STM32_USART_3_CLOCK_BUS DT_ST_STM32_USART_40004800_CLOCK_BUS
86+
#define DT_UART_STM32_USART_3_HW_FLOW_CONTROL DT_ST_STM32_USART_40004800_HW_FLOW_CONTROL
8487

8588
#define DT_I2C_1_BASE_ADDRESS DT_ST_STM32_I2C_V2_40005400_BASE_ADDRESS
8689
#define DT_I2C_1_EVENT_IRQ_PRI DT_ST_STM32_I2C_V2_40005400_IRQ_EVENT_PRIORITY

soc/arm/st_stm32/stm32f4/dts_fixup.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
#define DT_USART_1_IRQ DT_ST_STM32_USART_40011000_IRQ_0
111111
#define DT_UART_STM32_USART_1_CLOCK_BITS DT_ST_STM32_USART_40011000_CLOCK_BITS
112112
#define DT_UART_STM32_USART_1_CLOCK_BUS DT_ST_STM32_USART_40011000_CLOCK_BUS
113+
#define DT_UART_STM32_USART_1_HW_FLOW_CONTROL DT_ST_STM32_USART_40011000_HW_FLOW_CONTROL
113114

114115
#define DT_UART_STM32_USART_2_BASE_ADDRESS DT_ST_STM32_USART_40004400_BASE_ADDRESS
115116
#define DT_UART_STM32_USART_2_BAUD_RATE DT_ST_STM32_USART_40004400_CURRENT_SPEED
@@ -118,6 +119,7 @@
118119
#define DT_USART_2_IRQ DT_ST_STM32_USART_40004400_IRQ_0
119120
#define DT_UART_STM32_USART_2_CLOCK_BITS DT_ST_STM32_USART_40004400_CLOCK_BITS
120121
#define DT_UART_STM32_USART_2_CLOCK_BUS DT_ST_STM32_USART_40004400_CLOCK_BUS
122+
#define DT_UART_STM32_USART_2_HW_FLOW_CONTROL DT_ST_STM32_USART_40004400_HW_FLOW_CONTROL
121123

122124
#define DT_UART_STM32_USART_3_BASE_ADDRESS DT_ST_STM32_USART_40004800_BASE_ADDRESS
123125
#define DT_UART_STM32_USART_3_BAUD_RATE DT_ST_STM32_USART_40004800_CURRENT_SPEED
@@ -126,6 +128,7 @@
126128
#define DT_USART_3_IRQ DT_ST_STM32_USART_40004800_IRQ_0
127129
#define DT_UART_STM32_USART_3_CLOCK_BITS DT_ST_STM32_USART_40004800_CLOCK_BITS
128130
#define DT_UART_STM32_USART_3_CLOCK_BUS DT_ST_STM32_USART_40004800_CLOCK_BUS
131+
#define DT_UART_STM32_USART_3_HW_FLOW_CONTROL DT_ST_STM32_USART_40004800_HW_FLOW_CONTROL
129132

130133
#define DT_UART_STM32_UART_4_BASE_ADDRESS DT_ST_STM32_UART_40004C00_BASE_ADDRESS
131134
#define DT_UART_STM32_UART_4_BAUD_RATE DT_ST_STM32_UART_40004C00_CURRENT_SPEED
@@ -134,6 +137,7 @@
134137
#define DT_UART_4_IRQ DT_ST_STM32_UART_40004C00_IRQ_0
135138
#define DT_UART_STM32_UART_4_CLOCK_BITS DT_ST_STM32_UART_40004C00_CLOCK_BITS
136139
#define DT_UART_STM32_UART_4_CLOCK_BUS DT_ST_STM32_UART_40004C00_CLOCK_BUS
140+
#define DT_UART_STM32_UART_4_HW_FLOW_CONTROL DT_ST_STM32_UART_40004C00_HW_FLOW_CONTROL
137141

138142
#define DT_UART_STM32_USART_6_NAME DT_ST_STM32_USART_40011400_LABEL
139143
#define DT_UART_STM32_USART_6_BASE_ADDRESS DT_ST_STM32_USART_40011400_BASE_ADDRESS
@@ -142,6 +146,7 @@
142146
#define DT_USART_6_IRQ DT_ST_STM32_USART_40011400_IRQ_0
143147
#define DT_UART_STM32_USART_6_CLOCK_BITS DT_ST_STM32_USART_40011400_CLOCK_BITS
144148
#define DT_UART_STM32_USART_6_CLOCK_BUS DT_ST_STM32_USART_40011400_CLOCK_BUS
149+
#define DT_UART_STM32_USART_6_HW_FLOW_CONTROL DT_ST_STM32_USART_40011400_HW_FLOW_CONTROL
145150

146151
#define DT_I2C_1_BASE_ADDRESS DT_ST_STM32_I2C_V1_40005400_BASE_ADDRESS
147152
#define DT_I2C_1_EVENT_IRQ_PRI DT_ST_STM32_I2C_V1_40005400_IRQ_EVENT_PRIORITY

0 commit comments

Comments
 (0)