@@ -63,33 +63,32 @@ static void usartConfigurePinInversion(uartPort_t *uartPort) {
63
63
#endif
64
64
}
65
65
66
+ static uartDevice_t * uartFindDevice (uartPort_t * uartPort )
67
+ {
68
+ for (uint32_t i = 0 ; i < UARTDEV_COUNT_MAX ; i ++ ) {
69
+ uartDevice_t * candidate = uartDevmap [i ];
70
+
71
+ if (& candidate -> port == uartPort ) {
72
+ return candidate ;
73
+ }
74
+ }
75
+ return NULL ;
76
+ }
77
+
78
+ static void uartConfigurePinSwap (uartPort_t * uartPort )
79
+ {
80
+ uartDevice_t * uartDevice = uartFindDevice (uartPort );
81
+ if (!uartDevice ) {
82
+ return ;
83
+ }
84
+
85
+ if (uartDevice -> pinSwap ) {
86
+ usart_transmit_receive_pin_swap (uartDevice -> port .USARTx ,TRUE);
87
+ }
88
+ }
89
+
66
90
void uartReconfigure (uartPort_t * uartPort )
67
91
{
68
- // USART_InitTypeDef USART_InitStructure;
69
- // USART_Cmd(uartPort->USARTx, DISABLE);
70
- // USART_InitStructure.USART_BaudRate = uartPort->port.baudRate;
71
-
72
- // according to the stm32 documentation wordlen has to be 9 for parity bits
73
- // this does not seem to matter for rx but will give bad data on tx!
74
- // This seems to cause RX to break on STM32F1, see https://github.com/betaflight/betaflight/pull/1654
75
- // if ( (uartPort->port.options & SERIAL_PARITY_EVEN)) {
76
- // USART_InitStructure.USART_WordLength = USART_WordLength_9b;
77
- // } else {
78
- // USART_InitStructure.USART_WordLength = USART_WordLength_8b;
79
- // }
80
-
81
- // USART_InitStructure.USART_StopBits = (uartPort->port.options & SERIAL_STOPBITS_2) ? USART_StopBits_2 : USART_StopBits_1;
82
- // USART_InitStructure.USART_Parity = (uartPort->port.options & SERIAL_PARITY_EVEN) ? USART_Parity_Even : USART_Parity_No;
83
- //
84
- // USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
85
- // USART_InitStructure.USART_Mode = 0;
86
- // if (uartPort->port.mode & MODE_RX)
87
- // USART_InitStructure.USART_Mode |= USART_Mode_Rx;
88
- // if (uartPort->port.mode & MODE_TX)
89
- // USART_InitStructure.USART_Mode |= USART_Mode_Tx;
90
- //
91
- // USART_Init(uartPort->USARTx, &USART_InitStructure);
92
- // void usart_init(usart_type* usart_x, uint32_t baud_rate, usart_data_bit_num_type data_bit, usart_stop_bit_num_type stop_bit)
93
92
94
93
usart_enable (uartPort -> USARTx ,DISABLE );
95
94
//init
@@ -111,9 +110,12 @@ void uartReconfigure(uartPort_t *uartPort)
111
110
if (uartPort -> port .mode & MODE_TX )
112
111
usart_transmitter_enable (uartPort -> USARTx ,TRUE);
113
112
114
- //config pin swap
113
+ //config pin inverter
115
114
usartConfigurePinInversion (uartPort );
116
115
116
+ //config pin swap
117
+ uartConfigurePinSwap (uartPort );
118
+
117
119
if (uartPort -> port .options & SERIAL_BIDIR )
118
120
// USART_HalfDuplexCmd(uartPort->USARTx, ENABLE);
119
121
usart_single_line_halfduplex_select (uartPort -> USARTx , TRUE);
0 commit comments