FatFs - Generic FAT File System Module


17 posts
by Arjan » Sat Dec 15, 2012 6:27 pm
Hi,

I am just wondering. Is there any work in progress on low level disk I/O functions that are required by the FatFs module?

Thanks. Arjan.
Posts: 128
Joined: Sat Sep 08, 2012 1:59 pm
by tritonium » Sat Dec 15, 2012 6:43 pm
Hi
Yes I believe Dexos is about to release some code see....

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=72&t=25606

post 8

He is building a bare metal OS and USB and Fatfs are work in progress.... :D

Dave H
Posts: 78
Joined: Tue Jan 03, 2012 7:10 pm
by DexOS » Sat Dec 15, 2012 9:29 pm
Arjan wrote:Hi,

I am just wondering. Is there any work in progress on low level disk I/O functions that are required by the FatFs module?

Thanks. Arjan.

As tritonium pointed out, i am working on such functions, they will be included in the next ver of DexBasic.
If you need them in the mean time, let me know and i will post them.

Note: they are just raw read\write sectors from sd card.
Batteries not included, Some assembly required.
User avatar
Posts: 860
Joined: Wed May 16, 2012 6:32 pm
by Joeboy » Sun Dec 16, 2012 11:29 pm
I'd like to see your disk I/O code if you're up for posting it, DexOs. Cheers.
Posts: 24
Joined: Wed Oct 31, 2012 11:59 am
by DexOS » Mon Dec 17, 2012 1:43 am
Joeboy wrote:I'd like to see your disk I/O code if you're up for posting it, DexOs. Cheers.

Sure, i am going to release all the code to DexBasic and DexOS RPI port on Xmas Day, it my present to the RPI community ;) .
Hope people will add to it.
But if you can not wait until Xmas, PM me.

PS: Nice sound code :) .
Batteries not included, Some assembly required.
User avatar
Posts: 860
Joined: Wed May 16, 2012 6:32 pm
by Joeboy » Mon Dec 17, 2012 10:55 am
Ok that's cool. Looking forward to unzipping my xmas present.
Posts: 24
Joined: Wed Oct 31, 2012 11:59 am
by Arjan » Mon Dec 17, 2012 12:47 pm
Hi Dexos,

With reference to http://elm-chan.org/fsw/ff/en/appnote.html#port, I may assume that you have currently implemented the following functions,
. disk_intitialize
. disk_status
. disk_read
. disk_write

Correct?

Thanks.
Posts: 128
Joined: Sat Sep 08, 2012 1:59 pm
by DexOS » Mon Dec 17, 2012 9:54 pm
Arjan wrote:Hi Dexos,

With reference to http://elm-chan.org/fsw/ff/en/appnote.html#port, I may assume that you have currently implemented the following functions,
. disk_intitialize
. disk_status
. disk_read
. disk_write

Correct?

Thanks.

Yes, i have implemented all those functions :)
Batteries not included, Some assembly required.
User avatar
Posts: 860
Joined: Wed May 16, 2012 6:32 pm
by Arjan » Mon Dec 31, 2012 1:24 pm
Hi DexOs,

Thanks for the source code!

I did some fist look and I have found the following functions in your code :

*. InitialSDcard --> FatFS DSTATUS disk_status (BYTE drv)

*. ReadSingleBlock --> Could be part of FatFS DRESULT disk_read (
BYTE drv, /* Physical drive nmuber (0..) */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to read (1..128) */
)

for reading just one sector -->

[code]
if (count == 1) { /* Single block read */
@ ReadSingleBlock -> sector
}
else { /* Multiple block read */
if (send_cmd(CMD18, sector) == 0) { /* READ_MULTIPLE_BLOCK */
do {
if (!rcvr_datablock(buff, 512)) break;
buff += 512;
} while (--count);
send_cmd(CMD12, 0); /* STOP_TRANSMISSION */
}
}
[/code]

And I am not able to find the implementation for :

DSTATUS disk_status (
BYTE drv /* Physical drive nmuber (0..) */
)

Please advice. Thanks.

Regards, Arjan
Posts: 128
Joined: Sat Sep 08, 2012 1:59 pm
by DexOS » Mon Dec 31, 2012 5:40 pm
The disk_status return drive number, which in the RPI case theres only one.
It also returns media removal, media change and disk_initialize function failed.
So for now you can just write a function, that just tests a var for initialize OK, that is set when you call initialize function, if that function return without error you set the var to 1 , which means media present and initialize OK, if not its 0 which means initialize error or media not present .
If you need i can write this function and add a media change part to it.
Any more ? just ask.
Batteries not included, Some assembly required.
User avatar
Posts: 860
Joined: Wed May 16, 2012 6:32 pm
by Arjan » Tue Jan 01, 2013 6:55 pm
Hi DexOS,

I have created an Eclipse CDT (C/C++ Development Tooling) project for the FatFs code. And with the attached stub (mmc.c) I was able to compile the code.

However, when including your code I noticed that the DexBasicSource is not gcc-as compatible. So unfortunately I am not able to use your code without modification.

Any ideas here? Thanks. Arjan
Posts: 128
Joined: Sat Sep 08, 2012 1:59 pm
by DexOS » Wed Jan 02, 2013 3:54 pm
Arjan wrote:Hi DexOS,

I have created an Eclipse CDT (C/C++ Development Tooling) project for the FatFs code. And with the attached stub (mmc.c) I was able to compile the code.

However, when including your code I noticed that the DexBasicSource is not gcc-as compatible. So unfortunately I am not able to use your code without modification.

Any ideas here? Thanks. Arjan

I will convert the fasmarm to gcc-asm compatible, for you, but i can not do it until the weekend.
Batteries not included, Some assembly required.
User avatar
Posts: 860
Joined: Wed May 16, 2012 6:32 pm
by Arjan » Wed Jan 02, 2013 7:00 pm
Hi DexOS,

Thank you!

I am waiting new hardware and I am still in the process of writing the application with its documentation. So I am not in that hurry :-)

Thanks again. Regards, Arjan
Posts: 128
Joined: Sat Sep 08, 2012 1:59 pm
by Arjan » Sun May 26, 2013 6:30 pm
I've got FatFs working.

See https://github.com/vanvught/OpenILDA/tr ... dcard-emmc and https://github.com/vanvught/OpenILDA/tree/master/emmc

The emmc source is taken from https://github.com/jncronin/rpi-boot

The diskio.c source is based on code from NXP app note AN10916
Posts: 128
Joined: Sat Sep 08, 2012 1:59 pm
by allexoll » Fri Nov 22, 2013 3:35 pm
Did you get the multiple block read working? I'm also using jcn's code, but CMD18 always fails... i've found a work around, in diskio.c i check if count > 1 then i do multiple single block read, as DexOs does. but this is quite slow, reading a file that's around 1.1MB takes aproximatly 10 seconds...

with CMD18 i get
Code: Select all
SD: error sending CMD18, error = 0x00000000.  Retrying...
SD: error sending CMD18, error = 0x00010000.  Retrying...
Posts: 35
Joined: Sat Feb 23, 2013 12:27 pm
by DexOS » Fri Nov 22, 2013 4:04 pm
allexoll wrote:Did you get the multiple block read working? I'm also using jcn's code, but CMD18 always fails... i've found a work around, in diskio.c i check if count > 1 then i do multiple single block read, as DexOs does. but this is quite slow, reading a file that's around 1.1MB takes aproximatly 10 seconds...

with CMD18 i get
Code: Select all
SD: error sending CMD18, error = 0x00000000.  Retrying...
SD: error sending CMD18, error = 0x00010000.  Retrying...

I am still using single block read, which as you said is slow.
But i get a speed of 6 second to read a 1.4 MB file or 4 seconds if i use the latest firmware.
But i know i will get 4mb per second (with read single block) once i set up for the card in the pi, instead of using bare min settings.
The multi read needs to be on sector one after the other, like loading a cluster etc.
Hope this helps.
Batteries not included, Some assembly required.
User avatar
Posts: 860
Joined: Wed May 16, 2012 6:32 pm
by Arjan » Fri Nov 22, 2013 4:05 pm
See https://github.com/vanvught/OpenILDA/bl ... e/diskio.c
I am using
Code: Select all
cache_read(dev, buf, buf_size, sector)
and when device supports multiple block read , it will be used.
Posts: 128
Joined: Sat Sep 08, 2012 1:59 pm