@@ -3,7 +3,6 @@ package msc
33import (
44 "machine"
55 "machine/usb"
6- "machine/usb/msc/csw"
76)
87
98func setupPacketHandler (setup usb.Setup ) bool {
@@ -18,11 +17,17 @@ func (m *msc) setupPacketHandler(setup usb.Setup) bool {
1817 wValue := (uint16 (setup .WValueH ) << 8 ) | uint16 (setup .WValueL )
1918 switch setup .BRequest {
2019 case usb .CLEAR_FEATURE :
21- ok = m .handleClearFeature (setup , wValue )
20+ if setup .BmRequestType == 0x02 { // Host-to-Device | Standard | Endpoint
21+ ok = m .handleClearFeature (setup , wValue )
22+ }
2223 case usb .GET_MAX_LUN :
23- ok = m .handleGetMaxLun (setup , wValue )
24+ if setup .BmRequestType == 0xA1 { // Device-to-Host | Class | Interface
25+ ok = m .handleGetMaxLun (setup , wValue )
26+ }
2427 case usb .MSC_RESET :
25- ok = m .handleReset (setup , wValue )
28+ if setup .BmRequestType == 0x21 { // Host-to-Device | Class | Interface
29+ ok = m .handleReset (setup , wValue )
30+ }
2631 }
2732 return ok
2833}
@@ -53,24 +58,25 @@ func (m *msc) handleClearFeature(setup usb.Setup, wValue uint16) bool {
5358 } else if wIndex == usb .MSC_ENDPOINT_OUT {
5459 m .stallEndpoint (usb .MSC_ENDPOINT_OUT )
5560 }
56- return ok
61+ machine .SendZlp ()
62+ return true
5763 }
5864
5965 // Clear the direction bit from the endpoint address for comparison
6066 wIndex := setup .WIndex & 0x7F
6167
62- // Clear the IN/OUT stalls if addressed to the endpoint, or both if addressed to the interface
63- if wIndex == usb .MSC_ENDPOINT_IN || wIndex == mscInterface {
68+ // Clear the IN/OUT stalls if addressed to the endpoint
69+ if wIndex == usb .MSC_ENDPOINT_IN {
6470 m .clearStallEndpoint (usb .MSC_ENDPOINT_IN )
6571 ok = true
6672 }
67- if wIndex == usb .MSC_ENDPOINT_OUT || wIndex == mscInterface {
73+ if wIndex == usb .MSC_ENDPOINT_OUT {
6874 m .clearStallEndpoint (usb .MSC_ENDPOINT_OUT )
6975 ok = true
7076 }
7177 // Send a CSW if needed to resume after the IN endpoint stall is cleared
7278 if m .state == mscStateStatus && wIndex == usb .MSC_ENDPOINT_IN {
73- m .sendCSW (csw . StatusPassed )
79+ m .sendCSW (m . respStatus )
7480 ok = true
7581 }
7682
0 commit comments