From 42f4a29e3e6947d7da8d29c5e73fb7721ed1a8be Mon Sep 17 00:00:00 2001 From: Koen De Vleeschauwer Date: Mon, 18 Sep 2023 09:22:50 +0200 Subject: [PATCH] rtt: fix hang when aux serial not read --- src/platforms/common/stm32/rtt_if.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/platforms/common/stm32/rtt_if.c b/src/platforms/common/stm32/rtt_if.c index 57544cf5652..f781918e837 100644 --- a/src/platforms/common/stm32/rtt_if.c +++ b/src/platforms/common/stm32/rtt_if.c @@ -121,8 +121,11 @@ uint32_t rtt_write(const char *buf, uint32_t len) if (len != 0 && usbdev && usb_get_config() && gdb_serial_get_dtr()) { for (uint32_t p = 0; p < len; p += CDCACM_PACKET_SIZE) { uint32_t plen = MIN(CDCACM_PACKET_SIZE, len - p); - while (usbd_ep_write_packet(usbdev, CDCACM_UART_ENDPOINT, buf + p, plen) <= 0) - continue; + uint32_t start_ms = platform_time_ms(); + while (usbd_ep_write_packet(usbdev, CDCACM_UART_ENDPOINT, buf + p, plen) <= 0) { + if (platform_time_ms() - start_ms >= 25) + return 0; /* drop silently */ + } } /* flush 64-byte packet on full-speed */ if (CDCACM_PACKET_SIZE == 64 && (len % CDCACM_PACKET_SIZE) == 0)