5 years, 10 months ago.

Is it true that handling of SD cards is not implemented in the current MBED on-line Compiler?

Dear Developers,

I'm stucked in the middle of a development process. The next module test should be about SD-Card data logging, which is an "easy-as-1-2-3" process in Arduino platform. What I've tried are all available library + sample ("HelloWorld") code combinations back since 2011 (with more than 10 imports). For most, I've got the same response from the compiler:

Warning: Overloaded function "mbed::FileSystemHandle::open"  is hidden by "FATFileSystem::open"  -- virtual function override intended? in "SDFileSystemDMA/FATFileSystem/FATFileSystem.h", Line: 48, Col: 26
Error: Object of abstract class type "FATFileHandle" is not allowed in "SDFileSystemDMA/FATFileSystem/FATFileSystem.cpp", Line: 106, Col: 17

I've tried virtually traveling back in time with former mbed versions too for those libraries which have a huge footprint of work (many imports). No luck (same issue everywhere). I've tried different platforms (Nucleo F401, L011, mbed L1768), same problem everytime.

I would be very pleased to have any guidance to a working solution.

Thanks in advance!

Tamás

2 Answers

5 years, 4 months ago.

Zoltan,

I'm having the same problem, and am using the online compiler. I just imported your SD Card Example Program from above, and without making any changes still get Error: Cannot open source input file "SDBlockDevice.h": No such file or directory in "main.cpp", Line: 23, Col: 28

This shouldn't be this hard - I've read all your web pages documenting SD behavior regarding 5.10 changes and it's extremely confusing.

...Tom Kreyche

Accepted Answer

-

posted by Zoltan Hudak 17 Jul 2019

Hello Tom,

I fully agree. The related documentation should explain that for some target boards an mbed_app.json file with the content as below shall be added to the project. I have recompiled the example SD card program with the latest Mbed OS 5.13.0 and then tested on my LPC1768. Hopefully it will work also for you.

NOTE: To figure out whether a particular Mbed board already supports SD cards check the https://github.com/ARMmbed/mbed-os/tree/master/targets/targets.json file. If for the given target board you read something like components_add": ["SD", (...)] then it already supports SD cards. Otherwise you have to include such support using an mbed_app.json file.

posted by Zoltan Hudak 17 Jul 2019
5 years, 10 months ago.

Hello, Tamas

SD support is now implemented as component. In order to use it in your program add an mbed_app.json file with the following content to your project:

mbed_app.json

{
    "target_overrides": {
        "LPC1768": {
            "target.components_add": ["SD"]
        }
    }
}

NOTE: Substitute LPC1768 with the actual name of your mbed board.

The example code at https://os.mbed.com/docs/v5.10/apis/fatfilesystem.html worked fine for me with SD cards after modifying the start section as below :

main.cpp

#include "mbed.h"
#include <stdio.h>
#include <errno.h>

// 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
//SPIFBlockDevice bd(
//        MBED_CONF_SPIF_DRIVER_SPI_MOSI,
//        MBED_CONF_SPIF_DRIVER_SPI_MISO,
//        MBED_CONF_SPIF_DRIVER_SPI_CLK,
//        MBED_CONF_SPIF_DRIVER_SPI_CS);

SDBlockDevice bd(p5, p6, p7, p8);

// File system declaration
//LittleFileSystem fs("fs");
FATFileSystem fs("fs");


// Set up the button to trigger an erase
//InterruptIn irq(BUTTON1);
InterruptIn irq(p9);

void erase() {

...

Hi, I'm also having trouble using an SD card with mbed. I tried using the mbed-os-example-filesystem as recommended, I've changed the json to the one above (I'm also using an LPC1768) and basically copy-pasted your code above to replace the start of the example, however it's not compiling - I get an error of "Expression must have pointer type "int err = bd->init();"" Can you suggest why this might be happening ?

posted by Frances Conboy 06 Feb 2019

I'm sorry for all the troubbles but it seems that in contrary to the example code

int err = bd.init();

you have most likely

int err = bd->init();

in the tested code.

To avoid additional frustration I have published a fork of the mbed example program which worked fine for me on an LPC1768 board with Mbed OS-5.11.3. To make sure you are going to compile the same thing

  • Close your online compiler page in case there is one opened
  • Then click on the orange button [Import into Compiler] located in the top-right corner on the SD Card example program repository page.

I hope that will help. Best regards, Zoltan.

posted by Zoltan Hudak 06 Feb 2019

Thanks, Zoltán,

Now I'm back for development after some time. I really appreciate your attempt to help solving my issue. Which is still not solved yet. I've included all your forked repositry into a new project. One file (SDBlockDevice.h) was missing, I found and also included this version: https://os.mbed.com/users/JackB/code/SDBlockDevice/ , and later (after deleting the first), this version: https://os.mbed.com/users/Swabey89/code/SDBlockDevice2/. Neither worked. I get the following error code from the on-line compiler: Error: Object of abstract class type "SDBlockDevice" is not allowed "SDBlockDevice blockDevice(PC_3, PC_2, PB_10, PB_9); mosi, miso, sck, cs" That's the point I'm stucked in again. Köszi, Tamás

posted by Tamas Szekffy 16 Feb 2019

Hello Tamás, SD card support is now intergrated into the Mbed OS 5 library. But to make it work you have to activate it by adding an mbed_app.json file to your project rather than to import an additional user library. My suggestion is:

  • Import the SD card example program into your online compiler.
  • Open the mbed_app.json file and substitute LPC1768 with your target board name (for example NUCLEO_F401RE)
  • In the main.cpp replace

SDBlockDevice   blockDevice(p5, p6, p7, p8);  // mosi, miso, sck, cs

with

SDBlockDevice   blockDevice(PC_3, PC_2, PB_10, PB_9);  // mosi, miso, sck, cs
  • Select the target board for the online compiler in the top-right corner (for example NUCLEO-F401RE)

NOTE: The erase function does not seem to work properly because the implementation for the SDBlockDevice is missing.

posted by Zoltan Hudak 18 Feb 2019

Dear Zoltán,

After many unsuccessful attempts, this weekend finally bought the solution. With your help. I really appreciate all your efforts to make this possible.

(Jövök egy sörrel, vagy mi...)

Yours sincerely,

Tamás

posted by Tamas Szekffy 07 Apr 2019