|
1 | 1 | // The MIT License (MIT)
|
2 | 2 | // Copyright (c) 2019 Ha Thach for Adafruit Industries
|
3 | 3 |
|
| 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 | + |
4 | 13 | #include "Adafruit_TinyUSB.h"
|
5 | 14 | #include "Adafruit_SPIFlash.h"
|
6 | 15 |
|
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 |
| - |
15 | 16 | #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; |
18 | 21 | #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 | + |
19 | 29 | #if (SPI_INTERFACES_COUNT == 1)
|
20 | 30 | #define FLASH_SS SS // Flash chip SS pin.
|
21 | 31 | #define FLASH_SPI_PORT SPI // What SPI port is Flash on?
|
|
24 | 34 | #define FLASH_SPI_PORT SPI1 // What SPI port is Flash on?
|
25 | 35 | #endif
|
26 | 36 |
|
27 |
| -Adafruit_SPIFlash flash(FLASH_SS, &FLASH_SPI_PORT); // Use hardware SPI |
| 37 | + Adafruit_SPIFlash flash(FLASH_SS, &FLASH_SPI_PORT); // Use hardware SPI |
28 | 38 | #endif
|
29 | 39 |
|
30 | 40 | Adafruit_USBD_MSC usb_msc;
|
31 | 41 |
|
32 |
| - |
33 | 42 | // the setup function runs once when you press reset or power the board
|
34 | 43 | void setup()
|
35 | 44 | {
|
| 45 | +#if defined(__SAMD51__) |
| 46 | + flash.begin(); |
| 47 | +#else |
36 | 48 | flash.begin(FLASH_TYPE);
|
37 |
| - |
| 49 | +#endif |
| 50 | + |
38 | 51 | // Set disk vendor id, product id and revision with string up to 8, 16, 4 characters respectively
|
39 | 52 | usb_msc.setID("Adafruit", "SPI Flash", "1.0");
|
40 | 53 |
|
|
0 commit comments