Cleanup code style in Harakiri PID controller merge.
[betaflight.git] / docs / Serial.md
blob025821d0dc831ab8bd85e3c881d80da2d8a7f339
1 # Serial
3 Cleanflight has enhanced serial port flexibility but configuration is slightly more complex as a result.
5 Cleanflight has the concept of a function (MSP, GPS, Serial RX, etc) and a port (VCP, UARTx, SoftSerial x).
6 Not all functions can be used on all ports due to hardware pin mapping, conflicting features, hardware, and software
7 constraints.
9 ## Serial port types
11 * USB Virtual Com Port (VCP) - USB pins on a USB port connected directly to the processor without requiring
12 a dedicated USB to UART adapter.  VCP does not 'use' a physical UART port.
13 * UART - A pair of dedicated hardware transmit and receive pins with signal detection and generation done in hardware.
14 * SoftSerial - A pair of hardware transmit and receive pins with signal detection and generation done in software.
16 UART is the most efficent in terms of CPU usage.
17 SoftSerial is the least efficient and slowest, SoftSerial should only be used for low-bandwith usages, such as telemetry transmission.
19 UART ports are sometimes exposed via on-board USB to UART converters, such as the CP2102 as found on the Naze and Flip32 boards.
20 If the flight controller does not have an onboard USB to UART converter and doesn't support VCP then an external USB to UART board is required.
21 These are sometimes referred to as FTDI boards.  FTDI is just a common manufacturer of a chip (the FT232RL) used on USB to UART boards.
23 When selecting a USB to UART converter choose one that has DTR exposed as well as a selector for 3.3v and 5v since they are more useful.
25 Examples:
27  * [FT232RL FTDI USB To TTL Serial Converter Adapter](http://www.banggood.com/FT232RL-FTDI-USB-To-TTL-Serial-Converter-Adapter-Module-For-Arduino-p-917226.html)
28  * [USB To TTL / COM Converter Module buildin-in CP2102](http://www.banggood.com/Wholesale-USB-To-TTL-Or-COM-Converter-Module-Buildin-in-CP2102-New-p-27989.html)
30 Both SoftSerial and UART ports can be connected to your computer via USB to UART converter boards. 
32 ## Serial Configuration
34 To make configuration easier, common usage scenarios are listed below.
36 ### Serial port scenarios
38 ```
39 0   UNUSED
40 1   MSP, CLI, TELEMETRY, SMARTPORT TELEMETRY, GPS-PASSTHROUGH
41 2   GPS ONLY
42 3   RX SERIAL ONLY
43 4   TELEMETRY ONLY
44 5   MSP, CLI, GPS-PASSTHROUGH
45 6   CLI ONLY
46 7   GPS-PASSTHROUGH ONLY
47 8   MSP ONLY
48 9   SMARTPORT TELEMETRY ONLY
49 10  BLACKBOX ONLY
50 11  MSP, CLI, BLACKBOX, GPS-PASSTHROUGH
51 ```
53 ### Constraints
55 If the configuration is invalid the serial port configuration will reset to its defaults and features may be disabled.
57 * There must always be a port available to use for MSP
58 * There must always be a port available to use for CLI
59 * There can only be 1 CLI port.
60 * There is a maximum of 2 MSP ports.
61 * To use a port for a function, the function's corresponding feature must be also be enabled.
62 e.g. after configuring a port for GPS enable the GPS feature.
63 * If SoftSerial is used, then all SoftSerial ports must use the same baudrate.
66 ### Examples
68 All examples assume default configuration (via CLI `defaults` command)
70 a) Parallel PWM, GPS and FrSky TELEMETRY (when armed)
72 - TELEMETRY,MSP,CLI,GPS PASSTHROUGH on UART1
73 - GPS on UART2
75 ```
76 feature RX_PARALLEL_PWM
77 feature TELEMETRY
78 feature GPS
79 set serial_port_2_scenario = 2
80 save
81 ```
83 b) Graupner SumD RX SERIAL and HoTT TELEMETRY via SoftSerial
85 - MSP,CLI,GPS PASSTHROUGH on UART1
86 - RX SERIAL on UART2
87 - HoTT Telemetry on SOFTSERIAL1
88 ```
89 feature -RX_PARALLEL_PWM
90 feature RX_SERIAL
91 feature TELEMETRY
92 feature SOFTSERIAL 
93 set serial_port_1_scenario = 5
94 set serialrx_provider = 3
95 set serial_port_2_scenario = 3
96 set telemetry_provider = 1
97 set serial_port_3_scenario = 4
98 save
99 ```
101 c) PPM RX, GPS and FrSky TELEMETRY via SoftSerial
103 - MSP, CLI, GPS PASSTHROUGH on UART1
104 - GPS on UART2
105 - TELEMETRY on SOFTSERIAL1
108 feature -RX_PARALLEL_PWM
109 feature RX_PPM
110 feature TELEMETRY
111 feature GPS
112 feature SOFTSERIAL
113 set serial_port_1_scenario = 5
114 set serial_port_2_scenario = 2
115 set serial_port_3_scenario = 4
116 save
118 d) RX SERIAL, GPS and TELEMETRY (when armed) MSP/CLI via SoftSerial
120 - GPS on UART1
121 - RX SERIAL on UART2
122 - TELEMETRY,MSP,CLI,GPS PASSTHROUGH on SOFTSERIAL1
125 feature -RX_PARALLEL_PWM
126 feature TELEMETRY
127 feature GPS
128 feature RX_SERIAL
129 feature SOFTSERIAL
130 set serial_port_1_scenario = 2
131 set serial_port_2_scenario = 3
132 set serial_port_3_scenario = 1
133 set msp_baudrate = 19200
134 set cli_baudrate = 19200
135 set gps_passthrough_baudrate = 19200
136 save
139 e) PPX RX, HoTT Telemetry via UART2
141 - MSP,CLI,GPS PASSTHROUGH on UART1
142 - HoTT telemetry on UART2
145 feature -RX_PARALLEL_PWM
146 feature RX_PPM
147 feature TELEMETRY
148 set serial_port_1_scenario = 5
149 set serial_port_2_scenario = 4
150 set telemetry_provider = 1
153 f) PPM RX, GPS, HoTT Telemetry via SoftSerial 1
155 - MSP,CLI,GPS PASSTHROUGH on UART1
156 - GPS on UART2
157 - HoTT telemetry on SOFTSERIAL1
160 feature -RX_PARALLEL_PWM
161 feature RX_PPM
162 feature TELEMETRY
163 feature GPS
164 feature SOFTSERIAL
165 set serial_port_2_scenario = 2
166 set serial_port_3_scenario = 4
167 set telemetry_provider = 1
168 save
171 g) S.BUS RX SERIAL 
173 - TELEMETRY, MSP, CLI, GPS PASSTHROUGH on UART1
174 - RX SERIAL on UART2
177 feature -RX_PARALLEL_PWM
178 feature RX_SERIAL
179 set serialrx_provider = 2
180 set serial_port_2_scenario = 3
181 save
184 h) Spektrum RX SERIAL 
186 - TELEMETRY, MSP, CLI, GPS PASSTHROUGH on UART1
187 - RX SERIAL on UART2
190 feature -RX_PARALLEL_PWM
191 feature RX_SERIAL
192 set serialrx_provider = 0
193 set serial_port_2_scenario = 3
194 save
197 i) MSP via USART1 and SoftSerial 1 
199 - TELEMETRY, MSP, CLI, GPS PASSTHROUGH on UART1
200 - MSP on SOFTSERIAL1
201 - Both ports will be at 19200 (limited by SoftSerial)
202 - USART2 can still be used for GPS/SerialRX/Telemetry, etc.
205 feature -RX_PARALLEL_PWM
206 feature RC_PPM
207 feature SOFTSERIAL
208 set serial_port_1_scenario = 1
209 set serial_port_3_scenario = 8
210 set msp_baudrate = 19200
211 set cli_baudrate = 19200
212 set gps_passthrough_baudrate = 19200
213 save