FatFS Wrapper

This forum is about you. Feel free to discuss anything is related to embedded and electronics, your awesome projects, your ideas, your announcements, not necessarily related to ChibiOS but to embedded in general. This forum is NOT for support.
mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Location: Karlsruhe, Germany
Been thanked: 1 time
Contact:

FatFS Wrapper

Postby mabl » Sun Jun 10, 2012 12:34 pm

Hello all,

I guess some of you have already run into the huge memory consumption of FatFS, especially when used from different threads. So I've set out and wrote a wrapper using a worker thread. The result can be found here:

https://github.com/mabl/ChibiosFatFSWorkerWrapper

Feedback is always welcome :-)

User avatar
Giovanni
Site Admin
Posts: 13086
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 759 times
Been thanked: 637 times
Contact:

Re: FatFS Wrapper

Postby Giovanni » Sun Jun 10, 2012 12:40 pm

It is a good idea and looks very good.

I have been thinking for a while to create a file system abstract interface, there are already abstract files, it could be used as implementation.

Giovanni

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: FatFS Wrapper

Postby Tectu » Sun Jun 10, 2012 1:54 pm

This looks nice, but could you also upload some example code to show how to use it?


~ Tectu

mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Location: Karlsruhe, Germany
Been thanked: 1 time
Contact:

Re: FatFS Wrapper

Postby mabl » Mon Jun 11, 2012 9:08 am

Hi Tectu,

it should be straight forward to use the wrapper. Just
  • Include the wrapper source directory and add fatfsWrapper.c to the C files
  • Call wf_init() before you do any work wit fatfs
  • Replace all calls to fatfs, those starting with f_ with wf_. So i.e. f_mount becomes wf_mount.
  • Disable all functions you do not need in fatfsWrapperConfig.h. This is because now the compiler will not be intelligent enough (because of the wrapped calls in the worker) to detect which functions you will actually use - and your program size will increase dramatically.
  • If you have replaced ALL calls to fatfs with the wrapped calles, you might also just deactivate the reentrancy of FatFS, since it will be only called from one single thread sequentially.


As end result, all fatfs access will now go over one single thread, so that only this thread needs to have a big working area - and not each thread doing file system access.

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: FatFS Wrapper

Postby Tectu » Mon Jun 11, 2012 9:12 am

I'll give it a try in a few days!
I am currently working on a project with uses SD card, and I had some serious issues with the working areas and also the "syncronisation". It looks like you just did what I need.

Thank you for your great work! :)


~ Tectu

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: FatFS Wrapper

Postby Tectu » Thu Jun 14, 2012 3:12 pm

finaly got some time to try it. Works really good!

Thanks you for sharing your excellent work!


~ Tectu

User avatar
Badger
Posts: 346
Joined: Mon Apr 18, 2011 6:07 pm
Location: Bath, UK
Contact:

Re: FatFS Wrapper

Postby Badger » Thu Jun 14, 2012 10:46 pm

This was something I was planning to do, but never got around to. Now you've done it for me :D

I will integrate into my projects and provide feedback soon.

thanks!

mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Location: Karlsruhe, Germany
Been thanked: 1 time
Contact:

Re: FatFS Wrapper

Postby mabl » Thu Jul 05, 2012 6:51 am

I made several fixes to the wrapper, now it should work out of the box :roll:

rubenswerk
Posts: 104
Joined: Wed Feb 22, 2012 11:39 am
Location: Austria

Re: FatFS Wrapper

Postby rubenswerk » Sun Aug 12, 2012 9:40 pm

mabl, thank you - it works out of the box!
Just one suggestion - the worker thread priority should be part of the configuration file.

User avatar
Tectu
Posts: 1226
Joined: Thu May 10, 2012 9:50 am
Location: Switzerland
Contact:

Re: FatFS Wrapper

Postby Tectu » Sun Aug 12, 2012 9:54 pm

I suggest to pass the priority to the init.

Code: Select all

wf_init(tprio_t priority);

Made a pull request, maybe he will add it :D



~ Tectu


Return to “User Projects”

Who is online

Users browsing this forum: No registered users and 1 guest