usb_serial_jtag: Fix bug of blocking TX xfer when using driver,

Merges https://github.com/espressif/esp-idf/pull/10208
This commit is contained in:
Cao Sen Miao 2023-02-22 14:39:06 +08:00
parent 6cf1d8ea40
commit 897082dbe5
3 changed files with 20 additions and 5 deletions

View File

@ -43,7 +43,9 @@ typedef struct {
* USB-SERIAL-JTAG driver's ISR will be attached to the same CPU core that calls this function. Thus, users
* should ensure that the same core is used when calling `usb_serial_jtag_driver_uninstall()`.
*
* @note Blocking mode will result in usb_serial_jtag_write_bytes() blocking until all bytes have been written to the TX FIFO.
* @note Blocking mode will result in usb_serial_jtag_write_bytes() blocking for a
* short period if the TX FIFO if full. It will not block again until the buffer
* has some space available again.
*
* @param usb_serial_jtag_driver_config_t Configuration for usb_serial_jtag driver.
*
@ -73,7 +75,7 @@ int usb_serial_jtag_read_bytes(void* buf, uint32_t length, TickType_t ticks_to_w
*
* @param src data buffer address
* @param size data length to send
* @param ticks_to_wait Timeout in RTOS ticks
* @param ticks_to_wait Maximum timeout in RTOS ticks
*
* @return
* - The number of bytes pushed to the TX FIFO

View File

@ -77,6 +77,8 @@ typedef struct {
// When the driver is used (via esp_vfs_usb_serial_jtag_use_driver),
// reads are either blocking or non-blocking depending on this flag.
bool non_blocking;
// TX has already tried a blocking send.
bool tx_tried_blocking;
// Newline conversion mode when transmitting
esp_line_endings_t tx_mode;
// Newline conversion mode when receiving
@ -404,7 +406,18 @@ static void usbjtag_tx_char_via_driver(int fd, int c)
{
char ch = (char) c;
TickType_t ticks = (TX_FLUSH_TIMEOUT_US / 1000) / portTICK_PERIOD_MS;
usb_serial_jtag_write_bytes(&ch, 1, ticks);
if (usb_serial_jtag_write_bytes(&ch, 1, 0) != 0) {
s_ctx.tx_tried_blocking = false;
return;
}
if (s_ctx.tx_tried_blocking == false) {
if (usb_serial_jtag_write_bytes(&ch, 1, ticks) != 0) {
return;
} else {
s_ctx.tx_tried_blocking = true;
}
}
}
void esp_vfs_usb_serial_jtag_use_nonblocking(void)

View File

@ -55,9 +55,9 @@ There are several limitations to the USB Serial/JTAG console feature. These may
2. If the application enters deep sleep mode, the USB Serial/JTAG device will disappear from the system.
3. For data sent in the direction of ESP32 to PC Terminal (e.g. stdout, logs), the ESP32 first writes to a small internal buffer. If this buffer becomes full (for example, if no PC Terminal is connected), the ESP32 will do a one-time wait of 50ms hoping for the PC Terminal to request the data. This can appear as a very brief 'pause' in your application.
3. For data sent in the direction of {IDF_TARGET_NAME} to PC Terminal (e.g. stdout, logs), the {IDF_TARGET_NAME} first writes to a small internal buffer. If this buffer becomes full (for example, if no PC Terminal is connected), the {IDF_TARGET_NAME} will do a one-time wait of 50ms hoping for the PC Terminal to request the data. This can appear as a very brief 'pause' in your application.
4. For data sent in the PC Terminal to ESP32 direction (e.g. console commands), many PC Terminals will wait for the ESP32 to ingest the bytes before allowing you to sending more data. This is in contrast to using a USB-to-Serial (UART) bridge chip, which will always ingest the bytes and send them to a (possibly not listening) ESP32.
4. For data sent in the PC Terminal to {IDF_TARGET_NAME} direction (e.g. console commands), many PC Terminals will wait for the {IDF_TARGET_NAME} to ingest the bytes before allowing you to sending more data. This is in contrast to using a USB-to-Serial (UART) bridge chip, which will always ingest the bytes and send them to a (possibly not listening) {IDF_TARGET_NAME}.
5. The USB Serial/JTAG device won't work in sleep modes as normal due to the lack of APB clock in sleep modes. This includes deep-sleep, light-sleep (automataic light-sleep as well).