From ee21a7f39dbd143e6dfa8e7918df55b6afa1e49a Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Wed, 27 Dec 2023 17:30:17 +0100 Subject: [PATCH] speed up s3cdc flash read --- flasher_stub/stub_io.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/flasher_stub/stub_io.c b/flasher_stub/stub_io.c index 6cff6c377..f20f93b0d 100644 --- a/flasher_stub/stub_io.c +++ b/flasher_stub/stub_io.c @@ -171,8 +171,15 @@ void stub_tx_one_char(char c) #endif // WITH_USB_OTG uart_tx_one_char(c); #if WITH_USB_JTAG_SERIAL + static int transferred_without_flush = 0; if (stub_uses_usb_jtag_serial()){ - stub_tx_flush(); + // Defer flushing until we have a (full - 1) packet or a 0xc0 byte to increase throughput. + // Note that deferring flushing until we have a full packet causes hang-ups on some platforms. + transferred_without_flush++; + if( c == '\xc0' || transferred_without_flush == 63 ) { + stub_tx_flush(); + transferred_without_flush = 0; + } } #endif // WITH_USB_JTAG_SERIAL } @@ -296,6 +303,15 @@ void stub_io_set_baudrate(uint32_t current_baud, uint32_t new_baud) return; } #endif // WITH_USB_OTG +#if WITH_USB_JTAG_SERIAL + /* Workaround for ESP32-S3: UART baud rate divider is not set correctly by get_new_uart_divider. */ + if (stub_uses_usb_jtag_serial()) { + ets_delay_us(10000); + uart_div_modify(0, 0); + ets_delay_us(1000); + return; + } +#endif ets_delay_us(10000); uart_div_modify(0, get_new_uart_divider(current_baud, new_baud)); ets_delay_us(1000);