Mount Moteino M0 as USB Mass Storage in Windows using TinyUSB msc_external_flash

Started by brandock, January 17, 2021, 10:10:16 AM

brandock

I am trying to get the msc_external_flash example sketch from the Adafruit TinyUSB library to work and mount the SPIFlash as a USB drive in Windows/MacOS. I can get the SPIFlash to initialize and list the files on the flash disk in the serial monitor, but it won't mount in Windows or MacOS as expected. I'm suspicious that I don't have all the proper settings for the W25X40CL Winbond SPIflash used by Moteino M0, but I can't say for certain. I am hoping someone has been down this road already and can point me in the right direction..

I'm compiling the Mass Storage examples from the Adafruit TinyUSB library. I compile them for the Adafruit Feather M0 board using the tinyUSB stack. I'm doing a couple of overrides in the sketches specific to the Moteino M0, namely:
#define EXTERNAL_FLASH_USE_SPI SPI
#define EXTERNAL_FLASH_USE_CS 8


and, in the setup()

#define EXTERNAL_FLASH_USE_SPI SPI
#define EXTERNAL_FLASH_USE_CS 8


Here are the definitions I'm using in Adafruit_SPIFlash/src/flash_devices.h.

// Brandock: Settings for the Winbond W25X40CL 4MiB SPI flash.
// Datasheet:
// https://www.winbond.com/resource-files/w25x40cl_e01.pdf
#define W25X40CL                                                             \
  {                                                                            \
    .total_size = (1UL << 22), /* 4 MiB */                                     \
        .start_up_time_us = 10000, .manufacturer_id = 0xef,                    \
    .memory_type = 0x30, .capacity = 0x13, .max_clock_speed_mhz = 104,         \
    .quad_enable_bit_mask = 0x00, .has_sector_protection = true,              \
    .supports_fast_read = true, .supports_qspi = false,                         \
    .supports_qspi_writes = false, .write_status_register_split = false,       \
    .single_status_byte = true, .is_fram = false,                             \
  }


I also add the flash device to Adafruit_SPIFlash/src/Adafruit_SPIFlashBase.cpp list of possible_devices

    // Other common flash devices
    W25Q16JV_IQ,
    W25X40CL,


I modify and load the SdFat_format example sketch to get the SPIFlash formatted. Then I modify and load the SdFat_datalogging sketch to get a file on the filesystem. Then I load the modified msc_external_flash sketch and see my file in the serial monitor.

Adafruit TinyUSB Mass Storage External Flash example
JEDEC ID: EF3013
Flash size: 4194304
Flash contents:
        14 data.csv


But -- the USB Mass Storage disk doesn't mount in MacOS nor Windows.

Any ideas would be appreciated.

brandock

I got some help from Felix (thanks, Felix!) and have this working now. There are some updates to the Moteino M0 board manager that Felix did, and it was necessary to define the Winbond SPIFlash.

The mass storage examples from the TinyUSB library with the modifications are here if you are interested. https://github.com/brandock/TinyUSB-Examples-for-Moteino-M0

I was able to compile these with the Moteino M0 board manager (as updated) and the TinyUSB stack.

There is one extra example of a combination of the data logging and mounting the SPI flash as a USB mass storage device to retrieve the data.