// VolumeName.ino
// An example of how to retrieve Fat32 and ExFat volume names using SdFat.
// Works with SD cards and USB mass storage drives.
#include "Arduino.h"
#include "mscFS.h"
// Setup USBHost_t36 and as many HUB ports as needed.
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
// Setup MSC for the number of USB Drives you are using. (Two for this example)
// Mutiple USB drives can be used. Hot plugging is supported. There is a slight
// delay after a USB MSC device is plugged in. This is waiting for initialization
// but after it is initialized ther should be no delay.
msController msDrive1(myusb);
#define sdDrive 1
#define msDrive 2
#define SD_CONFIG SdioConfig(FIFO_SDIO)
// set up variables using the mscFS utility library functions:
UsbFs msc1;
SdFs sd;
// Get ExFat volume name.
bool getExFatVolumeLabel(uint8_t drvType) {
uint8_t buf[32];
UsbExFat volName;
SdExFat volName1;
ExFatFile root;
msController *mscDrive;
DirLabel_t *dir;
if (drvType == msDrive) {
mscDrive = &msDrive1;
if (!volName.begin(mscDrive)) {
return false;
}
if (!root.openRoot(&volName)) {
Serial.println("openRoot failed");
return false;
}
}
if (drvType == sdDrive) {
if (!volName1.begin(SD_CONFIG)) {
return false;
}
if (!root.openRoot(&volName1)) {
Serial.println("openRoot failed");
return false;
}
}
root.read(buf, 32);
dir = reinterpret_cast<DirLabel_t*>(buf);
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < dir->labelLength; i++) {
Serial.write(dir->unicode[2 * i]);
}
Serial.println();
return true;
}
// Get Fat32 volume name.
bool getFat32VolumeLabel(uint8_t drvType) {
uint8_t buf[512];
if (drvType == msDrive) {
msc1.usbDrive()->readSector(msc1.dataStartSector(), buf);
}
if (drvType == sdDrive) {
sd.card()->readSector(sd.dataStartSector(), buf);
}
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
Serial.write(buf[i]);
}
Serial.println();
return true;
}
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
SysCall::yield(); // wait for serial port to connect.
}
// Start USBHost_t36, HUB(s) and USB devices.
myusb.begin();
//--------------------------------------------------
Serial.printf("Initialize USB drive...");
}
void loop(void) {
myusb.Task();
if (!msDrive1) {
Serial.println("Waiting up to 5 seconds for USB drive");
elapsedMillis em = 0;
while (!msDrive1 && (em < 5000) ) myusb.Task();
}
if (msDrive1) {
if (!msc1.begin(&msDrive1)) {
msc1.errorPrint(&Serial);
Serial.println("initialization failed.\n");
} else {
Serial.println("USB drive 1 is present.\n");
}
if (msc1.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if (!getFat32VolumeLabel(msDrive))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFat\n");
if (!getExFatVolumeLabel(msDrive))
Serial.printf("Failed to get volume label\n");
}
msc1.ls(LS_SIZE | LS_DATE | LS_R);
}
//--------------------------------------------------
Serial.printf("\nInitialize SD card...");
if (!sd.begin(SD_CONFIG)) {
Serial.println("initialization failed.\n");
} else {
Serial.println("SD card is present.\n");
}
if (sd.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if (!getFat32VolumeLabel(sdDrive))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFAT\n");
if (!getExFatVolumeLabel(sdDrive)) {
Serial.printf("Failed to get volume label\n");
}
}
sd.ls(LS_SIZE | LS_DATE | LS_R);
Serial.println("done...");
Serial.println("Press any key to run again");
while (Serial.read() == -1);
while (Serial.read() != -1);
}
Take this with a grain of salt, but what I am planning to look at includes:Question:
To set up a volume say for an exFat partion I do a:
expartVol.begin(sd.card(), true, 1);
for an SD Card. Now, if I am using a usb drive (non sd). What do I do for a blockdevice or pointer to the device. There is no equivalent .card() for a thumb drive?
Take this with a grain of salt, but what I am planning to look at includes:
In the sketches we have: msController msDrive1(myusb);
Each one of these is for a physical USB drive, I believe it claims the device at an interface level, but I am pretty sure that all of the partitions are one one of these.
And each one of these uses another class: UsbFs msc1;
And the call: if (!msc1.begin(&msDrive1)) {
Starts up the one logical drive using the msDrive1...
And the begin code will sooner or later funnel down to call in the SDFat project:
bool ExFatPartition::init(BlockDevice* dev, uint8_t part);
Or the Fat version:
bool FatPartition::init(BlockDevice* dev, uint8_t part)
Need to walk back to where this one gets called... probably from the begin method which is called by the ...
Question:
To set up a volume say for an exFat partion I do a:
expartVol.begin(sd.card(), true, 1);
for an SD Card. Now, if I am using a usb drive (non sd). What do I do for a blockdevice or pointer to the device. There is no equivalent .card() for a thumb drive?
UsbFs msc1;
expartVol.begin(msc1.usbDrive(), true, 1);
bool FsVolume::begin(BlockDevice* blockDev) {
Serial.printf("FsVolume::begin(%x)\n", (uint32_t)blockDev);
bool FsVolume::begin(BlockDevice* blockDev) {
Serial.printf("FsVolume::begin(%x)\n", (uint32_t)blockDev);
m_blockDev = blockDev;
m_fVol = nullptr;
m_xVol = new (m_volMem) ExFatVolume;
[COLOR="#FF0000"] if (m_xVol && m_xVol->begin(m_blockDev, false)) {[/COLOR]
goto done;
}
m_xVol = nullptr;
m_fVol = new (m_volMem) FatVolume;
[COLOR="#FF0000"] if (m_fVol && m_fVol->begin(m_blockDev, false)) {[/COLOR]
goto done;
}
m_cwv = nullptr;
m_fVol = nullptr;
return false;
done:
m_cwv = this;
return true;
}
bool mscBegin(msController *pDrive) {
return usbDriveBegin(pDrive) && Vol::begin(m_USBmscDrive);
bool begin(msController *pdrv) {
return mscBegin(pdrv);
msc1 Partition Table
part,boot,bgnCHS[3],type,endCHS[3],start,length
exFAT: 1,0,0x20,0x21,0x0,0x7,0xFE,0xFF,0xFF,2048,204800000
FAT32: 2,0,0xFE,0xFF,0xFF,0xC,0xFE,0xFF,0xFF,204802048,29634560
3,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
Fat Type: ExFat
Volume Name: New Volume
Fat Type: Fat32
Volume Name: 3��м
// Get Fat32 volume name.
bool getFat32VolumeLabel(uint8_t drvType, uint8_t part) {
FatVolume partVol;
uint8_t buf[512];
partVol.begin(msc1.usbDrive(), true, part);
partVol.chvol();
if(drvType == msDrive) {
[COLOR="#FF0000"]msc1.usbDrive()->readSector(dataStart[part],buf);[/COLOR]
}
// VolumeName.ino
// An example of how to retrieve Fat32 and ExFat volume names using SdFat.
// Works with SD cards and USB mass storage drives.
#include "Arduino.h"
#include "mscFS.h"
// Setup USBHost_t36 and as many HUB ports as needed.
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
USBHub hub4(myusb);
// Setup MSC for the number of USB Drives you are using. (Two for this example)
// Mutiple USB drives can be used. Hot plugging is supported. There is a slight
// delay after a USB MSC device is plugged in. This is waiting for initialization
// but after it is initialized ther should be no delay.
msController msDrive1(myusb);
msController msDrive2(myusb);
#define sdDrive 1
#define msDrive 2
#define SD_CONFIG SdioConfig(FIFO_SDIO)
// set up variables using the mscFS utility library functions:
UsbFs msc1;
SdFs sd;
//FatVolume partVol;
//create holding array for partions
uint8_t partitionTable[4];
int32_t dataStart[4];
// Get ExFat volume name.
bool getExFatVolumeLabel(uint8_t drvType, uint8_t part) {
uint8_t buf[32];
UsbExFat volName;
SdExFat volName1;
ExFatFile root;
msController *mscDrive;
DirLabel_t *dir;
ExFatVolume expartVol;
if(drvType == msDrive) {
mscDrive = &msDrive1;
if (!volName.begin(&msDrive1)) {
return false;
}
expartVol.begin(msc1.usbDrive(), true, part);
expartVol.chvol();
if (!root.openRoot(&expartVol)) {
Serial.println("openRoot failed");
return false;
}
}
if(drvType == sdDrive) {
if (!volName1.begin(SD_CONFIG)) {
return false;
}
if (!root.openRoot(&volName1)) {
Serial.println("openRoot failed");
return false;
}
}
root.read(buf,32);
dir = reinterpret_cast<DirLabel_t*>(buf);
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < dir->labelLength; i++) {
Serial.write(dir->unicode[2*i]);
}
Serial.println();
return true;
}
// Get Fat32 volume name.
bool getFat32VolumeLabel(uint8_t drvType, uint8_t part) {
FatVolume partVol;
uint8_t buf[512];
partVol.begin(msc1.usbDrive(), true, part);
partVol.chvol();
if(drvType == msDrive) {
msc1.usbDrive()->readSector(dataStart[part],buf);
}
if(drvType == sdDrive) {
sd.card()->readSector(sd.dataStartSector(),buf);
}
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
Serial.write(buf[i]);
}
Serial.println();
return true;
}
bool mbrDmp() {
MbrSector_t mbr;
bool valid = true;
if (!msc1.usbDrive()->readSector(0, (uint8_t*)&mbr)) {
Serial.print("\nread MBR failed.\n");
//errorPrint();
return false;
}
Serial.print("\nmsc1 Partition Table\n");
Serial.print("part,boot,bgnCHS[3],type,endCHS[3],start,length\n");
for (uint8_t ip = 1; ip < 5; ip++) {
MbrPart_t *pt = &mbr.part[ip - 1];
// if ((pt->boot != 0 && pt->boot != 0X80) ||
// getLe32(pt->relativeSectors) > sdCardCapacity(&m_csd)) {
// valid = false;
// }
if((pt->type) == 12) Serial.print("FAT32: ");
if((pt->type) == 7) Serial.print("exFAT: ");
partitionTable[ip-1] = pt->type;
dataStart[ip-1] = getLe32(pt->relativeSectors);
Serial.print( int(ip));Serial.print( ',');
Serial.print(int(pt->boot), HEX);Serial.print( ',');
for (int i = 0; i < 3; i++ ) {
Serial.print("0x");Serial.print(int(pt->beginCHS[i]), HEX); Serial.print( ',');
}
Serial.print("0x");Serial.print(int(pt->type), HEX); Serial.print( ',');
for (int i = 0; i < 3; i++ ) {
Serial.print("0x");Serial.print(int(pt->endCHS[i]), HEX); Serial.print( ',');
}
Serial.print(getLe32(pt->relativeSectors), DEC);Serial.print(',');
Serial.println(getLe32(pt->totalSectors));
}
return true;
}
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
SysCall::yield(); // wait for serial port to connect.
}
// Start USBHost_t36, HUB(s) and USB devices.
myusb.begin();
//--------------------------------------------------
Serial.printf("Initialize USB drive...");
if (!msc1.begin(&msDrive1)) {
msc1.errorPrint(&Serial);
Serial.println("initialization failed.\n");
} else {
Serial.println("USB drive 1 is present.\n");
}
mbrDmp();
/*
if(msc1.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if(!getFat32VolumeLabel(msDrive))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFat\n");
if(!getExFatVolumeLabel(msDrive,1))
Serial.printf("Failed to get volume label\n");
}
msc1.ls(LS_SIZE | LS_DATE | LS_R);
*/
for(uint8_t i = 1; i < 5; i++){
if(partitionTable[i-1] == 7){
Serial.printf("Fat Type: ExFat\n");
if(!getExFatVolumeLabel(msDrive,i))
Serial.printf("Failed to get volume label\n");
} else if(partitionTable[i-1] == 12){
Serial.printf("Fat Type: Fat32\n");
if(!getFat32VolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
} else {
Serial.println("No or Not Supported Partition");
}
}
//--------------------------------------------------
Serial.printf("\nInitialize SD card...");
if (!sd.begin(SD_CONFIG)) {
Serial.println("initialization failed.\n");
} else {
Serial.println("SD card is present.\n");
}
if(sd.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if(!getFat32VolumeLabel(sdDrive, 1))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFAT\n");
if(!getExFatVolumeLabel(sdDrive,1)) {
Serial.printf("Failed to get volume label\n");
}
}
//sd.ls(LS_SIZE | LS_DATE | LS_R);
Serial.println("done...");
}
void loop(void) {
}
msc1 Partition Table
part,boot,bgnCHS[3],type,endCHS[3],start,length
exFAT: 1,0,0x20,0x21,0x0,0x7,0xFE,0xFF,0xFF,2048,204800000
FAT32: 2,0,0xFE,0xFF,0xFF,0xC,0xFE,0xFF,0xFF,204802048,29634560
3,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
Fat Type: ExFat
Volume Name: New Volume
Fat Type: Fat32
Volume Name: ....
2020-12-27 14:47 5725283 VSLAM_and_Navigation_System_of_Unmanned_Ground_Vehicle_Based_on_RGB-D_Camera.pdf
No or Not Supported Partition
No or Not Supported Partition
msc1 Partition Table
part,boot,bgnCHS[3],type,endCHS[3],start,length
exFAT: 1,0,0x20,0x21,0x0,0x7,0xFE,0xFF,0xFF,2048,204800000
FAT32: 2,0,0xFE,0xFF,0xFF,0xC,0xFE,0xFF,0xFF,204802048,29634560
3,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
Fat Type: ExFat
Volume Name: New Volume
Fat Type: Fat32
Volume Name: NEW VOLUME
2020-12-27 14:47 5725283 VSLAM_and_Navigation_System_of_Unmanned_Ground_Vehicle_Based_on_RGB-D_Camera.pdf
No or Not Supported Partition
No or Not Supported Partition
// VolumeName.ino
// An example of how to retrieve Fat32 and ExFat volume names using SdFat.
// Works with SD cards and USB mass storage drives.
#include "Arduino.h"
#include "mscFS.h"
// Setup USBHost_t36 and as many HUB ports as needed.
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
USBHub hub4(myusb);
// Setup MSC for the number of USB Drives you are using. (Two for this example)
// Mutiple USB drives can be used. Hot plugging is supported. There is a slight
// delay after a USB MSC device is plugged in. This is waiting for initialization
// but after it is initialized ther should be no delay.
msController msDrive1(myusb);
msController msDrive2(myusb);
#define sdDrive 1
#define msDrive 2
#define SD_CONFIG SdioConfig(FIFO_SDIO)
// set up variables using the mscFS utility library functions:
UsbFs msc1;
SdFs sd;
//FatVolume partVol;
//create holding array for partions
uint8_t partitionTable[4];
int32_t dataStart[4];
// Get ExFat volume name.
bool getExFatVolumeLabel(uint8_t drvType, uint8_t part) {
uint8_t buf[32];
UsbExFat volName;
SdExFat volName1;
ExFatFile root;
msController *mscDrive;
DirLabel_t *dir;
ExFatVolume expartVol;
if(drvType == msDrive) {
mscDrive = &msDrive1;
if (!volName.begin(&msDrive1)) {
return false;
}
expartVol.begin(msc1.usbDrive(), true, part);
expartVol.chvol();
if (!root.openRoot(&expartVol)) {
Serial.println("openRoot failed");
return false;
}
}
if(drvType == sdDrive) {
if (!volName1.begin(SD_CONFIG)) {
return false;
}
if (!root.openRoot(&volName1)) {
Serial.println("openRoot failed");
return false;
}
}
root.read(buf,32);
dir = reinterpret_cast<DirLabel_t*>(buf);
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < dir->labelLength; i++) {
Serial.write(dir->unicode[2*i]);
}
Serial.println();
return true;
}
// Get Fat32 volume name.
bool getFat32VolumeLabel(uint8_t drvType, uint8_t part) {
FatVolume partVol;
uint8_t buf[512];
partVol.begin(msc1.usbDrive(), true, part);
partVol.chvol();
if(drvType == msDrive) {
msc1.usbDrive()->readSector(partVol.dataStartSector(),buf);
}
if(drvType == sdDrive) {
sd.card()->readSector(sd.dataStartSector(),buf);
}
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
Serial.write(buf[i]);
}
Serial.println();
partVol.ls(LS_SIZE | LS_DATE | LS_R);
return true;
}
bool mbrDmp() {
MbrSector_t mbr;
bool valid = true;
if (!msc1.usbDrive()->readSector(0, (uint8_t*)&mbr)) {
Serial.print("\nread MBR failed.\n");
//errorPrint();
return false;
}
Serial.print("\nmsc1 Partition Table\n");
Serial.print("part,boot,bgnCHS[3],type,endCHS[3],start,length\n");
for (uint8_t ip = 1; ip < 5; ip++) {
MbrPart_t *pt = &mbr.part[ip - 1];
// if ((pt->boot != 0 && pt->boot != 0X80) ||
// getLe32(pt->relativeSectors) > sdCardCapacity(&m_csd)) {
// valid = false;
// }
if((pt->type) == 12) Serial.print("FAT32: ");
if((pt->type) == 7) Serial.print("exFAT: ");
partitionTable[ip-1] = pt->type;
dataStart[ip-1] = getLe32(pt->relativeSectors);
Serial.print( int(ip));Serial.print( ',');
Serial.print(int(pt->boot), HEX);Serial.print( ',');
for (int i = 0; i < 3; i++ ) {
Serial.print("0x");Serial.print(int(pt->beginCHS[i]), HEX); Serial.print( ',');
}
Serial.print("0x");Serial.print(int(pt->type), HEX); Serial.print( ',');
for (int i = 0; i < 3; i++ ) {
Serial.print("0x");Serial.print(int(pt->endCHS[i]), HEX); Serial.print( ',');
}
Serial.print(getLe32(pt->relativeSectors), DEC);Serial.print(',');
Serial.println(getLe32(pt->totalSectors));
}
return true;
}
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
SysCall::yield(); // wait for serial port to connect.
}
// Start USBHost_t36, HUB(s) and USB devices.
myusb.begin();
//--------------------------------------------------
Serial.printf("Initialize USB drive...");
if (!msc1.begin(&msDrive1)) {
msc1.errorPrint(&Serial);
Serial.println("initialization failed.\n");
} else {
Serial.println("USB drive 1 is present.\n");
}
mbrDmp();
/*
if(msc1.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if(!getFat32VolumeLabel(msDrive))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFat\n");
if(!getExFatVolumeLabel(msDrive,1))
Serial.printf("Failed to get volume label\n");
}
msc1.ls(LS_SIZE | LS_DATE | LS_R);
*/
for(uint8_t i = 1; i < 5; i++){
if(partitionTable[i-1] == 7){
Serial.printf("Fat Type: ExFat\n");
if(!getExFatVolumeLabel(msDrive,i))
Serial.printf("Failed to get volume label\n");
} else if(partitionTable[i-1] == 12){
Serial.printf("Fat Type: Fat32\n");
if(!getFat32VolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
} else {
Serial.println("No or Not Supported Partition");
}
}
//--------------------------------------------------
Serial.printf("\nInitialize SD card...");
if (!sd.begin(SD_CONFIG)) {
Serial.println("initialization failed.\n");
} else {
Serial.println("SD card is present.\n");
}
if(sd.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if(!getFat32VolumeLabel(sdDrive, 1))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFAT\n");
if(!getExFatVolumeLabel(sdDrive,1)) {
Serial.printf("Failed to get volume label\n");
}
}
//sd.ls(LS_SIZE | LS_DATE | LS_R);
Serial.println("done...");
}
void loop(void) {
}
// VolumeName.ino
// An example of how to retrieve Fat32 and ExFat volume names using SdFat.
// Works with SD cards and USB mass storage drives.
#include "Arduino.h"
#include "mscFS.h"
// Setup USBHost_t36 and as many HUB ports as needed.
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
USBHub hub4(myusb);
// Setup MSC for the number of USB Drives you are using. (Two for this example)
// Mutiple USB drives can be used. Hot plugging is supported. There is a slight
// delay after a USB MSC device is plugged in. This is waiting for initialization
// but after it is initialized ther should be no delay.
msController msDrive1(myusb);
msController msDrive2(myusb);
#define sdDrive 1
#define msDrive 2
#define SD_CONFIG SdioConfig(FIFO_SDIO)
// set up variables using the mscFS utility library functions:
UsbFs msc1;
SdFs sd;
//FatVolume partVol;
//create holding array for partions
uint8_t partitionTable[4];
int32_t dataStart[4];
// Get ExFat volume name.
bool getExFatVolumeLabel(uint8_t drvType, uint8_t part) {
uint8_t buf[32];
UsbExFat volName;
SdExFat volName1;
ExFatFile root;
msController *mscDrive;
DirLabel_t *dir;
ExFatVolume expartVol;
if (drvType == msDrive) {
mscDrive = &msDrive1;
if (!volName.begin(&msDrive1)) {
return false;
}
expartVol.begin(msc1.usbDrive(), true, part);
expartVol.chvol();
if (!root.openRoot(&expartVol)) {
Serial.println("openRoot failed");
return false;
}
}
if (drvType == sdDrive) {
if (!volName1.begin(SD_CONFIG)) {
return false;
}
if (!root.openRoot(&volName1)) {
Serial.println("openRoot failed");
return false;
}
}
root.read(buf, 32);
dir = reinterpret_cast<DirLabel_t*>(buf);
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < dir->labelLength; i++) {
Serial.write(dir->unicode[2 * i]);
}
Serial.println();
return true;
}
// Get Fat32 volume name.
bool getFat32VolumeLabel(uint8_t drvType, uint8_t part) {
FatVolume partVol;
uint8_t buf[512];
partVol.begin(msc1.usbDrive(), true, part);
partVol.chvol();
if (drvType == msDrive) {
msc1.usbDrive()->readSector(partVol.dataStartSector(), buf);
}
if (drvType == sdDrive) {
sd.card()->readSector(sd.dataStartSector(), buf);
}
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
Serial.write(buf[i]);
}
Serial.println();
partVol.ls(LS_SIZE | LS_DATE | LS_R);
return true;
}
bool mbrDmp() {
MbrSector_t mbr;
bool valid = true;
if (!msc1.usbDrive()->readSector(0, (uint8_t*)&mbr)) {
Serial.print("\nread MBR failed.\n");
//errorPrint();
return false;
}
Serial.print("\nmsc1 Partition Table\n");
Serial.print("part,boot,bgnCHS[3],type,endCHS[3],start,length\n");
for (uint8_t ip = 1; ip < 5; ip++) {
MbrPart_t *pt = &mbr.part[ip - 1];
// if ((pt->boot != 0 && pt->boot != 0X80) ||
// getLe32(pt->relativeSectors) > sdCardCapacity(&m_csd)) {
// valid = false;
// }
if ((pt->type) == 12) Serial.print("FAT32: ");
if ((pt->type) == 7) Serial.print("exFAT: ");
partitionTable[ip - 1] = pt->type;
dataStart[ip - 1] = getLe32(pt->relativeSectors);
Serial.print( int(ip)); Serial.print( ',');
Serial.print(int(pt->boot), HEX); Serial.print( ',');
for (int i = 0; i < 3; i++ ) {
Serial.print("0x"); Serial.print(int(pt->beginCHS[i]), HEX); Serial.print( ',');
}
Serial.print("0x"); Serial.print(int(pt->type), HEX); Serial.print( ',');
for (int i = 0; i < 3; i++ ) {
Serial.print("0x"); Serial.print(int(pt->endCHS[i]), HEX); Serial.print( ',');
}
Serial.print(getLe32(pt->relativeSectors), DEC); Serial.print(',');
Serial.println(getLe32(pt->totalSectors));
}
return true;
}
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
SysCall::yield(); // wait for serial port to connect.
}
// Start USBHost_t36, HUB(s) and USB devices.
myusb.begin();
}
void loop(void) {
//--------------------------------------------------
myusb.Task();
if (!msDrive1) {
Serial.println("Waiting up to 5 seconds for USB drive");
elapsedMillis em = 0;
while (!msDrive1 && (em < 5000) ) myusb.Task();
}
if (msDrive1) {
Serial.printf("Initialize USB drive...");
if (!msc1.begin(&msDrive1)) {
msc1.errorPrint(&Serial);
Serial.println("initialization failed.\n");
} else {
Serial.println("USB drive 1 is present.\n");
}
mbrDmp();
/*
if(msc1.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if(!getFat32VolumeLabel(msDrive))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFat\n");
if(!getExFatVolumeLabel(msDrive,1))
Serial.printf("Failed to get volume label\n");
}
msc1.ls(LS_SIZE | LS_DATE | LS_R);
*/
for (uint8_t i = 1; i < 5; i++) {
if (partitionTable[i - 1] == 7) {
Serial.printf("Fat Type: ExFat\n");
if (!getExFatVolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
} else if (partitionTable[i - 1] == 12) {
Serial.printf("Fat Type: Fat32\n");
if (!getFat32VolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
} else {
Serial.println("No or Not Supported Partition");
}
}
}
//--------------------------------------------------
Serial.printf("\nInitialize SD card...");
if (!sd.begin(SD_CONFIG)) {
Serial.println("initialization failed.\n");
} else {
Serial.println("SD card is present.\n");
}
if (sd.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if (!getFat32VolumeLabel(sdDrive, 1))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFAT\n");
if (!getExFatVolumeLabel(sdDrive, 1)) {
Serial.printf("Failed to get volume label\n");
}
}
//sd.ls(LS_SIZE | LS_DATE | LS_R);
Serial.println("done...");
Serial.println("Press any key to run again");
while (Serial.read() == -1);
while (Serial.read() != -1);
}
Waiting up to 5 seconds for USB drive
connected 1
initialized 0
Initialize USB drive...mscIint()
msReset()
msGetMaxLun()
WaitMediaReady()
msTestReady()
msGetCSW()
msDeviceInquiry()
msDoCommand():
msGetCSW()
msProcessError()
msReadDeviceCapacity()
msDoCommand():
msGetCSW()
msProcessError()
checkConnectedInitialized()
FsVolume::begin(20001c60)
ExFatPartition::init(20001c60, 1)
checkConnectedInitialized()
<<< msReadBlocks(0 1 200)
msDoCommand():
msGetCSW()
msProcessError()
checkConnectedInitialized()
<<< msReadBlocks(800 1 200)
msDoCommand():
msGetCSW()
msProcessError()
FatPartition::init(20001c60, 1)
checkConnectedInitialized()
<<< msReadBlocks(0 1 200)
msDoCommand():
msGetCSW()
msProcessError()
checkConnectedInitialized()
<<< msReadBlocks(800 1 200)
msDoCommand():
msGetCSW()
msProcessError()
USB drive 1 is present.
checkConnectedInitialized()
<<< msReadBlocks(0 1 200)
msDoCommand():
msGetCSW()
msProcessError()
msc1 Partition Table
part,boot,bgnCHS[3],type,endCHS[3],start,length
1,0,0x4,0x1,0x4,0xB,0xFE,0xC2,0xFF,2048,8192000
2,0,0xE,0x51,0xFE,0xE,0x98,0x98,0x80,8194048,2097152
exFAT: 3,0,0x98,0x99,0x80,0x7,0xEE,0xDC,0xD2,10291200,5435392
4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
No or Not Supported Partition
No or Not Supported Partition
Fat Type: ExFat
mscIint()
msReset()
msGetMaxLun()
WaitMediaReady()
msTestReady()
msGetCSW()
msDeviceInquiry()
msDoCommand():
msGetCSW()
msProcessError()
msReadDeviceCapacity()
msDoCommand():
msGetCSW()
msProcessError()
checkConnectedInitialized()
ExFatPartition::init(2006fb0c, 1)
checkConnectedInitialized()
<<< msReadBlocks(0 1 200)
msDoCommand():
msGetCSW()
msProcessError()
checkConnectedInitialized()
<<< msReadBlocks(800 1 200)
msDoCommand():
msGetCSW()
msProcessError()
Failed to get volume label
No or Not Supported Partition
Initialize SD card...FsVolume::begin(200034f0)
ExFatPartition::init(200034f0, 1)
FatPartition::init(200034f0, 1)
SD card is present.
Fat Type: ExFAT
ExFatPartition::init(2006ff9c, 1)
Failed to get volume label
done...
Press any key to run again
msc1 Partition Table
part,boot,bgnCHS[3],type,endCHS[3],start,length
1,0,0x4,0x1,0x4,[COLOR="#FF0000"]0xB[/COLOR],0xFE,0xC2,0xFF,2048,8192000
2,0,0xE,0x51,0xFE,[COLOR="#FF0000"]0xE,[/COLOR]0x98,0x98,0x80,8194048,2097152
exFAT: 3,0,0x98,0x99,0x80,[COLOR="#FF0000"]0x7[/COLOR],0xEE,0xDC,0xD2,10291200,5435392
4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
No or Not Supported Partition
No or Not Supported Partition
Fat Type: ExFat
@all - Wondering in my above Partition table dump you see:
Code:msc1 Partition Table part,boot,bgnCHS[3],type,endCHS[3],start,length 1,0,0x4,0x1,0x4,[COLOR="#FF0000"]0xB[/COLOR],0xFE,0xC2,0xFF,2048,8192000 2,0,0xE,0x51,0xFE,[COLOR="#FF0000"]0xE,[/COLOR]0x98,0x98,0x80,8194048,2097152 exFAT: 3,0,0x98,0x99,0x80,[COLOR="#FF0000"]0x7[/COLOR],0xEE,0xDC,0xD2,10291200,5435392 4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0 No or Not Supported Partition No or Not Supported Partition Fat Type: ExFat
The three partition types:
Only one was understood 7 for ExFat
The first partition: I formatted for Fat32: Turns out there are at least two different Fat32s.
0xb - FAT32 with CHS addressing - The one that was formatted on it...
0xc - FAT32 with LBA addressing - The one you are looking for
Then the second partition: Fat16 with LBA... Not sure if we support?
There appear to be a few different Fat16, like 4 and 6...
msc1 Partition Table
part,boot,bgnCHS[3],type,endCHS[3],start,length
exFAT: 1,0,0x20,0x21,0x0,0x7,0xFE,0xFF,0xFF,2048,234436608
2,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
3,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
Fat Type: ExFat
Volume Name: 120GB_Ext
No or Not Supported Partition
No or Not Supported Partition
No or Not Supported Partition
Initialize SD card...SD card is present.
Fat Type: Fat32
Volume Name: B
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
[B][COLOR="#FF0000"]if ( buf[i] > 0 && buf[i] < 127 )[/COLOR][/B]
Serial.write(buf[i]);
}
Waiting up to 5 seconds for USB drive
Initialize USB drive...USB drive 1 is present.
msc1 Partition Table
part,boot,bgnCHS[3],type,endCHS[3],start,length
FAT32: 1,80,0x20,0x21,0x0,0xC,0xFE,0xFF,0xFF,2048,67108864
FAT32: 2,0,0xFE,0xFF,0xFF,0xC,0xFE,0xFF,0xFF,67110912,54128640
3,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
Fat Type: Fat32
Volume Name: [B][COLOR="#FF0000"]B Info[/COLOR][/B]
2017-10-06 02:44 0 efi/
2017-10-06 02:44 0 boot/
2017-09-18 16:30 1224608 bootx64.efi
2017-10-06 02:44 0 microsoft/
2017-10-06 02:44 0 boot/
2017-03-18 13:59 16384 BCD
2017-10-06 02:44 0 fonts/
2017-03-18 13:57 3695719 chs_boot.ttf
...
2018-04-26 19:30 0 ICON/
2018-04-26 19:30 34145 remove.ico
2018-04-26 19:30 0 Metadata/
2018-04-26 19:30 59471 767402d9-4a9b-4b86-a7cc-87ee0b9dda64.devicemetadata-ms
2018-04-26 19:30 132642 7da5fe49-047b-4050-af5d-4db9c0b308b1.devicemetadata-ms
2018-04-26 19:30 59446 90faa471-b2ba-4151-a2ae-42a27fa17081.devicemetadata-ms
2018-04-26 19:30 59468 bbf1d96f-8f14-4421-afd3-00c29d8c5ae0.devicemetadata-ms
2018-04-26 19:30 59445 c4d649ac-a413-49dd-845f-0c1ca1416b1a.devicemetadata-ms
2018-04-26 19:30 137533 cf65cfb5-3970-491b-bb2b-15660bf3abab.devicemetadata-ms
2018-04-26 19:30 59075 d22853f4-2a28-43da-9432-cba889d49fa8.devicemetadata-ms
2018-04-26 19:30 75178 fc02c085-991f-446a-a8c4-c4945bd9f129.devicemetadata-ms
2018-04-26 19:30 280279 ffd10825-4187-4972-bc05-15501fc41dd7.devicemetadata-ms
2017-11-06 16:59 0 PATCH/
2018-04-26 19:30 0 README/
2018-04-26 19:30 81920 AdvProperties.html
2018-04-26 19:30 0 TOOL/
2018-04-26 19:30 256352 RTInstaller32.dat
2018-04-26 19:30 287584 RTInstaller64.dat
2018-04-26 19:30 0 WIN10/
2018-04-26 19:30 0 32/
2018-04-26 19:30 19307 rtux86w10.cat
2018-04-26 19:30 451154 rtux86w10.INF
2018-04-26 19:30 344544 rtux86w10.sys
2018-04-26 19:30 0 64/
2018-04-26 19:30 19340 rtux64w10.cat
2018-04-26 19:30 451154 rtux64w10.INF
2018-04-26 19:30 429024 rtux64w10.sys
done...
Press any key to run again
...
2018-04-26 19:30 0 64/
2018-04-26 19:30 19340 rtux64w10.cat
2018-04-26 19:30 451154 rtux64w10.INF
2018-04-26 19:30 429024 rtux64w10.sys
[B]Fat Type: Fat32
Volume Name: 64G_PT#2
2021-02-24 09:01 0 FPartTwo.txt
[/B]No or Not Supported Partition
No or Not Supported Partition
Initialize SD card...initialization failed.
Fat Type: ExFAT
Failed to get volume label
done...
Press any key to run again
Waiting up to 5 seconds for USB drive
Initialize USB drive...FsVolume::begin(20001b28)
ExFatPartition::init(20001b28, 1)
FatPartition::init(20001b28, 1)
USB drive 1 is present.
msc1 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
4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
Fat Type: Fat32
FatPartition::init(20001b28, 1)
Volume Name: FAT32
2010-03-22 07:11 3343737 DSC03357.JPG
2021-01-01 00:00 0 example.txt
Fat Type: Fat16
FatPartition::init(20001b28, 2)
2E 20 20 20 20 20 20 20 20 20 20 10 00 60 AE 6D 56 52 56 52 00 00 AF 6D 56 52 02 00 00 00 00 00 :. ..`.mVRVR...mVR......
2E 2E 20 20 20 20 20 20 20 20 20 10 00 60 AE 6D 56 52 56 52 00 00 AF 6D 56 52 00 00 00 00 00 00 :.. ..`.mVRVR...mVR......
42 74 00 00 00 FF FF FF FF FF FF 0F 00 CE FF FF FF FF FF FF FF FF FF FF FF FF 00 00 FF FF FF FF :Bt..............................
01 57 00 50 00 53 00 65 00 74 00 0F 00 CE 74 00 69 00 6E 00 67 00 73 00 2E 00 00 00 64 00 61 00 :.W.P.S.e.t....t.i.n.g.s.....d.a.
57 50 53 45 54 54 7E 31 44 41 54 20 00 64 AE 6D 56 52 58 52 00 00 AF 6D 56 52 03 00 0C 00 00 00 :WPSETT~1DAT .d.mVRXR...mVR......
42 47 00 75 00 69 00 64 00 00 00 0F 00 FF FF FF FF FF FF FF FF FF FF FF FF FF 00 00 FF FF FF FF :BG.u.i.d........................
01 49 00 6E 00 64 00 65 00 78 00 0F 00 FF 65 00 72 00 56 00 6F 00 6C 00 75 00 00 00 6D 00 65 00 :.I.n.d.e.x....e.r.V.o.l.u...m.e.
49 4E 44 45 58 45 7E 31 20 20 20 20 00 7B 11 5D 58 52 58 52 00 00 12 5D 58 52 19 00 4C 00 00 00 :INDEXE~1 .{.]XRXR...]XR..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 :................................
Volume Name: .
2021-01-13 17:56 340510 T4-Cardlike.jpg
Fat Type: ExFat
ExFatPartition::init(2006fb0c, 1)
Failed to get volume label
No or Not Supported Partition
Initialize SD card...FsVolume::begin(200033b0)
ExFatPartition::init(200033b0, 1)
FatPartition::init(200033b0, 1)
SD card is present.
Fat Type: ExFAT
ExFatPartition::init(2006ff9c, 1)
Failed to get volume label
done...
Press any key to run again
// VolumeName.ino
// An example of how to retrieve Fat32 and ExFat volume names using SdFat.
// Works with SD cards and USB mass storage drives.
#include "Arduino.h"
#include "mscFS.h"
// Setup USBHost_t36 and as many HUB ports as needed.
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
USBHub hub4(myusb);
// Setup MSC for the number of USB Drives you are using. (Two for this example)
// Mutiple USB drives can be used. Hot plugging is supported. There is a slight
// delay after a USB MSC device is plugged in. This is waiting for initialization
// but after it is initialized ther should be no delay.
msController msDrive1(myusb);
msController msDrive2(myusb);
#define sdDrive 1
#define msDrive 2
#define SD_CONFIG SdioConfig(FIFO_SDIO)
// set up variables using the mscFS utility library functions:
UsbFs msc1;
SdFs sd;
//FatVolume partVol;
//create holding array for partions
uint8_t partitionTable[4];
int32_t dataStart[4];
// Get ExFat volume name.
bool getExFatVolumeLabel(uint8_t drvType, uint8_t part) {
uint8_t buf[32];
UsbExFat volName;
SdExFat volName1;
ExFatFile root;
msController *mscDrive;
DirLabel_t *dir;
ExFatVolume expartVol;
if (drvType == msDrive) {
mscDrive = &msDrive1;
if (!volName.begin(&msDrive1)) {
return false;
}
expartVol.begin(msc1.usbDrive(), true, part);
expartVol.chvol();
if (!root.openRoot(&expartVol)) {
Serial.println("openRoot failed");
return false;
}
}
if (drvType == sdDrive) {
if (!volName1.begin(SD_CONFIG)) {
return false;
}
if (!root.openRoot(&volName1)) {
Serial.println("openRoot failed");
return false;
}
}
root.read(buf, 32);
dir = reinterpret_cast<DirLabel_t*>(buf);
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < dir->labelLength; i++) {
Serial.write(dir->unicode[2 * i]);
}
Serial.println();
return true;
}
// Get Fat32 volume name.
bool getFat32VolumeLabel(uint8_t drvType, uint8_t part) {
FatVolume partVol;
uint8_t buf[512];
partVol.begin(msc1.usbDrive(), true, part);
partVol.chvol();
if (drvType == msDrive) {
msc1.usbDrive()->readSector(partVol.dataStartSector(), buf);
}
if (drvType == sdDrive) {
sd.card()->readSector(sd.dataStartSector(), buf);
}
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
Serial.write(buf[i]);
}
Serial.println();
partVol.ls(LS_SIZE | LS_DATE | LS_R);
return true;
}
// Get Fat16 volume name.
bool getFat16VolumeLabel(uint8_t drvType, uint8_t part) {
FatVolume partVol;
uint8_t buf[512];
partVol.begin(msc1.usbDrive(), true, part);
partVol.chvol();
if (drvType == msDrive) {
msc1.usbDrive()->readSector(partVol.dataStartSector(), buf);
}
if (drvType == sdDrive) {
sd.card()->readSector(sd.dataStartSector(), buf);
}
print_hexbytes(buf, 512);
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
Serial.write(buf[i]);
}
Serial.println();
partVol.ls(LS_SIZE | LS_DATE | LS_R);
return true;
}
bool mbrDmp() {
MbrSector_t mbr;
bool valid = true;
if (!msc1.usbDrive()->readSector(0, (uint8_t*)&mbr)) {
Serial.print("\nread MBR failed.\n");
//errorPrint();
return false;
}
Serial.print("\nmsc1 Partition Table\n");
Serial.print("part,boot,bgnCHS[3],type,endCHS[3],start,length\n");
for (uint8_t ip = 1; ip < 5; ip++) {
MbrPart_t *pt = &mbr.part[ip - 1];
// if ((pt->boot != 0 && pt->boot != 0X80) ||
// getLe32(pt->relativeSectors) > sdCardCapacity(&m_csd)) {
// valid = false;
// }
switch (pt->type) {
case 4:
case 6:
case 0xe:
Serial.print("FAT16: ");
break;
case 11:
case 12:
Serial.print("FAT32: ");
break;
case 7:
Serial.print("exFAT: ");
break;
}
partitionTable[ip - 1] = pt->type;
dataStart[ip - 1] = getLe32(pt->relativeSectors);
Serial.print( int(ip)); Serial.print( ',');
Serial.print(int(pt->boot), HEX); Serial.print( ',');
for (int i = 0; i < 3; i++ ) {
Serial.print("0x"); Serial.print(int(pt->beginCHS[i]), HEX); Serial.print( ',');
}
Serial.print("0x"); Serial.print(int(pt->type), HEX); Serial.print( ',');
for (int i = 0; i < 3; i++ ) {
Serial.print("0x"); Serial.print(int(pt->endCHS[i]), HEX); Serial.print( ',');
}
Serial.print(getLe32(pt->relativeSectors), DEC); Serial.print(',');
Serial.println(getLe32(pt->totalSectors));
}
return true;
}
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
SysCall::yield(); // wait for serial port to connect.
}
// Start USBHost_t36, HUB(s) and USB devices.
myusb.begin();
}
void loop(void) {
//--------------------------------------------------
myusb.Task();
if (!msDrive1) {
Serial.println("Waiting up to 5 seconds for USB drive");
elapsedMillis em = 0;
while (!msDrive1 && (em < 5000) ) myusb.Task();
}
if (msDrive1) {
Serial.printf("Initialize USB drive...");
if (!msc1.begin(&msDrive1)) {
msc1.errorPrint(&Serial);
Serial.println("initialization failed.\n");
} else {
Serial.println("USB drive 1 is present.\n");
}
mbrDmp();
/*
if(msc1.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if(!getFat32VolumeLabel(msDrive))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFat\n");
if(!getExFatVolumeLabel(msDrive,1))
Serial.printf("Failed to get volume label\n");
}
msc1.ls(LS_SIZE | LS_DATE | LS_R);
*/
for (uint8_t i = 1; i < 5; i++) {
switch (partitionTable[i - 1]) {
case 11:
case 12:
Serial.printf("Fat Type: Fat32\n");
if (!getFat32VolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
break;
case 4:
case 6:
case 0xe:
Serial.printf("Fat Type: Fat16\n");
if (!getFat16VolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
break;
case 7:
Serial.printf("Fat Type: ExFat\n");
if (!getExFatVolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
break;
default:
Serial.println("No or Not Supported Partition");
}
}
}
//--------------------------------------------------
Serial.printf("\nInitialize SD card...");
if (!sd.begin(SD_CONFIG)) {
Serial.println("initialization failed.\n");
} else {
Serial.println("SD card is present.\n");
}
if (sd.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if (!getFat32VolumeLabel(sdDrive, 1))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFAT\n");
if (!getExFatVolumeLabel(sdDrive, 1)) {
Serial.printf("Failed to get volume label\n");
}
}
//sd.ls(LS_SIZE | LS_DATE | LS_R);
Serial.println("done...");
Serial.println("Press any key to run again");
while (Serial.read() == -1);
while (Serial.read() != -1);
}
void print_hexbytes(const void *ptr, int len)
{
if (ptr == NULL || len <= 0) return;
const uint8_t *p = (const uint8_t *)ptr;
while (len) {
for (uint8_t i = 0; i < 32; i++) {
if (i > len) break;
Serial.printf("%02X ", p[i]);
}
Serial.print(":");
for (uint8_t i = 0; i < 32; i++) {
if (i > len) break;
Serial.printf("%c", ((p[i] >= ' ') && (p[i] <= '~')) ? p[i] : '.');
}
Serial.println();
p += 32;
len -= 32;
}
}
Waiting up to 5 seconds for USB drive
Initialize SD card...initialization failed.
Fat Type: ExFAT
Failed to get volume label
done...
Press any key to run again
Initialize USB drive...USB drive 1 is present.
msc1 Partition Table
part,boot,bgnCHS[3],type,endCHS[3],start,length
FAT32: >>>pt->type: 12
1,80,0x20,0x21,0x0,0xC,0xFE,0xFF,0xFF,2048,30963712
>>>pt->type: 0
2,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
>>>pt->type: 0
3,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
>>>pt->type: 0
4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
Fat Type: Fat32
[B]Volume Name: B Info[/B]
2020-05-10 23:45 128 autorun.inf
2020-05-30 16:22 0 boot/
2020-05-10 23:45 16384 bcd
2020-05-10 23:45 3170304 boot.sdi
2020-05-10 23:45 1024 bootfix.bin
2020-05-10 23:45 110392 bootsect.exe
...
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
[B][COLOR="#FF0000"]if ( buf[i] > 0 && buf[i] < 127 )[/COLOR][/B]
Serial.write(buf[i]);
}
// VolumeName.ino
// An example of how to retrieve Fat32 and ExFat volume names using SdFat.
// Works with SD cards and USB mass storage drives.
#include "Arduino.h"
#include "mscFS.h"
// Setup USBHost_t36 and as many HUB ports as needed.
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
USBHub hub4(myusb);
// Setup MSC for the number of USB Drives you are using. (Two for this example)
// Mutiple USB drives can be used. Hot plugging is supported. There is a slight
// delay after a USB MSC device is plugged in. This is waiting for initialization
// but after it is initialized ther should be no delay.
msController msDrive1(myusb);
msController msDrive2(myusb);
#define sdDrive 1
#define msDrive 2
#define SD_CONFIG SdioConfig(FIFO_SDIO)
// set up variables using the mscFS utility library functions:
UsbFs msc1;
SdFs sd;
//FatVolume partVol;
//create holding array for partions
uint8_t partitionTable[4];
int32_t dataStart[4];
// Get ExFat volume name.
bool getExFatVolumeLabel(uint8_t drvType, uint8_t part) {
uint8_t buf[32];
UsbExFat volName;
SdExFat volName1;
ExFatFile root;
msController *mscDrive;
DirLabel_t *dir;
ExFatVolume expartVol;
if (drvType == msDrive) {
mscDrive = &msDrive1;
if (!volName.begin(&msDrive1)) {
Serial.println("EXFat volName.begin failed");
return false;
}
expartVol.begin(msc1.usbDrive(), true, part);
expartVol.chvol();
if (!root.openRoot(&expartVol)) {
Serial.println("openRoot failed");
return false;
}
}
if (drvType == sdDrive) {
if (!volName1.begin(SD_CONFIG)) {
return false;
}
if (!root.openRoot(&volName1)) {
Serial.println("openRoot failed");
return false;
}
}
root.read(buf, 32);
dir = reinterpret_cast<DirLabel_t*>(buf);
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < dir->labelLength; i++) {
Serial.write(dir->unicode[2 * i]);
}
Serial.println();
return true;
}
// Get Fat32 volume name.
bool getFat32VolumeLabel(uint8_t drvType, uint8_t part) {
FatVolume partVol;
uint8_t buf[512];
partVol.begin(msc1.usbDrive(), true, part);
partVol.chvol();
if (drvType == msDrive) {
msc1.usbDrive()->readSector(partVol.dataStartSector(), buf);
}
if (drvType == sdDrive) {
sd.card()->readSector(sd.dataStartSector(), buf);
}
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
Serial.write(buf[i]);
}
Serial.println();
partVol.ls(LS_SIZE | LS_DATE | LS_R);
return true;
}
// Get Fat16 volume name.
bool getFat16VolumeLabel(uint8_t drvType, uint8_t part) {
FatVolume partVol;
MbrSector_t mbr;
uint8_t buf[512];
partVol.begin(msc1.usbDrive(), true, part);
partVol.chvol();
if (drvType == msDrive) {
// lets read in the Master boot record...
msc1.usbDrive()->readSector(0, (uint8_t*)&mbr);
MbrPart_t *pt = &mbr.part[part - 1];
uint32_t starting_sector = getLe32(pt->relativeSectors);
msc1.usbDrive()->readSector(starting_sector, buf);
Serial.printf("\nFAT first sector:(%x)\n", starting_sector);
print_hexbytes(buf, 512);
pbs_t* pbs = (pbs_t*)&buf;
BpbFat16_t *bpt16 = reinterpret_cast<BpbFat16_t*>(pbs->bpb);
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
Serial.write(bpt16->volumeLabel[i]);
}
}
if (drvType == sdDrive) {
sd.card()->readSector(sd.dataStartSector(), buf);
print_hexbytes(buf, 512);
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
Serial.write(buf[i]);
}
}
Serial.println();
partVol.ls(LS_SIZE | LS_DATE | LS_R);
return true;
}
bool mbrDmp() {
MbrSector_t mbr;
bool valid = true;
if (!msc1.usbDrive()->readSector(0, (uint8_t*)&mbr)) {
Serial.print("\nread MBR failed.\n");
//errorPrint();
return false;
}
Serial.print("\nmsc1 Partition Table\n");
Serial.print("part,boot,bgnCHS[3],type,endCHS[3],start,length\n");
for (uint8_t ip = 1; ip < 5; ip++) {
MbrPart_t *pt = &mbr.part[ip - 1];
// if ((pt->boot != 0 && pt->boot != 0X80) ||
// getLe32(pt->relativeSectors) > sdCardCapacity(&m_csd)) {
// valid = false;
// }
switch (pt->type) {
case 4:
case 6:
case 0xe:
Serial.print("FAT16: ");
break;
case 11:
case 12:
Serial.print("FAT32: ");
break;
case 7:
Serial.print("exFAT: ");
break;
}
partitionTable[ip - 1] = pt->type;
dataStart[ip - 1] = getLe32(pt->relativeSectors);
Serial.print( int(ip)); Serial.print( ',');
Serial.print(int(pt->boot), HEX); Serial.print( ',');
for (int i = 0; i < 3; i++ ) {
Serial.print("0x"); Serial.print(int(pt->beginCHS[i]), HEX); Serial.print( ',');
}
Serial.print("0x"); Serial.print(int(pt->type), HEX); Serial.print( ',');
for (int i = 0; i < 3; i++ ) {
Serial.print("0x"); Serial.print(int(pt->endCHS[i]), HEX); Serial.print( ',');
}
Serial.print(getLe32(pt->relativeSectors), DEC); Serial.print(',');
Serial.println(getLe32(pt->totalSectors));
}
return true;
}
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
SysCall::yield(); // wait for serial port to connect.
}
// Start USBHost_t36, HUB(s) and USB devices.
myusb.begin();
}
void loop(void) {
//--------------------------------------------------
myusb.Task();
if (!msDrive1) {
Serial.println("Waiting up to 5 seconds for USB drive");
elapsedMillis em = 0;
while (!msDrive1 && (em < 5000) ) myusb.Task();
}
if (msDrive1) {
Serial.printf("Initialize USB drive...");
if (!msc1.begin(&msDrive1)) {
msc1.errorPrint(&Serial);
Serial.println("initialization failed.\n");
} else {
Serial.println("USB drive 1 is present.\n");
}
mbrDmp();
/*
if(msc1.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if(!getFat32VolumeLabel(msDrive))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFat\n");
if(!getExFatVolumeLabel(msDrive,1))
Serial.printf("Failed to get volume label\n");
}
msc1.ls(LS_SIZE | LS_DATE | LS_R);
*/
for (uint8_t i = 1; i < 5; i++) {
switch (partitionTable[i - 1]) {
case 11:
case 12:
Serial.printf("\nFat Type: Fat32\n");
if (!getFat32VolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
break;
case 4:
case 6:
case 0xe:
Serial.printf("\nFat Type: Fat16\n");
if (!getFat16VolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
break;
case 7:
Serial.printf("\nFat Type: ExFat\n");
if (!getExFatVolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
break;
default:
Serial.println("No or Not Supported Partition");
}
}
}
//--------------------------------------------------
Serial.printf("\nInitialize SD card...");
if (!sd.begin(SD_CONFIG)) {
Serial.println("initialization failed.\n");
} else {
Serial.println("SD card is present.\n");
}
if (sd.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if (!getFat32VolumeLabel(sdDrive, 1))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFAT\n");
if (!getExFatVolumeLabel(sdDrive, 1)) {
Serial.printf("Failed to get volume label\n");
}
}
//sd.ls(LS_SIZE | LS_DATE | LS_R);
Serial.println("done...");
Serial.println("Press any key to run again");
while (Serial.read() == -1);
while (Serial.read() != -1);
}
void print_hexbytes(const void *ptr, int len)
{
if (ptr == NULL || len <= 0) return;
const uint8_t *p = (const uint8_t *)ptr;
while (len) {
for (uint8_t i = 0; i < 32; i++) {
if (i > len) break;
Serial.printf("%02X ", p[i]);
}
Serial.print(":");
for (uint8_t i = 0; i < 32; i++) {
if (i > len) break;
Serial.printf("%c", ((p[i] >= ' ') && (p[i] <= '~')) ? p[i] : '.');
}
Serial.println();
p += 32;
len -= 32;
}
}
Waiting up to 5 seconds for USB drive
Initialize USB drive...FsVolume::begin(20001b70)
ExFatPartition::init(20001b70, 1)
FatPartition::init(20001b70, 1)
USB drive 1 is present.
msc1 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
4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
Fat Type: Fat32
FatPartition::init(20001b70, 1)
Volume Name: VOLFAT32
2010-03-22 07:11 3343737 DSC03357.JPG
2021-01-01 00:00 0 example.txt
2021-02-24 16:35 0 OnFat32.txt
Fat Type: Fat16
FatPartition::init(20001b70, 2)
FAT first sector:(7d0800)
EB 3C 90 4D 53 44 4F 53 35 2E 30 00 02 20 08 00 02 00 02 00 00 F8 00 01 3F 00 FF 00 00 08 7D 00 :.<.MSDOS5.0.. ..........?.....}.
00 00 20 00 80 00 29 19 4C 09 02 4E 4F 20 4E 41 4D 45 20 20 20 20 46 41 54 31 36 20 20 20 33 C9 :.. ...).L..NO NAME FAT16 3.
8E D1 BC F0 7B 8E D9 B8 00 20 8E C0 FC BD 00 7C 38 4E 24 7D 24 8B C1 99 E8 3C 01 72 1C 83 EB 3A :....{.... .....|8N$}$....<.r...:
66 A1 1C 7C 26 66 3B 07 26 8A 57 FC 75 06 80 CA 02 88 56 02 80 C3 10 73 EB 33 C9 8A 46 10 98 F7 :f..|&f;.&.W.u.....V....s.3..F...
66 16 03 46 1C 13 56 1E 03 46 0E 13 D1 8B 76 11 60 89 46 FC 89 56 FE B8 20 00 F7 E6 8B 5E 0B 03 :f..F..V..F....v.`.F..V.. ....^..
C3 48 F7 F3 01 46 FC 11 4E FE 61 BF 00 00 E8 E6 00 72 39 26 38 2D 74 17 60 B1 0B BE A1 7D F3 A6 :.H...F..N.a......r9&8-t.`....}..
61 74 32 4E 74 09 83 C7 20 3B FB 72 E6 EB DC A0 FB 7D B4 7D 8B F0 AC 98 40 74 0C 48 74 13 B4 0E :at2Nt... ;.r.....}.}....@t.Ht...
BB 07 00 CD 10 EB EF A0 FD 7D EB E6 A0 FC 7D EB E1 CD 16 CD 19 26 8B 55 1A 52 B0 01 BB 00 00 E8 :.........}....}......&.U.R......
3B 00 72 E8 5B 8A 56 24 BE 0B 7C 8B FC C7 46 F0 3D 7D C7 46 F4 29 7D 8C D9 89 4E F2 89 4E F6 C6 :;.r.[.V$..|...F.=}.F.)}...N..N..
06 96 7D CB EA 03 00 00 20 0F B6 C8 66 8B 46 F8 66 03 46 1C 66 8B D0 66 C1 EA 10 EB 5E 0F B6 C8 :..}..... ...f.F.f.F.f..f....^...
4A 4A 8A 46 0D 32 E4 F7 E2 03 46 FC 13 56 FE EB 4A 52 50 06 53 6A 01 6A 10 91 8B 46 18 96 92 33 :JJ.F.2....F..V..JRP.Sj.j...F...3
D2 F7 F6 91 F7 F6 42 87 CA F7 76 1A 8A F2 8A E8 C0 CC 02 0A CC B8 01 02 80 7E 02 0E 75 04 B4 42 :......B...v..............~..u..B
8B F4 8A 56 24 CD 13 61 61 72 0B 40 75 01 42 03 5E 0B 49 75 06 F8 C3 41 BB 00 00 60 66 6A 00 EB :...V$..aar.@u.B.^.Iu...A...`fj..
B0 42 4F 4F 54 4D 47 52 20 20 20 20 0D 0A 52 65 6D 6F 76 65 20 64 69 73 6B 73 20 6F 72 20 6F 74 :.BOOTMGR ..Remove disks or ot
68 65 72 20 6D 65 64 69 61 2E FF 0D 0A 44 69 73 6B 20 65 72 72 6F 72 FF 0D 0A 50 72 65 73 73 20 :her media....Disk error...Press
61 6E 79 20 6B 65 79 20 74 6F 20 72 65 73 74 61 72 74 0D 0A 00 00 00 00 00 00 00 AC CB D8 55 AA :any key to restart............U.
Volume Name: NO NAME
2021-01-13 17:56 340510 T4-Cardlike.jpg
2021-02-24 16:34 0 OnFat16.txt
Fat Type: ExFat
ExFatPartition::init(2006fb0c, 1)
EXFat volName.begin failed
Failed to get volume label
No or Not Supported Partition
Initialize SD card...FsVolume::begin(200033f0)
ExFatPartition::init(200033f0, 1)
FatPartition::init(200033f0, 1)
SD card is present.
Fat Type: ExFAT
ExFatPartition::init(2006ff9c, 1)
Failed to get volume label
done...
Press any key to run again
// VolumeName.ino
// An example of how to retrieve Fat32 and ExFat volume names using SdFat.
// Works with SD cards and USB mass storage drives.
#include "Arduino.h"
#include "mscFS.h"
// Setup USBHost_t36 and as many HUB ports as needed.
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
USBHub hub4(myusb);
// Setup MSC for the number of USB Drives you are using. (Two for this example)
// Mutiple USB drives can be used. Hot plugging is supported. There is a slight
// delay after a USB MSC device is plugged in. This is waiting for initialization
// but after it is initialized ther should be no delay.
msController msDrive1(myusb);
msController msDrive2(myusb);
#define sdDrive 1
#define msDrive 2
#define SD_CONFIG SdioConfig(FIFO_SDIO)
// set up variables using the mscFS utility library functions:
UsbFs msc1;
SdFs sd;
//FatVolume partVol;
//create holding array for partions
uint8_t partitionTable[4];
int32_t dataStart[4];
// Get ExFat volume name.
bool getExFatVolumeLabel(uint8_t drvType, uint8_t part) {
uint8_t buf[32];
UsbExFat volName;
SdExFat volName1;
ExFatFile root;
msController *mscDrive;
DirLabel_t *dir;
ExFatVolume expartVol;
if (drvType == msDrive) {
mscDrive = &msDrive1;
if (!volName.begin(&msDrive1)) {
Serial.println("EXFat volName.begin failed");
return false;
}
expartVol.begin(msc1.usbDrive(), true, part);
expartVol.chvol();
if (!root.openRoot(&expartVol)) {
Serial.println("openRoot failed");
return false;
}
}
if (drvType == sdDrive) {
if (!volName1.begin(SD_CONFIG)) {
return false;
}
if (!root.openRoot(&volName1)) {
Serial.println("openRoot failed");
return false;
}
}
root.read(buf, 32);
dir = reinterpret_cast<DirLabel_t*>(buf);
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < dir->labelLength; i++) {
Serial.write(dir->unicode[2 * i]);
}
Serial.println();
return true;
}
// Get Fat32 volume name.
bool getFat32VolumeLabel(uint8_t drvType, uint8_t part) {
FatVolume partVol;
uint8_t buf[512];
partVol.begin(msc1.usbDrive(), true, part);
partVol.chvol();
if (drvType == msDrive) {
msc1.usbDrive()->readSector(partVol.dataStartSector(), buf);
}
if (drvType == sdDrive) {
sd.card()->readSector(sd.dataStartSector(), buf);
}
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
Serial.write(buf[i]);
}
Serial.println();
partVol.ls(LS_SIZE | LS_DATE | LS_R);
return true;
}
// Get Fat16 volume name.
bool getFat16VolumeLabel(uint8_t drvType, uint8_t part) {
FatVolume partVol;
MbrSector_t mbr;
uint8_t buf[512];
partVol.begin(msc1.usbDrive(), true, part);
partVol.chvol();
if (drvType == msDrive) {
msc1.usbDrive()->readSector(partVol.rootDirStart(), buf);
// print_hexbytes(buf, 512);
}
if (drvType == sdDrive) {
sd.card()->readSector(sd.dataStartSector(), buf);
print_hexbytes(buf, 512);
}
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
Serial.write(buf[i]);
}
Serial.println();
partVol.ls(LS_SIZE | LS_DATE | LS_R);
return true;
}
bool mbrDmp() {
MbrSector_t mbr;
bool valid = true;
if (!msc1.usbDrive()->readSector(0, (uint8_t*)&mbr)) {
Serial.print("\nread MBR failed.\n");
//errorPrint();
return false;
}
Serial.print("\nmsc1 Partition Table\n");
Serial.print("part,boot,bgnCHS[3],type,endCHS[3],start,length\n");
for (uint8_t ip = 1; ip < 5; ip++) {
MbrPart_t *pt = &mbr.part[ip - 1];
// if ((pt->boot != 0 && pt->boot != 0X80) ||
// getLe32(pt->relativeSectors) > sdCardCapacity(&m_csd)) {
// valid = false;
// }
switch (pt->type) {
case 4:
case 6:
case 0xe:
Serial.print("FAT16: ");
break;
case 11:
case 12:
Serial.print("FAT32: ");
break;
case 7:
Serial.print("exFAT: ");
break;
}
partitionTable[ip - 1] = pt->type;
dataStart[ip - 1] = getLe32(pt->relativeSectors);
Serial.print( int(ip)); Serial.print( ',');
Serial.print(int(pt->boot), HEX); Serial.print( ',');
for (int i = 0; i < 3; i++ ) {
Serial.print("0x"); Serial.print(int(pt->beginCHS[i]), HEX); Serial.print( ',');
}
Serial.print("0x"); Serial.print(int(pt->type), HEX); Serial.print( ',');
for (int i = 0; i < 3; i++ ) {
Serial.print("0x"); Serial.print(int(pt->endCHS[i]), HEX); Serial.print( ',');
}
Serial.print(getLe32(pt->relativeSectors), DEC); Serial.print(',');
Serial.println(getLe32(pt->totalSectors));
}
return true;
}
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
SysCall::yield(); // wait for serial port to connect.
}
// Start USBHost_t36, HUB(s) and USB devices.
myusb.begin();
}
void loop(void) {
//--------------------------------------------------
myusb.Task();
if (!msDrive1) {
Serial.println("Waiting up to 5 seconds for USB drive");
elapsedMillis em = 0;
while (!msDrive1 && (em < 5000) ) myusb.Task();
}
if (msDrive1) {
Serial.printf("Initialize USB drive...");
if (!msc1.begin(&msDrive1)) {
msc1.errorPrint(&Serial);
Serial.println("initialization failed.\n");
} else {
Serial.println("USB drive 1 is present.\n");
}
mbrDmp();
/*
if(msc1.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if(!getFat32VolumeLabel(msDrive))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFat\n");
if(!getExFatVolumeLabel(msDrive,1))
Serial.printf("Failed to get volume label\n");
}
msc1.ls(LS_SIZE | LS_DATE | LS_R);
*/
for (uint8_t i = 1; i < 5; i++) {
switch (partitionTable[i - 1]) {
case 11:
case 12:
Serial.printf("\nFat Type: Fat32\n");
if (!getFat32VolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
break;
case 4:
case 6:
case 0xe:
Serial.printf("\nFat Type: Fat16\n");
if (!getFat16VolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
break;
case 7:
Serial.printf("\nFat Type: ExFat\n");
if (!getExFatVolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
break;
default:
Serial.println("No or Not Supported Partition");
}
}
}
//--------------------------------------------------
Serial.printf("\nInitialize SD card...");
if (!sd.begin(SD_CONFIG)) {
Serial.println("initialization failed.\n");
} else {
Serial.println("SD card is present.\n");
}
if (sd.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if (!getFat32VolumeLabel(sdDrive, 1))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFAT\n");
if (!getExFatVolumeLabel(sdDrive, 1)) {
Serial.printf("Failed to get volume label\n");
}
}
//sd.ls(LS_SIZE | LS_DATE | LS_R);
Serial.println("done...");
Serial.println("Press any key to run again");
while (Serial.read() == -1);
while (Serial.read() != -1);
}
void print_hexbytes(const void *ptr, int len)
{
if (ptr == NULL || len <= 0) return;
const uint8_t *p = (const uint8_t *)ptr;
while (len) {
for (uint8_t i = 0; i < 32; i++) {
if (i > len) break;
Serial.printf("%02X ", p[i]);
}
Serial.print(":");
for (uint8_t i = 0; i < 32; i++) {
if (i > len) break;
Serial.printf("%c", ((p[i] >= ' ') && (p[i] <= '~')) ? p[i] : '.');
}
Serial.println();
p += 32;
len -= 32;
}
}
Waiting up to 5 seconds for USB drive
Initialize USB drive...FsVolume::begin(20001b58)
ExFatPartition::init(20001b58, 1)
FatPartition::init(20001b58, 1)
USB drive 1 is present.
msc1 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
4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
Fat Type: Fat32
FatPartition::init(20001b58, 1)
Volume Name: VOLFAT32
2010-03-22 07:11 3343737 DSC03357.JPG
2021-01-01 00:00 0 example.txt
2021-02-24 16:35 0 OnFat32.txt
Fat Type: Fat16
FatPartition::init(20001b58, 2)
Volume Name: VOLFAT16
2021-01-13 17:56 340510 T4-Cardlike.jpg
2021-02-24 16:34 0 OnFat16.txt
Fat Type: ExFat
ExFatPartition::init(2006fb0c, 1)
EXFat volName.begin failed
Failed to get volume label
No or Not Supported Partition
Initialize SD card...FsVolume::begin(200033f0)
ExFatPartition::init(200033f0, 1)
FatPartition::init(200033f0, 1)
SD card is present.
Fat Type: ExFAT
ExFatPartition::init(2006ff9c, 1)
Failed to get volume label
done...
Press any key to run again
msc1.usbDrive()->readSector(partVol.rootDirStart(), buf);
msc1 Partition Table
part,boot,bgnCHS[3],type,endCHS[3],start,length
FAT16: 1,80,0x1,0x1,0x0,0xE,0xFE,0x3F,0x79,63,1974208
2,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
3,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
Fat Type: Fat16
Volume Name: NEW VOLUME
2020-11-17 13:56 220021 T4.1-Cardlike0.jpg
No or Not Supported Partition
No or Not Supported Partition
No or Not Supported Partition
sd.card()->readSector(sd.rootDirStart(), buf);
Waiting up to 5 seconds for USB drive
Initialize USB drive...
Waiting up to 5 seconds for USB drive
Initialize SD card...initialization failed.
Fat Type: ExFAT
Failed to get volume label
done...
Press any key to run again
Initialize USB drive...USB drive 1 is present.
msc1 Partition Table
part,boot,bgnCHS[3],type,endCHS[3],start,length
FAT32: 1,80,0x20,0x21,0x0,0xC,0xFE,0xFF,0xFF,2048,67108864
FAT32: 2,0,0xFE,0xFF,0xFF,0xC,0xFE,0xFF,0xFF,67110912,54128640
3,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
4,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0
Fat Type: Fat32
Volume Name: B
// VolumeName.ino
// An example of how to retrieve Fat32 and ExFat volume names using SdFat.
// Works with SD cards and USB mass storage drives.
#include "Arduino.h"
#include "mscFS.h"
// Setup USBHost_t36 and as many HUB ports as needed.
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
USBHub hub4(myusb);
IntervalTimer clocked100ms;
volatile int32_t cmsReport = -1;
// Setup MSC for the number of USB Drives you are using. (Two for this example)
// Mutiple USB drives can be used. Hot plugging is supported. There is a slight
// delay after a USB MSC device is plugged in. This is waiting for initialization
// but after it is initialized ther should be no delay.
msController msDrive1(myusb);
msController msDrive2(myusb);
#define sdDrive 1
#define msDrive 2
#define SD_CONFIG SdioConfig(FIFO_SDIO)
// set up variables using the mscFS utility library functions:
UsbFs msc1;
SdFs sd;
//FatVolume partVol;
//create holding array for partions
uint8_t partitionTable[4];
int32_t dataStart[4];
// Get ExFat volume name.
bool getExFatVolumeLabel(uint8_t drvType, uint8_t part) {
uint8_t buf[32];
UsbExFat volName;
SdExFat volName1;
ExFatFile root;
msController *mscDrive;
DirLabel_t *dir;
ExFatVolume expartVol;
if (drvType == msDrive) {
mscDrive = &msDrive1;
if (!volName.begin(&msDrive1)) {
Serial.println("EXFat volName.begin failed");
return false;
}
expartVol.begin(msc1.usbDrive(), true, part);
expartVol.chvol();
if (!root.openRoot(&expartVol)) {
Serial.println("openRoot failed");
return false;
}
}
if (drvType == sdDrive) {
if (!volName1.begin(SD_CONFIG)) {
return false;
}
if (!root.openRoot(&volName1)) {
Serial.println("openRoot failed");
return false;
}
}
root.read(buf, 32);
dir = reinterpret_cast<DirLabel_t*>(buf);
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < dir->labelLength; i++) {
Serial.write(dir->unicode[2 * i]);
}
Serial.println();
return true;
}
// Get Fat32 volume name.
bool getFat32VolumeLabel(uint8_t drvType, uint8_t part) {
FatVolume partVol;
uint8_t buf[512];
partVol.begin(msc1.usbDrive(), true, part);
partVol.chvol();
if (drvType == msDrive) {
msc1.usbDrive()->readSector(partVol.dataStartSector(), buf);
}
if (drvType == sdDrive) {
sd.card()->readSector(sd.dataStartSector(), buf);
}
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
if ( buf[i] > 0 && buf[i] < 127 )
Serial.write(buf[i]);
}
Serial.println();
partVol.ls(LS_SIZE | LS_DATE | LS_R);
return true;
}
// Get Fat16 .
bool getFat16VolumeLabel(uint8_t drvType, uint8_t part) {
FatVolume partVol;
MbrSector_t mbr;
uint8_t buf[512];
partVol.begin(msc1.usbDrive(), true, part);
partVol.chvol();
if (drvType == msDrive) {
// lets read in the Master boot record...
msc1.usbDrive()->readSector(0, (uint8_t*)&mbr);
MbrPart_t *pt = &mbr.part[part - 1];
uint32_t starting_sector = getLe32(pt->relativeSectors);
msc1.usbDrive()->readSector(starting_sector, buf);
Serial.printf("\nFAT first sector:(%x)\n", starting_sector);
print_hexbytes(buf, 512);
pbs_t* pbs = (pbs_t*)&buf;
BpbFat16_t *bpt16 = reinterpret_cast<BpbFat16_t*>(pbs->bpb);
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
Serial.write(bpt16->volumeLabel[i]);
}
}
if (drvType == sdDrive) {
sd.card()->readSector(sd.dataStartSector(), buf);
print_hexbytes(buf, 512);
Serial.print(F("Volume Name: "));
for (size_t i = 0; i < 11; i++) {
if ( buf[i] > 0 && buf[i] < 127 )
Serial.write(buf[i]);
}
}
Serial.println();
partVol.ls(LS_SIZE | LS_DATE | LS_R);
return true;
}
bool mbrDmp() {
MbrSector_t mbr;
bool valid = true;
if (!msc1.usbDrive()->readSector(0, (uint8_t*)&mbr)) {
Serial.print("\nread MBR failed.\n");
//errorPrint();
return false;
}
Serial.print("\nmsc1 Partition Table\n");
Serial.print("part,boot,bgnCHS[3],type,endCHS[3],start,length\n");
for (uint8_t ip = 1; ip < 5; ip++) {
MbrPart_t *pt = &mbr.part[ip - 1];
// if ((pt->boot != 0 && pt->boot != 0X80) ||
// getLe32(pt->relativeSectors) > sdCardCapacity(&m_csd)) {
// valid = false;
// }
switch (pt->type) {
case 4:
case 6:
case 0xe:
Serial.print("FAT16: ");
break;
case 11:
case 12:
Serial.print("FAT32: ");
break;
case 7:
Serial.print("exFAT: ");
break;
}
partitionTable[ip - 1] = pt->type;
dataStart[ip - 1] = getLe32(pt->relativeSectors);
Serial.print( int(ip)); Serial.print( ',');
Serial.print(int(pt->boot), HEX); Serial.print( ',');
for (int i = 0; i < 3; i++ ) {
Serial.print("0x"); Serial.print(int(pt->beginCHS[i]), HEX); Serial.print( ',');
}
Serial.print("0x"); Serial.print(int(pt->type), HEX); Serial.print( ',');
for (int i = 0; i < 3; i++ ) {
Serial.print("0x"); Serial.print(int(pt->endCHS[i]), HEX); Serial.print( ',');
}
Serial.print(getLe32(pt->relativeSectors), DEC); Serial.print(',');
Serial.println(getLe32(pt->totalSectors));
}
return true;
}
void setup()
{
#if 0 // easy test to check HardFault Detection response
int *pp=0;
*pp=5;
#endif
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
SysCall::yield(); // wait for serial port to connect.
}
// Start USBHost_t36, HUB(s) and USB devices.
myusb.begin();
[B]//#define SHOW_CLOCK_CARAT 1
#ifdef SHOW_CLOCK_CARAT
clocked100ms.begin(clock_isr, 100000);
#endif
[/B]
}
void clock_isr() {
if (cmsReport >= 0 ) {
if (cmsReport > 0 ) {
if (cmsReport <10 )
Serial.print( "^");
else if ( !(cmsReport%10) )
Serial.print( "~");
}
cmsReport++;
}
}
void loop(void) {
//--------------------------------------------------
[B] cmsReport=0;
[/B] myusb.Task();
if (!msDrive1) {
Serial.println("Waiting up to 5 seconds for USB drive");
elapsedMillis em = 0;
while (!msDrive1 && (em < 5000) ) myusb.Task();
}
if (msDrive1) {
Serial.printf("Initialize USB drive...");
if (!msc1.begin(&msDrive1)) {
msc1.errorPrint(&Serial);
Serial.println("initialization failed.\n");
} else {
Serial.println("USB drive 1 is present.\n");
}
[B] cmsReport=-1;
[/B]
mbrDmp();
/*
if(msc1.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if(!getFat32VolumeLabel(msDrive))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFat\n");
if(!getExFatVolumeLabel(msDrive,1))
Serial.printf("Failed to get volume label\n");
}
msc1.ls(LS_SIZE | LS_DATE | LS_R);
*/
for (uint8_t i = 1; i < 5; i++) {
switch (partitionTable[i - 1]) {
case 11:
case 12:
Serial.printf("\nFat Type: Fat32\n");
if (!getFat32VolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
break;
case 4:
case 6:
case 0xe:
Serial.printf("\nFat Type: Fat16\n");
if (!getFat16VolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
break;
case 7:
Serial.printf("\nFat Type: ExFat\n");
if (!getExFatVolumeLabel(msDrive, i))
Serial.printf("Failed to get volume label\n");
break;
default:
Serial.println("No or Not Supported Partition");
}
}
}
[B] cmsReport=-1;
[/B] //--------------------------------------------------
Serial.printf("\nInitialize SD card...");
if (!sd.begin(SD_CONFIG)) {
Serial.println("initialization failed.\n");
} else {
Serial.println("SD card is present.\n");
}
if (sd.fatType() == 32) {
Serial.printf("Fat Type: Fat32\n");
if (!getFat32VolumeLabel(sdDrive, 1))
Serial.printf("Failed to get volume label\n");
} else {
Serial.printf("Fat Type: ExFAT\n");
if (!getExFatVolumeLabel(sdDrive, 1)) {
Serial.printf("Failed to get volume label\n");
}
}
//sd.ls(LS_SIZE | LS_DATE | LS_R);
Serial.println("done...");
Serial.println("Press any key to run again");
while (Serial.read() == -1);
while (Serial.read() != -1);
}
void print_hexbytes(const void *ptr, int len)
{
if (ptr == NULL || len <= 0) return;
const uint8_t *p = (const uint8_t *)ptr;
while (len) {
for (uint8_t i = 0; i < 32; i++) {
if (i > len) break;
Serial.printf("%02X ", p[i]);
}
Serial.print(":");
for (uint8_t i = 0; i < 32; i++) {
if (i > len) break;
Serial.printf("%c", ((p[i] >= ' ') && (p[i] <= '~')) ? p[i] : '.');
}
Serial.println();
p += 32;
len -= 32;
}
}
USBHS_USBCMD = USBHS_USBCMD_ITC(1) | USBHS_USBCMD_RS |
^Waiting up to 5 seconds for USB drive
^^Initialize USB drive...^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Waiting up to 5 seconds for USB drive
^^Initialize USB drive...^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Waiting up to 5 seconds for USB drive
^^^^^^^^^^^^^
Initialize SD card...initialization failed.
Fat Type: ExFAT
Failed to get volume label
done...
Press any key to run again
Initialize USB drive...^^^^^^^^^USB drive 1 is present.
msc1 Partition Table
Waiting up to 5 seconds for USB drive
^^^^^^^^^^^^^Initialize USB drive...USB drive 1 is present.
msc1 Partition Table
part,boot,bgnCHS[3],type,endCHS[3],start,length
FAT32: 1,80,0x20,0x21,0x0,0xC,0xFE,0xFF,0xFF,2048,67108864
FAT32: 2,0,0xFE,0xFF,0xFF,0xC,0xFE,0xFF,0xFF,67110912,54128640
3,0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0,0