cdc_uart: add CTS/RTS configuration options to board_example_config For high data rate applications it's desirable to use hardware flow control to prevent characters getting dropped when faced with the vagaries of RTOS and kernel latencies. Adding PROBE_UART_HWFC enables the UART's CTS/RTS pins, and SET_LINE_STATE messages no longer affect the RTS pin.
diff --git a/include/board_example_config.h b/include/board_example_config.h index 825e6fb..517916b 100644 --- a/include/board_example_config.h +++ b/include/board_example_config.h
@@ -37,6 +37,10 @@ /* Include CDC interface to bridge to target UART. Omit if not used. */ #define PROBE_CDC_UART + +/* Board implements hardware flow control for UART RTS/CTS instead of ACM control */ +#define PROBE_UART_HWFC + /* Target reset GPIO (active-low). Omit if not used.*/ #define PROBE_PIN_RESET 1 @@ -68,9 +72,17 @@ #define PROBE_UART_RX 5 #define PROBE_UART_INTERFACE uart1 #define PROBE_UART_BAUDRATE 115200 -/* Flow control - some or all of these can be omitted if not used */ + +#if defined(PROBE_UART_HWFC) +/* Hardware flow control - see 1.4.3 in the RP2040 datasheet for valid pin settings */ +#define PROBE_UART_CTS 6 +#define PROBE_UART_RTS 7 +#else +/* Software flow control - RTS and DTR can be omitted if not used */ #define PROBE_UART_RTS 9 +#endif #define PROBE_UART_DTR 10 + #endif /* LED config - some or all of these can be omitted if not used */
diff --git a/src/cdc_uart.c b/src/cdc_uart.c index 6379aad..5c79781 100644 --- a/src/cdc_uart.c +++ b/src/cdc_uart.c
@@ -57,11 +57,23 @@ gpio_set_pulls(PROBE_UART_RX, 1, 0); uart_init(PROBE_UART_INTERFACE, PROBE_UART_BAUDRATE); +#ifdef PROBE_UART_HWFC + /* HWFC implies that hardware flow control is implemented and the + * UART operates in "full-duplex" mode (See USB CDC PSTN120 6.3.12). + * Default to pulling in the active direction, so an unconnected CTS + * behaves the same as if CTS were not enabled. */ + gpio_set_pulls(PROBE_UART_CTS, 0, 1); + gpio_set_function(PROBE_UART_RTS, GPIO_FUNC_UART); + gpio_set_function(PROBE_UART_CTS, GPIO_FUNC_UART); + uart_set_hw_flow(PROBE_UART_INTERFACE, true, true); +#else #ifdef PROBE_UART_RTS gpio_init(PROBE_UART_RTS); gpio_set_dir(PROBE_UART_RTS, GPIO_OUT); gpio_put(PROBE_UART_RTS, 1); #endif +#endif + #ifdef PROBE_UART_DTR gpio_init(PROBE_UART_DTR); gpio_set_dir(PROBE_UART_DTR, GPIO_OUT);