CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

FAT16 file system for MMC using SPI interface
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

FAT
PostPosted: Mon Apr 30, 2007 7:16 am     Reply with quote

This code was written as a hobby project at a time when MicroSoft specifications were public and its patents were undecided by US Courts. I sent this code to some one in England who then against my wishes placed the code on the web. In response I considered
(especially since the Microsoft patent wasn't yet decided in fact it had been denied) it would be better to post the code on this board since it could be accompanied by appropriate disclaimers. After a change of Administrations in the US the patent office reversed itself and upheld Microsoft's patent.
Writing files brings a person much closer to patent infringement than reading
so the code gives no encouragement or examples whatsoever about writing files. I have never written files using this code to any Microsoft operating system even though I own my computer and it's in my own home. Again FAT is fully owned by Microsoft and everyone should seek legal advice so as to respect fully Microsoft's ownership rights. Permission to use FAT can be obtained from MicroSoft for around $250,000. Anyone using FAT would be well advised to obtain Microsoft's permission. Microsoft is trademarked and is used here only to provide context.
miky



Joined: 06 May 2007
Posts: 10
Location: Prague

View user's profile Send private message

PostPosted: Sun May 06, 2007 12:37 pm     Reply with quote

Hi Douglas,
trying to run the code on 18f452 (20Mhz) on Kingstone 512MB SD card. I've changed the init:
c=mmc_cmd(0x77,0x00000000,128,0x00,0x99);
c=mmc_cmd(0x69,0x00000000,128,0x00,0x99);
if (c==0x00) { goto ready;}
so the init SD works. I've placed 120MB file on the card and I can read the card via file_read properly. I am also able to write into file (with SPI_CLK_DIV_64 when using resistors as 3.3.v dividers) but with following issues:
1. when the resulting file is <5kB then it works, SD is readable on PC reader
2. when the resulting file is ~128kB then I see in debug that clusters are modified and FAT is updated - each FAT update takes aprox 10s!
3. when reading from pic I see some corrupt data around cluster updates
4. when reading SD from PC reader the file is corrupt and unreadable.
The write loop is as follows (buff0 is 128):
int32 ofst = 128;
...
error0 = file_set(0,ofst);
error0=file_write(0,buff0);
if (error0>0 && error0<255 ) {
printf("\n\r fwrite 0 failed error=%U\n\r",error0);
goto mmc_exit;
};
ofst = ofst + 128;
....
Any hint how the proper write sequence shall look like (e.g. are the clusters changes fully handled in file_write routine?.
Thanks,
Miky
sauer



Joined: 02 Jul 2007
Posts: 2

View user's profile Send private message

PostPosted: Mon Jul 02, 2007 1:55 pm     Reply with quote

Crying or Very sad Annyone have the actualized driver mmcdos.c? I tried the code listed by Douglas Kennedy an it doesn't work. I can't compile it. I'm using the CCS 4.020 version. I try to compile using the PIC18F252.

Last edited by sauer on Mon Jul 02, 2007 1:56 pm; edited 1 time in total
etiedon



Joined: 23 Jul 2007
Posts: 12

View user's profile Send private message

PostPosted: Fri Aug 10, 2007 3:25 am     Reply with quote

I have a problem like that;

Library works perfect with mmc3.0 (16mb)

And when using read_BLOCK response of r1 is 0

But when i use it with reduced-size mcc (512 mb) when i use read_BLOCK response of r1 is 255..So it doesnt read properly.

What is the meaning of r1 response(255) ? And what is the possible solutions?

Thanks for your help.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Aug 15, 2007 4:05 pm     Reply with quote

Quote:
What is the meaning of r1 response(255) ?
The highest bit is set, meaning the card is still busy. Depending on brand and memory size it will take more or less time to prepare the data block.

Quote:
And what is the possible solutions?
Try to give the card more time before timing out. in read_block() see how things improve when you change the line
Code:
r1=mmc_cmd(0x51,address,16,0x00,0x40);
to
Code:
r1=mmc_cmd(0x51,address,255,0x00,0x40);
etiedon



Joined: 23 Jul 2007
Posts: 12

View user's profile Send private message

PostPosted: Wed Aug 15, 2007 4:25 pm     Reply with quote

ckielstra wrote:
Quote:
What is the meaning of r1 response(255) ?
The highest bit is set, meaning the card is still busy. Depending on brand and memory size it will take more or less time to prepare the data block.

Quote:
And what is the possible solutions?
Try to give the card more time before timing out. in read_block() see how things improve when you change the line
Code:
r1=mmc_cmd(0x51,address,16,0x00,0x40);
to
Code:
r1=mmc_cmd(0x51,address,255,0x00,0x40);


I solved that problem. Mmc 512mb reads only 512 block size of blocks. Its different then 16mb.

But i didnt find any useful documents with that topic, 'what is the electrical and timing differences between cards'

You need to try to find the solution.
Pret



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

Re: FAT
PostPosted: Wed Aug 29, 2007 3:22 am     Reply with quote

Douglas Kennedy wrote:
This code was written as a hobby project at a time when MicroSoft specifications were public and its patents were undecided by US Courts. I sent this code to some one in England who then against my wishes placed the code on the web. In response I considered
(especially since the Microsoft patent wasn't yet decided in fact it had been denied) it would be better to post the code on this board since it could be accompanied by appropriate disclaimers. After a change of Administrations in the US the patent office reversed itself and upheld Microsoft's patent.
Writing files brings a person much closer to patent infringement than reading
so the code gives no encouragement or examples whatsoever about writing files. I have never written files using this code to any Microsoft operating system even though I own my computer and it's in my own home. Again FAT is fully owned by Microsoft and everyone should seek legal advice so as to respect fully Microsoft's ownership rights. Permission to use FAT can be obtained from MicroSoft for around $250,000. Anyone using FAT would be well advised to obtain Microsoft's permission. Microsoft is trademarked and is used here only to provide context.


Do you know if this applies to Europe too? As i've been heard, this patent does not include europe territory, according with European Union. Can anyone confirm this?
app



Joined: 09 Feb 2008
Posts: 1

View user's profile Send private message

PostPosted: Sat Feb 09, 2008 11:58 am     Reply with quote

hi

function set_BLOCKLEN is not work.
r1=mmc_cmd(0x50,size,16,0x00,0x40);

Response r1 is not 0x00
ratgod



Joined: 27 Jan 2006
Posts: 69
Location: Manchester, England

View user's profile Send private message

PostPosted: Thu Aug 14, 2008 11:19 pm     Reply with quote

Does anyone have any example code of reading text from a test file?
I have the card initialized ok, it appears to find the file ok but when I do a read I don't get anything back.

any ideas or examples?

also, does anyone know how to specify the filename correctly? I'm using "test" as a file name as I'm not sure how to get it to work with "test.txt"

thanks
emresensoy



Joined: 27 Dec 2008
Posts: 2

View user's profile Send private message

big card read problem
PostPosted: Sat Dec 27, 2008 4:57 am     Reply with quote

Hi to everyone,
I use this code with 18f452 with 1gb sd, 128 mb sd and 64 mb sd card,
and everything is ok.
But with 1gb sd card if a file data is at address like 29589000
the open_file routine works, there is no problem, but the file_read
routine doesn't work.
Code:

if (read_BLOCK(address,buff)==false) return(12);

This line returns 12 and not read.

I think the problem is at read_block command with this:
Code:
read_block(0x29589000,buff);

buff stayed still clear, nothing is read.

Is there anyone to help me about this ?
Sorry for bad english.
manish12



Joined: 18 Jan 2009
Posts: 15

View user's profile Send private message

where is these func ?
PostPosted: Wed Jan 28, 2009 7:38 am     Reply with quote

Code:
init_dram();

set_dram_address(0);

While compiling I am getting error: function not defined.
harrie215



Joined: 15 Apr 2005
Posts: 6
Location: Netherlands

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Mar 17, 2009 3:15 pm     Reply with quote

Code:
 start mmctest                                                                                                                       
 Start SPI MMC                                                                                                                       
cmd1                                                                                                                                 
 MMC initialized                                                                                                                     
                                                                                                                                     
 opened as 0 file 3.wav with rec size 32                                                                                             
                                                                                                                                     
 fread 0 failed error=10     


I can't find what's going wrong.
husam



Joined: 17 Feb 2010
Posts: 10
Location: jordan

View user's profile Send private message

PostPosted: Sun Feb 28, 2010 1:41 pm     Reply with quote

hi ,
is necessary to use PIC18F452 only ?? if no how .. ??
noyz



Joined: 31 Jan 2009
Posts: 59

View user's profile Send private message

PostPosted: Thu Jun 02, 2011 2:05 pm     Reply with quote

I am wondering. Is it possible to use MicroSD as both as FAT file system
and as an external memory.
ex:
Write to file different types of string...
and have a memory very accessible like RAM.. write at 0x20. Something like that.

I want to have a vector really big and it doesn't fit in MCU ram.
Should I use a file or is it possible what i wrote up.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group