From 04b512097e55eaa71f3f5fc92fa3bd4efa672e06 Mon Sep 17 00:00:00 2001 From: mikeysklar Date: Tue, 21 Apr 2026 12:30:25 -0700 Subject: [PATCH] raspberrypi: bump MSC buffer to 16KB for RP2040 boards with SD-over-MSC On Adafruit Feather RP2040 Adalogger and similar RP2040 boards that expose an SD card as a second USB MSC LUN, the default 1024-byte MSC buffer triggers bulk-IN endpoint stalls on macOS during multi-sector READ(10) probes. macOS retries ~18 times over 5 minutes then gives up; Linux handles the same firmware cleanly. Bumping CFG_TUD_MSC_BUFSIZE to 16384 clears the stall. This PR only applies the bump when CHIP_VARIANT=RP2040 and CIRCUITPY_SDCARDIO=1, so RP2350 boards and non-SD RP2040 boards keep the small buffer and the ~15KB RAM cost. This is a stopgap workaround. Metro RP2350 and Fruit Jam (both RP2350) handle the same macOS traffic fine at 1024 bytes, so the underlying issue is almost certainly in the RP2040 USB peripheral or tinyusb's rp2 device driver. Root-cause ticket will be filed separately. --- ports/raspberrypi/Makefile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index cef2806c87497..aa4637ca1a6b9 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -200,10 +200,22 @@ CFLAGS += \ -DCFG_TUD_CDC_RX_BUFSIZE=256 \ -DCFG_TUD_MIDI_TX_BUFSIZE=128 \ -DCFG_TUD_CDC_TX_BUFSIZE=256 \ - -DCFG_TUD_MSC_BUFSIZE=1024 \ -DPICO_RP2040_USB_DEVICE_UFRAME_FIX=1 \ -DPICO_RP2040_USB_DEVICE_ENUMERATION_FIX=1 \ +# CFG_TUD_MSC_BUFSIZE: 1024 bytes is enough for internal flash MSC but +# causes macOS bulk-IN endpoint stalls on RP2040 during multi-sector SD +# card READ(10) probes. Boards that expose an SD card over USB MSC can +# opt into a larger buffer by setting CIRCUITPY_USB_MSC_LARGE_BUFFER = 1 +# in their mpconfigboard.mk. Costs ~15 KB RAM; only worth enabling when +# the board actually has SD hardware exposed over USB MSC. +# Root cause tracked at hathach/tinyusb. +ifeq ($(CIRCUITPY_USB_MSC_LARGE_BUFFER),1) +CFLAGS += -DCFG_TUD_MSC_BUFSIZE=16384 +else +CFLAGS += -DCFG_TUD_MSC_BUFSIZE=1024 +endif + # option to override default optimization level, set in boards/$(BOARD)/mpconfigboard.mk CFLAGS += $(OPTIMIZATION_FLAGS)