aboutsummaryrefslogtreecommitdiff
path: root/docs/serial_driver.md
diff options
context:
space:
mode:
authorStefan Kerkmann <karlk90@pm.me>2021-05-27 05:37:54 +0200
committerGitHub <noreply@github.com>2021-05-26 20:37:54 -0700
commitd9610120de0452bc6a548bd36b1d4fdfba56d071 (patch)
treea4fb5379522d2c8c174dde6e80990af643343596 /docs/serial_driver.md
parenta78964c91839e5bc682806b88635c3a1a3d01da5 (diff)
downloadqmk_firmware-d9610120de0452bc6a548bd36b1d4fdfba56d071.tar.gz
qmk_firmware-d9610120de0452bc6a548bd36b1d4fdfba56d071.zip
Add Full-duplex serial driver for ARM boards (#9842)
Diffstat (limited to 'docs/serial_driver.md')
-rw-r--r--docs/serial_driver.md154
1 files changed, 147 insertions, 7 deletions
diff --git a/docs/serial_driver.md b/docs/serial_driver.md
index c98f4c117..359fc5955 100644
--- a/docs/serial_driver.md
+++ b/docs/serial_driver.md
@@ -3,16 +3,18 @@ This driver powers the [Split Keyboard](feature_split_keyboard.md) feature.
3 3
4?> Serial in this context should be read as **sending information one bit at a time**, rather than implementing UART/USART/RS485/RS232 standards. 4?> Serial in this context should be read as **sending information one bit at a time**, rather than implementing UART/USART/RS485/RS232 standards.
5 5
6All drivers in this category have the following characteristics: 6Drivers in this category have the following characteristics:
7* Provides data and signaling over a single conductor 7* bit bang and USART Half-duplex provide data and signaling over a single conductor
8* Limited to single master, single slave 8* USART Full-duplex provide data and signaling over two conductors
9* They are all limited to single master and single slave communication scheme
9 10
10## Supported Driver Types 11## Supported Driver Types
11 12
12| | AVR | ARM | 13| | AVR | ARM |
13|-------------------|--------------------|--------------------| 14| ----------------- | ------------------ | ------------------ |
14| bit bang | :heavy_check_mark: | :heavy_check_mark: | 15| bit bang | :heavy_check_mark: | :heavy_check_mark: |
15| USART Half-duplex | | :heavy_check_mark: | 16| USART Half-duplex | | :heavy_check_mark: |
17| USART Full-duplex | | :heavy_check_mark: |
16 18
17## Driver configuration 19## Driver configuration
18 20
@@ -42,7 +44,7 @@ Configure the driver via your config.h:
42Along with the generic options above, you must also turn on the `PAL_USE_CALLBACKS` feature in your halconf.h. 44Along with the generic options above, you must also turn on the `PAL_USE_CALLBACKS` feature in your halconf.h.
43 45
44### USART Half-duplex 46### USART Half-duplex
45Targeting STM32 boards where communication is offloaded to a USART hardware device. The advantage is that this provides fast and accurate timings. `SOFT_SERIAL_PIN` for this driver is the configured USART TX pin. **The TX pin must have appropriate pull-up resistors**. To configure it, add this to your rules.mk: 47Targeting STM32 boards where communication is offloaded to a USART hardware device. The advantage over bitbang is that this provides fast and accurate timings. `SERIAL_PIN_TX` for this driver is the configured USART TX pin. As this Pin is configured in open-drain mode an **external pull-up resistor is needed to keep the line high** (resistor values of 1.5k to 8.2k are known to work). To configure it, add this to your rules.mk:
46 48
47```make 49```make
48SERIAL_DRIVER = usart 50SERIAL_DRIVER = usart
@@ -50,7 +52,8 @@ SERIAL_DRIVER = usart
50 52
51Configure the hardware via your config.h: 53Configure the hardware via your config.h:
52```c 54```c
53#define SOFT_SERIAL_PIN B6 // USART TX pin 55#define SOFT_SERIAL_PIN B6 // USART TX pin
56//#define USART1_REMAP // Remap USART TX and RX pins on STM32F103 MCUs, see table below.
54#define SELECT_SOFT_SERIAL_SPEED 1 // or 0, 2, 3, 4, 5 57#define SELECT_SOFT_SERIAL_SPEED 1 // or 0, 2, 3, 4, 5
55 // 0: about 460800 baud 58 // 0: about 460800 baud
56 // 1: about 230400 baud (default) 59 // 1: about 230400 baud (default)
@@ -58,7 +61,7 @@ Configure the hardware via your config.h:
58 // 3: about 57600 baud 61 // 3: about 57600 baud
59 // 4: about 38400 baud 62 // 4: about 38400 baud
60 // 5: about 19200 baud 63 // 5: about 19200 baud
61#define SERIAL_USART_DRIVER SD1 // USART driver of TX pin. default: SD1 64#define SERIAL_USART_DRIVER SD1 // USART driver of TX pin. default: SD1
62#define SERIAL_USART_TX_PAL_MODE 7 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 7 65#define SERIAL_USART_TX_PAL_MODE 7 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 7
63#define SERIAL_USART_TIMEOUT 100 // USART driver timeout. default 100 66#define SERIAL_USART_TIMEOUT 100 // USART driver timeout. default 100
64``` 67```
@@ -68,3 +71,140 @@ You must also enable the ChibiOS `SERIAL` feature:
68* In your board's mcuconf.h: `#define STM32_SERIAL_USE_USARTn TRUE` (where 'n' matches the peripheral number of your selected USART on the MCU) 71* In your board's mcuconf.h: `#define STM32_SERIAL_USE_USARTn TRUE` (where 'n' matches the peripheral number of your selected USART on the MCU)
69 72
70Do note that the configuration required is for the `SERIAL` peripheral, not the `UART` peripheral. 73Do note that the configuration required is for the `SERIAL` peripheral, not the `UART` peripheral.
74
75### USART Full-duplex
76Targeting STM32 boards where communication is offloaded to a USART hardware device. The advantage over bitbang is that this provides fast and accurate timings. USART Full-Duplex requires two conductors **without** pull-up resistors instead of one conductor with a pull-up resistor unlike the Half-duplex driver, but it is more efficent as it uses DMA transfers, which can result in even faster transmission speeds.
77
78#### Pin configuration
79
80`SERIAL_USART_TX_PIN` is the USART `TX` pin, `SERIAL_USART_RX_PIN` is the USART `RX` pin. No external pull-up resistors are needed as the `TX` pin operates in push-pull mode. To use this driver the usart peripherals `TX` and `RX` pins must be configured with the correct Alternate-functions. If you are using a Proton-C everything is already setup, same is true for STM32F103 MCUs. For MCUs which are using a modern flexible GPIO configuration you have to specify these by setting `SERIAL_USART_TX_PAL_MODE` and `SERIAL_USART_RX_PAL_MODE`. Refeer to the corresponding datasheets of your MCU or find those settings in the table below.
81
82#### Connecting the halves and Pin Swap
83Please note that `TX` of the master half has to be connected with the `RX` pin of the slave half and `RX` of the master half has to be connected with the `TX` pin of the slave half! Usually this pin swap has to be done outside of the MCU e.g. with cables or on the pcb. Some MCUs like the STM32F303 used on the Proton-C allow this pin swap directly inside the MCU, this feature can be enabled using `#define SERIAL_USART_PIN_SWAP` in your config.h.
84
85#### Setup
86To use the driver, add this to your rules.mk:
87
88```make
89SERIAL_DRIVER = usart_duplex
90```
91
92Next configure the hardware via your config.h:
93
94```c
95#define SERIAL_USART_TX_PIN B6 // USART TX pin
96#define SERIAL_USART_RX_PIN B7 // USART RX pin
97//#define USART1_REMAP // Remap USART TX and RX pins on STM32F103 MCUs, see table below.
98//#define SERIAL_USART_PIN_SWAP // Swap TX and RX pins if keyboard is master halve.
99 // Check if this feature is necessary with your keyboard design and available on the mcu.
100#define SELECT_SOFT_SERIAL_SPEED 1 // or 0, 2, 3, 4, 5
101 // 0: 460800 baud
102 // 1: 230400 baud (default)
103 // 2: 115200 baud
104 // 3: 57600 baud
105 // 4: 38400 baud
106 // 5: 19200 baud
107#define SERIAL_USART_DRIVER UARTD1 // USART driver of TX and RX pin. default: UARTD1
108#define SERIAL_USART_TX_PAL_MODE 7 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 7
109#define SERIAL_USART_RX_PAL_MODE 7 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 7
110#define SERIAL_USART_TIMEOUT 100 // USART driver timeout. default 100
111```
112
113You must also enable the ChibiOS `UART` with blocking api feature:
114* In your board's halconf.h: `#define HAL_USE_UART TRUE` and `#define UART_USE_WAIT TRUE`
115* In your board's mcuconf.h: `#define STM32_UART_USE_USARTn TRUE` (where 'n' matches the peripheral number of your selected USART on the MCU)
116
117Do note that the configuration required is for the `UART` peripheral, not the `SERIAL` peripheral.
118
119#### Pins for USART Peripherals with Alternate Functions for selected STM32 MCUs
120
121##### STM32F303 / Proton-C [Datasheet](https://www.st.com/resource/en/datasheet/stm32f303cc.pdf)
122
123Pin Swap available: :heavy_check_mark:
124
125| Pin | Function | Mode |
126| ---------- | -------- | ---- |
127| **USART1** | | |
128| PA9 | TX | AF7 |
129| PA10 | RX | AF7 |
130| PB6 | TX | AF7 |
131| PB7 | RX | AF7 |
132| PC4 | TX | AF7 |
133| PC5 | RX | AF7 |
134| PE0 | TX | AF7 |
135| PE1 | RX | AF7 |
136| **USART2** | | |
137| PA2 | TX | AF7 |
138| PA3 | RX | AF7 |
139| PA14 | TX | AF7 |
140| PA15 | RX | AF7 |
141| PB3 | TX | AF7 |
142| PB4 | RX | AF7 |
143| PD5 | TX | AF7 |
144| PD6 | RX | AF7 |
145| **USART3** | | |
146| PB10 | TX | AF7 |
147| PB11 | RX | AF7 |
148| PC10 | TX | AF7 |
149| PC11 | RX | AF7 |
150| PD8 | TX | AF7 |
151| PD9 | RX | AF7 |
152
153##### STM32F072 [Datasheet](https://www.st.com/resource/en/datasheet/stm32f072c8.pdf)
154
155Pin Swap available: :heavy_check_mark:
156
157| Pin | Function | Mode |
158| ------ | -------- | ---- |
159| USART1 | | |
160| PA9 | TX | AF1 |
161| PA10 | RX | AF1 |
162| PB6 | TX | AF0 |
163| PB7 | RX | AF0 |
164| USART2 | | |
165| PA2 | TX | AF1 |
166| PA3 | RX | AF1 |
167| PA14 | TX | AF1 |
168| PA15 | RX | AF1 |
169| USART3 | | |
170| PB10 | TX | AF4 |
171| PB11 | RX | AF4 |
172| PC4 | TX | AF1 |
173| PC5 | RX | AF1 |
174| PC10 | TX | AF1 |
175| PC11 | RX | AF1 |
176| PD8 | TX | AF0 |
177| PD9 | RX | AF0 |
178| USART4 | | |
179| PA0 | TX | AF4 |
180| PA1 | RX | AF4 |
181
182##### STM32F103 Medium Density (C8-CB) [Datasheet](https://www.st.com/resource/en/datasheet/stm32f103c8.pdf)
183
184Pin Swap available: N/A
185
186TX Pin is always Alternate Function Push-Pull, RX Pin is always regular input pin for any USART peripheral. **For STM32F103 no additional Alternate Function configuration is necessary. QMK is already configured.**
187
188Pin remapping:
189
190The pins of USART Peripherals use default Pins that can be remapped to use other pins using the AFIO registers. Default pins are marked **bold**. Add the appropriate defines to your config.h file.
191
192| Pin | Function | Mode | USART_REMAP |
193| ---------- | -------- | ---- | ------------------- |
194| **USART1** | | | |
195| **PA9** | TX | AFPP | |
196| **PA10** | RX | IN | |
197| PB6 | TX | AFPP | USART1_REMAP |
198| PB7 | RX | IN | USART1_REMAP |
199| **USART2** | | | |
200| **PA2** | TX | AFPP | |
201| **PA3** | RX | IN | |
202| PD5 | TX | AFPP | USART2_REMAP |
203| PD6 | RX | IN | USART2_REMAP |
204| **USART3** | | | |
205| **PB10** | TX | AFPP | |
206| **PB11** | RX | IN | |
207| PC10 | TX | AFPP | USART3_PARTIALREMAP |
208| PC11 | RX | IN | USART3_PARTIALREMAP |
209| PD8 | TX | AFPP | USART3_FULLREMAP |
210| PD9 | RX | IN | USART3_FULLREMAP |