Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 2 months ago.
SD Card File System example broken with current MBED library - MBED OS2
Steps to repro:
1. Import the SD Card File System "Hello World" Program below(I use LPC1768 platform):
https://os.mbed.com/cookbook/SD-Card-File-System
2. This compiles successfully!
3. Right-Click the mbed library in the project and select Update.
4. No longer compiles. I get the following error:
Error: Object of abstract class type "FATFileHandle" is not allowed in "SDFileSystem/FATFileSystem/FATFileSystem.cpp", Line: 100, Col: 17
Looks like the example comes with an older version of the MBED library. Don't know when or which update broke it. I'd like to avoid MBED OS5.x for the moment as I'm writing some low overhead sharable libraries before I explore development on an RTOS.
Any help would be appreciated. I tried some of the other SDFileSystem "branches" and FATFileSystem branches as well with no luck.
Thanks in advance!
2 Answers
6 years, 2 months ago.
Hello Douglas,
Since mbed development is focusing mainly on MBED OS-5, I thought it would be nice to utilise the new FATFileSystem also for the MBED OS-2.
The following worked for me on an LPC1768 board using the online compiler and I hope it could be useful also for other users as well:
- Download the MBED OS-5 library as ZIP file from https://github.com/ARMmbed/mbed-os to your PC's local hard drive and unzip.
- Open the
features
folder and ZIP thefilesystem
folder into a (for examplefilesystem.zip
) file. - Download the MBED OS-5 SD-Driver as ZIP file from https://github.com/ARMmbed/sd-driver to your PC's local hard drive (don't unzip).
- Create a new MBED OS-2 project.
- Import the
filesystem
andsd-driver-master
libraries into the new project as follows:- In
Program Workspace
right-click on the project name and selectImport library...
->From Import Wizard...
- Proceed to the
Upload
tab and, in the right-bottom corner, click on theBrowse...
button. - Navigate to the MBED OS-5
features
folder on your hard drive and select thefilesystem.zip
file you have created. - To complete the import, click on the
Import!
button in the top-right corner . - Repeat the same for the
sd-driver-master.zip
file you have downloaded.
- In
- In your browser navigate to https://os.mbed.com/docs/v5.9/reference/fatfilesystem.html and search for the
FATFileSystem example
main.cpp
code. - Replace the
main.cpp
code in your project with theFATFileSystem example
. - Modify your
main.cpp
as below:
... // Block devices //#include "SPIFBlockDevice.h" //#include "DataFlashBlockDevice.h" #include "SDBlockDevice.h" #include "HeapBlockDevice.h" // File systems #include "LittleFileSystem.h" #include "FATFileSystem.h" // Physical block device, can be any device that supports the BlockDevice API SDBlockDevice bd( p5, p6, p7, p8); // mosi, miso, sck, cs // File system declaration FATFileSystem fs("fs"); // Set up the button to trigger an erase InterruptIn irq(p9); void erase() { printf("Initializing the block device... "); fflush(stdout); int err = bd.init(); printf("%s\n", (err ? "Fail :(" : "OK")); if (err) { error("error: %s (%d)\n", strerror(-err), err); } printf("Erasing the block device... "); fflush(stdout); err = bd.erase(0, bd.size()); printf("%s\n", (err ? "Fail :(" : "OK")); if (err) { error("error: %s (%d)\n", strerror(-err), err); } printf("Deinitializing the block device... "); fflush(stdout); err = bd.deinit(); printf("%s\n", (err ? "Fail :(" : "OK")); if (err) { error("error: %s (%d)\n", strerror(-err), err); } } // Entry point for the example int main() { printf("--- Mbed OS filesystem example ---\n"); // Setup the erase event on button press, use the event queue // to avoid running in interrupt context //irq.fall(mbed_event_queue()->event(erase)); // Try to mount the filesystem printf("Mounting the filesystem... "); ...
- Connect an SD card to your mbed board as defined in
main.cpp
:
SDBlockDevice bd( p5, p6, p7, p8); // mosi, miso, sck, cs
- Compile the project and download the binary to the board.
- After pressing and releasing the
Reset
button you should see on the serial monitor something as below:
--- Mbed OS filesystem example --- Mounting the filesystem... OK Opening "/fs/numbers.txt"... OK Incrementing numbers (0/10)... Incrementing numbers (1/10)... Incrementing numbers (2/10)... Incrementing numbers (3/10)... Incrementing numbers (4/10)... Incrementing numbers (5/10)... Incrementing numbers (6/10)... Incrementing numbers (7/10)... Incrementing numbers (8/10)... Incrementing numbers (9/10)... Incrementing numbers (10/10)... OK Closing "/fs/numbers.txt"... OK Opening the root directory... OK root directory: numbers.txt Closing the root directory... OK Opening "/fs/numbers.txt"... OK numbers: 4 2 3 4 5 6 7 8 9 10 ÿ Closing "/fs/numbers.txt"... OK Unmounting... OK Mbed OS filesystem example done!
Unfortunately, this would not be a great solution for me. I'm developing an evaluation platform and to require the end user to perform this kind of "code surgery" would make the platform less viable off the shelf. Also, I've implemented a multi-slave SPI bus, so even with the current system, I needed to change all of the SPI access routines in the SDCard library to be compatible. It appears that MBED OS5 buries the SPI access for block devices further down in it's own library, which would make it much more difficult to thread into my multi-slave architecture...
I'm currently diff-ing the libraries to see If I can figure out a fix to make FatFileSystem work with the latest MBED OS2, but any help would be appreciated. It seems like the SDCard file system example first got broken in release 138 and I'd hate to have to constrain my user base to v137. Also, I need to figure out how to get the FF-LPC546XX compiles working in MBED OS2, and that support didn't exist at all in v137.
posted by 04 Oct 20186 years, 2 months ago.
I am using the best system and mobile phone and In this, we use the SD card file system broken with the mbed file. which is really helpful for us. And In this mobile, I can access the Gmail and stored some data in SD card. if I have any issue with Gmail then go the website https://googlesupport.co/gmail-support-uk/" which provides the best solution which is really helpful for us. it is really helpful for us.
Here's a new twist: When using mbed revisions 138 through 144, the compile sometimes completes without error. However, the binary file is about 9K "Lighter" (29K vs 38K) and the SD filesystem code reports that it cannot open the file for writing. Revisions 145 and above seem to report the error above on the first compile. Sometimes I get a different error on the second compile. Is this all basically because of all of the "Depricated" references I see in the diff between revision 137, which both compiles AND works successfully, and revision 138? It seems like for MBED OS2 alot of stuff was depricated, but not replaced with anything usable. Is that the case?
posted by Douglas S 04 Oct 2018OK, Here's what I'm piecing together: FatFIleHandle is an extension of the parent class FileHandle. Starting in MBED OS2 Rev138, the constructor function of FileHandle was depricated. FatFileSystem creates an object of FatFileHandle using "new". Since the parent class has depricated the constructor(which, by the way, does nothing {}), the compile breaks? Does this sound correct? Seems like there is a simple fix to FatFileSystem that could correct this, but I'm not smart enough to figure it out? Of course, this may just be the first layer of the onion. I may try some offline ARM GCC compiles to see if I can figure this out, but any help would be greatly appreciated. Surely, someone out there in MBED OS2 land is using FatFileSystem, whether for SDCard or something else, right?
posted by Douglas S 04 Oct 2018