Many TLAs: MTP MSC FS SD SDFat LittleFS UsbMSCFat to work with each other 8)

Morning all (or time in your part of the world),

Starting to play with MTP again...

First off: Integration question, probably for @PaulStoffregen.

In an SdFat-beta project issue conversation with Bill about supporting the changes above, he verified that the dates and times for files for the SDFat stuff is already defined and is actually in our SDFat library in the build...

Code:
/** Get a file's access date and time.
   *
   * \param[out] pdate Packed date for directory entry.
   * \param[out] ptime Packed time for directory entry.
   *
   * \return true for success or false for failure.
   */
  bool getAccessDateTime(uint16_t* pdate, uint16_t* ptime);
  /** Get a file's create date and time.
   *
   * \param[out] pdate Packed date for directory entry.
   * \param[out] ptime Packed time for directory entry.
   *
   * \return true for success or false for failure.
   */
  bool getCreateDateTime(uint16_t* pdate, uint16_t* ptime);
  /** Get a file's Modify date and time.
   *
   * \param[out] pdate Packed date for directory entry.
   * \param[out] ptime Packed time for directory entry.
   *
   * \return true for success or false for failure.
   */
  bool getModifyDateTime(uint16_t* pdate, uint16_t* ptime);
  /** Set a file's timestamps in its directory entry.
   *
   * \param[in] flags Values for \a flags are constructed by a bitwise-inclusive
   * OR of flags from the following list
   *
   * T_ACCESS - Set the file's last access date and time.
   *
   * T_CREATE - Set the file's creation date and time.
   *
   * T_WRITE - Set the file's last write/modification date and time.
   *
   * \param[in] year Valid range 1980 - 2107 inclusive.
   *
   * \param[in] month Valid range 1 - 12 inclusive.
   *
   * \param[in] day Valid range 1 - 31 inclusive.
   *
   * \param[in] hour Valid range 0 - 23 inclusive.
   *
   * \param[in] minute Valid range 0 - 59 inclusive.
   *
   * \param[in] second Valid range 0 - 59 inclusive
   *
   * \note It is possible to set an invalid date since there is no check for
   * the number of days in a month.
   *
   * \note
   * Modify and access timestamps may be overwritten if a date time callback
   * function has been set by dateTimeCallback().
   *
   * \return true for success or false for failure.
   */
  bool timestamp(uint8_t flags, uint16_t year, uint8_t month, uint8_t day,
                 uint8_t hour, uint8_t minute, uint8_t second);

So question is, should some of this be peculated up into the FS File class? Personally I think it should as again I would see cases where files change over MTP (or elsewhere) and if I were using things like configuration files, I might want to know the file changed...
 
Quick follow on:
I just pushed up changes into my branch: https://github.com/KurtE/UsbMscFat/tree/VolumeName_SD
To hopefully have the MSC wrappers for the files/volume now call into the new PFs... stuff.

Including the possibility of passing in partitions... Have not changed the MTP sketch yet... Coming up soon.
But first up will be to change the naming of the MTP MSC objects, to maybe make the names like: MSC0-<volume label>
Maybe add the volume label stuff to volume interface...
 
Morning all (or time in your part of the world),

Starting to play with MTP again...

First off: Integration question, probably for @PaulStoffregen.

In an SdFat-beta project issue conversation with Bill about supporting the changes above, he verified that the dates and times for files for the SDFat stuff is already defined and is actually in our SDFat library in the build...

........

So question is, should some of this be peculated up into the FS File class? Personally I think it should as again I would see cases where files change over MTP (or elsewhere) and if I were using things like configuration files, I might want to know the file changed...

To be honest - think it should as well. Would be good info to have available and inline with SDFat-beta
 
Quick follow on:
I just pushed up changes into my branch: https://github.com/KurtE/UsbMscFat/tree/VolumeName_SD
To hopefully have the MSC wrappers for the files/volume now call into the new PFs... stuff.

Including the possibility of passing in partitions... Have not changed the MTP sketch yet... Coming up soon.
But first up will be to change the naming of the MTP MSC objects, to maybe make the names like: MSC0-<volume label>
Maybe add the volume label stuff to volume interface...

Cool. So many choices. Think volume stuff needs to be added to volume interface - would make it more transparent I think ?
 
@mjs513 and @wwatson - Yes I think it would be a good place.

But right now I am trying to rethink some of the integration of the MSC stuff into MTP... Trying to decide how far to try to take.

Things like: If we are geared around the PFsFile and PFsVolume our own versions of the FsFile...

But then we also have the MSCFile which is public File which is a wrapper around the file type passed in.....
Maybe PFsFile should derive from File? and maybe PFsVolume should derive from FS?

But disregarding that: In MTP
We currently logically check for MSC USB Host drives that come on line (The USBHost Object returns true)...

That is I currently have: msController msDrive[USE_MSC_FAT](myusb);
I am also holding on to that many MSCClass objects...
MSCClass msc[USE_MSC_FAT];

Currently these are one to one...

But now suppose assume I wish to add all of the relevant Partitions.
As such I Need to add some number of Partition objects??? As such should these msc objects
Actually then be: UsbFs objects like in VolumeName sketch?

And then have wrappers of the PFsVolume objects which are not necessarily one to one. And these are the things added and removed to storage...

Other than that is crystal clear :D ;)
 
@KurtE - @wwatson
Would think you would need a UsbFS pointing to each partition?

Think it was like my thought that for each partition you need a addfilesystem(....,....,..., partition number) so it would know to associate a FS with that partition.

Think think is what you saying :confused::)
 
Again as you mentioned maybe, as I added the ability to pass through the partition number on that begin, that maybe I should just try that and maybe again only
need to object types still. Will try... Probably easier then hitting head too many times with 2x4....

Will then need to loop through when the device goes away and see how many objects were then pointing at the object...

Now back to playing.... First take dogs for morning walk!
 
Yet another new day :D

I have been playing with the MTP stuff, with partitions... And pulling out a fair percentage of the few hairs I have left :D

I have hacked my way through to try to support N USB drives with M partitions...
Code:
#define USE_MSC_FAT 2     // set to > 0 experiment with MTP (USBHost.t36 + mscFS)
#define USE_MSC_FAT_VOL 8 // Max MSC FAT Volumes.

Data associated with this some I can probably get rid of once I understand what I am doing... Note it also handles pressing in SD Card after program starts...
Code:
#if USE_MSC_FAT > 0
#if defined(__IMXRT1062__) || defined(ARDUINO_TEENSY36)
#include <mscFS.h>
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);

#ifndef USE_MSC_FAT_VOL 
#define USE_MSC_FAT_VOL USE_MSC_FAT
#endif


// start off with one controller. 
msController msDrive[USE_MSC_FAT](myusb);
bool msDrive_previous[USE_MSC_FAT]; // Was this drive there the previous time through?
MSCClass msc[USE_MSC_FAT];
char  nmsc_str[USE_MSC_FAT_VOL][20];

uint16_t msc_storage_index[USE_MSC_FAT_VOL];
uint8_t msc_drive_index[USE_MSC_FAT_VOL]; // probably can find easy way not to need this.

The helper function I have to add the drives and partitions:
Code:
void checkUSBandSDIOStatus(bool fInit) {
#if USE_MSC_FAT > 0
  bool usb_drive_changed_state = false;
  myusb.Task(); // make sure we are up to date.
  if (fInit) {
    // make sure all of the indexes are -1..
    for (int ii = 0; ii < USE_MSC_FAT_VOL; ii++) {msc_storage_index[ii] = (uint16_t)-1; msc_drive_index[ii] = -1;}
    for (int ii = 0; ii < USE_MSC_FAT; ii++)  msDrive_previous[ii] = false;
  }

  for (int index_usb_drive = 0; index_usb_drive < USE_MSC_FAT; index_usb_drive++)
  {
    msController *pdriver = &msDrive[index_usb_drive];
    if (*pdriver != msDrive_previous[index_usb_drive]) {
      // Drive status changed.
      msDrive_previous[index_usb_drive] = *pdriver;
      usb_drive_changed_state = true; // something changed
      if (*pdriver) 
      {
        Serial.println("USB Drive Inserted");
        mbrDmp(pdriver);

        // Now lets see if we can iterate over all of the possible parititions of this drive
        for (int index_drive_partition=1; index_drive_partition < 5; index_drive_partition++) {
          // lets see if we can find an available msc object to use... 
          for (int index_msc = 0; index_msc < USE_MSC_FAT_VOL; index_msc++) {
            if (msc_storage_index[index_msc] == (uint16_t)-1) 
            {
              // lets try to open a partition.
              Serial.printf("  Try Partiton:%d on MSC Index:%d\n", index_drive_partition, index_msc);
              if (msc[index_msc].begin(pdriver, false, index_drive_partition))
              {
                Serial.println("    ** SUCCEEDED **");
                // now see if we can get the volume label.  
                uint8_t volName[20];
                if (getPartitionVolumeLabel(msc[index_msc].mscfs, volName, sizeof(volName))) {
                  Serial.printf(">> USB partition %d valume ID: %s\n", index_drive_partition, volName);
                  snprintf(nmsc_str[index_msc], sizeof(nmsc_str[index_msc]), "MSC%d-%s", index_usb_drive, volName);
                } 
                else snprintf(nmsc_str[index_msc], sizeof(nmsc_str[index_msc]), "MSC%d-%d", index_usb_drive, index_drive_partition);
                msc_drive_index[index_msc] = index_usb_drive;
                msc_storage_index[index_msc] = storage.addFilesystem(msc[index_msc], nmsc_str[index_msc]);
#if 0
                elapsedMicros emmicro = 0;
                uint64_t totalSize = msc[index_usb_drive].totalSize();
                uint32_t elapsed_totalSize = emmicro;
                uint64_t usedSize  = msc[index_usb_drive].usedSize();
                Serial.printf("new Storage %d %s %llu(%u) %llu(%u)\n", index_msc, nmsc_str[index_msc], totalSize, elapsed_totalSize, usedSize, (uint32_t)emmicro - elapsed_totalSize); 
#endif                
                if (!fInit) mtpd.send_StoreAddedEvent(msc_storage_index[index_msc]);
              }
              break;
            }
          }
        }
      }
      else
      {
        // drive went away...
        for (int index_msc = 0; index_msc < USE_MSC_FAT_VOL; index_msc++) {
          // check for any indexes that were in use that were associated with that drive
          // Don't need to check for fInit here as we wont be removing drives during init...
          if (msc_drive_index[index_msc]== index_usb_drive) {
            mtpd.send_StoreRemovedEvent(msc_storage_index[index_msc]);
            storage.removeFilesystem(msc_storage_index[index_msc]);
            msc_storage_index[index_msc] = (uint16_t)-1;
            msc_drive_index[index_msc] = -1;
        }
        }
      }
    }
  }

  if (usb_drive_changed_state && !fInit) {
    delay(10); // give some time to handle previous one
    mtpd.send_DeviceResetEvent();
  }
#endif

#ifdef _SD_DAT3
  if (BUILTIN_SDCARD_missing_index != -1)
  {
   // delayMicroseconds(5);
    bool r = digitalReadFast(_SD_DAT3);
    if (r)
    {
      // looks like SD Inserted. so disable the pin for now...
      pinMode(_SD_DAT3, INPUT_DISABLE);

      delay(1);
      Serial.printf("\n*** SDIO Card Inserted ***");
      if(!sdx[BUILTIN_SDCARD_missing_index].sdfs.begin(SdioConfig(FIFO_SDIO)))
      { Serial.printf("SDIO Storage %d %d %s failed or missing",BUILTIN_SDCARD_missing_index,cs[BUILTIN_SDCARD_missing_index],sd_str[BUILTIN_SDCARD_missing_index]);  Serial.println();
      }
      else
      {
        // The SD is valid now... 
        uint32_t store = storage.getStoreID(sd_str[BUILTIN_SDCARD_missing_index]);
        if (store != 0xFFFFFFFFUL) 
        {
          mtpd.send_StoreRemovedEvent(store);
          delay(50);
          //mtpd.send_StorageInfoChangedEvent(store);
          mtpd.send_StoreAddedEvent(store);

        } else {
          // not in our list, try adding it
          store = storage.addFilesystem(sdx[BUILTIN_SDCARD_missing_index], sd_str[BUILTIN_SDCARD_missing_index]);
          mtpd.send_StoreAddedEvent(store);
        }


        uint64_t totalSize = sdx[BUILTIN_SDCARD_missing_index].totalSize();
        uint64_t usedSize  = sdx[BUILTIN_SDCARD_missing_index].usedSize();
        Serial.printf("SDIO Storage %d %d %s ",BUILTIN_SDCARD_missing_index,cs[BUILTIN_SDCARD_missing_index],sd_str[BUILTIN_SDCARD_missing_index]);
        Serial.print(totalSize); Serial.print(" "); Serial.println(usedSize);

      }
      BUILTIN_SDCARD_missing_index = -1; // only try this once
    }
  }
#endif  
}
Note I currently have changes to MTP and MSC projects, plus some hacks in the SDFat (more debug code) trying to understand why things are doing what they are doing.

Right now testing with just one USB drive, the one that has 3 partitions... But only two show up...
screenshot.jpg
Debug output:
Code:
MTP_test
FsVolume::begin(20004250)
ExFatVolume::begin(20004250 0 1
ExFatPartition::init(20004250, 1)
   after part>4
   after boot test
   after EXFAT
   Return true
   After init
   After chdir
sd_addFilesystem: 0 20003dbc sdio
SDIO Storage 0 254 sdio 32017219584 4653056
SD Storage 1 10 sd1 failed or missing
sd_addFilesystem: 1 20006bb8 RAM1
RAM Storage 0 RAM1 199936 512
sd_addFilesystem: 2 20006c80 RAM2
RAM Storage 1 RAM2 3999744 4096
sd_addFilesystem: 3 20003520 PROGM
Program Storage 0 PROGM 983040 8192
QSPI Storage 0 QSPI failed or missing
SPIFlash Storage 0 5 sflash5 failed or missing
SPIFlash Storage 1 6 sflash6 failed or missing
SPIFlash Storage 2 7 prop failed or missing
Flash ID: 00 00 00
SPIFlash NAND Storage 0 3 WINBOND1G failed or missing
Flash ID: 00 00 00
SPIFlash NAND Storage 1 4 WINBOND2G failed or missing

Initializing USB MSC drives...
USB Drive Inserted

msc # Partition Table
	part,boot,bgnCHS[3],type,endCHS[3],start,length
FAT32:	1,0,0x4,0x1,0x4,0xB,0xFE,0xC2,0xFF,2048,8192000
FAT16:	2,0,0xE,0x51,0xFE,0xE,0x98,0x98,0x80,8194048,2097152
exFAT:	3,0,0x98,0x99,0x80,0x7,0xEE,0xDC,0xD2,10291200,5435392
pt_#0:	4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
  Try Partiton:1 on MSC Index:0
UsbBase::mscBegin called 20006d60 0 1
    After usbDriveBegin
PFsVolume::begin(20007eec)
ExFatVolume::begin(20007eec 0 1
ExFatPartition::init(20007eec, 1)
   after part>4
   after boot test
FatVolume::Begin 20007eec 0 1
 *** Return true
    ** SUCCEEDED **
>> USB partition 1 valume ID: VOLFAT32
sd_addFilesystem: 4 20007a58 MSC0-VOLFAT32
  Try Partiton:2 on MSC Index:1
UsbBase::mscBegin called 20006d60 0 2
    After usbDriveBegin
PFsVolume::begin(2000839c)
ExFatVolume::begin(2000839c 0 2
ExFatPartition::init(2000839c, 2)
   after part>4
   after boot test
FatVolume::Begin 2000839c 0 2
 *** Return true
    ** SUCCEEDED **
>> USB partition 2 valume ID: VOLFAT16
sd_addFilesystem: 5 20007f08 MSC0-VOLFAT16
  Try Partiton:3 on MSC Index:2
UsbBase::mscBegin called 20006d60 0 3
    After usbDriveBegin
PFsVolume::begin(2000884c)
[COLOR="#FF0000"]ExFatVolume::begin(2000884c 0 3
ExFatPartition::init(2000884c, 3)
   after part>4[/COLOR]
FatVolume::Begin 2000884c 0 3
  Try Partiton:4 on MSC Index:2
UsbBase::mscBegin called 20006d60 0 4
    After usbDriveBegin
PFsVolume::begin(2000884c)
ExFatVolume::begin(2000884c 0 4
ExFatPartition::init(2000884c, 4)
   after part>4
FatVolume::Begin 2000884c 0 4

**** dir of sd[0] ****
T4.1-Cardlike.jpg
T4-Cardlike.jpg
DSC03355.JPG
test1.txt
mtpindex.dat

Setup done
CMD: 1002(OPEN_SESSION)l: 16 T:0 : 1
RESP:2001(RSP:OK)l: 16 T:0 : 1
CMD: 1001(GET_DEVICE_INFO)l: 12 T:1
RESP:2001(RSP:OK)l: 12 T:1
CMD: 1014(GET_DEVICE_PROP_DESC)l: 16 T:2 : d402
RESP:2001(RSP:OK)l: 16 T:2 : d402
CMD: 1004(GET_STORAGE_IDS)l: 12 T:3
RESP:2001(RSP:OK)l: 12 T:3
CMD: 1005(GET_STORAGE_INFO)l: 16 T:4 : 1
1 0 name:sdio vol:
1 0 name:sdio vol:
RESP:2001(RSP:OK)l: 16 T:4 : 1
CMD: 1005(GET_STORAGE_INFO)l: 16 T:5 : 2
2 1 name:RAM1 vol:
2 1 name:RAM1 vol:
RESP:2001(RSP:OK)l: 16 T:5 : 2
CMD: 1005(GET_STORAGE_INFO)l: 16 T:6 : 3
3 2 name:RAM2 vol:
3 2 name:RAM2 vol:
RESP:2001(RSP:OK)l: 16 T:6 : 3
CMD: 1005(GET_STORAGE_INFO)l: 16 T:7 : 4
4 3 name:PROGM vol:
4 3 name:PROGM vol:
RESP:2001(RSP:OK)l: 16 T:7 : 4
CMD: 1005(GET_STORAGE_INFO)l: 16 T:8 : 5
5 4 name:MSC0-VOLFAT32 vol:
5 4 name:MSC0-VOLFAT32 vol:
RESP:2001(RSP:OK)l: 16 T:8 : 5
CMD: 1005(GET_STORAGE_INFO)l: 16 T:9 : 6
6 5 name:MSC0-VOLFAT16 vol:
6 5 name:MSC0-VOLFAT16 vol:
RESP:2001(RSP:OK)l: 16 T:9 : 6
CMD: 9801(GET_OBJECT_PROPS_SUPPORTED)l: 16 T:a : 3000
RESP:2001(RSP:OK)l: 16 T:a : 3000
CMD: 9801(GET_OBJECT_PROPS_SUPPORTED)l: 16 T:b : 3001
RESP:2001(RSP:OK)l: 16 T:b : 3001
The part in RED is where it should have gone through and detected the ExFat partition, but the ExFat code bailed on:
Code:
bool ExFatPartition::init(BlockDevice* dev, uint8_t part) {
  uint32_t volStart = 0;
  uint8_t* cache;
  pbs_t* pbs;
  BpbExFat_t* bpb;
  MbrSector_t* mbr;
  MbrPart_t* mp;
  Serial.printf("ExFatPartition::init(%x, %u)\n",(uint32_t)dev, part);

  m_fatType = 0;
  m_blockDev = dev;
  cacheInit(m_blockDev);
  cache = dataCacheGet(0, FsCache::CACHE_FOR_READ);
  if (part > 4 || !cache) {
    DBG_FAIL_MACRO;
    goto fail;
  }
  Serial.println("   after part>4");
 [COLOR="#FF0000"] if (part >= 1) {
    mbr = reinterpret_cast<MbrSector_t*>(cache);
    mp = &mbr->part[part - 1];
    if ((mp->boot != 0 && mp->boot != 0X80) || mp->type == 0) {
      DBG_FAIL_MACRO;
      goto fail;
    }[/COLOR]
    Serial.println("   after boot test");
    volStart = getLe32(mp->relativeSectors);
    cache = dataCacheGet(volStart, FsCache::CACHE_FOR_READ);
    if (!cache) {
      DBG_FAIL_MACRO;
      goto fail;
    }
  }
  pbs = reinterpret_cast<pbs_t*>(cache);
  if (strncmp(pbs->oemName, "EXFAT", 5)) {
    DBG_FAIL_MACRO;
    goto fail;
  }
  Serial.println("   after EXFAT");

  bpb = reinterpret_cast<BpbExFat_t*>(pbs->bpb);
  if (bpb->bytesPerSectorShift != m_bytesPerSectorShift) {
    DBG_FAIL_MACRO;
    goto fail;
  }
  m_fatStartSector = volStart + getLe32(bpb->fatOffset);
  m_fatLength = getLe32(bpb->fatLength);
  m_clusterHeapStartSector = volStart + getLe32(bpb->clusterHeapOffset);
  m_clusterCount = getLe32(bpb->clusterCount);
  m_rootDirectoryCluster = getLe32(bpb->rootDirectoryCluster);
  m_sectorsPerClusterShift = bpb->sectorsPerClusterShift;
  m_bytesPerCluster = 1UL << (m_bytesPerSectorShift + m_sectorsPerClusterShift);
  m_clusterMask = m_bytesPerCluster - 1;
  // Set m_bitmapStart to first free cluster.
  m_bitmapStart = 0;
  bitmapFind(0, 1);
  m_fatType = FAT_TYPE_EXFAT;
  Serial.println("   Return true");

  return true;

 fail:
  return false;
}
I showed the debug code that I put in the ExVolume and you can see the last output was the >4 messages... So it bailed in the boot test... Not sure why in this case as it works with the VolumeLabel sketch...

More debugging! I could create new temporary branches of any of this if anyone wants to play along. :)

Kurt

EDIT: Forgot to mention that current hack in MTP get storage info that if partition > 3gb I just return half free and not ask for it to crunch through all of the sectors... only temporary need to find better solution, but...
 
Morning @KurtE and @all
Very cool what you got managed to accomplish in a short time, relatively speaking, considering how intertwined all this stuff is.

More debugging! I could create new temporary branches of any of this if anyone wants to play along.
Of course, you know I am a gluten for punishment.
 
Morning @KurtE and @all
Very cool what you got managed to accomplish in a short time, relatively speaking, considering how intertwined all this stuff is.

Of course, you know I am a gluten for punishment.

I have added some additional debug code:

So far I pushed up a few debug output edits to the Msc... project in the branch: https://github.com/KurtE/UsbMscFat/tree/VolumeName_SD

A new MTP branch based off my other branch: https://github.com/KurtE/MTP_t4/tree/test_msc_parts

The SDFat changes are in the release build.. Just debug stuff:
I added a dump of the MBR in it, which I can see is wrong!
Code:
//------------------------------------------------------------------------------
    extern void dump_hexbytes(const void *ptr, int len);
bool ExFatPartition::init(BlockDevice* dev, uint8_t part) {
  uint32_t volStart = 0;
  uint8_t* cache;
  pbs_t* pbs;
  BpbExFat_t* bpb;
  MbrSector_t* mbr;
  MbrPart_t* mp;
  Serial.printf("ExFatPartition::init(%x, %u)\n",(uint32_t)dev, part);

  m_fatType = 0;
  m_blockDev = dev;
  cacheInit(m_blockDev);
  cache = dataCacheGet(0, FsCache::CACHE_FOR_READ);
  dump_hexbytes(cache, 512);
  if (part > 4 || !cache) {
    DBG_FAIL_MACRO;
    goto fail;
  }
  Serial.println("   after part>4");
  if (part >= 1) {
    mbr = reinterpret_cast<MbrSector_t*>(cache);

    mp = &mbr->part[part - 1];
    if ((mp->boot != 0 && mp->boot != 0X80) || mp->type == 0) {
      DBG_FAIL_MACRO;
      goto fail;
    }
    Serial.println("   after boot test");
    volStart = getLe32(mp->relativeSectors);
    cache = dataCacheGet(volStart, FsCache::CACHE_FOR_READ);
    if (!cache) {
      DBG_FAIL_MACRO;
      goto fail;
    }
  }
  pbs = reinterpret_cast<pbs_t*>(cache);
  if (strncmp(pbs->oemName, "EXFAT", 5)) {
    DBG_FAIL_MACRO;
    goto fail;
  }
  Serial.println("   after EXFAT");

  bpb = reinterpret_cast<BpbExFat_t*>(pbs->bpb);
  if (bpb->bytesPerSectorShift != m_bytesPerSectorShift) {
    DBG_FAIL_MACRO;
    goto fail;
  }
  m_fatStartSector = volStart + getLe32(bpb->fatOffset);
  m_fatLength = getLe32(bpb->fatLength);
  m_clusterHeapStartSector = volStart + getLe32(bpb->clusterHeapOffset);
  m_clusterCount = getLe32(bpb->clusterCount);
  m_rootDirectoryCluster = getLe32(bpb->rootDirectoryCluster);
  m_sectorsPerClusterShift = bpb->sectorsPerClusterShift;
  m_bytesPerCluster = 1UL << (m_bytesPerSectorShift + m_sectorsPerClusterShift);
  m_clusterMask = m_bytesPerCluster - 1;
  // Set m_bitmapStart to first free cluster.
  m_bitmapStart = 0;
  bitmapFind(0, 1);
  m_fatType = FAT_TYPE_EXFAT;
  Serial.println("   Return true");

  return true;

 fail:
  return false;
}

Another note: When I was trying two drives, I was still limited to 2 partitions. Sort of like something is using up my max drives...
Code:
MTP_test
FsVolume::begin(20004250)
ExFatVolume::begin(20004250 0 1
ExFatPartition::init(20004250, 1)
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 15 08 14 51 00 00 00 FE D3 67 C9 00 00 00 82 :................ ...Q.....g.....
03 00 07 FE FF FF 00 20 00 00 00 58 BA 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :....... ...X....................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA :..............................U.
   after part>4
   after boot test
   after EXFAT
   Return true
   After init
   After chdir
sd_addFilesystem: 0 20003dbc sdio
SDIO Storage 0 254 sdio 32017219584 4653056
SD Storage 1 10 sd1 failed or missing
sd_addFilesystem: 1 20006bb8 RAM1
RAM Storage 0 RAM1 199936 512
sd_addFilesystem: 2 20006c80 RAM2
RAM Storage 1 RAM2 3999744 4096
sd_addFilesystem: 3 20003520 PROGM
Program Storage 0 PROGM 983040 8192
QSPI Storage 0 QSPI failed or missing
SPIFlash Storage 0 5 sflash5 failed or missing
SPIFlash Storage 1 6 sflash6 failed or missing
SPIFlash Storage 2 7 prop failed or missing
Flash ID: 00 00 00
SPIFlash NAND Storage 0 3 WINBOND1G failed or missing
Flash ID: 00 00 00
SPIFlash NAND Storage 1 4 WINBOND2G failed or missing

Initializing USB MSC drives...
USB Drive Inserted

msc # Partition Table
	part,boot,bgnCHS[3],type,endCHS[3],start,length
FAT32:	1,0,0x4,0x1,0x4,0xB,0xFE,0xC2,0xFF,2048,8192000
FAT16:	2,0,0xE,0x51,0xFE,0xE,0x98,0x98,0x80,8194048,2097152
exFAT:	3,0,0x98,0x99,0x80,0x7,0xEE,0xDC,0xD2,10291200,5435392
pt_#0:	4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
  Try Partiton:1 on MSC Index:0
UsbBase::mscBegin called 20006d60 0 1
    After usbDriveBegin
PFsVolume::begin(20007eec)
ExFatVolume::begin(20007eec 0 1
ExFatPartition::init(20007eec, 1)
FA B8 00 10 8E D0 BC 00 B0 B8 00 00 8E D8 8E C0 FB BE 00 7C BF 00 06 B9 00 02 F3 A4 EA 21 06 00 :...................|.........!..
00 BE BE 07 38 04 75 0B 83 C6 10 81 FE FE 07 75 F3 EB 16 B4 02 B0 01 BB 00 7C B2 80 8A 74 01 8B :....8.u........u.........|...t..
4C 02 CD 13 EA 00 7C 00 00 EB FE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :L.....|.........................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 7D 66 6D 00 00 00 04 :........................8}fm....
01 04 0B FE C2 FF 00 08 00 00 00 00 7D 00 00 0E 51 FE 0E 98 98 80 00 08 7D 00 00 00 20 00 00 98 :............}...Q.......}... ...
99 80 07 EE DC D2 00 08 9D 00 00 F0 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA :............R.................U.
   after part>4
   after boot test
FatVolume::Begin 20007eec 0 1
 *** Return true
    ** SUCCEEDED **
>> USB partition 1 valume ID: VOLFAT32
sd_addFilesystem: 4 20007a58 MSC0-VOLFAT32
  Try Partiton:2 on MSC Index:1
UsbBase::mscBegin called 20006d60 0 2
    After usbDriveBegin
PFsVolume::begin(2000839c)
ExFatVolume::begin(2000839c 0 2
ExFatPartition::init(2000839c, 2)
FA B8 00 10 8E D0 BC 00 B0 B8 00 00 8E D8 8E C0 FB BE 00 7C BF 00 06 B9 00 02 F3 A4 EA 21 06 00 :...................|.........!..
00 BE BE 07 38 04 75 0B 83 C6 10 81 FE FE 07 75 F3 EB 16 B4 02 B0 01 BB 00 7C B2 80 8A 74 01 8B :....8.u........u.........|...t..
4C 02 CD 13 EA 00 7C 00 00 EB FE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :L.....|.........................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 7D 66 6D 00 00 00 04 :........................8}fm....
01 04 0B FE C2 FF 00 08 00 00 00 00 7D 00 00 0E 51 FE 0E 98 98 80 00 08 7D 00 00 00 20 00 00 98 :............}...Q.......}... ...
99 80 07 EE DC D2 00 08 9D 00 00 F0 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA :............R.................U.
   after part>4
   after boot test
FatVolume::Begin 2000839c 0 2
 *** Return true
    ** SUCCEEDED **
>> USB partition 2 valume ID: VOLFAT16
sd_addFilesystem: 5 20007f08 MSC0-VOLFAT16
  Try Partiton:3 on MSC Index:2
UsbBase::mscBegin called 20006d60 0 3
    After usbDriveBegin
PFsVolume::begin(2000884c)
ExFatVolume::begin(2000884c 0 3
ExFatPartition::init(2000884c, 3)
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 15 08 14 51 00 00 00 FE D3 67 C9 00 00 00 82 :................ ...Q.....g.....
03 00 07 FE FF FF 00 20 00 00 00 58 BA 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :....... ...X....................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA :..............................U.
   after part>4
FatVolume::Begin 2000884c 0 3
  Try Partiton:4 on MSC Index:2
UsbBase::mscBegin called 20006d60 0 4
    After usbDriveBegin
PFsVolume::begin(2000884c)
ExFatVolume::begin(2000884c 0 4
ExFatPartition::init(2000884c, 4)
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 15 08 14 51 00 00 00 FE D3 67 C9 00 00 00 82 :................ ...Q.....g.....
03 00 07 FE FF FF 00 20 00 00 00 58 BA 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :....... ...X....................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA :..............................U.
   after part>4
FatVolume::Begin 2000884c 0 4

**** dir of sd[0] ****
T4.1-Cardlike.jpg
T4-Cardlike.jpg
DSC03355.JPG
test1.txt
mtpindex.dat

Setup done
CMD: 1002(OPEN_SESSION)l: 16 T:0 : 1
RESP:2001(RSP:OK)l: 16 T:0 : 1
CMD: 1001(GET_DEVICE_INFO)l: 12 T:1
RESP:2001(RSP:OK)l: 12 T:1
CMD: 1014(GET_DEVICE_PROP_DESC)l: 16 T:2 : d402
RESP:2001(RSP:OK)l: 16 T:2 : d402
CMD: 1004(GET_STORAGE_IDS)l: 12 T:3
RESP:2001(RSP:OK)l: 12 T:3
CMD: 1005(GET_STORAGE_INFO)l: 16 T:4 : 1
1 0 name:sdio vol:
1 0 name:sdio vol:
RESP:2001(RSP:OK)l: 16 T:4 : 1
CMD: 1005(GET_STORAGE_INFO)l: 16 T:5 : 2
2 1 name:RAM1 vol:
2 1 name:RAM1 vol:
RESP:2001(RSP:OK)l: 16 T:5 : 2
CMD: 1005(GET_STORAGE_INFO)l: 16 T:6 : 3
3 2 name:RAM2 vol:
3 2 name:RAM2 vol:
RESP:2001(RSP:OK)l: 16 T:6 : 3
CMD: 1005(GET_STORAGE_INFO)l: 16 T:7 : 4
4 3 name:PROGM vol:
4 3 name:PROGM vol:
RESP:2001(RSP:OK)l: 16 T:7 : 4
CMD: 1005(GET_STORAGE_INFO)l: 16 T:8 : 5
5 4 name:MSC0-VOLFAT32 vol:
5 4 name:MSC0-VOLFAT32 vol:
RESP:2001(RSP:OK)l: 16 T:8 : 5
CMD: 1005(GET_STORAGE_INFO)l: 16 T:9 : 6
6 5 name:MSC0-VOLFAT16 vol:
6 5 name:MSC0-VOLFAT16 vol:
RESP:2001(RSP:OK)l: 16 T:9 : 6
CMD: 9801(GET_OBJECT_PROPS_SUPPORTED)l: 16 T:a : 3000
RESP:2001(RSP:OK)l: 16 T:a : 3000
CMD: 9801(GET_OBJECT_PROPS_SUPPORTED)l: 16 T:b : 3001
RESP:2001(RSP:OK)l: 16 T:b : 3001
Curious what happens if I change my drives to 3?

It brings up the third partition... Interesting! need to investigate...
 
Curious what happens if I change my drives to 3?

It brings up the third partition... Interesting! need to investigate...
Thanks Kurt will see if I can get everything synched up. Anyway, think that makes sense. Think that goes back to what we were saying earlier, each partition is going to be its own drive: 1 drive = 1 volume, at least in MTP. Maybe you should consider using USE_MSC_FAT solely for drive count and come up with a another counter for partitions on each each drive - so theoretically 2 drives with 3 partitions each should show as 2*3 = 6 drives in MTP?
 
Thanks @mjs513

I understand what you are saying, but so far not sure where the connection is made:
Code:
USB Drive Inserted

msc # Partition Table
	part,boot,bgnCHS[3],type,endCHS[3],start,length
FAT32:	1,0,0x4,0x1,0x4,0xB,0xFE,0xC2,0xFF,2048,8192000
FAT16:	2,0,0xE,0x51,0xFE,0xE,0x98,0x98,0x80,8194048,2097152
exFAT:	3,0,0x98,0x99,0x80,0x7,0xEE,0xDC,0xD2,10291200,5435392
pt_#0:	4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
  Try Partiton:1 on MSC Index:0
[COLOR="#FF0000"]UsbBase::mscBegin called 20006d60 0 1[/COLOR]
    After usbDriveBegin
PFsVolume::begin(200083cc)
ExFatVolume::begin(200083cc 0 1
ExFatPartition::init(200083cc, 1)
FA B8 00 10 8E D0 BC 00 B0 B8 00 00 8E D8 8E C0 FB BE 00 7C BF 00 06 B9 00 02 F3 A4 EA 21 06 00 :...................|.........!..
00 BE BE 07 38 04 75 0B 83 C6 10 81 FE FE 07 75 F3 EB 16 B4 02 B0 01 BB 00 7C B2 80 8A 74 01 8B :....8.u........u.........|...t..
4C 02 CD 13 EA 00 7C 00 00 EB FE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :L.....|.........................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 7D 66 6D 00 00 00 04 :........................8}fm....
01 04 0B FE C2 FF 00 08 00 00 00 00 7D 00 00 0E 51 FE 0E 98 98 80 00 08 7D 00 00 00 20 00 00 98 :............}...Q.......}... ...
99 80 07 EE DC D2 00 08 9D 00 00 F0 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA :............R.................U.
   after part>4
   after boot test
FatVolume::Begin 200083cc 0 1
 *** Return true
    ** SUCCEEDED **
>> USB partition 1 valume ID: VOLFAT32
sd_addFilesystem: 4 20007f38 MSC0-VOLFAT32
  Try Partiton:2 on MSC Index:1
UsbBase::mscBegin called [COLOR="#FF0000"]20006d60 [/COLOR]0 2
    After usbDriveBegin
PFsVolume::begin(2000887c)
ExFatVolume::begin(2000887c 0 2
ExFatPartition::init(2000887c, 2)
FA B8 00 10 8E D0 BC 00 B0 B8 00 00 8E D8 8E C0 FB BE 00 7C BF 00 06 B9 00 02 F3 A4 EA 21 06 00 :...................|.........!..
00 BE BE 07 38 04 75 0B 83 C6 10 81 FE FE 07 75 F3 EB 16 B4 02 B0 01 BB 00 7C B2 80 8A 74 01 8B :....8.u........u.........|...t..
4C 02 CD 13 EA 00 7C 00 00 EB FE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :L.....|.........................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 7D 66 6D 00 00 00 04 :........................8}fm....
01 04 0B FE C2 FF 00 08 00 00 00 00 7D 00 00 0E 51 FE 0E 98 98 80 00 08 7D 00 00 00 20 00 00 98 :............}...Q.......}... ...
99 80 07 EE DC D2 00 08 9D 00 00 F0 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA :............R.................U.
   after part>4
   after boot test
FatVolume::Begin 2000887c 0 2
 *** Return true
    ** SUCCEEDED **
>> USB partition 2 valume ID: VOLFAT16
sd_addFilesystem: 5 200083e8 MSC0-VOLFAT16
  Try Partiton:3 on MSC Index:2
UsbBase::mscBegin called [COLOR="#FF0000"]20006d60 [/COLOR]0 3
    After usbDriveBegin
PFsVolume::begin(20008d2c)
ExFatVolume::begin(20008d2c 0 3
ExFatPartition::init(20008d2c, 3)
FA B8 00 10 8E D0 BC 00 B0 B8 00 00 8E D8 8E C0 FB BE 00 7C BF 00 06 B9 00 02 F3 A4 EA 21 06 00 :...................|.........!..
00 BE BE 07 38 04 75 0B 83 C6 10 81 FE FE 07 75 F3 EB 16 B4 02 B0 01 BB 00 7C B2 80 8A 74 01 8B :....8.u........u.........|...t..
4C 02 CD 13 EA 00 7C 00 00 EB FE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :L.....|.........................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 7D 66 6D 00 00 00 04 :........................8}fm....
01 04 0B FE C2 FF 00 08 00 00 00 00 7D 00 00 0E 51 FE 0E 98 98 80 00 08 7D 00 00 00 20 00 00 98 :............}...Q.......}... ...
99 80 07 EE DC D2 00 08 9D 00 00 F0 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA :............R.................U.
   after part>4
   after boot test
   after EXFAT
   Return true
   After init
   After chdir
    ** SUCCEEDED **
>> USB partition 3 valume ID: VolEXFAT
sd_addFilesystem: 6 20008898 MSC0-VolEXFAT
  Try Partiton:4 on MSC Index:3
UsbBase::mscBegin called [COLOR="#FF0000"]20006d60 [/COLOR]0 4
    After usbDriveBegin
PFsVolume::begin(200091dc)
ExFatVolume::begin(200091dc 0 4
ExFatPartition::init(200091dc, 4)
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 15 08 14 51 00 00 00 FE D3 67 C9 00 00 00 82 :................ ...Q.....g.....
03 00 07 FE FF FF 00 20 00 00 00 58 BA 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :....... ...X....................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA :..............................U.
   after part>4

In each of these 4 cases I am passing in the pointer to the same USBHost_t36 MSC object associated with the device, and
in the VolName sketch we do the same, and the three partitions map to the same device, where the partitions simply take the requests
for things like, first FAT cluster is ... And then pass that number off to physical device.

So I think in the MTP case here I need to look into:
Code:
[COLOR="#FF0000"]UsbBase::mscBegin called 20006d60 0 1[/COLOR]
    After usbDriveBegin
On how it is mapping the actual drive to something else and what resources it is using.
 
@KurtE - got it.

Oh just ran across another issue using a SDCard in a USB Adpater.

If I run VolumeName sketch it pulls up the MBR as:
Code:
msc # Partition Table
	part,boot,bgnCHS[3],type,endCHS[3],start,length
FAT32:	1,80,0x0,0x1,0x10,0xC,0x3,0xE0,0xFF,2048,524288
FAT32:	2,0,0xC2,0x23,0x20,0xC,0xFE,0xFF,0xFF,526336,16564224
exFAT:	3,0,0xFE,0xFF,0xFF,0x7,0xFE,0xFF,0xFF,17092608,232642560
pt_#0:	4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
Now if I run MTP_test.ino its getting stuck at "USB Drive Inserted"
Code:
MTP_test
SDIO Storage 0 254 sdio failed or missing
SD Storage 1 10 sd1 failed or missing
sd_addFilesystem: 0 20007038 RAM1
RAM Storage 0 RAM1 199936 512
sd_addFilesystem: 1 20007100 RAM2
RAM Storage 1 RAM2 3999744 4096
sd_addFilesystem: 2 200039a0 PROGM
Program Storage 0 PROGM 983040 8192
sd_addFilesystem: 3 20003ee0 QSPI
QSPI Storage 0 QSPI 16777216 8192
sd_addFilesystem: 4 20003fb4 sflash5
SPIFlash Storage 0 5 sflash5 67108864 8192
sd_addFilesystem: 5 2000408c sflash6
SPIFlash Storage 1 6 sflash6 67108864 8192
SPIFlash Storage 2 7 prop failed or missing
sd_addFilesystem: 6 20008080 WINBOND1G
Storage 0 3 WINBOND1G 131596288 9175040
sd_addFilesystem: 7 20008170 WINBOND2G
Storage 1 4 WINBOND2G 265289728 9306112

[COLOR="#FF0000"]Initializing USB MSC drives...
USB Drive Inserted[/COLOR]
 
It might be a problem with my mbr dump code, it is pretty big hack, I try to call the read sector directly...
Code:
bool mbrDmp(msController *pdrv) {
  MbrSector_t mbr;
  // bool valid = true;
  if (pdrv->msReadBlocks(0, 1, 512, (uint8_t*)&mbr)) {
    Serial.print("\nread MBR failed.\n");
    //errorPrint();
    return false;
  }
Maybe something not setup properly yet... probably need cleaner way... Will work on soon. You might comment out call and see if it goes farther...

In my code, I fixed a major issue ;) in a Serial output: valume -> volume :D
 
Right now I am looking into the file USBFat.h code:
at:
Code:
template <class Vol>
class UsbBase : public Vol {
 public:
  //----------------------------------------------------------------------------
  /** Initialize USB drive and file system.
   *
   * \param[in] msController drive.
   * \return true for success or false for failure.
   */
  bool begin(msController *pdrv, bool setCwv = true, uint8_t part = 1) {
	return mscBegin(pdrv, setCwv, part);
  }
  //----------------------------------------------------------------------------
  /** Initialize USB drive and file system for USB Drive.
   *
   * \param[in] msController drive configuration.
   * \return true for success or false for failure.
   */
  bool mscBegin(msController *pDrive, bool setCwv = true, uint8_t part = 1) {
    Serial.printf("UsbBase::mscBegin called %x %x %d\n", (uint32_t)pDrive, setCwv, part);
    if (!usbDriveBegin(pDrive)) return false;
    Serial.println("    After usbDriveBegin");
    return Vol::begin(m_USBmscDrive, setCwv, part);
  }
  //----------------------------------------------------------------------------
  /** \return Pointer to USB MSC object. */
  mscDevice* usbDrive() {return m_USBmscDrive;}

I am looking at what is this m_USBmscFactory.newMSCDevice(pDrive);

stuff doing.
 
Ok - commented out the MBR and seems to have got it working. But noticed something funny. I modified the drive partitions so Part 1 = Fat32, 2 = Fat32, 3 = extFat, 4 = Fat16. Going through the debug noticed that it looks like 2 partition 1's are created one for the drive and 1 for the actual partition:
Code:
Initializing USB MSC drives...
USB Drive Inserted
[COLOR="#FF0000"]  Try Partiton:1 on MSC Index:0
[/COLOR]UsbBase::mscBegin called 200071e0 0 1
    After usbDriveBegin
PFsVolume::begin(20008d2c)
    ** SUCCEEDED **
[COLOR="#FF0000"]>> USB partition 1 volume ID: system-boot
[/COLOR]sd_addFilesystem: 8 20008898 MSC0-system-boot
  Try Partiton:2 on MSC Index:1
UsbBase::mscBegin called 200071e0 0 2
    After usbDriveBegin
PFsVolume::begin(200091dc)
    ** SUCCEEDED **
[COLOR="#008000"]>> USB partition 2 volume ID: NEW VOLUME1
[/COLOR]sd_addFilesystem: 9 20008d48 MSC0-NEW VOLUME1
  Try Partiton:3 on MSC Index:2
UsbBase::mscBegin called 200071e0 0 3
    After usbDriveBegin
PFsVolume::begin(2000968c)
    ** SUCCEEDED **
[COLOR="#008000"]>> USB partition 3 volume ID: exFat
[/COLOR]sd_addFilesystem: 10 200091f8 MSC0-exFat
  Try Partiton:4 on MSC Index:3
UsbBase::mscBegin called 200071e0 0 4
    After usbDriveBegin
PFsVolume::begin(20009b3c)
sd_addFilesystem: 11 2000423c sdio
so my 4th partition would be at index 5? Have to play some more
 
As you mentioned, it all is real strange...

I have been off doing some other stuff for a bit!

Will try to debug some more.
 
Sorry just got back: It gets sort of interesting, I turned on the debug code in MassStorageDevice(USBHost) Not the big debug turn on, but one specific to this class:#define DBGprint 1

I also edited a lot of the debug messages to include the this pointer: like:
Serial.printf("mscIint(%x)\n", (uint32_t)this);


Code:
MTP_test
FsVolume::begin(200043d0)
ExFatVolume::begin(200043d0 0 1
ExFatPartition::init(200043d0, 1)
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 15 08 14 51 00 00 00 FE D3 67 C9 00 00 00 82 :................ ...Q.....g.....
03 00 07 FE FF FF 00 20 00 00 00 58 BA 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :....... ...X....................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA :..............................U.
   after part>4
   after boot test
   after EXFAT
   Return true
   After init
   After chdir
sd_addFilesystem: 0 20003f3c sdio
SDIO Storage 0 254 sdio 32017219584 4653056
SD Storage 1 10 sd1 failed or missing
sd_addFilesystem: 1 20006d38 RAM1
RAM Storage 0 RAM1 199936 512
sd_addFilesystem: 2 20006e00 RAM2
RAM Storage 1 RAM2 3999744 4096
sd_addFilesystem: 3 200036a0 PROGM
Program Storage 0 PROGM 983040 8192
QSPI Storage 0 QSPI failed or missing
SPIFlash Storage 0 5 sflash5 failed or missing
SPIFlash Storage 1 6 sflash6 failed or missing
SPIFlash Storage 2 7 prop failed or missing
Flash ID: FF FF FF
SPIFlash NAND Storage 0 3 WINBOND1G failed or missing
Flash ID: FF FF FF
SPIFlash NAND Storage 1 4 WINBOND2G failed or missing

Initializing USB MSC drives...
USB Drive Inserted
<<< msReadBlocks(0 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()

msc # Partition Table
	part,boot,bgnCHS[3],type,endCHS[3],start,length
FAT32:	1,0,0x4,0x1,0x4,0xB,0xFE,0xC2,0xFF,2048,8192000
FAT16:	2,0,0xE,0x51,0xFE,0xE,0x98,0x98,0x80,8194048,2097152
exFAT:	3,0,0x98,0x99,0x80,0x7,0xEE,0xDC,0xD2,10291200,5435392
pt_#0:	4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
  Try Partiton:1 on MSC Index:0
UsbBase::mscBegin called 20006ee0 0 1
mscIint(20006ee0)
msReset()
msGetMaxLun(20006ee0)
WaitMediaReady(20006ee0)
msTestReady()
msGetCSW()
msDeviceInquiry()
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
msReadDeviceCapacity()
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
checkConnectedInitialized(20006ee0)
    After usbDriveBegin
PFsVolume::begin(2000854c)
ExFatVolume::begin(2000854c 0 1
ExFatPartition::init(2000854c, 1)
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(0 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
FA B8 00 10 8E D0 BC 00 B0 B8 00 00 8E D8 8E C0 FB BE 00 7C BF 00 06 B9 00 02 F3 A4 EA 21 06 00 :...................|.........!..
00 BE BE 07 38 04 75 0B 83 C6 10 81 FE FE 07 75 F3 EB 16 B4 02 B0 01 BB 00 7C B2 80 8A 74 01 8B :....8.u........u.........|...t..
4C 02 CD 13 EA 00 7C 00 00 EB FE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :L.....|.........................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 7D 66 6D 00 00 00 04 :........................8}fm....
01 04 0B FE C2 FF 00 08 00 00 00 00 7D 00 00 0E 51 FE 0E 98 98 80 00 08 7D 00 00 00 20 00 00 98 :............}...Q.......}... ...
99 80 07 EE DC D2 00 08 9D 00 00 F0 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA :............R.................U.
   after part>4
   after boot test
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(800 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
FatVolume::Begin 2000854c 0 1
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(0 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(800 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
 *** Return true
    ** SUCCEEDED **
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(46a0 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
>> USB partition 1 volume ID: VOLFAT32
sd_addFilesystem: 4 200080b8 MSC0-VOLFAT32
  Try Partiton:2 on MSC Index:1
UsbBase::mscBegin called 20006ee0 0 2
mscIint(20006ee0)
msReset()
msGetMaxLun(20006ee0)
WaitMediaReady(20006ee0)
msTestReady()
msGetCSW()
msDeviceInquiry()
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
msReadDeviceCapacity()
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
checkConnectedInitialized(20006ee0)
    After usbDriveBegin
PFsVolume::begin(200089fc)
ExFatVolume::begin(200089fc 0 2
ExFatPartition::init(200089fc, 2)
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(0 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
FA B8 00 10 8E D0 BC 00 B0 B8 00 00 8E D8 8E C0 FB BE 00 7C BF 00 06 B9 00 02 F3 A4 EA 21 06 00 :...................|.........!..
00 BE BE 07 38 04 75 0B 83 C6 10 81 FE FE 07 75 F3 EB 16 B4 02 B0 01 BB 00 7C B2 80 8A 74 01 8B :....8.u........u.........|...t..
4C 02 CD 13 EA 00 7C 00 00 EB FE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :L.....|.........................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 7D 66 6D 00 00 00 04 :........................8}fm....
01 04 0B FE C2 FF 00 08 00 00 00 00 7D 00 00 0E 51 FE 0E 98 98 80 00 08 7D 00 00 00 20 00 00 98 :............}...Q.......}... ...
99 80 07 EE DC D2 00 08 9D 00 00 F0 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA :............R.................U.
   after part>4
   after boot test
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(7d0800 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
FatVolume::Begin 200089fc 0 2
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(0 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(7d0800 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
 *** Return true
    ** SUCCEEDED **
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(7d0a08 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
>> USB partition 2 volume ID: VOLFAT16
sd_addFilesystem: 5 20008568 MSC0-VOLFAT16
  Try Partiton:3 on MSC Index:2
UsbBase::mscBegin called 20006ee0 0 3
mscIint(20006ee0)
msReset()
msGetMaxLun(20006ee0)
WaitMediaReady(20006ee0)
msTestReady()
msGetCSW()
msDeviceInquiry()
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
msReadDeviceCapacity()
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
checkConnectedInitialized(20006ee0)
    After usbDriveBegin
PFsVolume::begin(20008eac)
ExFatVolume::begin(20008eac 0 3
ExFatPartition::init(20008eac, 3)
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(0 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
FA B8 00 10 8E D0 BC 00 B0 B8 00 00 8E D8 8E C0 FB BE 00 7C BF 00 06 B9 00 02 F3 A4 EA 21 06 00 :...................|.........!..
00 BE BE 07 38 04 75 0B 83 C6 10 81 FE FE 07 75 F3 EB 16 B4 02 B0 01 BB 00 7C B2 80 8A 74 01 8B :....8.u........u.........|...t..
4C 02 CD 13 EA 00 7C 00 00 EB FE 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :L.....|.........................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 7D 66 6D 00 00 00 04 :........................8}fm....
01 04 0B FE C2 FF 00 08 00 00 00 00 7D 00 00 0E 51 FE 0E 98 98 80 00 08 7D 00 00 00 20 00 00 98 :............}...Q.......}... ...
99 80 07 EE DC D2 00 08 9D 00 00 F0 52 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA :............R.................U.
   after part>4
   after boot test
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(9d0800 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
   after EXFAT
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(9d0b80 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(9d0b81 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
   Return true
   After init
   After chdir
    ** SUCCEEDED **
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(9d0c00 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
>> USB partition 3 volume ID: VolEXFAT
sd_addFilesystem: 6 20008a18 MSC0-VolEXFAT
  Try Partiton:4 on MSC Index:3
UsbBase::mscBegin called 20006ee0 0 4
mscIint(20006ee0)
msReset()
msGetMaxLun(20006ee0)
WaitMediaReady(20006ee0)
msTestReady()
msGetCSW()
msDeviceInquiry()
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
msReadDeviceCapacity()
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
checkConnectedInitialized(20006ee0)
    After usbDriveBegin
PFsVolume::begin(2000935c)
ExFatVolume::begin(2000935c 0 4
ExFatPartition::init(2000935c, 4)
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :................................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 15 08 14 51 00 00 00 FE D3 67 C9 00 00 00 82 :................ ...Q.....g.....
03 00 07 FE FF FF 00 20 00 00 00 58 BA 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 :....... ...X....................
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA :..............................U.
   after part>4
FatVolume::Begin 2000935c 0 4

**** dir of sd[0] ****
T4.1-Cardlike.jpg
T4-Cardlike.jpg
DSC03355.JPG
test1.txt
mtpindex.dat

Setup done
CMD: 1002(OPEN_SESSION)l: 16 T:0 : 1
RESP:2001(RSP:OK)l: 16 T:0 : 1
CMD: 1001(GET_DEVICE_INFO)l: 12 T:1
RESP:2001(RSP:OK)l: 12 T:1
CMD: 1014(GET_DEVICE_PROP_DESC)l: 16 T:2 : d402
RESP:2001(RSP:OK)l: 16 T:2 : d402
CMD: 1004(GET_STORAGE_IDS)l: 12 T:3
RESP:2001(RSP:OK)l: 12 T:3
CMD: 1005(GET_STORAGE_INFO)l: 16 T:4 : 1
1 0 name:sdio vol:
1 0 name:sdio vol:
RESP:2001(RSP:OK)l: 16 T:4 : 1
CMD: 1005(GET_STORAGE_INFO)l: 16 T:5 : 2
2 1 name:RAM1 vol:
2 1 name:RAM1 vol:
RESP:2001(RSP:OK)l: 16 T:5 : 2
CMD: 1005(GET_STORAGE_INFO)l: 16 T:6 : 3
3 2 name:RAM2 vol:
3 2 name:RAM2 vol:
RESP:2001(RSP:OK)l: 16 T:6 : 3
CMD: 1005(GET_STORAGE_INFO)l: 16 T:7 : 4
4 3 name:PROGM vol:
4 3 name:PROGM vol:
RESP:2001(RSP:OK)l: 16 T:7 : 4
CMD: 1005(GET_STORAGE_INFO)l: 16 T:8 : 5
5 4 name:MSC0-VOLFAT32 vol:
5 4 name:MSC0-VOLFAT32 vol:
RESP:2001(RSP:OK)l: 16 T:8 : 5
CMD: 1005(GET_STORAGE_INFO)l: 16 T:9 : 6
checkConnectedInitialized(20006ee0)
<<< msReadBlocks(7d0808 1 200)
msDoCommand(20006ee0):
msGetCSW()
msProcessError()
checkConnectedInitialized(20006ee0)
I cut out some of the later stuff, but it looks like most everything is funneling to the first USB connection.
 
I cut out some of the later stuff, but it looks like most everything is funneling to the first USB connection.
That actually makes sense based on the dump and what we did when were originally testing using the SD card.

First we had to attach the device to get the blockdevice (sd.card) then we used sd.card to attached the partitions. That is I guess what we are seeing with usbhost?
 
For the heck of it, to get another data point I am going to step back and play with the VolumeName sketch, and instead of processing one partition at a time, I am going to try to open up all partitions (up to 4) and then try doing things on them...

Just sort of curious.
 
Ok, I changed that test sketch like:
Code:
// Function to handle one MS Drive...
void procesMSDrive(uint8_t drive_number, msController &msDrive, UsbFs &msc)
{
  Serial.printf("Initialize USB drive...");
  cmsReport = 0;
  if (!msc.begin(&msDrive)) {
    Serial.println("");
    msc.errorPrint(&Serial);
    Serial.printf("initialization drive %u failed.\n", drive_number);
  } else {
    Serial.printf("USB drive %u is present.\n", drive_number);
  }
  cmsReport = -1;

  //  mbrDmp( &msc );
  mbrDmp( msc.usbDrive() );

  #if 1
  bool partition_valid[4];
  PFsVolume partVol[4];
  uint8_t volName[32];

  for (uint8_t i = 0; i < 4; i++) {
    partition_valid[i] = partVol[i].begin(msc.usbDrive(), true, i+1);
    Serial.printf("Partition %u valid:%u\n", i, partition_valid[i]);
  }
  for (uint8_t i = 0; i < 4; i++) {
    if(partition_valid[i]) {
      switch (partVol[i].fatType())
      {
        case FAT_TYPE_FAT12: Serial.printf("%d:>> Fat12: ", i); break;
        case FAT_TYPE_FAT16: Serial.printf("%d:>> Fat16: ", i); break;
        case FAT_TYPE_FAT32: Serial.printf("%d:>> Fat32: ", i); break;
        case FAT_TYPE_EXFAT: Serial.printf("%d:>> ExFat: ", i); break;
      }
      if (getPartitionVolumeLabel(partVol[i], volName, sizeof(volName))) {
        Serial.printf("Volume name:(%s)", volName);
      }
      elapsedMicros em_sizes = 0;
      uint64_t used_size =  (uint64_t)(partVol[i].clusterCount() - partVol[i].freeClusterCount())
                            * (uint64_t)partVol[i].bytesPerCluster();
      uint64_t total_size = (uint64_t)partVol[i].clusterCount() * (uint64_t)partVol[i].bytesPerCluster();
      Serial.printf(" Partition Total Size:%llu Used:%llu time us: %u\n", total_size, used_size, (uint32_t)em_sizes);

      partVol[i].ls();
    }
  }

  #else
  for (uint8_t i = 1; i < 5; i++) {
    PFsVolume partVol;
    uint8_t volName[32];
    if (!partVol.begin(msc.usbDrive(), true, i)) continue; // not a valid volume.
    partVol.chvol();

    switch (partVol.fatType())
    {
      case FAT_TYPE_FAT12: Serial.print("\n>> Fat12: "); break;
      case FAT_TYPE_FAT16: Serial.print("\n>> Fat16: "); break;
      case FAT_TYPE_FAT32: Serial.print("\n>> Fat32: "); break;
      case FAT_TYPE_EXFAT: Serial.print("\n>> ExFat: "); break;
    }
    if (getPartitionVolumeLabel(partVol, volName, sizeof(volName))) {
      Serial.printf("Volume name:(%s)", volName);
    }
    elapsedMicros em_sizes = 0;
    uint64_t used_size =  (uint64_t)(partVol.clusterCount() - partVol.freeClusterCount())
                          * (uint64_t)partVol.bytesPerCluster();
    uint64_t total_size = (uint64_t)partVol.clusterCount() * (uint64_t)partVol.bytesPerCluster();
    Serial.printf(" Partition Total Size:%llu Used:%llu time us: %u\n", total_size, used_size, (uint32_t)em_sizes);

    partVol.ls();
  }
  #endif
}

Here is the output, minus lots of my debug output.

Code:
Waiting up to 5 seconds for USB drive 2
USB drive 1 is present.

msc # Partition Table
	part,boot,bgnCHS[3],type,endCHS[3],start,length
FAT32:	1,0,0x4,0x1,0x4,0xB,0xFE,0xC2,0xFF,2048,8192000
FAT16:	2,0,0xE,0x51,0xFE,0xE,0x98,0x98,0x80,8194048,2097152
exFAT:	3,0,0x98,0x99,0x80,0x7,0xEE,0xDC,0xD2,10291200,5435392
pt_#0:	4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
PFsVolume::begin(20002070)

Partition 0 valid:1
Partition 1 valid:1
Partition 2 valid:1
Partition 3 valid:0

0:>> Fat32: Volume name:(VOLFAT32) Partition Total Size:4186095616 Used:65425408 time us: 6085498
DSC03357.JPG
example.txt
OnFat32.txt
..

1:>> Fat16: Volume name:(VOLFAT16) Partition Total Size:1073446912 Used:11714560 time us: 191500
T4-Cardlike.jpg
OnFat16.txt
...

2:>> ExFat: Volume name:(VolEXFAT) Partition Total Size:2782461952 Used:232030208 time us: 17002
T4.1-Cardlike.jpg
OnExFat.txt
Hitec-laser-6-receiver.jpg
Arduino-mega-Brat.jpg

Initialize SD card...FsVolume::begin(20003eb0)

So looks like I can walk through the 4 (3 valid) partitions...
 
That looks great KurtE ...

Got distracted with the FrankB HardFault - made a sample that saves state on fault and picks up where it left off - doing that with Prime numbers - simple restart but shows capturing 2 words of state and coming back running.

Then I decided to play more with the primes looping ...
 
@all - I may take break from this for rest of day.

Then I may try to see if I can reduce the number of abstractions and the like and get it to work... That is how much different does the VolumeName code and the MTP code need to be? to process the partitions...

But need a fresh clear mind before doing that.

So may hack away on some other stuff... Like wondering about the USB capture code for Logic Analyzer and if I can create new report output which is more streamlined for the data I want...

Note: I know I can not fully capture the fast 480mhz high speed inputs... But one trick that the Saleae mentioned, is what they did a few years ago when they were trying to capture data from some of these devices,
the used an older style USB Hub 1.2 (Not 2) which forced the device to output at the lower speeds which they can capture. But that is a whole different topic!
 
@KurtE
Took a break as well today and played with SDR. Got it finally working in windows so now can have some fun listening to radio :)

Anyway made the changes in post#46 but used the SDCard/adapter with 4 partitions. The sketch picked up the 1st 3 but not the 4th which is a FAT16 but has a ID of 0xF?
Code:
Waiting up to 5 seconds for USB drive 1
Waiting up to 5 seconds for USB drive 2
^^^^^^^^^~~~~:(Initialize USB drive...UsbBase::mscBegin called 200029e0 1 1
^^^^^^^^    After usbDriveBegin
PFsVolume::begin(20002530)
USB drive 1 is present.

msc # Partition Table
	part,boot,bgnCHS[3],type,endCHS[3],start,length
FAT32:	1,80,0x20,0x21,0x0,0xC,0xC2,0x22,0x20,2048,524288
FAT32:	2,0,0xC2,0x23,0x20,0xC,0xFE,0xFF,0xFF,526336,16564224
exFAT:	3,0,0xFE,0xFF,0xFF,0x7,0xFE,0xFF,0xFF,17090560,229376000
pt_#15:	4,0,0xFE,0xFF,0xFF,0xF,0xFE,0xFF,0xFF,246468545,3268671
PFsVolume::begin(20002530)
Partition 0 valid:1
PFsVolume::begin(20002530)
Partition 1 valid:1
PFsVolume::begin(20002530)
Partition 2 valid:1
PFsVolume::begin(20002530)
Partition 3 valid:0
0:>> Fat32: Volume name:(system-boot)###FatPartition::freeClusterCount: FT:32 start:2080 todo:516192
 Partition Total Size:264289280 Used:961024 time us: 2127998
bench0.txt
bench1.txt
bench2.txt
bench3.txt
bench4.txt
bench5.txt
1:>> Fat32: Volume name:(NEW VOLUME1)###FatPartition::freeClusterCount: FT:32 start:526814 todo:2066434

 Partition Total Size:8464105472 Used:983040 time us: 8072748
bench0.txt
bench1.txt
bench2.txt
bench3.txt
bench4.txt
bench5.txt
2:>> ExFat: Volume name:(exFat) Partition Total Size:117435269120 Used:1966080 time us: 109502
aoyue-8032a.pdf

Initialize SD card...initialization failed.

done...
Press any key to run again
ok maybe some more playing with the volume sketch.
 
@All - Trying to get caught up:)

I am writing up doc's that explain more of what MSC does and the way's I have used it with the various versions of MSC. Maybe this will help with the current issues.
Maybe not:)

Hot plugging is not working properly and that may be due to device detection, mounting and unmounting. Also may be why directory listings do no match the device or exist at all after device change. This is without using partitions.

As far as SD's not sure yet.

It seems that things are not initializing properly. More testing, more time, more thought...
 
Back
Top