Skip to content

Commit 51cd4da

Browse files
committed
atmel-samd: Add mass storage support.
Fixes micropython#260
1 parent c80e190 commit 51cd4da

File tree

11 files changed

+344
-223
lines changed

11 files changed

+344
-223
lines changed

atmel-samd/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ INC += -I. \
4444
-Iasf4/$(CHIP_FAMILY)/usb \
4545
-Iasf4/$(CHIP_FAMILY)/usb/class/cdc \
4646
-Iasf4/$(CHIP_FAMILY)/usb/class/hid \
47+
-Iasf4/$(CHIP_FAMILY)/usb/class/msc \
4748
-Iasf4/$(CHIP_FAMILY)/usb/device \
4849
-Iasf4_conf/$(CHIP_FAMILY) \
4950
-Iboards/$(BOARD) \
@@ -181,6 +182,7 @@ SRC_ASF := \
181182
hpl/tc/hpl_tc.c \
182183
hpl/usb/hpl_usb.c \
183184
usb/class/cdc/device/cdcdf_acm.c \
185+
usb/class/msc/device/mscdf.c \
184186
usb/device/usbdc.c \
185187
usb/usb_protocol.c \
186188
hal/utils/src/utils_list.c \
@@ -204,8 +206,7 @@ endif
204206
SRC_ASF := $(addprefix asf4/$(CHIP_FAMILY)/, $(SRC_ASF))
205207

206208
# Skip this source for now.
207-
# access_vfs.c \
208-
shared_dma.c \
209+
# shared_dma.c \
209210
210211
SRC_C = \
211212
background.c \
@@ -216,6 +217,7 @@ SRC_C = \
216217
$(CHIP_FAMILY)_pins.c \
217218
tick.c \
218219
usb.c \
220+
usb_mass_storage.c \
219221
$(FLASH_IMPL) \
220222
bindings/samd/__init__.c \
221223
boards/$(BOARD)/board.c \

atmel-samd/access_vfs.c

Lines changed: 0 additions & 191 deletions
This file was deleted.

atmel-samd/asf4_conf/samd21/hpl_usb_config.h

Lines changed: 4 additions & 4 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_N_4
42+
#define CONF_USB_D_NUM_EP_SP CONF_USB_D_EP_N_MAX
4343
#endif
4444

4545
// </h>
@@ -60,7 +60,7 @@
6060
// <i> The number of physical endpoints - 1
6161
// <id> usbd_arch_max_ep_n
6262
#ifndef CONF_USB_D_MAX_EP_N
63-
#define CONF_USB_D_MAX_EP_N CONF_USB_N_2
63+
#define CONF_USB_D_MAX_EP_N CONF_USB_D_EP_N_MAX
6464
#endif
6565

6666
// <y> USB Speed Limit
@@ -156,7 +156,7 @@
156156
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
157157
// <id> usb_ep2_I_CACHE
158158
#ifndef CONF_USB_EP2_I_CACHE
159-
#define CONF_USB_EP2_I_CACHE 0
159+
#define CONF_USB_EP2_I_CACHE 64
160160
#endif
161161
// </h>
162162

@@ -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 0
311+
#define CONF_USB_EP6_I_CACHE 64
312312
#endif
313313
// </h>
314314

atmel-samd/asf4_conf/samd51/hpl_usb_config.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
// <y> Max number of endpoints supported
3030
// <i> Limits the number of endpoints (described by EP address) can be used in app.
31+
// NOTE(tannewt): This not only limits the number of endpoints but also the
32+
// addresses. In other words, even if you use endpoint 6 you need to set this to 11.
3133
// <CONF_USB_N_1"> 1 (EP0 only)
3234
// <CONF_USB_N_2"> 2 (EP0 + 1 endpoint)
3335
// <CONF_USB_N_3"> 3 (EP0 + 2 endpoints)
@@ -39,7 +41,7 @@
3941
// <CONF_USB_D_N_EP_MAX"> Max possible (by "Max Endpoint Number" config)
4042
// <id> usbd_num_ep_sp
4143
#ifndef CONF_USB_D_NUM_EP_SP
42-
#define CONF_USB_D_NUM_EP_SP CONF_USB_N_4
44+
#define CONF_USB_D_NUM_EP_SP CONF_USB_D_N_EP_MAX
4345
#endif
4446

4547
// </h>
@@ -60,7 +62,7 @@
6062
// <i> The number of physical endpoints - 1
6163
// <id> usbd_arch_max_ep_n
6264
#ifndef CONF_USB_D_MAX_EP_N
63-
#define CONF_USB_D_MAX_EP_N CONF_USB_N_2
65+
#define CONF_USB_D_MAX_EP_N CONF_USB_D_EP_N_MAX
6466
#endif
6567

6668
// <y> USB Speed Limit
@@ -308,7 +310,7 @@
308310
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
309311
// <id> usb_ep6_I_CACHE
310312
#ifndef CONF_USB_EP6_I_CACHE
311-
#define CONF_USB_EP6_I_CACHE 0
313+
#define CONF_USB_EP6_I_CACHE 64
312314
#endif
313315
// </h>
314316

atmel-samd/background.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
#include "background.h"
2727

2828
// #include "common-hal/audioio/AudioOut.h"
29+
#include "usb_mass_storage.h"
2930

3031
void run_background_tasks(void) {
3132
// audioout_background();
32-
// udi_msc_process_trans();
33+
usb_msc_background();
3334
}

atmel-samd/internal_flash.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,13 @@ bool internal_flash_write_block(const uint8_t *src, uint32_t block) {
172172
return false;
173173
}
174174
int32_t error_code;
175-
// A block is formed by two rows of flash. We must erase each row
176-
// before we write back to it.
177175
error_code = flash_erase(&internal_flash_desc,
178176
dest,
179177
FILESYSTEM_BLOCK_SIZE / flash_get_page_size(&internal_flash_desc));
180178
if (error_code != ERR_NONE) {
181179
return false;
182180
}
183181

184-
// A block is made up of multiple pages. Write each page
185-
// sequentially.
186182
error_code = flash_append(&internal_flash_desc, dest, src, FILESYSTEM_BLOCK_SIZE);
187183
if (error_code != ERR_NONE) {
188184
return false;

atmel-samd/mpconfigport.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ typedef long mp_off_t;
132132
#include "mpconfigboard.h"
133133
#include "include/sam.h"
134134

135+
// ASF4 defines.
136+
#define CONF_USB_COMPOSITE_CDC_ACM_EN 1
137+
#define CONF_USB_COMPOSITE_MSC_EN 1
138+
135139
#ifdef SAMD21
136140
#define CIRCUITPY_MCU_FAMILY samd21
137141
#define MICROPY_PY_SYS_PLATFORM "Atmel SAMD21"

atmel-samd/supervisor/filesystem.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void filesystem_init(bool create_allowed) {
6565

6666
// set label
6767
f_setlabel(&vfs_fat->fatfs, "CIRCUITPY");
68+
flash_flush();
6869
} else if (res != FR_OK) {
6970
return;
7071
}

0 commit comments

Comments
 (0)