Skip to content

Commit 7b4814f

Browse files
committed
update msc_external_flash to work with spi and qspi flash on m0 and m4
1 parent 42433d5 commit 7b4814f

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

examples/MassStorage/msc_spiflash/msc_spiflash.ino renamed to examples/MassStorage/msc_external_flash/msc_external_flash.ino

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
// The MIT License (MIT)
22
// Copyright (c) 2019 Ha Thach for Adafruit Industries
33

4+
/* This example demo how to expose on-board external Flash as USB Mass Storage.
5+
* - For Feather/Metro M0 express series with SPI flash device
6+
* follow library is required
7+
* https://github.com/adafruit/Adafruit_SPIFlash
8+
*
9+
* - For Feather/Metro M4 expres series with QSPI flash, additional QSPI is reuiqred
10+
* https://github.com/adafruit/Adafruit_QSPI
11+
*/
12+
413
#include "Adafruit_TinyUSB.h"
514
#include "Adafruit_SPIFlash.h"
615

7-
// Configuration of the flash chip pins and flash fatfs object.
8-
// You don't normally need to change these if using a Feather/Metro
9-
// M0 express board.
10-
#define FLASH_TYPE SPIFLASHTYPE_W25Q16BV // Flash chip type.
11-
// If you change this be
12-
// sure to change the fatfs
13-
// object type below to match.
14-
1516
#if defined(__SAMD51__)
16-
// Alternatively you can define and use non-SPI pins, QSPI isnt on a sercom
17-
Adafruit_SPIFlash flash(PIN_QSPI_SCK, PIN_QSPI_IO1, PIN_QSPI_IO0, PIN_QSPI_CS);
17+
// use QSPI libary for M4 series
18+
#include "Adafruit_QSPI_GD25Q.h"
19+
20+
Adafruit_QSPI_GD25Q flash;
1821
#else
22+
// Configuration of the flash chip pins and flash fatfs object.
23+
// You don't normally need to change these if using a Feather/Metro
24+
// M0 express board.
25+
26+
// Flash chip type. If you change this be sure to change the fatfs to match as well
27+
#define FLASH_TYPE SPIFLASHTYPE_W25Q16BV
28+
1929
#if (SPI_INTERFACES_COUNT == 1)
2030
#define FLASH_SS SS // Flash chip SS pin.
2131
#define FLASH_SPI_PORT SPI // What SPI port is Flash on?
@@ -24,17 +34,20 @@
2434
#define FLASH_SPI_PORT SPI1 // What SPI port is Flash on?
2535
#endif
2636

27-
Adafruit_SPIFlash flash(FLASH_SS, &FLASH_SPI_PORT); // Use hardware SPI
37+
Adafruit_SPIFlash flash(FLASH_SS, &FLASH_SPI_PORT); // Use hardware SPI
2838
#endif
2939

3040
Adafruit_USBD_MSC usb_msc;
3141

32-
3342
// the setup function runs once when you press reset or power the board
3443
void setup()
3544
{
45+
#if defined(__SAMD51__)
46+
flash.begin();
47+
#else
3648
flash.begin(FLASH_TYPE);
37-
49+
#endif
50+
3851
// Set disk vendor id, product id and revision with string up to 8, 16, 4 characters respectively
3952
usb_msc.setID("Adafruit", "SPI Flash", "1.0");
4053

0 commit comments

Comments
 (0)