@@ -45,6 +45,7 @@ typedef struct uartDevice_s {
4545 uint8_t af ;
4646 uint8_t irq ;
4747 uint32_t irqPriority ;
48+ bool pinSwap ;
4849} uartDevice_t ;
4950
5051#ifdef USE_UART1
@@ -59,7 +60,12 @@ static uartDevice_t uart1 =
5960#endif
6061 .rcc_apb2 = RCC_APB2 (USART1 ),
6162 .irq = USART1_IRQn ,
62- .irqPriority = NVIC_PRIO_SERIALUART
63+ .irqPriority = NVIC_PRIO_SERIALUART ,
64+ #ifdef USE_UART1_PIN_SWAP
65+ .pinSwap = true,
66+ #else
67+ .pinSwap = false,
68+ #endif
6369};
6470#endif
6571
@@ -75,7 +81,12 @@ static uartDevice_t uart2 =
7581#endif
7682 .rcc_apb1 = RCC_APB1 (USART2 ),
7783 .irq = USART2_IRQn ,
78- .irqPriority = NVIC_PRIO_SERIALUART
84+ .irqPriority = NVIC_PRIO_SERIALUART ,
85+ #ifdef USE_UART2_PIN_SWAP
86+ .pinSwap = true,
87+ #else
88+ .pinSwap = false,
89+ #endif
7990};
8091#endif
8192
@@ -91,7 +102,12 @@ static uartDevice_t uart3 =
91102#endif
92103 .rcc_apb1 = RCC_APB1 (USART3 ),
93104 .irq = USART3_IRQn ,
94- .irqPriority = NVIC_PRIO_SERIALUART
105+ .irqPriority = NVIC_PRIO_SERIALUART ,
106+ #ifdef USE_UART3_PIN_SWAP
107+ .pinSwap = true,
108+ #else
109+ .pinSwap = false,
110+ #endif
95111};
96112#endif
97113
@@ -107,7 +123,12 @@ static uartDevice_t uart4 =
107123#endif
108124 .rcc_apb1 = RCC_APB1 (UART4 ),
109125 .irq = UART4_IRQn ,
110- .irqPriority = NVIC_PRIO_SERIALUART
126+ .irqPriority = NVIC_PRIO_SERIALUART ,
127+ #ifdef USE_UART4_PIN_SWAP
128+ .pinSwap = true,
129+ #else
130+ .pinSwap = false,
131+ #endif
111132};
112133#endif
113134
@@ -123,7 +144,12 @@ static uartDevice_t uart5 =
123144#endif
124145 .rcc_apb1 = RCC_APB1 (UART5 ),
125146 .irq = UART5_IRQn ,
126- .irqPriority = NVIC_PRIO_SERIALUART
147+ .irqPriority = NVIC_PRIO_SERIALUART ,
148+ #ifdef USE_UART5_PIN_SWAP
149+ .pinSwap = true,
150+ #else
151+ .pinSwap = false,
152+ #endif
127153};
128154#endif
129155
@@ -139,7 +165,12 @@ static uartDevice_t uart6 =
139165#endif
140166 .rcc_apb2 = RCC_APB2 (USART6 ),
141167 .irq = USART6_IRQn ,
142- .irqPriority = NVIC_PRIO_SERIALUART
168+ .irqPriority = NVIC_PRIO_SERIALUART ,
169+ #ifdef USE_UART6_PIN_SWAP
170+ .pinSwap = true,
171+ #else
172+ .pinSwap = false,
173+ #endif
143174};
144175#endif
145176
@@ -152,7 +183,12 @@ static uartDevice_t uart7 =
152183 .af = GPIO_MUX_8 ,
153184 .rcc_apb1 = RCC_APB1 (UART7 ),
154185 .irq = UART7_IRQn ,
155- .irqPriority = NVIC_PRIO_SERIALUART
186+ .irqPriority = NVIC_PRIO_SERIALUART ,
187+ #ifdef USE_UART7_PIN_SWAP
188+ .pinSwap = true,
189+ #else
190+ .pinSwap = false,
191+ #endif
156192};
157193#endif
158194
@@ -165,7 +201,12 @@ static uartDevice_t uart8 =
165201 .af = GPIO_MUX_8 ,
166202 .rcc_apb1 = RCC_APB1 (UART8 ),
167203 .irq = UART8_IRQn ,
168- .irqPriority = NVIC_PRIO_SERIALUART
204+ .irqPriority = NVIC_PRIO_SERIALUART ,
205+ #ifdef USE_UART8_PIN_SWAP
206+ .pinSwap = true,
207+ #else
208+ .pinSwap = false,
209+ #endif
169210};
170211#endif
171212
@@ -258,6 +299,30 @@ void uartClearIdleFlag(uartPort_t *s)
258299 (void ) s -> USARTx -> dt ;
259300}
260301
302+ static uartDevice_t * uartFindDevice (uartPort_t * uartPort )
303+ {
304+ for (uint32_t i = 0 ; i < UARTDEV_MAX ; i ++ ) {
305+ uartDevice_t * pDevice = uartHardwareMap [i ];
306+
307+ if (pDevice -> dev == uartPort -> USARTx ) {
308+ return pDevice ;
309+ }
310+ }
311+ return NULL ;
312+ }
313+
314+ void uartConfigurePinSwap (uartPort_t * uartPort )
315+ {
316+ uartDevice_t * uartDevice = uartFindDevice (uartPort );
317+ if (!uartDevice ) {
318+ return ;
319+ }
320+
321+ if (uartDevice -> pinSwap ) {
322+ usart_transmit_receive_pin_swap (uartPort -> USARTx , TRUE);
323+ }
324+ }
325+
261326uartPort_t * serialUART (UARTDevice_e device , uint32_t baudRate , portMode_t mode , portOptions_t options )
262327{
263328 uartPort_t * s ;
0 commit comments