9 months ago.

Error: Variable type 'SDBlockDevice' is an abstract class

I teach a class using the Freedom KL46Z boards. I have sample code for accessing the SD card via an Adafruit Datalogging shield. This code has worked fine in the past and I used it as recently as August 2019 with the summer class. I was preparing for this week's lecture and double-checking the sample code. As of today, the code will not compile. I get the following message:

Error: Variable type 'SDBlockDevice' is an abstract class

The line of code prompting this is as follows:

SDBlockDevice sd_block_dev(PTD6,PTD7,PTD5,PTD4);

I also tried with the "Arduino-like" pin names as below but it created the same error message.

SDBlockDevice sd_block_dev(D11,D12,D13,D10);

Any thoughts? Thanks.

Forgot to mention. All libraries have been updated to the most current version as of today.

posted by William Stapleton 06 Oct 2019

1 Answer

9 months ago.

Hello William,

The Freedom KL46Z board is normally not equipped with an SD card slot. That's why for the the KL46Z target (and it's predecessor "Target") there is no such entry as "components_add": ["SD"] in the mbed-os/targets/targets.json configuration file (as you can check also below) :


    "KL46Z": {
        "supported_form_factors": ["ARDUINO"],
        "core": "Cortex-M0+",
        "extra_labels": ["Freescale", "KLXX", "FLASH_CMSIS_ALGO"],
        "is_disk_virtual": true,
        "supported_toolchains": ["GCC_ARM", "ARM", "IAR"],
        "inherits": ["Target"],
        "detect_code": ["0220"],
        "device_has": [
        "release_versions": ["2", "5"],
        "device_name": "MKL46Z256xxx4",
        "bootloader_supported": true

If you connect an external SD card, like Adafruit Datalogging shield, then to should tell Mbed about that by adding an mbed_app.json cofiguration file with the following content to the project:


    "target_overrides": {
        "KL46Z": {
            "target.components_add": ["SD"]

That will instruct Mbed to include the code associated with SD card to the project.

Thank you. I'll try this. I have not had to deal with the json file type before so I guess i have some homework to do.

Out of curiosity, why is this step necessary now when it was not necessary in the past? Similarly, where should I have found this new step documented?

posted by William Stapleton 06 Oct 2019

The Mbed project started with only one board - The LPC1768 called "the mbed board". Then more a more boards got support and project configuration became essential. I don't remember when it happened exactly but I think json files are used for more than a year. Mbed projects are quite bulky so configuration files also help reduce the amount of code to be compiled by including only the parts required for the given project.

The structure of an Mbed OS project is documented here.

posted by Zoltan Hudak 07 Oct 2019

I added the json file as shown above and now I get the following error compiling for the Freedom KL46Z:

Error: Library name 'sd' is not unique (defined in '/tmp/chroots/ch-9abc7706-21de-4177-84cc-906044ec2125/extras/mbed-os.lib/components/storage/blockdevice/COMPONENT_SD/mbed_lib.json' and '/tmp/chroots/ch-9abc7706-21de-4177-84cc-906044ec2125/src/sd-driver/config/mbed_lib.json')

For whatever it is worth, I get the same error message when I switch to the Freedom K66F, which does have the built-in SD Card and, one would think, should have native SD Card support.

Removing the json file, updating all libraries, and trying again repeats the same error message for the K66F.

Switching back to the KL46Z and trying again to compile without the json file gives a new error message:

Info: 'stdalign.h' file not found in "extras/mbed-os.lib/features/frameworks/nanostack-libservice/mbed-client-libservice/ns_types.h", Line: 124, Col: 10

Requesting an update for mbed-os library one more time and recompiling on the KL46Z gives yet another error message:

Error: Function-like macro 'MBED_ENCODE_VERSION' is not defined in "spif-driver/SPIFBlockDevice.cpp", Line: 28, Col: 80

Considering that this last is not even a library that I am using, I am wondering if the compiler is having issues.

posted by William Stapleton 17 Oct 2019

It seems there are two SD libraries in your project. Because recent versions of Mbed OS 5 have the SD card driver integrated into the system (It's located in the /mbed-os/components/storage/blockdevice/COMPONENT_SD folder) you should remove the external SD card library from your project (delete the sd-driver folder from your project).

posted by Zoltan Hudak 17 Oct 2019

OK. I had this working. Today, when I tried making a minor adjustment to the program and recompiling , I got the following: Error: Unknown type name 'SDBlockDevice'; did you mean 'BlockDevice'? in "EE3420_configure.h", Line: 344, Col: 1 The line of code was: SDBlockDevice sd_block_dev(PTD6,PTD7,PTD5,PTD4);

Any ideas?

posted by William Stapleton 16 Nov 2019