Skip to content

Commit e729db5

Browse files
narvalotechjori-nordic
authored andcommitted
Add hardware flow-control
1 parent 05e4815 commit e729db5

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
cmake_minimum_required(VERSION 3.13)
44

5+
option(FLOW_CONTROL "Enable Hardware Flow-control on the UARTs" FALSE)
6+
57
include(pico-sdk/pico_sdk_init.cmake)
68

79
project(pico_uart_bridge)
@@ -19,4 +21,8 @@ target_link_libraries(uart_bridge
1921
pico_stdlib
2022
tinyusb_device)
2123

24+
if(FLOW_CONTROL)
25+
target_compile_definitions(uart_bridge PUBLIC FLOW_CONTROL=1)
26+
endif()
27+
2228
pico_add_extra_outputs(uart_bridge)

README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,23 @@ This software is provided without warranty, according to the MIT License, and sh
1111
Raspberry Pi Pico Pinout
1212
------------------------
1313

14-
| Raspberry Pi Pico GPIO | Function |
15-
|:----------------------:|:--------:|
16-
| GPIO0 (Pin 1) | UART0 TX |
17-
| GPIO1 (Pin 2) | UART0 RX |
18-
| GPIO4 (Pin 6) | UART1 TX |
19-
| GPIO5 (Pin 7) | UART1 RX |
14+
| Raspberry Pi Pico GPIO | Function |
15+
|:----------------------:|:---------:|
16+
| GPIO0 (Pin 1) | UART0 TX |
17+
| GPIO1 (Pin 2) | UART0 RX |
18+
| GPIO2 (Pin 4) | UART0 CTS |
19+
| GPIO3 (Pin 5) | UART0 RTS |
20+
| GPIO4 (Pin 6) | UART1 TX |
21+
| GPIO5 (Pin 7) | UART1 RX |
22+
| GPIO6 (Pin 9) | UART1 CTS |
23+
| GPIO7 (Pin 10) | UART1 RTS |
24+
25+
Optional Hardware Flow-control
26+
------------------------------
27+
28+
Hardware Flow-control is disabled by default, but can be compiled in by running:
29+
30+
``` bash
31+
cmake -DFLOW_CONTROL .
32+
make
33+
```

uart-bridge.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ typedef struct {
2828
uart_inst_t *const inst;
2929
uint8_t tx_pin;
3030
uint8_t rx_pin;
31+
#ifdef FLOW_CONTROL
32+
uint8_t rts_pin;
33+
uint8_t cts_pin;
34+
#endif
3135
} uart_id_t;
3236

3337
typedef struct {
@@ -47,10 +51,18 @@ const uart_id_t UART_ID[CFG_TUD_CDC] = {
4751
.inst = uart0,
4852
.tx_pin = 0,
4953
.rx_pin = 1,
54+
#ifdef FLOW_CONTROL
55+
.cts_pin = 2,
56+
.rts_pin = 3,
57+
#endif
5058
}, {
5159
.inst = uart1,
5260
.tx_pin = 4,
5361
.rx_pin = 5,
62+
#ifdef FLOW_CONTROL
63+
.cts_pin = 6,
64+
.rts_pin = 7,
65+
#endif
5466
}
5567
};
5668

@@ -233,6 +245,10 @@ void init_uart_data(uint8_t itf) {
233245
/* Pinmux */
234246
gpio_set_function(ui->tx_pin, GPIO_FUNC_UART);
235247
gpio_set_function(ui->rx_pin, GPIO_FUNC_UART);
248+
#ifdef FLOW_CONTROL
249+
gpio_set_function(ui->rts_pin, GPIO_FUNC_UART);
250+
gpio_set_function(ui->cts_pin, GPIO_FUNC_UART);
251+
#endif
236252

237253
/* USB CDC LC */
238254
ud->usb_lc.bit_rate = DEF_BIT_RATE;
@@ -257,7 +273,11 @@ void init_uart_data(uint8_t itf) {
257273

258274
/* UART start */
259275
uart_init(ui->inst, ud->usb_lc.bit_rate);
276+
#ifdef FLOW_CONTROL
277+
uart_set_hw_flow(ui->inst, true, true);
278+
#else
260279
uart_set_hw_flow(ui->inst, false, false);
280+
#endif
261281
uart_set_format(ui->inst, databits_usb2uart(ud->usb_lc.data_bits),
262282
stopbits_usb2uart(ud->usb_lc.stop_bits),
263283
parity_usb2uart(ud->usb_lc.parity));

0 commit comments

Comments
 (0)