Nucleo L432KC SDBlockDevice errors

Hi all,

I’m trying to use SDBlockDevice.h to create a class for my SD card, however including that header incurs errors regarding undeclared arduino pin aliases that are in fact declared. I’ve got SD in my target overrides section in mbed_app.json and including this header file works fine on my F429ZI.
Errors

Hello,

these errors really occur and it is right behavior because system/ current setting do not count there exist something else than Arduino Uno header standart, let’s look on that.

There is declaration of SDBlockDevice constructor, it defines default parameters (macros) MBED_CONF_SD_SPI_XX for the constructor. These macros are generated by build system before compilation and macros are fiilled to mbed_config.h (you can found it in build folder) file which is full of settings like this one.
But what are values of these macros? The file mbed_lib.json says these macros are equal to ARDUINO_UNO_SPI_XX. That if defined here and says ARDUINO_UNO_SPI_XX are equal to ARDUINO_UNO_DX which are pin alisase for pin masks according to Arduino UNO header standart. Definition of these are defined in PinNames.h of specific target, but only when the target is fit with that standard. It is marked like Arduino UNO Form Factor.
So because L432KC is not Arduino Uno FF and because of that it does not have Arduino Uno pin aliases, macros are empty = not defined.

That is the reason why the Nucleo-F429ZI (Arduino UNO header standard) is OK and Nucleo-L432KC (Arduino Nano header standard) not.

The configuration system - Program setup | Mbed OS 6 Documentation
Standard Pin Names - Porting | Mbed OS 6 Documentation

That was description of why, and now how to deal with that.
Into your mbed_app.json just add pin seting for for SD card, that will override default settings descripted above

{
    "target_overrides": {
        "NUCLEO_L432KC": {
            "sd.SPI_MOSI": "PA_7",
            "sd.SPI_MISO": "PA_6",
            "sd.SPI_CLK":  "PA_5",
            "sd.SPI_CS":   "PA_4",
            "target.components_add": ["SD"]
        }
    }
}

Then you can call also the constructor without pins because they are already defined via mbed_app.json above.

//SDBlockDevice sd(PA_7,PA_6,PA_5,PA_4);
//SDBlockDevice sd(A6,A5,A4,A3);
SDBlockDevice sd;

BR, Jan

Thanks for the response.

I tried amending mbed_app.json as you showed and while this compiled successfully, I now have 38 linker errors pointing to files not located within my active program, but the mbed studio installation folders. Not sure if this is related.

Ok, that will be because of this settings.
Change it one more time and add one more line fot that, like below

{
    "target_overrides": {
        "NUCLEO_L432KC": {
            "sd.SPI_MOSI": "PA_7",
            "sd.SPI_MISO": "PA_6",
            "sd.SPI_CLK":  "PA_5",
            "sd.SPI_CS":   "PA_4",
            "target.components_add": ["SD"],
            "target.c_lib": "std"
        }
    }
}

BR, Jan