2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
29 #include "build/build_config.h"
31 #include "io/serial.h"
32 #include "drivers/serial.h"
33 #include "drivers/serial_uart.h"
35 #include "pg/pg_ids.h"
37 // Backward compatibility for exisiting targets
39 // F1 targets don't explicitly define pins.
44 #define UART1_RX_PIN PA10
47 #define UART1_TX_PIN PA9
53 #define UART2_RX_PIN PA3
56 #define UART2_TX_PIN PA2
61 // XXX Is there an F3 target that does not define UART pins?
66 #define UART1_TX_PIN PA9
69 #define UART1_RX_PIN PA10
75 #define UART2_TX_PIN PD5
78 #define UART2_RX_PIN PD6
84 #define UART3_TX_PIN PB10
87 #define UART3_RX_PIN PB11
93 #define UART4_TX_PIN PC10
96 #define UART4_RX_PIN PC11
102 #define UART5_TX_PIN PC12
105 #define UART5_RX_PIN PD2
110 // Default pin (NONE).
113 # if !defined(UART1_RX_PIN)
114 # define UART1_RX_PIN NONE
116 # if !defined(UART1_TX_PIN)
117 # define UART1_TX_PIN NONE
119 # if !defined(INVERTER_PIN_UART1)
120 # define INVERTER_PIN_UART1 NONE
125 # if !defined(UART2_RX_PIN)
126 # define UART2_RX_PIN NONE
128 # if !defined(UART2_TX_PIN)
129 # define UART2_TX_PIN NONE
131 # if !defined(INVERTER_PIN_UART2)
132 # define INVERTER_PIN_UART2 NONE
137 # if !defined(UART3_RX_PIN)
138 # define UART3_RX_PIN NONE
140 # if !defined(UART3_TX_PIN)
141 # define UART3_TX_PIN NONE
143 # if !defined(INVERTER_PIN_UART3)
144 # define INVERTER_PIN_UART3 NONE
149 # if !defined(UART4_RX_PIN)
150 # define UART4_RX_PIN NONE
152 # if !defined(UART4_TX_PIN)
153 # define UART4_TX_PIN NONE
155 # if !defined(INVERTER_PIN_UART4)
156 # define INVERTER_PIN_UART4 NONE
161 # if !defined(UART5_RX_PIN)
162 # define UART5_RX_PIN NONE
164 # if !defined(UART5_TX_PIN)
165 # define UART5_TX_PIN NONE
167 # if !defined(INVERTER_PIN_UART5)
168 # define INVERTER_PIN_UART5 NONE
173 # if !defined(UART6_RX_PIN)
174 # define UART6_RX_PIN NONE
176 # if !defined(UART6_TX_PIN)
177 # define UART6_TX_PIN NONE
179 # if !defined(INVERTER_PIN_UART6)
180 # define INVERTER_PIN_UART6 NONE
185 # if !defined(UART7_RX_PIN)
186 # define UART7_RX_PIN NONE
188 # if !defined(UART7_TX_PIN)
189 # define UART7_TX_PIN NONE
191 # if !defined(INVERTER_PIN_UART7)
192 # define INVERTER_PIN_UART7 NONE
197 # if !defined(UART8_RX_PIN)
198 # define UART8_RX_PIN NONE
200 # if !defined(UART8_TX_PIN)
201 # define UART8_TX_PIN NONE
203 # if !defined(INVERTER_PIN_UART8)
204 # define INVERTER_PIN_UART8 NONE
209 # if !defined(UART9_RX_PIN)
210 # define UART9_RX_PIN NONE
212 # if !defined(UART9_TX_PIN)
213 # define UART9_TX_PIN NONE
215 # if !defined(INVERTER_PIN_UART9)
216 # define INVERTER_PIN_UART9 NONE
221 # if !defined(UART10_RX_PIN)
222 # define UART10_RX_PIN NONE
224 # if !defined(UART10_TX_PIN)
225 # define UART10_TX_PIN NONE
227 # if !defined(INVERTER_PIN_UART10)
228 # define INVERTER_PIN_UART10 NONE
233 # if !defined(LPUART1_RX_PIN)
234 # define LPUART1_RX_PIN NONE
236 # if !defined(LPUART1_TX_PIN)
237 # define LPUART1_TX_PIN NONE
239 # if !defined(INVERTER_PIN_LPUART1)
240 # define INVERTER_PIN_LPUART1 NONE
244 #ifdef USE_SOFTSERIAL1
245 # if !defined(SOFTSERIAL1_RX_PIN)
246 # define SOFTSERIAL1_RX_PIN NONE
248 # if !defined(SOFTSERIAL1_TX_PIN)
249 # define SOFTSERIAL1_TX_PIN NONE
253 #ifdef USE_SOFTSERIAL2
254 # if !defined(SOFTSERIAL2_RX_PIN)
255 # define SOFTSERIAL2_RX_PIN NONE
257 # if !defined(SOFTSERIAL2_TX_PIN)
258 # define SOFTSERIAL2_TX_PIN NONE
262 #if defined(USE_UART) || defined(USE_SOFTSERIAL1) || defined(USE_SOFTSERIAL1)
263 typedef struct serialDefaultPin_s
{
264 serialPortIdentifier_e ident
;
265 ioTag_t rxIO
, txIO
, inverterIO
;
266 } serialDefaultPin_t
;
268 static const serialDefaultPin_t serialDefaultPin
[] = {
270 { SERIAL_PORT_USART1
, IO_TAG(UART1_RX_PIN
), IO_TAG(UART1_TX_PIN
), IO_TAG(INVERTER_PIN_UART1
) },
273 { SERIAL_PORT_USART2
, IO_TAG(UART2_RX_PIN
), IO_TAG(UART2_TX_PIN
), IO_TAG(INVERTER_PIN_UART2
) },
276 { SERIAL_PORT_USART3
, IO_TAG(UART3_RX_PIN
), IO_TAG(UART3_TX_PIN
), IO_TAG(INVERTER_PIN_UART3
) },
279 { SERIAL_PORT_UART4
, IO_TAG(UART4_RX_PIN
), IO_TAG(UART4_TX_PIN
), IO_TAG(INVERTER_PIN_UART4
) },
282 { SERIAL_PORT_UART5
, IO_TAG(UART5_RX_PIN
), IO_TAG(UART5_TX_PIN
), IO_TAG(INVERTER_PIN_UART5
) },
285 { SERIAL_PORT_USART6
, IO_TAG(UART6_RX_PIN
), IO_TAG(UART6_TX_PIN
), IO_TAG(INVERTER_PIN_UART6
) },
288 { SERIAL_PORT_USART7
, IO_TAG(UART7_RX_PIN
), IO_TAG(UART7_TX_PIN
), IO_TAG(INVERTER_PIN_UART7
) },
291 { SERIAL_PORT_USART8
, IO_TAG(UART8_RX_PIN
), IO_TAG(UART8_TX_PIN
), IO_TAG(INVERTER_PIN_UART8
) },
294 { SERIAL_PORT_UART9
, IO_TAG(UART9_RX_PIN
), IO_TAG(UART9_TX_PIN
), IO_TAG(INVERTER_PIN_UART9
) },
297 { SERIAL_PORT_USART10
, IO_TAG(UART10_RX_PIN
), IO_TAG(UART10_TX_PIN
), IO_TAG(INVERTER_PIN_UART10
) },
300 { SERIAL_PORT_LPUART1
, IO_TAG(LPUART1_RX_PIN
), IO_TAG(LPUART1_TX_PIN
), IO_TAG(INVERTER_PIN_LPUART1
) },
302 #ifdef USE_SOFTSERIAL1
303 { SERIAL_PORT_SOFTSERIAL1
, IO_TAG(SOFTSERIAL1_RX_PIN
), IO_TAG(SOFTSERIAL1_TX_PIN
), IO_TAG(NONE
) },
305 #ifdef USE_SOFTSERIAL2
306 { SERIAL_PORT_SOFTSERIAL2
, IO_TAG(SOFTSERIAL2_RX_PIN
), IO_TAG(SOFTSERIAL2_TX_PIN
), IO_TAG(NONE
) },
310 PG_REGISTER_WITH_RESET_FN(serialPinConfig_t
, serialPinConfig
, PG_SERIAL_PIN_CONFIG
, 0);
312 void pgResetFn_serialPinConfig(serialPinConfig_t
*serialPinConfig
)
314 for (size_t index
= 0 ; index
< ARRAYLEN(serialDefaultPin
) ; index
++) {
315 const serialDefaultPin_t
*defpin
= &serialDefaultPin
[index
];
316 serialPinConfig
->ioTagRx
[SERIAL_PORT_IDENTIFIER_TO_INDEX(defpin
->ident
)] = defpin
->rxIO
;
317 serialPinConfig
->ioTagTx
[SERIAL_PORT_IDENTIFIER_TO_INDEX(defpin
->ident
)] = defpin
->txIO
;
318 serialPinConfig
->ioTagInverter
[SERIAL_PORT_IDENTIFIER_TO_INDEX(defpin
->ident
)] = defpin
->inverterIO
;