Skip to content

Commit 1625d14

Browse files
authored
Fix wire protocol hiccups for targets with CDC (#3224)
***NO_CI***
1 parent f1ebd5b commit 1625d14

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

CMake/binutils.ESP32.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,10 +752,14 @@ macro(nf_add_idf_as_library)
752752
string(APPEND SDKCONFIG_DEFAULT_CONTENTS "\nCONFIG_TINYUSB_CDC_ENABLED=y\n")
753753
string(APPEND SDKCONFIG_DEFAULT_CONTENTS "CONFIG_TINYUSB_DESC_PRODUCT_STRING=\"nanoFramework device\"\n")
754754
string(APPEND SDKCONFIG_DEFAULT_CONTENTS "CONFIG_TINYUSB_DESC_CDC_STRING=\"nanoFramework device\"\n")
755-
string(APPEND SDKCONFIG_DEFAULT_CONTENTS "CONFIG_TINYUSB_CDC_RX_BUFSIZE=64\n")
755+
# set the TX buffer as large as the WireProtocol packet size
756+
# no worries about the RX buffer
756757
string(APPEND SDKCONFIG_DEFAULT_CONTENTS "CONFIG_TINYUSB_CDC_TX_BUFSIZE=1024\n")
758+
# better to assign the tinyUSB task to the same core as the ReceiverTask
759+
string(APPEND SDKCONFIG_DEFAULT_CONTENTS "CONFIG_TINYUSB_TASK_AFFINITY=TINYUSB_TASK_AFFINITY_CPU0\n")
757760

758761
message(STATUS "Support for embedded USB CDC enabled")
762+
759763
else()
760764
message(STATUS "Support for embedded USB CDC **IS NOT** enabled")
761765

targets/ESP32/_common/WireProtocol_HAL_Interface.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ static bool WP_Initialise(COM_HANDLE port)
275275
tinyusb_config_cdcacm_t amc_cfg = {
276276
.usb_dev = TINYUSB_USBDEV_0,
277277
.cdc_port = TINYUSB_CDC_ACM_0,
278+
// parameter deprecated, therefore it doesn't matter what we put here
278279
.rx_unread_buf_sz = 1056,
279280
.callback_rx = &WP_Cdc_Rx_Callback,
280281
.callback_rx_wanted_char = NULL,
@@ -339,7 +340,9 @@ uint8_t WP_TransmitMessage(WP_Message *message)
339340
}
340341
}
341342

342-
tinyusb_cdcacm_write_flush(TINYUSB_CDC_ACM_0, 0);
343+
// need to call flush with a timeout to have it behave cooperatively with the RTOS
344+
// OK to silently ignore errors here
345+
tinyusb_cdcacm_write_flush(TINYUSB_CDC_ACM_0, pdMS_TO_TICKS(250));
343346

344347
return true;
345348
}
@@ -358,16 +361,17 @@ static bool WP_Initialise(COM_HANDLE port)
358361
// uninstall driver for console
359362
// ESP_ERROR_CHECK(uart_driver_delete(ESP32_WP_UART));
360363

361-
uart_config_t uart_config = {// baudrate
362-
.baud_rate = TARGET_SERIAL_BAUDRATE,
363-
// baudrate
364-
.data_bits = UART_DATA_8_BITS,
365-
// parity mode
366-
.parity = UART_PARITY_DISABLE,
367-
// stop bit mode
368-
.stop_bits = UART_STOP_BITS_1,
369-
// hardware flow control(cts/rts)
370-
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE};
364+
uart_config_t uart_config = {
365+
// baudrate
366+
.baud_rate = TARGET_SERIAL_BAUDRATE,
367+
// baudrate
368+
.data_bits = UART_DATA_8_BITS,
369+
// parity mode
370+
.parity = UART_PARITY_DISABLE,
371+
// stop bit mode
372+
.stop_bits = UART_STOP_BITS_1,
373+
// hardware flow control(cts/rts)
374+
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE};
371375

372376
ESP_ERROR_CHECK(uart_param_config(ESP32_WP_UART, &uart_config));
373377

0 commit comments

Comments
 (0)