Cannot understand the FAT application

I want to create a file system on the MPC5748G internal Flash, and I was planning to use the FreeRTOS implementation of FAT. Ideally, I would like to designate an area in the flash to create space for the files (for example 8 blocks of 256 KB from 0x01000000 to 0x011FFFFF). I have dozen of SDK functions for flash usage, like initializing, writing, erasing checking, etc. I want to use them in the filesystem.

I’m struggling with understanding the provided ‘FreeRTOS Plus FAT SL with CLI’ example. As far as I understand the following functions need to be implemented to use the fat library:


however, I can’t figure out how to implement them - what should these functions do?

I downloaded the FreeRTOS 9.0.0 example and quickly got confused. In the example the function F_DRIVERINIT is defined in \api\api_mdriver.h on line 96 as

typedef F_DRIVER *( *F_DRIVERINIT )( unsigned long driver_param );

and I just don’t get it what it means…

To my understanding, this is a declaration of a type F_DRIVERINIT that essentially is a pointer to function pointer that takes ‘driver_param’ and returns F_DRIVER as a result. However this pointer to a function pointer is never assigned to anything later on - it doesn’t point to anything. Even more - the ‘driver_param’ also never is assigned to any value…

I’m really lost.

How to implement the FreeRTOS FAT for any memory of choice?

It might be that the example is using a RAM disk that doesn’t require any initialization so the init function is never called.

The functions and macros that you show do not belong to FreeRTOS+FAT.
I know of several projects that use FreeRTOS+FAT in combination with a flash.
I suppose that you know about wearing, especially when the FAT changes frequently.
SD-cards don’t have this problem so much.

So if you decide to use FreeRTOS+FAT, you can ask questions in this post.

Please find +FAT documentation here.

The question is about the FAT SL library from an old version of FreeRTOS.

Hi Peter,
could you please explain what you want to use the spi flash drive for?
I mean what going to be a the typical use like storing the configuration, or rather continiously changing temporary files?


I’m planning to store configuration.

Are you planning to use kind a freetext, expandable configuration, like ini format?

So, I figured it out.
Generally speaking, the FAT SL Library uses the concept of ‘sectors’ to read and write data. These are 512 bytes big, which means that I had to implement a few functions, and the most important ones are the read and write of 512 bytes to memory. Every next ‘sector’ is located 512 bytes away in the memory from the previous.

In my case I defined a pointer to a base address (starting address of flash memory block), and whenever I called a write function I set the pointer to base plus sector number multipled by the sector siez (512). Shortly speaking it looks like this:

dest_addr = BASE_ADDR + (sector_number * 512);
FLASH_write(dest_addr, source_data, size);

Apart from that, there are a few other functions necessary to implement, as well as F_DRIVER struct. the FAT SL has to be initialized, what means that a F_DRIVER has to point to the implementation of all these functions.

Generally some tips may be found here: FreeRTOS FAT SL – IoT Expert

Thank you for taking time to report back.