Skip to content

machine/usb: support bidirectional endpoints by dynamic registration#5447

Merged
deadprogram merged 3 commits into
devfrom
usb-endpoint-with-slice
Jun 7, 2026
Merged

machine/usb: support bidirectional endpoints by dynamic registration#5447
deadprogram merged 3 commits into
devfrom
usb-endpoint-with-slice

Conversation

@sago35
Copy link
Copy Markdown
Member

@sago35 sago35 commented Jun 7, 2026

This change is for enabling bidirectional endpoints.

Before the change, the endPoints could only be configured as either In or Out for the same endpoint. This change removes that restriction.
By merging this change, the modifications in #5405 will work properly.

The tests were conducted in the following environment. I have verified that HID works using the actual examples/hid-keyboard. Furthermore, I have confirmed that it functions correctly even when HID_ENDPOINT_IN is changed to a different number, or when it is defined in a bidirectional format.

  • rp2040
    • waveshare-rp2040-zero
  • rp2350
    • pico2
  • atsamd51
    • wioterminal
  • atsamd21
    • qtpy
  • nrf52840
    • feathre-nrf52840

I didn't have it on hand, so I would appreciate it if someone could test it. I think it should be fine as long as the hid-keyboard works.
I found a Pico 2, so I was able to confirm that it works correctly on the RP2350 as well.

@sago35
Copy link
Copy Markdown
Member Author

sago35 commented Jun 7, 2026

I have appended the changes from #5405 after this modification and confirmed that it works on the RP2040. However, it did not work on the Wio Terminal. This seems to require a bit more investigation.

@sago35 sago35 marked this pull request as draft June 7, 2026 03:23
@sago35 sago35 changed the title machine/usb: dynamically register USB endpoints using slice machine/usb: support bidirectional endpoints by dynamic registration Jun 7, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 7, 2026

Size difference with the dev branch:

Binary size difference
 flash                          ram
 before   after   diff          before   after   diff
   7516    7516      0   0.00%    2296    2296      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/at24cx/main.go
  71440   71440      0   0.00%    3640    3640      0   0.00% tinygo build -size short -o ./build/test.hex -target=pinetime     ./examples/bma42x/main.go
   7948    7948      0   0.00%    3336    3336      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/sram/main.go
  21980   21980      0   0.00%    3532    3532      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/time/main.go
   4540    4540      0   0.00%    2256    2256      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/easystepper/main.go
   7204    7204      0   0.00%    2260    2260      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/gc9a01/main.go
   5648    5648      0   0.00%    2256    2256      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hd44780/customchar/main.go
   5688    5688      0   0.00%    2256    2256      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hd44780/text/main.go
  16132   16132      0   0.00%    2340    2340      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/hub75/main.go
  26336   26336      0   0.00%    2304    2304      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/lsm303agr/main.go
  27776   27776      0   0.00%    3808    3808      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/microbitmatrix/main.go
  27784   27784      0   0.00%    5852    5852      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit-v2 ./examples/microbitmatrix/main.go
   6380    6380      0   0.00%    3268    3268      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setbuffer/main.go
   4764    4764      0   0.00%    2260    2260      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setpixel/main.go
   3113    3113      0   0.00%     560     560      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino ./examples/servo
  57688   57688      0   0.00%    3672    3672      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht3x/main.go
  57688   57688      0   0.00%    3680    3680      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/sht4x/main.go
  57688   57688      0   0.00%    3672    3672      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/shtc3/main.go
   6032    6032      0   0.00%    2260    2260      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ssd1331/main.go
   6924    6924      0   0.00%    2260    2260      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7735/main.go
   6604    6604      0   0.00%    2260    2260      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/st7789/main.go
   6492    6492      0   0.00%    2300    2300      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13/main.go
   6080    6080      0   0.00%    2292    2292      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13x/main.go
   6384    6384      0   0.00%    2300    2300      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd4in2/main.go
   5668    5668      0   0.00%    9706    9706      0   0.00% tinygo build -size short -o ./build/test.bin -target=m5stamp-c3          ./examples/ws2812
   1997    1997      0   0.00%     600     600      0   0.00% tinygo build -size short -o ./build/test.hex -target=arduino   ./examples/ws2812
   1488    1488      0   0.00%     182     182      0   0.00% tinygo build -size short -o ./build/test.hex -target=digispark ./examples/ws2812
   7116    7116      0   0.00%   10182   10182      0   0.00% tinygo build -size short -o ./build/test.bin -target=xiao-esp32c3 ./examples/ws2812
   7492    7492      0   0.00%    3308    3308      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-f103rb ./examples/shiftregister/main.go
   7184    7184      0   0.00%    2256    2256      0   0.00% tinygo build -size short -o ./build/test.hex -target=hifive1b ./examples/ssd1351/main.go
   9564    9564      0   0.00%    5232    5232      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-l432kc ./examples/aht20/main.go
  13384   13384      0   0.00%    4924    4924      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/sx126x/lora_rxtx/
 123052  123052      0   0.00%    8112    8112      0   0.00% tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/lora/lorawan/atcmd/
  62296   62296      0   0.00%    3768    3768      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/ndir/main_ndir.go
 344936  345356    420   0.12%   22468   22716    248   1.10% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/webserver/
  62348   62948    600   0.96%    8576    8812    236   2.75% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/i2csoft/adt7410/
 117504  118104    600   0.51%   13704   13940    236   1.72% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/webclient/
 104136  104744    608   0.58%   10408   10644    236   2.27% tinygo build -size short -o ./build/test.hex -target=metro-m4-airlift -stack-size 8kb ./examples/net/socket/
  67068   67684    616   0.92%    9368    9604    236   2.52% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/flash/console/qspi
 263272  263888    616   0.23%   47096   47332    236   0.50% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/slideshow
  74124   74748    624   0.84%   11108   11344    236   2.12% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/sdcard/console/
  12588   13224    636   5.05%    7324    7560    236   3.22% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/touch/resistive/pyportal_touchpaint/main.go
  64664   65312    648   1.00%    6568    6804    236   3.59% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp280/main.go
 353216  353868    652   0.18%   17376   17624    248   1.43% tinygo build -size short -o ./build/test.hex -target=pyportal -stack-size 8kb ./examples/net/http-get/
  63192   63848    656   1.04%    6296    6540    244   3.88% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840 ./examples/is31fl3731/main.go
  62948   63604    656   1.04%    6332    6568    236   3.73% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840 ./examples/max6675/main.go
 121036  121700    664   0.55%    8428    8664    236   2.80% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 -stack-size 8kb ./examples/net/tcpclient/
  10396   11064    668   6.43%    7264    7500    236   3.25% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/basic
  10428   11100    672   6.44%    7256    7492    236   3.25% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/scroll
  62132   62812    680   1.09%    6528    6764    236   3.62% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adt7410/main.go
  77024   77704    680   0.88%    7804    8040    236   3.02% tinygo build -size short -o ./build/test.hex -target=p1am-100 ./examples/p1am/main.go
  65648   66328    680   1.04%    6600    6836    236   3.58% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ndir/main_ndir.go
  71416   72100    684   0.96%    6688    6920    232   3.47% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/time/
 346304  346988    684   0.20%   22424   22668    244   1.09% tinygo build -size short -o ./build/test.hex -target=wioterminal -stack-size 8kb ./examples/net/mqttclient/paho/
  66024   66712    688   1.04%    6544    6780    236   3.61% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmi160/main.go
  72208   72896    688   0.95%    6584    6820    236   3.58% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp2515/main.go
  77576   78264    688   0.89%    6680    6916    236   3.53% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/dht/main.go
  71916   72604    688   0.96%    6688    6924    236   3.53% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/alarm/
  71812   72500    688   0.96%    6688    6924    236   3.53% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/timer/
  29664   30356    692   2.33%   38424   38660    236   0.61% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/ili9341/pyportal_boing
  10264   10960    696   6.78%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/tm1637/main.go
  42808   43504    696   1.63%    8964    9200    236   2.63% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/sx127x/lora_rxtx/
  13876   14584    708   5.10%    7136    7372    236   3.31% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/amg88xx
   8232    8944    712   8.65%    7128    7364    236   3.31% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/shifter/main.go
  10400   11112    712   6.85%    7128    7364    236   3.31% tinygo build -size short -o ./build/test.elf -target=wioterminal ./examples/axp192/m5stack-core2-blinky/
  12368   13080    712   5.76%    4900    5136    236   4.82% tinygo build -size short -o ./build/test.uf2 -target=nicenano ./examples/sharpmem/main.go
 120596  121308    712   0.59%   12516   12752    236   1.89% tinygo build -size short -o ./build/test.hex -target=elecrow-rp2350 -stack-size 8kb ./examples/net/ntpclient/
   9056    9772    716   7.91%    7128    7364    236   3.31% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/touch/resistive/fourwire/main.go
  28152   28872    720   2.56%    7168    7404    236   3.29% tinygo build -size short -o ./build/test.hex -target=feather-m4 ./examples/lsm303dlhc/main.go
  32248   32968    720   2.23%    5120    5356    236   4.61% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bme280/main.go
  69140   69860    720   1.04%    7436    7672    236   3.17% tinygo build -size short -o ./build/test.hex -target=pico ./examples/ndir/main_ndir.go
  68828   69548    720   1.05%    7404    7640    236   3.19% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mcp9808/main.go
  12628   13352    724   5.73%    8712    8948    236   2.71% tinygo build -size short -o ./build/test.hex -target=xiao-ble ./examples/ssd1306/
  18080   18804    724   4.00%    7568    7780    212   2.80% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/as560x/main.go
 175308  176032    724   0.41%   14516   14748    232   1.60% tinygo build -size short -o ./build/test.hex -target=elecrow-rp2040 -stack-size 8kb ./examples/net/tlsclient/
  70748   71476    728   1.03%    7328    7564    236   3.22% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/flash/console/spi
  88588   89316    728   0.82%    7756    7992    236   3.04% tinygo build -size short -o ./build/test.hex -target=challenger-rp2040 ./examples/net/ntpclient/
  24916   25648    732   2.94%   14076   14312    236   1.68% tinygo build -size short -o ./build/test.hex -target=feather-nrf52840-sense ./examples/waveshare-epd/epd1in54/main.go
  14532   15268    736   5.06%    6928    7164    236   3.41% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/hts221/main.go
  11272   12008    736   6.53%    5224    5460    236   4.52% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/ili9341/basic
   9920   10656    736   7.42%    4880    5116    236   4.84% tinygo build -size short -o ./build/test.hex -target=circuitplay-bluefruit ./examples/tone
  11652   12392    740   6.35%    6928    7164    236   3.41% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/apds9960/proximity/main.go
 157068  157808    740   0.47%    9384    9624    240   2.56% tinygo build -size short -o ./build/test.hex -target=nano-rp2040 -stack-size 8kb ./examples/net/mqttclient/natiu/
 315444  316192    748   0.24%   16648   16892    244   1.47% tinygo build -size short -o ./build/test.hex -target=nano-rp2040 -stack-size 8kb ./examples/net/websocket/dial/
  11356   12108    752   6.62%    5216    5452    236   4.52% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/ili9341/scroll
   9180    9932    752   8.19%    5120    5356    236   4.61% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp23017/main.go
  13916   14676    760   5.46%    6928    7164    236   3.41% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/lps22hb/main.go
 167484  168244    760   0.45%   10432   10676    244   2.34% tinygo build -size short -o ./build/test.hex -target=arduino-mkrwifi1010 -stack-size 8kb ./examples/net/tlsclient/
  10668   11448    780   7.31%    5120    5356    236   4.61% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis3dh/main.go
  10528   11312    784   7.45%    5088    5324    236   4.64% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/hd44780i2c/main.go
   9604   10396    792   8.25%    5104    5340    236   4.62% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ds18b20/main.go
   9580   10380    800   8.35%    5128    5364    236   4.60% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp23017-multiple/main.go
  15936   16740    804   5.05%    5088    5324    236   4.64% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl53l1x/main.go
  18576   19384    808   4.35%    6784    7020    236   3.48% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/adafruit4650
  12496   13304    808   6.47%    5128    5364    236   4.60% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/lsm6ds3/main.go
  16952   17760    808   4.77%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/thermistor/main.go
  16524   17332    808   4.89%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/microphone/main.go
   8924    9736    812   9.10%    5088    5324    236   4.64% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adxl345/main.go
   9084    9896    812   8.94%    5088    5324    236   4.64% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/main.go
  11980   12792    812   6.78%    5152    5388    236   4.58% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bmp388/main.go
  10172   10984    812   7.98%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mag3110/main.go
   9580   10392    812   8.48%    5088    5324    236   4.64% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mcp3008/main.go
   7624    8436    812  10.65%    5088    5324    236   4.64% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mma8653/main.go
   7528    8340    812  10.79%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mpu6050/main.go
  12428   13240    812   6.53%    5120    5356    236   4.61% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/veml6070/main.go
  13440   14252    812   6.04%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/lis2mdl/main.go
  11420   12232    812   7.11%    5104    5340    236   4.62% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/max72xx/main.go
   7336    8148    812  11.07%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/clkout/
  12368   13180    812   6.57%    5120    5356    236   4.61% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/ina219/main.go
   8168    8984    816   9.99%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bh1750/main.go
   7532    8348    816  10.83%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/blinkm/main.go
  23988   24804    816   3.40%    5952    6188    236   3.97% tinygo build -size short -o ./build/test.hex -target=metro-rp2350 ./examples/bno08x/i2c/main.go
   8580    9396    816   9.51%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/hcsr04/main.go
   8860    9676    816   9.21%    5088    5324    236   4.64% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/ina260/main.go
   8112    8928    816  10.06%    5088    5324    236   4.64% tinygo build -size short -o ./build/test.uf2 -target=circuitplay-express ./examples/makeybutton/main.go
   7924    8740    816  10.30%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/ttp229/main.go
  10024   10844    820   8.18%    5108    5344    236   4.62% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/itsybitsy-m0/main.go
  15516   16336    820   5.28%    6012    6248    236   3.93% tinygo build -size short -o ./build/test.hex -target=pico     ./examples/sgp30
  12040   12864    824   6.84%    5940    6176    236   3.97% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/seesaw/soil-sensor
  14488   15312    824   5.69%    5088    5324    236   4.64% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl6180x/main.go
  13724   14548    824   6.00%    5964    6200    236   3.96% tinygo build -size short -o ./build/test.hex -target=badger2040 ./examples/uc8151/main.go
  27912   28740    828   2.97%   19024   19260    236   1.24% tinygo build -size short -o ./build/test.hex -target=pico ./examples/waveshare-epd/epd2in66b/main.go
 396480  397308    828   0.21%   19404   19636    232   1.20% tinygo build -size short -o ./build/test.hex -target=matrixportal-m4 -stack-size 8kb ./examples/net/webstatic/
  13296   14128    832   6.26%    5892    6128    236   4.01% tinygo build -size short -o ./build/test.hex -target=xiao-rp2040 ./examples/ssd1306/
  13396   14228    832   6.21%    5892    6128    236   4.01% tinygo build -size short -o ./build/test.hex -target=thumby ./examples/ssd1306/
   7224    8056    832  11.52%    5120    5356    236   4.61% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/ws2812
   6932    7764    832  12.00%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l9110x/simple/main.go
  13068   13900    832   6.37%    6880    7116    236   3.43% tinygo build -size short -o ./build/test.hex -target=pico ./examples/irremote/main.go
  12580   13416    836   6.65%    5952    6188    236   3.97% tinygo build -size short -o ./build/test.hex -target=pico ./examples/touch/capacitive
  11900   12736    836   7.03%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/buzzer/main.go
  11968   12804    836   6.99%    5968    6204    236   3.95% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/scd4x/main.go
  27820   28660    840   3.02%    5120    5356    236   4.61% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp180/main.go
  13376   14216    840   6.28%    5948    6184    236   3.97% tinygo build -size short -o ./build/test.hex -target=qtpy-rp2040 ./examples/seesaw/rotary-encoder
   8876    9716    840   9.46%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l293x/speed/main.go
   9300   10140    840   9.03%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l9110x/speed/main.go
  12788   13628    840   6.57%    5900    6136    236   4.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/pcf8591/
  10692   11532    840   7.86%    5888    6124    236   4.01% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/xpt2046/main.go
  11812   12652    840   7.11%    5908    6144    236   3.99% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mpu6886/main.go
  11336   12176    840   7.41%    5900    6136    236   4.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/mpu9150/main.go
  10196   11036    840   8.24%    6372    6608    236   3.70% tinygo build -size short -o ./build/test.hex -target=macropad-rp2040 ./examples/encoders/quadrature-interrupt
  13592   14432    840   6.18%    5896    6132    236   4.00% tinygo build -size short -o ./build/test.hex -target=pico ./examples/tmc5160/main.go
  13964   14808    844   6.04%    5964    6200    236   3.96% tinygo build -size short -o ./build/test.hex -target=pico ./examples/pca9685/main.go
  13664   14508    844   6.18%    5916    6152    236   3.99% tinygo build -size short -o ./build/test.hex -target=pico ./examples/qmi8658c/main.go
  33452   34296    844   2.52%    7408    7648    240   3.24% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/ssd1289/main.go
   6956    7804    848  12.19%    5080    5316    236   4.65% tinygo build -size short -o ./build/test.hex -target=arduino-nano33 ./examples/l293x/simple/main.go
  37760   38608    848   2.25%    6604    6836    232   3.51% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/pcf8523/
  14284   15132    848   5.94%    5956    6192    236   3.96% tinygo build -size short -o ./build/test.hex -target=pico ./examples/ens160/main.go
  22876   23724    848   3.71%    7268    7504    236   3.25% tinygo build -size short -o ./build/test.hex -target=pico ./examples/w5500/main.go
  17880   18736    856   4.79%    5972    6208    236   3.95% tinygo build -size short -o ./build/test.hex -target=pico ./examples/si5351/main.go
  13324   14188    864   6.48%    5936    6172    236   3.98% tinygo build -size short -o ./build/test.hex -target=macropad-rp2040 ./examples/sh1106/macropad_spi
  29288   30160    872   2.98%    5316    5556    240   4.51% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/ds3231/alarms/main.go
  14024   14896    872   6.22%    6408    6644    236   3.68% tinygo build -size short -o ./build/test.hex -target=badger2040 ./examples/waveshare-epd/epd2in9v2/main.go
  44316   45192    876   1.98%    7736    7968    232   3.00% tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/tmc2209/main.go
  43208   44100    892   2.06%    5316    5556    240   4.51% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/ds3231/basic/main.go
  68652   69596    944   1.38%    6852    7088    236   3.44% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/uart/main.go
  67952   68900    948   1.40%    6704    6944    240   3.58% tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/i2c/main.go
6444558 6538330  93772   0.04% 1060314 1089138  28824   0.03%

@sago35
Copy link
Copy Markdown
Member Author

sago35 commented Jun 7, 2026

Although I have marked this PR as a draft, it looks good to me so far. However, while incorporating #5405 works fine on the RP2040, it did not work on the ATSAMD51. I think this will require a bit more investigation.

@sago35
Copy link
Copy Markdown
Member Author

sago35 commented Jun 7, 2026

When I configured the HID settings on the Wio Terminal to use EP4 In/Out, it worked. There might be a limitation with the USB Device on the ATSAMD51.

In the original configuration of #5405, it is set to use EP2/IN and EP4/OUT.

@sago35
Copy link
Copy Markdown
Member Author

sago35 commented Jun 7, 2026

Also, the following code worked on the Wio Terminal as well. From this, it appears to be an Endpoint limitation on the ATSAMD51.
And it also works on the RP2040, ATSAMD21, and nRF52840.

	Configuration: Append([][]byte{
		ConfigurationCDCHID.Bytes(),
		InterfaceAssociationCDC.Bytes(),
		InterfaceCDCControl.Bytes(),
		ClassSpecificCDCHeader.Bytes(),
		ClassSpecificCDCACM.Bytes(),
		ClassSpecificCDCUnion.Bytes(),
		ClassSpecificCDCCallManagement.Bytes(),
		EndpointIN(EndpointEP1, TransferTypeInterrupt, 0x10, 0x10).Bytes(),
		InterfaceCDCData.Bytes(),
		EndpointOUT(EndpointEP2, TransferTypeBulk, 0x40, 0x00).Bytes(),
		EndpointIN(EndpointEP2, TransferTypeBulk, 0x40, 0x00).Bytes(), // CDC: EP3IN -> EP2IN
		InterfaceHID.Bytes(),
		ClassHID.Bytes(),
		EndpointIN(EndpointEP3, TransferTypeInterrupt, 0x40, 0x01).Bytes(), // HID: EP2IN -> EP3IN
		EndpointOUT(EndpointEP3, TransferTypeInterrupt, 0x40, 0x01).Bytes(), // HID: EP4OUT -> EP3IN
	}),

@sago35 sago35 force-pushed the usb-endpoint-with-slice branch from e9be5cb to b828b3f Compare June 7, 2026 05:51
@sago35
Copy link
Copy Markdown
Member Author

sago35 commented Jun 7, 2026

Since it has been confirmed to work correctly on the RP2350 as well, this PR is ready for review.

@sago35 sago35 marked this pull request as ready for review June 7, 2026 05:59
Copy link
Copy Markdown
Contributor

@digitalentity digitalentity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great debugging! I totally missed the endPoints index in the #5405.

Copy link
Copy Markdown
Contributor

@digitalentity digitalentity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comfirmed working on RP2

@deadprogram
Copy link
Copy Markdown
Member

So we need both #5405 and also this PR for everything to work as expected, is that correct @sago35 and @digitalentity? If so then #5405 needs to also be moved out of draft.

@digitalentity
Copy link
Copy Markdown
Contributor

I think this PR alone is fine, the #5405 will need to change to make sure EPs are mapped in a supported way on all platforms (or even allocated fully dynamically in other of initialization).

@deadprogram
Copy link
Copy Markdown
Member

I think this PR alone is fine, the #5405 will need to change to make sure EPs are mapped in a supported way on all platforms (or even allocated fully dynamically in other of initialization).

OK thanks. @sago35 can you please rebase against the latest dev and resolve the merge conflict and then we can get this merged.

@sago35 sago35 force-pushed the usb-endpoint-with-slice branch from b828b3f to 607fba3 Compare June 7, 2026 13:09
@sago35
Copy link
Copy Markdown
Member Author

sago35 commented Jun 7, 2026

I don't know how to run the tests in builder/sizes_test.go, so for now, I need to wait for the CI to run at least once.

@digitalentity
Copy link
Copy Markdown
Contributor

I don't know how to run the tests in builder/sizes_test.go, so for now, I need to wait for the CI to run at least once.

make test runs them as well.

@sago35
Copy link
Copy Markdown
Member Author

sago35 commented Jun 7, 2026

Based on the CI results, I have fixed the binary size test for the Wio Terminal. Unfortunately, there is an overall increase in size. With this, the CI should pass as well.

@deadprogram
Copy link
Copy Markdown
Member

Thank you very much for working on this @sago35 and @digitalentity awesome collaboration! Now squash/merging.

@deadprogram deadprogram merged commit ca584de into dev Jun 7, 2026
26 checks passed
@deadprogram deadprogram deleted the usb-endpoint-with-slice branch June 7, 2026 18:33
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.

3 participants