Issue trying to mount FATFileSystem on SDBlockDevice (err -12)

Hi,

I’m trying to mount FAT on a SDBlockDevice but keep getting -12 (Not enough space) no matter what I try. Manually initializing the device and reading some of the properties works as expected, but when I try to mount I get the error.

The board I’m using is a FRDM-KL25Z and the SD card adapter is HW-125, bought pretty cheaply from one of the Chinese marketplaces (can’t remember which one now). I have a whole bag of these adapters, this seems to be the behaviour with all the ones I tested.

LittleFS crashes with a Hard Fault when I try to reformat, when I trace the error it points to some malloc operation.

Crash Info:
    Crash location = _free_r [0x000083CC] (based on PC value)
    Caller location = __rtos_malloc_lock [0x00005AEB] (based on LR value)
    Stack Pointer at the time of crash = [20001748]
    Target and Fault Info:
            Processor Arch: ARM-V6M
            Processor Variant: C60

I also tried different SD cards with the same result

Here’s the code I’m trying

#include “mbed.h”

#include “SDBlockDevice.h”

SDBlockDevice sd(PTD2, PTD3, PTD1, PTC6); // mosi, miso, sck, cs

#include “FATFileSystem.h”
FATFileSystem fs(“fs”);

// #include “LittleFileSystem.h”
// LittleFileSystem fs(“fs”);

int main()
{
// the commented out part is working as expected
// if (0 != sd.init())
// {
// printf(“Init failed \n”);
// return -1;
// }
// printf(“sd size: %llu\n”, sd.size());
// printf(“sd read size: %llu\n”, sd.get_read_size());
// printf(“sd program size: %llu\n”, sd.get_program_size());
// printf(“sd erase size: %llu\n”, sd.get_erase_size());

// sd.deinit();

int error = 0;

error = fs.mount(&sd);
if (error)
{
    printf("%s\n", strerror(-error));

    error = fs.reformat(&sd);
    if (error)
    {
        printf("%s\n", strerror(-error));
    }
}

}

Thank you all in advance