Skip to content

machine/usb/msc: reset MSC state when the host sets the configuration - #5809

Merged
deadprogram merged 2 commits into
msc-read-taskfrom
msc-bus-reset
Oct 2, 2026
Merged

deadprogram merged 2 commits into
msc-read-taskfrom
msc-bus-reset

Conversation

@deadprogram

Copy link
Copy Markdown
Member

Stacked on #5808, which moves #5805 to a branch in this repo. Replaces #5807.

When a command takes longer than the host timeout, Linux recovers with a USB port reset. MSC was not told about the reset, so it stayed in the data phase of the old command and treated the retried CBW as data. The retried command never completed and the Linux SCSI error handler ended up blocked.

The host sends SET_CONFIGURATION again after every USB reset, and that is handled in the shared usb.go for all chips. usb.SetupConfig gets an optional ResetHandler that is called there. MSC uses it to go back to waiting for a CBW, the same state reset as a Bulk-Only Reset, and also clears its stall flags since the endpoints are reinitialized.

Testing

On a Raspberry Pi Pico with a flash backed drive whose ReadAt stalls once for 40 s, longer than the 30 s Linux SCSI timeout:

  • Without this change the host port resets the device, the retried read never completes, and dd hangs in the kernel until the board is unplugged.
  • With it, the host resets once, the retried read works, and dd finishes with the same data as a normal read.

On dev without #5808 the same slow ReadAt blocks the USB interrupt and the device drops off the bus.

Also checked with both -scheduler=tasks and -scheduler=cores: the drive mounts, a 300 KB file written over USB reads back the same after a remount and a reboot, and src/examples/usb-storage still reads the same after a usbreset. src/examples/usb-storage builds for pico, xiao-rp2350, feather-nrf52840 and itsybitsy-m4.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

Size difference with the dev branch:

Binary size difference
 flash                          ram
 before   after   diff          before   after   diff
   8840    8840      0   0.00%    2320    2320      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/at24cx/main.go
  71856   71856      0   0.00%    3728    3728      0   0.00% tinygo build -size short -o ./build/test.hex -target=pinetime     ./examples/bma42x/main.go
   9256    9256      0   0.00%    3360    3360      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/sram/main.go
  22868   22868      0   0.00%    3592    3592      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/time/main.go
   4760    4760      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/easystepper/main.go
   6976    6976      0   0.00%    2344    2344      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/easystepper/async/main.go
   7540    7540      0   0.00%    2284    2284      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/gc9a01/main.go
  23684   23684      0   0.00%    8588    8588      0   0.00% tinygo build -size short -o ./build/test.bin -target=esp32-coreboard-v2 ./examples/gdew0154m09/main.go
   5880    5880      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hd44780/customchar/main.go
   5960    5960      0   0.00%    2280    2280      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hd44780/text/main.go
  16564   16564      0   0.00%    2428    2428      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hub75/main.go
  26600   26600      0   0.00%    2328    2328      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/lsm303agr/main.go
  30376   30376      0   0.00%    4152    4152      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/microbitmatrix/main.go
  30328   30328      0   0.00%    6196    6196      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit-v2 ./examples/microbitmatrix/main.go
   6676    6676      0   0.00%    3292    3292      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setbuffer/main.go
   5076    5076      0   0.00%    2284    2284      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setpixel/main.go
   2899    2899      0   0.00%     560     560      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino ./examples/servo
  58624   58624      0   0.00%    3728    3728      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht3x/main.go
  58576   58576      0   0.00%    3728    3728      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht4x/main.go
  58640   58640      0   0.00%    3728    3728      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/shtc3/main.go
   6372    6372      0   0.00%    2284    2284      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1331/main.go
   7220    7220      0   0.00%    2284    2284      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7735/main.go
   6916    6916      0   0.00%    2284    2284      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7789/main.go
   6788    6788      0   0.00%    2324    2324      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13/main.go
   6468    6468      0   0.00%    2316    2316      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13x/main.go
   6660    6660      0   0.00%    2324    2324      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd4in2/main.go
   6122    6122      0   0.00%    8464    8464      0   0.00% tinygo build -size short -o ./build/test.bin -target=m5stamp-c3          ./examples/ws2812
   1799    1799      0   0.00%     600     600      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino   ./examples/ws2812
   1280    1280      0   0.00%     182     182      0   0.00% tinygo build -size short -o ./build/test.hex -target=digispark ./examples/ws2812
   7776    7776      0   0.00%    8744    8744      0   0.00% tinygo build -size short -o ./build/test.bin -target=xiao-esp32c3 ./examples/ws2812
   8180    8180      0   0.00%    3324    3324      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-f103rb ./examples/shiftregister/main.go
   7596    7596      0   0.00%    2288    2288      0   0.00% tinygo build -size short -o ./build/test.hex -target=hifive1b ./examples/ssd1351/main.go
  10600   10600      0   0.00%    5280    5280      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-l432kc ./examples/aht20/main.go
  12464   12464      0   0.00%    4696    4696      0   0.00% tinygo build -size short -o ./build/test.elf -target=m5stack-core2 ./examples/ft6336/basic/
  20044   20044      0   0.00%    4964    4964      0   0.00% tinygo build -size short -o ./build/test.elf -target=m5stack-core2 ./examples/ft6336/touchpaint/
  14416   14416      0   0.00%    5060    5060      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/sx126x/lora_rxtx/
 125236  125236      0   0.00%    8448    8448      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/lora/lorawan/atcmd/
  63272   63272      0   0.00%    3792    3792      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ndir/main_ndir.go
  15816   15872     56   0.35%    6684    6708     24   0.36% tinygo build -size short -o ./build/test.hex -target=badger2040 ./examples/waveshare-epd/epd2in9v2/main.go
  11364   11436     72   0.63%    5412    5436     24   0.44% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adxl345/main.go
  12644   12716     72   0.57%    5412    5436     24   0.44% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mag3110/main.go
   9476    9548     72   0.76%    5364    5388     24   0.45% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ttp229/main.go
  10580   10668     88   0.83%    5372    5396     24   0.45% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/main.go
  13252   13340     88   0.66%    7212    7236     24   0.33% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/apds9960/proximity/main.go
  10068   10156     88   0.87%    5412    5436     24   0.44% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bh1750/main.go
   9364    9452     88   0.94%    5412    5436     24   0.44% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/blinkm/main.go
  68004   68092     88   0.13%    6828    6852     24   0.35% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmi160/main.go
  66660   66748     88   0.13%    6860    6884     24   0.35% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp280/main.go
  13764   13852     88   0.64%    5444    5468     24   0.44% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bmp388/main.go
  31312   31400     88   0.28%    5644    5668     24   0.43% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/ds3231/alarms/main.go
  73048   73136     88   0.12%    7688    7712     24   0.31% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/flash/console/spi
  69880   69968     88   0.13%    7060    7084     24   0.34% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/i2c/main.go
  70384   70472     88   0.13%    7164    7188     24   0.34% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/uart/main.go
  10140   10228     88   0.87%    5436    5460     24   0.44% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/hcsr04/main.go
  14164   14252     88   0.62%    5572    5596     24   0.43% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/ili9341/basic
  14188   14276     88   0.62%    5572    5596     24   0.43% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/ili9341/scroll
  12404   12492     88   0.71%    5412    5436     24   0.44% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis3dh/main.go
  14052   14140     88   0.63%    5420    5444     24   0.44% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/lsm6ds3/main.go
  11780   11868     88   0.75%    5372    5396     24   0.45% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp3008/main.go
  74444   74532     88   0.12%    6940    6964     24   0.35% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp2515/main.go
  10100   10188     88   0.87%    5412    5436     24   0.44% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mma8653/main.go
  10052   10140     88   0.88%    5412    5436     24   0.44% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mpu6050/main.go
  18756   18844     88   0.47%    5364    5388     24   0.45% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/thermistor/main.go
  12020   12108     88   0.73%    5364    5388     24   0.45% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/tm1637/main.go
  17196   17284     88   0.51%    5484    5508     24   0.44% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl53l1x/main.go
  15868   15956     88   0.55%    5484    5508     24   0.44% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl6180x/main.go
   8692    8780     88   1.01%    5404    5428     24   0.44% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/ws2812
  33428   33516     88   0.26%    5412    5436     24   0.44% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bme280/main.go
  13028   13116     88   0.68%    5364    5388     24   0.45% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/buzzer/main.go
   8452    8540     88   1.04%    5364    5388     24   0.45% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l293x/simple/main.go
  10388   10476     88   0.85%    5364    5388     24   0.45% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l293x/speed/main.go
   8420    8508     88   1.05%    5364    5388     24   0.45% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l9110x/simple/main.go
  10820   10908     88   0.81%    5364    5388     24   0.45% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l9110x/speed/main.go
  15220   15308     88   0.58%    5412    5436     24   0.44% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis2mdl/main.go
  12916   13004     88   0.68%    5388    5412     24   0.45% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/max72xx/main.go
  79876   79964     88   0.11%    7008    7032     24   0.34% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/dht/main.go
  73044   73132     88   0.12%    7048    7072     24   0.34% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/alarm/
   9044    9132     88   0.97%    5404    5428     24   0.44% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/clkout/
  72884   72972     88   0.12%    7048    7072     24   0.34% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/timer/
  14740   14828     88   0.60%    5412    5436     24   0.44% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/ina219/main.go
   9596    9684     88   0.92%    5372    5396     24   0.45% tinygo build -size short -o ./build/test.uf2 -target=circuitplay-express ./examples/makeybutton/main.go
  11300   11388     88   0.78%    5388    5412     24   0.45% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ds18b20/main.go
  71008   71096     88   0.12%    7712    7736     24   0.31% tinygo build -size short -o ./build/test.hex -target=pico ./examples/ndir/main_ndir.go
  67716   67804     88   0.13%    6900    6924     24   0.35% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ndir/main_ndir.go
  11880   11968     88   0.74%    6664    6688     24   0.36% tinygo build -size short -o ./build/test.hex -target=macropad-rp2040 ./examples/encoders/quadrature-interrupt
  46920   47008     88   0.19%    8328    8352     24   0.29% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/tmc2209/main.go
 163596  163684     88   0.05%   10020   10044     24   0.24% tinygo build -size short -o ./build/test.hex -target=nano-rp2040 -stack-size 8kb ./examples/net/mqttclient/natiu/
 122316  122404     88   0.07%   14348   14372     24   0.17% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/webclient/
 373148  373236     88   0.02%   19056   19080     24   0.13% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/mqttclient/paho/
 180352  180440     88   0.05%   12496   12520     24   0.19% tinygo build -size short -o ./build/test.hex -target=elecrow-rp2040 -stack-size 8kb ./examples/net/tlsclient/
  63380   63484    104   0.16%    6860    6884     24   0.35% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adt7410/main.go
  15508   15612    104   0.67%    7468    7492     24   0.32% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/amg88xx
  12768   12872    104   0.81%    5384    5408     24   0.45% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/itsybitsy-m0/main.go
  29188   29292    104   0.36%    5412    5436     24   0.44% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp180/main.go
  24588   24692    104   0.42%    6300    6324     24   0.38% tinygo build -size short -o ./build/test.hex -target=metro-rp2350 ./examples/bno08x/i2c/main.go
  45184   45288    104   0.23%    5644    5668     24   0.43% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/ds3231/basic/main.go
  68872   68976    104   0.15%    9728    9752     24   0.25% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/flash/console/qspi
  12084   12188    104   0.86%    5396    5420     24   0.44% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/hd44780i2c/main.go
  16116   16220    104   0.65%    7212    7236     24   0.33% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/hts221/main.go
  11668   11772    104   0.89%    7612    7636     24   0.32% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/basic
  31036   31140    104   0.34%   38772   38796     24   0.06% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/pyportal_boing
  11644   11748    104   0.89%    7612    7636     24   0.32% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/scroll
 265972  266076    104   0.04%   47456   47480     24   0.05% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/slideshow
  15524   15628    104   0.67%    7212    7236     24   0.33% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/lps22hb/main.go
  29796   29900    104   0.35%    7460    7484     24   0.32% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/lsm303dlhc/main.go
  11452   11556    104   0.91%    5404    5428     24   0.44% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp23017/main.go
  11884   11988    104   0.88%    5412    5436     24   0.44% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp23017-multiple/main.go
  79604   79708    104   0.13%    8100    8124     24   0.30% tinygo build -size short -o ./build/test.hex -target=p1am-100 ./examples/p1am/main.go
  15712   15816    104   0.66%    6240    6264     24   0.38% tinygo build -size short -o ./build/test.hex -target=pico ./examples/pca9685/main.go
  15456   15560    104   0.67%    6224    6248     24   0.39% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/seesaw/soil-sensor
  15056   15160    104   0.69%    6224    6248     24   0.39% tinygo build -size short -o ./build/test.hex -target=qtpy-rp2040 ./examples/seesaw/rotary-encoder
  17272   17376    104   0.60%    6304    6328     24   0.38% tinygo build -size short -o ./build/test.hex -target=pico     ./examples/sgp30
   9460    9564    104   1.10%    7412    7436     24   0.32% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/shifter/main.go
  14316   14420    104   0.73%    9092    9116     24   0.26% tinygo build -size short -o ./build/test.hex -target=xiao-ble ./examples/ssd1306/
  15136   15240    104   0.69%    6264    6288     24   0.38% tinygo build -size short -o ./build/test.hex -target=xiao-rp2040 ./examples/ssd1306/
  15072   15176    104   0.69%    6256    6280     24   0.38% tinygo build -size short -o ./build/test.hex -target=thumby ./examples/ssd1306/
  12020   12124    104   0.87%    5180    5204     24   0.46% tinygo build -size short -o ./build/test.hex -target=circuitplay-bluefruit ./examples/tone
  14276   14380    104   0.73%    6236    6260     24   0.38% tinygo build -size short -o ./build/test.hex -target=pico ./examples/touch/capacitive
  13848   13952    104   0.75%    7672    7696     24   0.31% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/touch/resistive/pyportal_touchpaint/main.go
  26480   26584    104   0.39%   14368   14392     24   0.17% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840-sense ./examples/waveshare-epd/epd1in54/main.go
  31088   31192    104   0.33%   19304   19328     24   0.12% tinygo build -size short -o ./build/test.hex -target=pico ./examples/waveshare-epd/epd2in66b/main.go
  64684   64788    104   0.16%    6588    6612     24   0.36% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840 ./examples/is31fl3731/main.go
  18268   18372    104   0.57%    5356    5380     24   0.45% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/microphone/main.go
  13988   14092    104   0.74%    5412    5436     24   0.44% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/veml6070/main.go
  67744   67848    104   0.15%    7044    7068     24   0.34% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/time/
  15648   15752    104   0.66%    6232    6256     24   0.39% tinygo build -size short -o ./build/test.hex -target=pico ./examples/qmi8658c/main.go
  14736   14840    104   0.71%    6224    6248     24   0.39% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/pcf8591/
  10564   10668    104   0.98%    5412    5436     24   0.44% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/ina260/main.go
  76332   76436    104   0.14%   11484   11508     24   0.21% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/sdcard/console/
  62836   62940    104   0.17%    8868    8892     24   0.27% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/i2csoft/adt7410/
  11668   11772    104   0.89%    7420    7444     24   0.32% tinygo build -size short -o ./build/test.elf -target=wioterminal ./examples/axp192/m5stack-core2-blinky/
  12396   12500    104   0.84%    6164    6188     24   0.39% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/xpt2046/main.go
  37224   37328    104   0.28%    7952    7976     24   0.30% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/ssd1289/main.go
  15152   15256    104   0.69%    7216    7240     24   0.33% tinygo build -size short -o ./build/test.hex -target=pico ./examples/irremote/main.go
  15416   15520    104   0.67%    6248    6272     24   0.38% tinygo build -size short -o ./build/test.hex -target=badger2040 ./examples/uc8151/main.go
  13744   13848    104   0.76%    6252    6276     24   0.38% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/scd4x/main.go
  15392   15496    104   0.68%    6224    6248     24   0.39% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mpu6886/main.go
  13216   13320    104   0.79%    6216    6240     24   0.39% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mpu9150/main.go
  69392   69496    104   0.15%    7672    7696     24   0.31% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mcp9808/main.go
  15260   15364    104   0.68%    6172    6196     24   0.39% tinygo build -size short -o ./build/test.hex -target=pico ./examples/tmc5160/main.go
  13960   14064    104   0.74%    5176    5200     24   0.46% tinygo build -size short -o ./build/test.uf2 -target=nicenano ./examples/sharpmem/main.go
  63696   63800    104   0.16%    6616    6640     24   0.36% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840 ./examples/max6675/main.go
  19944   20048    104   0.52%    6336    6360     24   0.38% tinygo build -size short -o ./build/test.hex -target=pico ./examples/si5351/main.go
  24968   25072    104   0.42%    7584    7608     24   0.32% tinygo build -size short -o ./build/test.hex -target=pico ./examples/w5500/main.go
  91092   91196    104   0.11%    8116    8140     24   0.30% tinygo build -size short -o ./build/test.hex -target=challenger-rp2040 ./examples/net/ntpclient/
 126316  126420    104   0.08%    9056    9080     24   0.27% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 -stack-size 8kb ./examples/net/tcpclient/
 374508  374612    104   0.03%   19996   20020     24   0.12% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/webserver/
 126620  126724    104   0.08%   12332   12356     24   0.19% tinygo build -size short -o ./build/test.hex -target=elecrow-rp2350 -stack-size 8kb ./examples/net/ntpclient/
  19948   20068    120   0.60%    7060    7084     24   0.34% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/adafruit4650
  10812   10932    120   1.11%    7404    7428     24   0.32% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/touch/resistive/fourwire/main.go
  40076   40196    120   0.30%    6812    6836     24   0.35% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/pcf8523/
  46832   46952    120   0.26%    9584    9608     24   0.25% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/sx127x/lora_rxtx/
  17428   17548    120   0.69%    6276    6300     24   0.38% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/scd30/main.go
  19996   20116    120   0.60%    7828    7852     24   0.31% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/as560x/main.go
  15100   15220    120   0.79%    6284    6308     24   0.38% tinygo build -size short -o ./build/test.hex -target=macropad-rp2040 ./examples/sh1106/macropad_spi
  16048   16168    120   0.75%    6232    6256     24   0.39% tinygo build -size short -o ./build/test.hex -target=pico ./examples/ens160/main.go
  92112   92232    120   0.13%    7964    7988     24   0.30% tinygo build -size short -o ./build/test.hex -target=pico ./examples/sd
 358284  358404    120   0.03%   13560   13584     24   0.18% tinygo build -size short -o ./build/test.hex -target=nano-rp2040 -stack-size 8kb ./examples/net/websocket/dial/
 108256  108376    120   0.11%   11036   11060     24   0.22% tinygo build -size short -o ./build/test.hex -target=metro-m4-airlift -stack-size 8kb ./examples/net/socket/
 426064  426184    120   0.03%   17540   17564     24   0.14% tinygo build -size short -o ./build/test.hex -target=matrixportal-m4 -stack-size 8kb ./examples/net/webstatic/
 172248  172368    120   0.07%    9224    9248     24   0.26% tinygo build -size short -o ./build/test.hex -target=arduino-mkrwifi1010 -stack-size 8kb ./examples/net/tlsclient/
 378552  378720    168   0.04%   14864   14888     24   0.16% tinygo build -size short -o ./build/test.hex -target=pyportal -stack-size 8kb ./examples/net/http-get/
7028732 7040988  12256   0.00% 1115246 1118222   2976   0.00%

@deadprogram

Copy link
Copy Markdown
Member Author

This PR is ready as part of stack. Tested on real hardware!

After a USB reset in the middle of a transfer MSC stayed in the data phase
of the old command, so the retried command never completed. The host sends
SET_CONFIGURATION again after every USB reset, so usb.SetupConfig now has an
optional ResetHandler that is called then, and MSC uses it to go back to
waiting for a CBW, the same as a Bulk-Only Reset.
@deadprogram

Copy link
Copy Markdown
Member Author

I tested this on top of the updated #5808, and with a rebased #5794 on top of both.

On a XIAO RP2350 with a flash backed drive and both -scheduler=tasks and -scheduler=cores, a ReadAt that stalls 40 s recovers after one host reset and the read matches. Without this PR the same read hangs dd in the kernel until the board is unplugged.

On a XIAO nRF52840 Sense with #5794 on top, a RAM drive whose ReadAt stalls 40 s also recovers after one host reset, and the file reads back the same.

One thing I still want to look at. After an UNMAP that fails and times out, the next write gets a host transport error in 10 of 11 runs with this PR and in none of 3 runs without it. That UNMAP error path never sends a CSW on dev either, so I will look at both together.

@deadprogram

Copy link
Copy Markdown
Member Author

Merging stack!

@deadprogram
deadprogram merged commit f6d269f into dev Oct 2, 2026
39 checks passed
@deadprogram
deadprogram deleted the msc-bus-reset branch October 2, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant