6 years, 4 months ago.

Need help with Block Device class and FAT File System

I'm working on the DISCO F746NG, and although there is SD-card functionality in the HAL (BSP_DISCO_F746NG) it isn't compatible with the mbed-os block device class.

Because of this, I took the HeapBlockDevice class as a startingpoint and tried to make a new block device class for this board.

https://os.mbed.com/users/Lightsource/code/BD_DISCO_F746NG/

I have verified that read and write works for singlel blocks at least. But with FATFileSystem the following happens. Mounting file system returns no errors.

- format returns error -5, and after that I also get hardware error when trying to read directly from the block device class method.

- Reading and writing files generates no errors, but it doesn't write any file nore can it read content, and it cannot display present file names.

I'm kind of stuck, not knowing how to get forward with this, so would really appreciate if someone who is really into the inner workings of these things could spot if there is something obvious I've done wrong.

A note, the BSP_DISCO_F746NG returns an odd block size, 1024. Which from what I know is never used. (asked a file system expert). It returns a corresponding block number that is correct for that size. If I use the value returned from the BSP, I cannot mount the file system. However, if I hard code 512 bytes block size, it mounts. But still I'm not getting any further.

Thanks!

1 Answer

6 years, 4 months ago.

Your block device is looking good!

Quote:

format returns error -5

Does it return zero on success? If the block device returns an error, the file system will raise an error and refuse to continue.

What happens if init is called twice? You may need to add some logic to protect against this like so:

int BD_DISCO_F746NG::init()
{
    if (_init_count > 0) {
        return BD_ERROR_OK;
    }
    _init_count++;
    
    blablabla
}
 
int BD_DISCO_F746NG::deinit()
{
    if (_init_count == 0) {
        return BD_ERROR_OK;
    }
    _init_count--;
    
    blablabla
}

Quote:

A note, the BSP_DISCO_F746NG returns an odd block size, 1024

That won't be a problem. The embedded storage space is full of many odd block sizes. At least it's a power of two!