From 21effa19610acea9198106e0aaa0b0d0ee34a83a Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 18 Sep 2023 15:56:42 +0200 Subject: [PATCH 1/2] UsbMsd: MSD_QSPI example, mount both QSPI partitions --- .../UsbMsd/examples/MSD_QSPI/MSD_QSPI.ino | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/libraries/UsbMsd/examples/MSD_QSPI/MSD_QSPI.ino b/libraries/UsbMsd/examples/MSD_QSPI/MSD_QSPI.ino index bd2f5b38c..c26451567 100644 --- a/libraries/UsbMsd/examples/MSD_QSPI/MSD_QSPI.ino +++ b/libraries/UsbMsd/examples/MSD_QSPI/MSD_QSPI.ino @@ -14,22 +14,16 @@ This example code is in the public domain. */ -/* - * CONFIGURATION DEFINES - */ - -/* the name of the filesystem */ -#define TEST_FS_NAME "qspi" - -#include "QSPIFlashBlockDevice.h" +#include "BlockDevice.h" +#include "MBRBlockDevice.h" #include "UsbMsd.h" #include "FATFileSystem.h" BlockDevice* root = BlockDevice::get_default_instance(); -USBMSD msd(root); -FATFileSystem fs(TEST_FS_NAME); - -std::string root_folder = std::string("/") + std::string(TEST_FS_NAME); +MBRBlockDevice sys_bd(root, 1); +MBRBlockDevice user_bd(root, 2); +FATFileSystem sys_fs("sys"); +FATFileSystem user_fs("user"); /* -------------------------------------------------------------------------- */ void printDirectoryContent(const char* name) { @@ -64,33 +58,38 @@ void printDirectoryContent(const char* name) { /* SETUP */ /* -------------------------------------------------------------------------- */ void setup() { - + /* SERIAL INITIALIZATION */ Serial.begin(9600); - while(!Serial) { - + while(!Serial) { } Serial.println("*** USB Mass Storage DEVICE on QSPI Flash ***"); - - + /* Mount the partition */ - int err = fs.mount(root); + int err = sys_fs.mount(&sys_bd); if (err) { - Serial.println("Unable to mount filesystem"); + Serial.println("Unable to mount system filesystem"); while(1) { - } - } + } + + /* Mount the partition */ + err = user_fs.mount(&user_bd); + if (err) { + Serial.println("Unable to mount user filesystem"); + while(1) { + } + } } /* -------------------------------------------------------------------------- */ /* LOOP */ /* -------------------------------------------------------------------------- */ void loop() { - Serial.print("Content of the folder "); - Serial.print(root_folder.c_str()); - Serial.println(":"); - printDirectoryContent(root_folder.c_str()); + Serial.println("Content of the system partition:"); + printDirectoryContent("/sys"); + Serial.println("Content of the user partition:"); + printDirectoryContent("/user"); delay(2000); } From 42e975ae53b34307678ed26451a959f7c060a1c5 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 18 Sep 2023 17:09:57 +0200 Subject: [PATCH 2/2] UsbMsd: MSD_QSPI example, handle LittleFS user partition --- libraries/UsbMsd/examples/MSD_QSPI/MSD_QSPI.ino | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libraries/UsbMsd/examples/MSD_QSPI/MSD_QSPI.ino b/libraries/UsbMsd/examples/MSD_QSPI/MSD_QSPI.ino index c26451567..877c072da 100644 --- a/libraries/UsbMsd/examples/MSD_QSPI/MSD_QSPI.ino +++ b/libraries/UsbMsd/examples/MSD_QSPI/MSD_QSPI.ino @@ -25,6 +25,8 @@ MBRBlockDevice user_bd(root, 2); FATFileSystem sys_fs("sys"); FATFileSystem user_fs("user"); +int err = 0; + /* -------------------------------------------------------------------------- */ void printDirectoryContent(const char* name) { /* -------------------------------------------------------------------------- */ @@ -67,7 +69,7 @@ void setup() { Serial.println("*** USB Mass Storage DEVICE on QSPI Flash ***"); /* Mount the partition */ - int err = sys_fs.mount(&sys_bd); + err = sys_fs.mount(&sys_bd); if (err) { Serial.println("Unable to mount system filesystem"); while(1) { @@ -77,9 +79,8 @@ void setup() { /* Mount the partition */ err = user_fs.mount(&user_bd); if (err) { - Serial.println("Unable to mount user filesystem"); - while(1) { - } + Serial.println("Unable to mount user filesystem. Only FatFS is supported"); + /* Probably the user is using LittleFs. Go on and show only system fs */ } } @@ -89,7 +90,9 @@ void setup() { void loop() { Serial.println("Content of the system partition:"); printDirectoryContent("/sys"); - Serial.println("Content of the user partition:"); - printDirectoryContent("/user"); + if(!err) { + Serial.println("Content of the user partition:"); + printDirectoryContent("/user"); + } delay(2000); }