How to use USBMSD? //For Portenta H7

I would like to use actual USB Storage Device (Over Hub), rather than, on board QSPI Flash.

Found following in USBMSD.cpp

USBMSD::USBMSD(mbed::BlockDevice *bd, bool connect_blocking, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
    : arduino::internal::PluggableUSBModule(1), _in_task(&_queue), _out_task(&_queue),
      _initialized(false), _media_removed(false), _bd(bd)
{
    PluggableUSBD().plug(this);
}

USBMSD::USBMSD(USBPhy *phy, mbed::BlockDevice *bd, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
    : arduino::internal::PluggableUSBModule(1), _in_task(&_queue), _out_task(&_queue),
      _initialized(false), _media_removed(false), _bd(bd)
{
    PluggableUSBD().plug(this);
}

Also, this would be the example of MSD meant for on Portenta's on board QSPIF,

1.How to convert it for USB mass storage device, would you mind writing bare minimum code, what should use instead of QSPIFBlockDevice
2.What is USBPhy

/*
   QSPI as USB Mass Storage
   This example shows how to expose a QSPIF BlockDevice (16MB external flash on the Portenta H7)
   as an USB stick. It can be adapted to any kind of BlockDevice (FlashIAP or either RAM via HeapBlockDevice)
   Before loading this example, make sure you execute WiFiFirmwareUpdater sketch
   to create and format the proper partitions.
*/

#include "PluggableUSBMSD.h"
#include "QSPIFBlockDevice.h"
#include "MBRBlockDevice.h"
#include "FATFileSystem.h"

static QSPIFBlockDevice root;
mbed::MBRBlockDevice wifi_data(&root, 1);
mbed::MBRBlockDevice ota_data(&root, 2);
static mbed::FATFileSystem wifi("wifi");
static mbed::FATFileSystem ota("ota");

void USBMSD::begin()
{
  int err = wifi.mount(&wifi_data);
  if (err) {
    while (!Serial);
    Serial.println("Please run WiFiFirmwareUpdater before");
    return;
  }
  ota.mount(&ota_data);
}


USBMSD MassStorage(&root);

void setup() {
  Serial.begin(115200);
  MassStorage.begin();
}

void printDirectory(char* name) {
  DIR *d;
  struct dirent *p;

  d = opendir(name);
  if (d != NULL) {
    while ((p = readdir(d)) != NULL) {
      Serial.println(p->d_name);
    }
  }
  closedir(d);
}

void loop() {
  if (MassStorage.media_removed()) {
    // list the content of the partitions
    // you may need to restart the board for the list to update if you copied new files
    Serial.println("Content of WiFi partition:");
    printDirectory("/wifi");
    Serial.println("Content of OTA partition:");
    printDirectory("/ota");
  }
  delay(1000);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.