Compare commits
16 commits
Author | SHA1 | Date | |
---|---|---|---|
Carsten Schmiemann | c0e2d44f19 | ||
Carsten Schmiemann | 14eba4cd40 | ||
Carsten Schmiemann | ed07f6dfab | ||
Carsten Schmiemann | 249c7fb383 | ||
Carsten Schmiemann | 88122c9365 | ||
Carsten Schmiemann | 313f2b3ac7 | ||
Carsten Schmiemann | 388a34e5bd | ||
Carsten Schmiemann | afc635a053 | ||
Carsten Schmiemann | 93f66b01fc | ||
ca81e5c242 | |||
67ce07178f | |||
9d05ed4b1d | |||
3aa5d05fe3 | |||
01e7831501 | |||
3e1672f2c9 | |||
8db03b41ac |
|
@ -2,12 +2,15 @@
|
|||
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
|
||||
option(FLOW_CONTROL "Enable Hardware Flow-control on the UARTs" FALSE)
|
||||
option(LINE_CONTROL "Enable Hardware Line-control on the UARTs" FALSE)
|
||||
|
||||
include(pico-sdk/pico_sdk_init.cmake)
|
||||
|
||||
project(pico_uart_bridge)
|
||||
|
||||
pico_sdk_init()
|
||||
|
||||
|
||||
add_executable(uart_bridge uart-bridge.c usb-descriptors.c)
|
||||
|
||||
target_include_directories(uart_bridge PUBLIC
|
||||
|
@ -20,4 +23,12 @@ target_link_libraries(uart_bridge
|
|||
pico_stdlib
|
||||
tinyusb_device)
|
||||
|
||||
if(FLOW_CONTROL)
|
||||
target_compile_definitions(uart_bridge PUBLIC FLOW_CONTROL=1)
|
||||
endif()
|
||||
|
||||
if(LINE_CONTROL)
|
||||
target_compile_definitions(uart_bridge PUBLIC LINE_CONTROL=1)
|
||||
endif()
|
||||
|
||||
pico_add_extra_outputs(uart_bridge)
|
||||
|
|
48
README.md
48
README.md
|
@ -1,6 +1,9 @@
|
|||
Raspberry Pi Pico USB-UART Bridge
|
||||
=================================
|
||||
|
||||
This is a fork of https://github.com/Noltari/pico-uart-bridge and a pull request which takes too long time to include.
|
||||
Some fixes applied by myself for a successful build.
|
||||
|
||||
This program bridges the Raspberry Pi Pico HW UARTs to two independent USB CDC serial devices in order to behave like any other USB-to-UART Bridge controllers.
|
||||
|
||||
Disclaimer
|
||||
|
@ -11,9 +14,42 @@ This software is provided without warranty, according to the MIT License, and sh
|
|||
Raspberry Pi Pico Pinout
|
||||
------------------------
|
||||
|
||||
| Raspberry Pi Pico GPIO | Function |
|
||||
|:----------------------:|:--------:|
|
||||
| GPIO0 (Pin 1) | UART0 TX |
|
||||
| GPIO1 (Pin 2) | UART0 RX |
|
||||
| GPIO4 (Pin 6) | UART1 TX |
|
||||
| GPIO5 (Pin 7) | UART1 RX |
|
||||
UART0:
|
||||
| Raspberry Pi Pico GPIO | Function |
|
||||
|:----------------------:|:---------:|
|
||||
| GPIO0 (Pin 1) | TX |
|
||||
| GPIO1 (Pin 2) | RX |
|
||||
| GPIO2 (Pin 4) | CTS |
|
||||
| GPIO3 (Pin 5) | RTS |
|
||||
| GPIO4 (Pin 6) | DTR |
|
||||
| GPIO5 (Pin 7) | DSR |
|
||||
|
||||
UART1:
|
||||
| Raspberry Pi Pico GPIO | Function |
|
||||
|:----------------------:|:---------:|
|
||||
| GPIO8 (Pin 11) | TX |
|
||||
| GPIO9 (Pin 12) | RX |
|
||||
| GPIO10 (Pin 14) | CTS |
|
||||
| GPIO11 (Pin 15) | RTS |
|
||||
| GPIO12 (Pin 16) | DTR |
|
||||
| GPIO13 (Pin 17) | DSR |
|
||||
|
||||
Optional Hardware Flow and Line control
|
||||
------------------------------
|
||||
|
||||
Hardware Flow-control (RTS/CTS) is disabled if you build it just with build.sh, but there are other buld scripts:
|
||||
|
||||
``` bash
|
||||
./build_w_flow_ctrl.sh
|
||||
```
|
||||
|
||||
Line control (DTR/DSR):
|
||||
|
||||
``` bash
|
||||
./build_w_line_ctrl.sh
|
||||
```
|
||||
|
||||
To enable both:
|
||||
``` bash
|
||||
./build_w_line_flow_ctrl.sh
|
||||
```
|
||||
|
|
17
build_w_flow_ctrl.sh
Normal file
17
build_w_flow_ctrl.sh
Normal file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/bash
|
||||
|
||||
BASE_DIR="$(dirname ${BASH_SOURCE[0]})"
|
||||
BUILD_DIR=$BASE_DIR/build
|
||||
PICO_SDK_DIR=$BASE_DIR/pico-sdk
|
||||
|
||||
main() {
|
||||
if [ ! -d "$PICO_SDK_DIR/.git" ]; then
|
||||
git submodule sync --recursive
|
||||
git submodule update --init --recursive
|
||||
fi
|
||||
|
||||
cmake -DFLOW_CONTROL=true -B $BUILD_DIR -S $BASE_DIR
|
||||
make -C $BUILD_DIR
|
||||
}
|
||||
|
||||
main $@
|
17
build_w_line_ctrl.sh
Normal file
17
build_w_line_ctrl.sh
Normal file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/bash
|
||||
|
||||
BASE_DIR="$(dirname ${BASH_SOURCE[0]})"
|
||||
BUILD_DIR=$BASE_DIR/build
|
||||
PICO_SDK_DIR=$BASE_DIR/pico-sdk
|
||||
|
||||
main() {
|
||||
if [ ! -d "$PICO_SDK_DIR/.git" ]; then
|
||||
git submodule sync --recursive
|
||||
git submodule update --init --recursive
|
||||
fi
|
||||
|
||||
cmake -DLINE_CONTROL=true -B $BUILD_DIR -S $BASE_DIR
|
||||
make -C $BUILD_DIR
|
||||
}
|
||||
|
||||
main $@
|
17
build_w_line_flow_ctrl.sh
Normal file
17
build_w_line_flow_ctrl.sh
Normal file
|
@ -0,0 +1,17 @@
|
|||
#!/bin/bash
|
||||
|
||||
BASE_DIR="$(dirname ${BASH_SOURCE[0]})"
|
||||
BUILD_DIR=$BASE_DIR/build
|
||||
PICO_SDK_DIR=$BASE_DIR/pico-sdk
|
||||
|
||||
main() {
|
||||
if [ ! -d "$PICO_SDK_DIR/.git" ]; then
|
||||
git submodule sync --recursive
|
||||
git submodule update --init --recursive
|
||||
fi
|
||||
|
||||
cmake -DLINE_CONTROL=true -DFLOW_CONTROL=true -B $BUILD_DIR -S $BASE_DIR
|
||||
make -C $BUILD_DIR
|
||||
}
|
||||
|
||||
main $@
|
|
@ -13,8 +13,8 @@
|
|||
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
|
||||
|
||||
#define CFG_TUD_CDC 2
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE 256
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE 256
|
||||
#define CFG_TUD_CDC_RX_BUFSIZE 1024
|
||||
#define CFG_TUD_CDC_TX_BUFSIZE 1024
|
||||
|
||||
void usbd_serial_init(void);
|
||||
|
||||
|
|
|
@ -28,6 +28,14 @@ typedef struct {
|
|||
uart_inst_t *const inst;
|
||||
uint8_t tx_pin;
|
||||
uint8_t rx_pin;
|
||||
#ifdef FLOW_CONTROL
|
||||
uint8_t rts_pin;
|
||||
uint8_t cts_pin;
|
||||
#endif
|
||||
#ifdef LINE_CONTROL
|
||||
uint8_t dtr_pin;
|
||||
uint8_t dsr_pin;
|
||||
#endif
|
||||
} uart_id_t;
|
||||
|
||||
typedef struct {
|
||||
|
@ -47,10 +55,26 @@ const uart_id_t UART_ID[CFG_TUD_CDC] = {
|
|||
.inst = uart0,
|
||||
.tx_pin = 0,
|
||||
.rx_pin = 1,
|
||||
#ifdef FLOW_CONTROL
|
||||
.cts_pin = 2,
|
||||
.rts_pin = 3,
|
||||
#endif
|
||||
#ifdef LINE_CONTROL
|
||||
.dtr_pin = 4,
|
||||
.dsr_pin = 5,
|
||||
#endif
|
||||
}, {
|
||||
.inst = uart1,
|
||||
.tx_pin = 4,
|
||||
.rx_pin = 5,
|
||||
.tx_pin = 8,
|
||||
.rx_pin = 9,
|
||||
#ifdef FLOW_CONTROL
|
||||
.cts_pin = 10,
|
||||
.rts_pin = 11,
|
||||
#endif
|
||||
#ifdef LINE_CONTROL
|
||||
.dtr_pin = 12,
|
||||
.dsr_pin = 13,
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -181,7 +205,7 @@ void core1_entry(void)
|
|||
int con = 0;
|
||||
|
||||
tud_task();
|
||||
|
||||
|
||||
for (itf = 0; itf < CFG_TUD_CDC; itf++) {
|
||||
if (tud_cdc_n_connected(itf)) {
|
||||
con = 1;
|
||||
|
@ -233,6 +257,17 @@ void init_uart_data(uint8_t itf) {
|
|||
/* Pinmux */
|
||||
gpio_set_function(ui->tx_pin, GPIO_FUNC_UART);
|
||||
gpio_set_function(ui->rx_pin, GPIO_FUNC_UART);
|
||||
#ifdef FLOW_CONTROL
|
||||
gpio_set_function(ui->rts_pin, GPIO_FUNC_UART);
|
||||
gpio_set_function(ui->cts_pin, GPIO_FUNC_UART);
|
||||
#endif
|
||||
|
||||
#ifdef LINE_CONTROL
|
||||
gpio_init(ui->dtr_pin);
|
||||
gpio_set_dir(ui->dtr_pin, GPIO_OUT);
|
||||
gpio_init(ui->dsr_pin);
|
||||
gpio_set_dir(ui->dsr_pin, GPIO_IN);
|
||||
#endif
|
||||
|
||||
/* USB CDC LC */
|
||||
ud->usb_lc.bit_rate = DEF_BIT_RATE;
|
||||
|
@ -257,20 +292,32 @@ void init_uart_data(uint8_t itf) {
|
|||
|
||||
/* UART start */
|
||||
uart_init(ui->inst, ud->usb_lc.bit_rate);
|
||||
#ifdef FLOW_CONTROL
|
||||
uart_set_hw_flow(ui->inst, true, true);
|
||||
#else
|
||||
uart_set_hw_flow(ui->inst, false, false);
|
||||
#endif
|
||||
uart_set_format(ui->inst, databits_usb2uart(ud->usb_lc.data_bits),
|
||||
stopbits_usb2uart(ud->usb_lc.stop_bits),
|
||||
parity_usb2uart(ud->usb_lc.parity));
|
||||
}
|
||||
|
||||
#ifdef LINE_CONTROL
|
||||
/* Invoked when line state has changed */
|
||||
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
|
||||
{
|
||||
const uart_id_t *ui = &UART_ID[itf];
|
||||
|
||||
gpio_put(ui->dtr_pin, dtr);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int itf;
|
||||
|
||||
set_sys_clock_khz(250000, false);
|
||||
|
||||
usbd_serial_init();
|
||||
|
||||
for (itf = 0; itf < CFG_TUD_CDC; itf++)
|
||||
init_uart_data(itf);
|
||||
|
||||
|
|
|
@ -18,18 +18,21 @@
|
|||
#define USBD_PID 0x000A /* Raspberry Pi Pico SDK CDC */
|
||||
|
||||
#define USBD_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN * CFG_TUD_CDC)
|
||||
#define USBD_MAX_POWER_MA 250
|
||||
#define USBD_MAX_POWER_MA 500
|
||||
|
||||
#define USBD_ITF_CDC_0 0
|
||||
#define USBD_ITF_CDC_1 2
|
||||
#define USBD_ITF_MAX 4
|
||||
|
||||
#define USBD_CDC_0_EP_CMD 0x81
|
||||
#define USBD_CDC_1_EP_CMD 0x84
|
||||
#define USBD_CDC_0_EP_OUT 0x02
|
||||
#define USBD_CDC_1_EP_OUT 0x05
|
||||
#define USBD_CDC_1_EP_CMD 0x83
|
||||
|
||||
#define USBD_CDC_0_EP_OUT 0x01
|
||||
#define USBD_CDC_1_EP_OUT 0x03
|
||||
|
||||
#define USBD_CDC_0_EP_IN 0x82
|
||||
#define USBD_CDC_1_EP_IN 0x85
|
||||
#define USBD_CDC_1_EP_IN 0x84
|
||||
|
||||
#define USBD_CDC_CMD_MAX_SIZE 8
|
||||
#define USBD_CDC_IN_OUT_MAX_SIZE 64
|
||||
|
||||
|
|
Loading…
Reference in a new issue