Skip to content

Commit c33113a

Browse files
digitalentitydeadprogram
authored andcommitted
fix(usb): implement endpoint stall for nRF52840.
Implement SetStallEPIn, SetStallEPOut, ClearStallEPIn, and ClearStallEPOut methods on the nRF52840 USBDevice struct using the hardware EPSTALL register to support MSC driver requirements. Also, correct the handleUSBIRQ loops to iterate over physical endpoint numbers rather than dynamic configuration entries to prevent missed or incorrectly routed endpoint interrupts.
1 parent eab4385 commit c33113a

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

builder/sizes_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ func TestBinarySize(t *testing.T) {
4242
// This is a small number of very diverse targets that we want to test.
4343
tests := []sizeTest{
4444
// microcontrollers
45-
{"hifive1b", "examples/echo", 3680, 280, 0, 2252},
46-
{"microbit", "examples/serial", 2694, 342, 8, 2248},
47-
{"wioterminal", "examples/pininterrupt", 7074, 1510, 120, 7248},
45+
{"hifive1b", "examples/echo", 3817, 299, 0, 2252},
46+
{"microbit", "examples/serial", 2820, 356, 8, 2248},
47+
{"wioterminal", "examples/pininterrupt", 8020, 1652, 132, 7480},
4848

4949
// TODO: also check wasm. Right now this is difficult, because
5050
// wasm binaries are run through wasm-opt and therefore the

src/machine/machine_nrf52840_usb.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func handleUSBIRQ(interrupt.Interrupt) {
172172
epDataStatus := nrf.USBD.EPDATASTATUS.Get()
173173
nrf.USBD.EPDATASTATUS.Set(epDataStatus)
174174
var i uint32
175-
for i = 1; i < uint32(len(endPoints)); i++ {
175+
for i = 1; i < NumberOfUSBEndpoints; i++ {
176176
// Check if endpoint has a pending interrupt
177177
inDataDone := epDataStatus&(nrf.USBD_EPDATASTATUS_EPIN1<<(i-1)) > 0
178178
outDataDone := epDataStatus&(nrf.USBD_EPDATASTATUS_EPOUT1<<(i-1)) > 0
@@ -191,7 +191,7 @@ func handleUSBIRQ(interrupt.Interrupt) {
191191
}
192192

193193
// ENDEPOUT[n] events
194-
for i := 0; i < len(endPoints); i++ {
194+
for i := 0; i < NumberOfUSBEndpoints; i++ {
195195
if nrf.USBD.EVENTS_ENDEPOUT[i].Get() > 0 {
196196
nrf.USBD.EVENTS_ENDEPOUT[i].Set(0)
197197
buf := handleEndpointRx(uint32(i))
@@ -367,3 +367,19 @@ func ReceiveUSBControlPacket() ([cdcLineInfoSize]byte, error) {
367367

368368
return b, nil
369369
}
370+
371+
func (dev *USBDevice) SetStallEPIn(ep uint32) {
372+
nrf.USBD.EPSTALL.Set(ep | nrf.USBD_EPSTALL_IO | nrf.USBD_EPSTALL_STALL)
373+
}
374+
375+
func (dev *USBDevice) SetStallEPOut(ep uint32) {
376+
nrf.USBD.EPSTALL.Set(ep | nrf.USBD_EPSTALL_STALL)
377+
}
378+
379+
func (dev *USBDevice) ClearStallEPIn(ep uint32) {
380+
nrf.USBD.EPSTALL.Set(ep | nrf.USBD_EPSTALL_IO)
381+
}
382+
383+
func (dev *USBDevice) ClearStallEPOut(ep uint32) {
384+
nrf.USBD.EPSTALL.Set(ep)
385+
}

0 commit comments

Comments
 (0)