Skip to content

Commit e165df3

Browse files
committed
test: add smoke test
1 parent 0ab6e25 commit e165df3

9 files changed

+36
-17
lines changed

GNUmakefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,10 @@ endif
792792
@$(MD5SUM) test.hex
793793
$(TINYGO) build -size short -o test.hex -target=feather-nrf52840 examples/usb-midi
794794
@$(MD5SUM) test.hex
795+
$(TINYGO) build -size short -o test.hex -target=pico examples/usb-storage
796+
@$(MD5SUM) test.hex
797+
$(TINYGO) build -size short -o test.hex -target=pico2 examples/usb-storage
798+
@$(MD5SUM) test.hex
795799
$(TINYGO) build -size short -o test.hex -target=nrf52840-s140v6-uf2-generic examples/machinetest
796800
@$(MD5SUM) test.hex
797801
ifneq ($(STM32), 0)

src/examples/usb-storage/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"machine"
5+
"machine/usb/msc"
6+
"time"
7+
)
8+
9+
func main() {
10+
msc.Port(machine.Flash)
11+
12+
for {
13+
time.Sleep(2 * time.Second)
14+
}
15+
}

src/machine/machine_atsamd21_usb.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,9 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
179179
setEPINTFLAG(i, epFlags)
180180
if (epFlags & sam.USB_DEVICE_EPINTFLAG_TRCPT0) > 0 {
181181
buf := handleEndpointRx(i)
182-
if usbRxHandler[i] != nil {
183-
usbRxHandler[i](buf)
182+
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
183+
AckUsbOutTransfer(i)
184184
}
185-
handleEndpointRxComplete(i)
186185
} else if (epFlags & sam.USB_DEVICE_EPINTFLAG_TRCPT1) > 0 {
187186
if usbTxHandler[i] != nil {
188187
usbTxHandler[i]()
@@ -402,7 +401,8 @@ func handleEndpointRx(ep uint32) []byte {
402401
return udd_ep_out_cache_buffer[ep][:count]
403402
}
404403

405-
func handleEndpointRxComplete(ep uint32) {
404+
// AckUsbOutTransfer is called to acknowledge the completion of a USB OUT transfer.
405+
func AckUsbOutTransfer(ep uint32) {
406406
// set byte count to zero
407407
usbEndpointDescriptors[ep].DeviceDescBank[0].PCKSIZE.ClearBits(usb_DEVICE_PCKSIZE_BYTE_COUNT_Mask << usb_DEVICE_PCKSIZE_BYTE_COUNT_Pos)
408408

src/machine/machine_atsamd51_usb.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,9 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
182182
setEPINTFLAG(i, epFlags)
183183
if (epFlags & sam.USB_DEVICE_ENDPOINT_EPINTFLAG_TRCPT0) > 0 {
184184
buf := handleEndpointRx(i)
185-
if usbRxHandler[i] != nil {
186-
usbRxHandler[i](buf)
185+
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
186+
AckUsbOutTransfer(i)
187187
}
188-
handleEndpointRxComplete(i)
189188
} else if (epFlags & sam.USB_DEVICE_ENDPOINT_EPINTFLAG_TRCPT1) > 0 {
190189
if usbTxHandler[i] != nil {
191190
usbTxHandler[i]()
@@ -405,7 +404,8 @@ func handleEndpointRx(ep uint32) []byte {
405404
return udd_ep_out_cache_buffer[ep][:count]
406405
}
407406

408-
func handleEndpointRxComplete(ep uint32) {
407+
// AckUsbOutTransfer is called to acknowledge the completion of a USB OUT transfer.
408+
func AckUsbOutTransfer(ep uint32) {
409409
// set byte count to zero
410410
usbEndpointDescriptors[ep].DeviceDescBank[0].PCKSIZE.ClearBits(usb_DEVICE_PCKSIZE_BYTE_COUNT_Mask << usb_DEVICE_PCKSIZE_BYTE_COUNT_Pos)
411411

src/machine/machine_nrf52840_usb.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,9 @@ func handleUSBIRQ(interrupt.Interrupt) {
193193
if nrf.USBD.EVENTS_ENDEPOUT[i].Get() > 0 {
194194
nrf.USBD.EVENTS_ENDEPOUT[i].Set(0)
195195
buf := handleEndpointRx(uint32(i))
196-
if usbRxHandler[i] != nil {
197-
usbRxHandler[i](buf)
196+
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
197+
AckUsbOutTransfer(uint32(i))
198198
}
199-
handleEndpointRxComplete(uint32(i))
200199
exitCriticalSection()
201200
}
202201
}
@@ -291,7 +290,8 @@ func handleEndpointRx(ep uint32) []byte {
291290
return udd_ep_out_cache_buffer[ep][:count]
292291
}
293292

294-
func handleEndpointRxComplete(ep uint32) {
293+
// AckUsbOutTransfer is called to acknowledge the completion of a USB OUT transfer.
294+
func AckUsbOutTransfer(ep uint32) {
295295
// set ready for next data
296296
nrf.USBD.SIZE.EPOUT[ep].Set(0)
297297
}

src/machine/machine_rp2040_usb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
9696
if s2&(1<<(i*2+1)) > 0 {
9797
buf := handleEndpointRx(uint32(i))
9898
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
99-
AckEndpointRxMessage(uint32(i))
99+
AckUsbOutTransfer(uint32(i))
100100
}
101101
}
102102
}

src/machine/machine_rp2350_usb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func handleUSBIRQ(intr interrupt.Interrupt) {
9999
if s2&(1<<(i*2+1)) > 0 {
100100
buf := handleEndpointRx(uint32(i))
101101
if usbRxHandler[i] == nil || usbRxHandler[i](buf) {
102-
AckEndpointRxMessage(uint32(i))
102+
AckUsbOutTransfer(uint32(i))
103103
}
104104
}
105105
}

src/machine/machine_rp2_usb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ func handleEndpointRx(ep uint32) []byte {
115115
return _usbDPSRAM.EPxBuffer[ep].Buffer0[:sz]
116116
}
117117

118-
// AckEndpointRxMessage is called to acknowledge the completion of a delayed USB OUT transfer.
119-
func AckEndpointRxMessage(ep uint32) {
118+
// AckUsbOutTransfer is called to acknowledge the completion of a USB OUT transfer.
119+
func AckUsbOutTransfer(ep uint32) {
120120
ep = ep & 0x7F
121121
setEPDataPID(ep, !epXdata0[ep])
122122
}

src/machine/usb/msc/msc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (m *msc) processTasks() {
132132
// Acknowledge the received data from the host
133133
m.queuedBytes = 0
134134
m.taskQueued = false
135-
machine.AckEndpointRxMessage(usb.MSC_ENDPOINT_OUT)
135+
machine.AckUsbOutTransfer(usb.MSC_ENDPOINT_OUT)
136136
}
137137
time.Sleep(10 * time.Microsecond)
138138
}

0 commit comments

Comments
 (0)