Skip to content

Commit f037a12

Browse files
committed
Require 64 bytes extra CDC RX buffer
Once the buffer has less that an endpoint's worth, TinyUSB won't request more from the host. When that happens, ctrl-c will no longer be sent to the device and TinyUSB won't find the wanted character. Fixes #4444
1 parent 00824ad commit f037a12

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

ports/broadcom/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ CFLAGS += $(OPTIMIZATION_FLAGS)
107107

108108
# TinyUSB defines
109109
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_BCM2711 -DCFG_TUD_MIDI_RX_BUFSIZE=512 \
110-
-DCFG_TUD_CDC_RX_BUFSIZE=512 -DCFG_TUD_MIDI_TX_BUFSIZE=512 \
110+
-DCFG_TUD_CDC_RX_BUFSIZE=640 -DCFG_TUD_MIDI_TX_BUFSIZE=512 \
111111
-DCFG_TUD_CDC_TX_BUFSIZE=512 -DCFG_TUD_MSC_BUFSIZE=1024
112112

113113
#Debugging/Optimization

ports/mimxrt10xx/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ INC += \
4848
CFLAGS += -ftree-vrp -DNDEBUG
4949

5050
# TinyUSB defines
51-
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_MIMXRT10XX -DCFG_TUD_CDC_RX_BUFSIZE=512 -DCFG_TUD_CDC_TX_BUFSIZE=512
51+
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_MIMXRT10XX -DCFG_TUD_CDC_RX_BUFSIZE=640 -DCFG_TUD_CDC_TX_BUFSIZE=512
5252
ifeq ($(CHIP_FAMILY),$(filter $(CHIP_FAMILY),MIMXRT1011 MIMXRT1015))
5353
CFLAGS += -DCFG_TUD_MIDI_RX_BUFSIZE=512 -DCFG_TUD_MIDI_TX_BUFSIZE=64 -DCFG_TUD_MSC_BUFSIZE=512
5454
else

supervisor/shared/usb/usb.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,20 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
317317

318318
#if MICROPY_KBD_EXCEPTION && CIRCUITPY_USB_CDC
319319

320+
// The CDC RX buffer impacts monitoring for ctrl-c. TinyUSB will only ask for
321+
// more from CDC if the free space in the buffer is greater than the endpoint
322+
// size. Setting CFG_TUD_CDC_RX_BUFSIZE to the endpoint size and then sending
323+
// any character will prevent ctrl-c from working. Require at least a 64
324+
// character buffer.
325+
#if CFG_TUD_CDC_RX_BUFSIZE < CFG_TUD_CDC_EP_BUFSIZE + 64
326+
#error "CFG_TUD_CDC_RX_BUFSIZE must be 64 bytes bigger than endpoint size."
327+
#endif
328+
320329
/**
321330
* Callback invoked when received an "wanted" char.
322331
* @param itf Interface index (for multiple cdc interfaces)
323332
* @param wanted_char The wanted char (set previously)
324333
*/
325-
326-
// Only called when console is enabled.
327334
void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char) {
328335
// Workaround for using shared/runtime/interrupt_char.c
329336
// Compare mp_interrupt_char with wanted_char and ignore if not matched

0 commit comments

Comments
 (0)