# Cannot understand the FAT application

**URL:** <https://forums.freertos.org/t/cannot-understand-the-fat-application/14679>\
**Category:** Libraries\
**Created:** [March 17, 2022, 7:10pm UTC](https://forums.freertos.org/t/cannot-understand-the-fat-application/14679 "2022-03-17T19:10:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter1](https://avatars.discourse-cdn.com/v4/letter/p/a587f6/32.png) [@peter1](https://forums.freertos.org/u/peter1)\
**Post date:** [March 17, 2022, 7:10pm UTC](https://forums.freertos.org/t/cannot-understand-the-fat-application/14679/1 "2022-03-17T19:10:57Z")

</div>

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:

```auto
    F_DRIVERINIT()
    F_GETPHY()
    F_READSECTOR()
    F_WRITESECTOR()
    F_GETSTATUS()
    F_RELEASE() 

```

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [March 17, 2022, 11:57pm UTC](https://forums.freertos.org/t/cannot-understand-the-fat-application/14679/2 "2022-03-17T23:57:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [March 18, 2022, 7:54am UTC](https://forums.freertos.org/t/cannot-understand-the-fat-application/14679/3 "2022-03-18T07:54:26Z")

</div>

The functions and macros that you show do not belong to [FreeRTOS+FAT](https://github.com/FreeRTOS/Lab-Project-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](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_FAT/index.html).

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [March 18, 2022, 2:39pm UTC](https://forums.freertos.org/t/cannot-understand-the-fat-application/14679/4 "2022-03-18T14:39:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![loszi](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/loszi/32/2367_2.png) [@loszi](https://forums.freertos.org/u/loszi)\
**Post date:** [March 21, 2022, 7:41am UTC](https://forums.freertos.org/t/cannot-understand-the-fat-application/14679/5 "2022-03-21T07:41:02Z")

</div>

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?

Szilárd

---

<div class="post-metadata">

**Author:** ![peter1](https://avatars.discourse-cdn.com/v4/letter/p/a587f6/32.png) [@peter1](https://forums.freertos.org/u/peter1)\
**Post date:** [March 21, 2022, 10:20am UTC](https://forums.freertos.org/t/cannot-understand-the-fat-application/14679/6 "2022-03-21T10:20:04Z")

</div>

I’m planning to store configuration.

---

<div class="post-metadata">

**Author:** ![loszi](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/loszi/32/2367_2.png) [@loszi](https://forums.freertos.org/u/loszi)\
**Post date:** [March 22, 2022, 5:47am UTC](https://forums.freertos.org/t/cannot-understand-the-fat-application/14679/7 "2022-03-22T05:47:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![peter1](https://avatars.discourse-cdn.com/v4/letter/p/a587f6/32.png) [@peter1](https://forums.freertos.org/u/peter1)\
**Post date:** [April 21, 2022, 12:01pm UTC](https://forums.freertos.org/t/cannot-understand-the-fat-application/14679/8 "2022-04-21T12:01:11Z")

</div>

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:

```auto
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](https://iotexpert.com/tag/freertos-fat-sl/)

---

<div class="post-metadata">

**Author:** ![aggarg](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/aggarg/32/4245_2.png) [@aggarg](https://forums.freertos.org/u/aggarg)\
**Post date:** [April 21, 2022, 3:39pm UTC](https://forums.freertos.org/t/cannot-understand-the-fat-application/14679/9 "2022-04-21T15:39:39Z")

</div>

Thank you for taking time to report back.
