Skip to content

Commit 4aeef10

Browse files
committed
atmel-samd: More USB polish
* Introduce a python script to generate the USB descriptor instead of a bunch of C macros. In the future, we can use this dynamically in CircuitPython. * Add support for detecting read-only mass storage mounts. Fixes adafruit#377
1 parent 1893669 commit 4aeef10

File tree

31 files changed

+542
-59
lines changed

31 files changed

+542
-59
lines changed

extmod/vfs_fat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
#define FSUSER_NATIVE (0x0001) // readblocks[2]/writeblocks[2] contain native func
3636
#define FSUSER_FREE_OBJ (0x0002) // fs_user_mount_t obj should be freed on umount
3737
#define FSUSER_HAVE_IOCTL (0x0004) // new protocol with ioctl
38-
// Device is write-able over USB and read-only to MicroPython.
39-
#define FSUSER_USB_WRITEABLE (0x0008)
38+
// Device is writable over USB and read-only to MicroPython.
39+
#define FSUSER_USB_WRITABLE (0x0008)
4040

4141
typedef struct _fs_user_mount_t {
4242
mp_obj_base_t base;

extmod/vfs_fat_diskio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ DSTATUS disk_status (
9898
}
9999

100100
// This is used to determine the writeability of the disk from MicroPython.
101-
// So, if its USB writeable we make it read-only from MicroPython.
101+
// So, if its USB writable we make it read-only from MicroPython.
102102
if (vfs->writeblocks[0] == MP_OBJ_NULL ||
103-
(vfs->flags & FSUSER_USB_WRITEABLE) != 0) {
103+
(vfs->flags & FSUSER_USB_WRITABLE) != 0) {
104104
return STA_PROTECT;
105105
} else {
106106
return 0;

main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ int __attribute__((used)) main(void) {
234234
autoreload_enable();
235235

236236
// By default our internal flash is readonly to local python code and
237-
// writeable over USB. Set it here so that boot.py can change it.
238-
filesystem_default_writeable(false);
237+
// writable over USB. Set it here so that boot.py can change it.
238+
filesystem_writable_by_python(false);
239239

240240
// If not in safe mode, run boot before initing USB and capture output in a
241241
// file.
@@ -244,12 +244,12 @@ int __attribute__((used)) main(void) {
244244
#ifdef CIRCUITPY_BOOT_OUTPUT_FILE
245245
// Since USB isn't up yet we can cheat and let ourselves write the boot
246246
// output file.
247-
filesystem_default_writeable(true);
247+
filesystem_writable_by_python(true);
248248
FIL file_pointer;
249249
boot_output_file = &file_pointer;
250250
f_open(&((fs_user_mount_t *) MP_STATE_VM(vfs_mount_table)->obj)->fatfs,
251251
boot_output_file, CIRCUITPY_BOOT_OUTPUT_FILE, FA_WRITE | FA_CREATE_ALWAYS);
252-
filesystem_default_writeable(false);
252+
filesystem_writable_by_python(false);
253253
#endif
254254

255255
// TODO(tannewt): Re-add support for flashing boot error output.

ports/atmel-samd/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ BASE_CFLAGS = \
7373
-Wcast-align \
7474
-Wno-error=lto-type-mismatch \
7575
-D__$(CHIP_VARIANT)__ \
76-
-DCONF_USB_COMPOSITE_IDPRODUCT=$(USB_PID) \
77-
-DCONF_USB_COMPOSITE_IDVENDER=$(USB_VID) \
7876
-ffunction-sections \
7977
-fdata-sections \
8078
-fshort-enums \
@@ -233,6 +231,7 @@ SRC_C = \
233231
lib/utils/sys_stdio_mphal.c \
234232
lib/libc/string0.c \
235233
lib/mp-readline/readline.c \
234+
$(BUILD)/autogen_usb_descriptor.c \
236235
# freetouch/adafruit_ptc.c
237236

238237
# Choose which flash filesystem impl to use.
@@ -359,6 +358,14 @@ $(BUILD)/firmware.uf2: $(BUILD)/firmware.bin
359358
$(ECHO) "Create $@"
360359
python2 $(TOP)/tools/uf2/utils/uf2conv.py -b $(BOOTLOADER_SIZE) -c -o $@ $^
361360

361+
$(BUILD)/autogen_usb_descriptor.c: tools/gen_usb_descriptor.py Makefile
362+
python3 tools/gen_usb_descriptor.py \
363+
--manufacturer $(USB_MANUFACTURER)\
364+
--product $(USB_PRODUCT)\
365+
--vid $(USB_VID)\
366+
--pid $(USB_PID)\
367+
$@
368+
362369
deploy: $(BUILD)/firmware.bin
363370
$(ECHO) "Writing $< to the board"
364371
$(BOSSAC) -u $<

ports/atmel-samd/asf4_conf/samd21/hpl_usb_config.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
// <CONF_USB_D_N_EP_MAX"> Max possible (by "Max Endpoint Number" config)
4040
// <id> usbd_num_ep_sp
4141
#ifndef CONF_USB_D_NUM_EP_SP
42-
#define CONF_USB_D_NUM_EP_SP CONF_USB_D_EP_N_MAX
42+
#define CONF_USB_D_NUM_EP_SP CONF_USB_D_N_EP_MAX
4343
#endif
4444

4545
// </h>
@@ -118,7 +118,7 @@
118118
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
119119
// <id> usb_ep1_I_CACHE
120120
#ifndef CONF_USB_EP1_I_CACHE
121-
#define CONF_USB_EP1_I_CACHE 64
121+
#define CONF_USB_EP1_I_CACHE 0
122122
#endif
123123
// </h>
124124

@@ -176,7 +176,7 @@
176176
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
177177
// <id> usb_arch_ep3_cache
178178
#ifndef CONF_USB_EP3_CACHE
179-
#define CONF_USB_EP3_CACHE 64
179+
#define CONF_USB_EP3_CACHE 0
180180
#endif
181181

182182
// <o> Cache buffer size for EP3 IN
@@ -194,7 +194,7 @@
194194
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
195195
// <id> usb_ep3_I_CACHE
196196
#ifndef CONF_USB_EP3_I_CACHE
197-
#define CONF_USB_EP3_I_CACHE 0
197+
#define CONF_USB_EP3_I_CACHE 64
198198
#endif
199199
// </h>
200200

@@ -252,7 +252,7 @@
252252
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
253253
// <id> usb_arch_ep5_cache
254254
#ifndef CONF_USB_EP5_CACHE
255-
#define CONF_USB_EP5_CACHE 64
255+
#define CONF_USB_EP5_CACHE 0
256256
#endif
257257

258258
// <o> Cache buffer size for EP5 IN
@@ -290,7 +290,7 @@
290290
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
291291
// <id> usb_arch_ep6_cache
292292
#ifndef CONF_USB_EP6_CACHE
293-
#define CONF_USB_EP6_CACHE 64
293+
#define CONF_USB_EP6_CACHE 0
294294
#endif
295295

296296
// <o> Cache buffer size for EP6 IN
@@ -308,7 +308,7 @@
308308
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
309309
// <id> usb_ep6_I_CACHE
310310
#ifndef CONF_USB_EP6_I_CACHE
311-
#define CONF_USB_EP6_I_CACHE 64
311+
#define CONF_USB_EP6_I_CACHE 0
312312
#endif
313313
// </h>
314314

@@ -328,7 +328,7 @@
328328
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
329329
// <id> usb_arch_ep7_cache
330330
#ifndef CONF_USB_EP7_CACHE
331-
#define CONF_USB_EP7_CACHE 64
331+
#define CONF_USB_EP7_CACHE 0
332332
#endif
333333

334334
// <o> Cache buffer size for EP7 IN

ports/atmel-samd/asf4_conf/samd51/hpl_usb_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
121121
// <id> usb_ep1_I_CACHE
122122
#ifndef CONF_USB_EP1_I_CACHE
123-
#define CONF_USB_EP1_I_CACHE 64
123+
#define CONF_USB_EP1_I_CACHE 0
124124
#endif
125125
// </h>
126126

@@ -158,7 +158,7 @@
158158
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
159159
// <id> usb_ep2_I_CACHE
160160
#ifndef CONF_USB_EP2_I_CACHE
161-
#define CONF_USB_EP2_I_CACHE 0
161+
#define CONF_USB_EP2_I_CACHE 64
162162
#endif
163163
// </h>
164164

ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
LD_FILE = boards/samd21x18-bootloader.ld
22
USB_VID = 0x2341
33
USB_PID = 0x824D
4+
USB_PRODUCT = "Arduino Zero"
5+
USB_MANUFACTURER = "Arduino"
46

57
INTERNAL_FLASH_FILESYSTEM = 1
68

ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
LD_FILE = boards/samd21x18-bootloader-crystalless.ld
22
USB_VID = 0x239A
33
USB_PID = 0x8019
4+
USB_PRODUCT = "CircuitPlayground Express"
5+
USB_MANUFACTURER = "Adafruit Industries LLC"
46

57
#SPI_FLASH_FILESYSTEM = 1
68
INTERNAL_FLASH_FILESYSTEM = 1

ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
LD_FILE = boards/samd21x18-bootloader.ld
22
USB_VID = 0x239A
33
USB_PID = 0x8015
4+
USB_PRODUCT = "Feather M0 Adalogger"
5+
USB_MANUFACTURER = "Adafruit Industries LLC"
46

57
INTERNAL_FLASH_FILESYSTEM = 1
68

0 commit comments

Comments
 (0)