Skip to content

Commit e9f9a39

Browse files
committed
fix: reduce max endpoints on non-rp2
1 parent e165df3 commit e9f9a39

File tree

7 files changed

+67
-23
lines changed

7 files changed

+67
-23
lines changed

builder/sizes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func TestBinarySize(t *testing.T) {
4444
// microcontrollers
4545
{"hifive1b", "examples/echo", 4560, 280, 0, 2268},
4646
{"microbit", "examples/serial", 2924, 388, 8, 2272},
47-
{"wioterminal", "examples/pininterrupt", 7550, 1494, 116, 7232},
47+
{"wioterminal", "examples/pininterrupt", 7383, 1489, 116, 6912},
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_atsamd21_usb.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ const (
1919

2020
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Pos = 14
2121
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Mask = 0x3FFF
22+
23+
NumberOfUSBEndpoints = 8
24+
)
25+
26+
var (
27+
endPoints = []uint32{
28+
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
29+
usb.CDC_ENDPOINT_ACM: (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn),
30+
usb.CDC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_BULK | usb.EndpointOut),
31+
usb.CDC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_BULK | usb.EndpointIn),
32+
usb.HID_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt In
33+
usb.HID_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt Out
34+
usb.MIDI_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
35+
usb.MIDI_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
36+
}
2237
)
2338

2439
// Configure the USB peripheral. The config is here for compatibility with the UART interface.

src/machine/machine_atsamd51_usb.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ const (
1919

2020
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Pos = 14
2121
usb_DEVICE_PCKSIZE_MULTI_PACKET_SIZE_Mask = 0x3FFF
22+
23+
NumberOfUSBEndpoints = 8
24+
)
25+
26+
var (
27+
endPoints = []uint32{
28+
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
29+
usb.CDC_ENDPOINT_ACM: (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn),
30+
usb.CDC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_BULK | usb.EndpointOut),
31+
usb.CDC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_BULK | usb.EndpointIn),
32+
usb.HID_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt In
33+
usb.HID_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt Out
34+
usb.MIDI_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
35+
usb.MIDI_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
36+
}
2237
)
2338

2439
// Configure the USB peripheral. The config is here for compatibility with the UART interface.

src/machine/machine_nrf52840_usb.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"unsafe"
1212
)
1313

14+
const NumberOfUSBEndpoints = 8
15+
1416
var (
1517
sendOnEP0DATADONE struct {
1618
ptr *byte
@@ -20,6 +22,17 @@ var (
2022
epinen uint32
2123
epouten uint32
2224
easyDMABusy volatile.Register8
25+
26+
endPoints = []uint32{
27+
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
28+
usb.CDC_ENDPOINT_ACM: (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn),
29+
usb.CDC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_BULK | usb.EndpointOut),
30+
usb.CDC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_BULK | usb.EndpointIn),
31+
usb.HID_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt In
32+
usb.HID_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt Out
33+
usb.MIDI_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
34+
usb.MIDI_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
35+
}
2336
)
2437

2538
// enterCriticalSection is used to protect access to easyDMA - only one thing

src/machine/machine_rp2_usb.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,27 @@ import (
88
"unsafe"
99
)
1010

11+
const NumberOfUSBEndpoints = 10
12+
1113
var (
1214
sendOnEP0DATADONE struct {
1315
offset int
1416
data []byte
1517
pid uint32
1618
}
19+
20+
endPoints = []uint32{
21+
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
22+
usb.CDC_ENDPOINT_ACM: (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn),
23+
usb.CDC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_BULK | usb.EndpointOut),
24+
usb.CDC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_BULK | usb.EndpointIn),
25+
usb.HID_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt In
26+
usb.HID_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt Out
27+
usb.MIDI_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
28+
usb.MIDI_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
29+
usb.MSC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
30+
usb.MSC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
31+
}
1732
)
1833

1934
func initEndpoint(ep, config uint32) {

src/machine/usb.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ var (
9494
)
9595

9696
var (
97-
usbEndpointDescriptors [usb.NumberOfEndpoints]descriptor.Device
97+
usbEndpointDescriptors [NumberOfUSBEndpoints]descriptor.Device
9898

9999
isEndpointHalt = false
100100
isRemoteWakeUpEnabled = false
@@ -107,10 +107,10 @@ var (
107107
var udd_ep_control_cache_buffer [256]uint8
108108

109109
//go:align 4
110-
var udd_ep_in_cache_buffer [usb.NumberOfEndpoints][64]uint8
110+
var udd_ep_in_cache_buffer [NumberOfUSBEndpoints][64]uint8
111111

112112
//go:align 4
113-
var udd_ep_out_cache_buffer [usb.NumberOfEndpoints][64]uint8
113+
var udd_ep_out_cache_buffer [NumberOfUSBEndpoints][64]uint8
114114

115115
// usb_trans_buffer max size is 255 since that is max size
116116
// for a descriptor (bLength is 1 byte), and the biggest use
@@ -120,23 +120,10 @@ var udd_ep_out_cache_buffer [usb.NumberOfEndpoints][64]uint8
120120
var usb_trans_buffer [255]uint8
121121

122122
var (
123-
usbTxHandler [usb.NumberOfEndpoints]func()
124-
usbRxHandler [usb.NumberOfEndpoints]func([]byte) bool
123+
usbTxHandler [NumberOfUSBEndpoints]func()
124+
usbRxHandler [NumberOfUSBEndpoints]func([]byte) bool
125125
usbSetupHandler [usb.NumberOfInterfaces]func(usb.Setup) bool
126-
usbStallHandler [usb.NumberOfEndpoints]func(usb.Setup) bool
127-
128-
endPoints = []uint32{
129-
usb.CONTROL_ENDPOINT: usb.ENDPOINT_TYPE_CONTROL,
130-
usb.CDC_ENDPOINT_ACM: (usb.ENDPOINT_TYPE_INTERRUPT | usb.EndpointIn),
131-
usb.CDC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_BULK | usb.EndpointOut),
132-
usb.CDC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_BULK | usb.EndpointIn),
133-
usb.HID_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt In
134-
usb.HID_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Interrupt Out
135-
usb.MIDI_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
136-
usb.MIDI_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
137-
usb.MSC_ENDPOINT_IN: (usb.ENDPOINT_TYPE_DISABLE), // Bulk In
138-
usb.MSC_ENDPOINT_OUT: (usb.ENDPOINT_TYPE_DISABLE), // Bulk Out
139-
}
126+
usbStallHandler [NumberOfUSBEndpoints]func(usb.Setup) bool
140127
)
141128

142129
// sendDescriptor creates and sends the various USB descriptor types that
@@ -215,7 +202,7 @@ func handleStandardSetup(setup usb.Setup) bool {
215202
if setup.WValueL == 1 { // DEVICEREMOTEWAKEUP
216203
isRemoteWakeUpEnabled = false
217204
} else if setup.WValueL == 0 { // ENDPOINTHALT
218-
if idx := setup.WIndex & 0x7F; idx < usb.NumberOfEndpoints && usbStallHandler[idx] != nil {
205+
if idx := setup.WIndex & 0x7F; idx < NumberOfUSBEndpoints && usbStallHandler[idx] != nil {
219206
// Host has requested to clear an endpoint stall. If the request is addressed to
220207
// an endpoint with a configured StallHandler, forward the message on.
221208
// The 0x7F mask is used to clear the direction bit from the endpoint number
@@ -230,7 +217,7 @@ func handleStandardSetup(setup usb.Setup) bool {
230217
if setup.WValueL == 1 { // DEVICEREMOTEWAKEUP
231218
isRemoteWakeUpEnabled = true
232219
} else if setup.WValueL == 0 { // ENDPOINTHALT
233-
if idx := setup.WIndex & 0x7F; idx < usb.NumberOfEndpoints && usbStallHandler[idx] != nil {
220+
if idx := setup.WIndex & 0x7F; idx < NumberOfUSBEndpoints && usbStallHandler[idx] != nil {
234221
// Host has requested to stall an endpoint. If the request is addressed to
235222
// an endpoint with a configured StallHandler, forward the message on.
236223
// The 0x7F mask is used to clear the direction bit from the endpoint number

src/machine/usb/usb.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ const (
8181
MIDI_ENDPOINT_OUT = 7 // for Bulk Out
8282
MSC_ENDPOINT_IN = 8 // for Bulk In
8383
MSC_ENDPOINT_OUT = 9 // for Bulk Out
84-
NumberOfEndpoints = 10
8584

8685
// bmRequestType
8786
REQUEST_HOSTTODEVICE = 0x00

0 commit comments

Comments
 (0)