SD card problem. I have interfaced SD card with Coldfire...

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SD card problem. I have interfaced SD card with Coldfire...

5,035 Views
jainabhs
Contributor I
SD card problem.
I have interfaced SD card with Coldfire CPU 5475 on evaluation board.
I formatted SD card for FAT 16 and wrote software for accessing files from SD card.
Everything works fine but following
The address of root directory is varying according to filename in following manner.
If filename is exactly 8 char, the address is correct as per my calulation.
If filename < 8 char, I have to add 32 bytes to addr calculated.
If filename > 8 char, I have to add 64 bytes to addr calculated.
can anyone tell me why this shift in root directory entry happens?
I have only one text file in SD card.
Thanks in advance for your help.
Abhishek Jain.
Labels (1)
0 Kudos
13 Replies

975 Views
jainabhs
Contributor I
Thank you very much erool,
This is exactly what is happening with me. It is much clearer now.
 
Thanks again.
 
Abhishek Jain.
0 Kudos

975 Views
vicky07
Contributor I

Hey guys am trying to interface SD Card with Coldfire V1 uC. The problem is dat I have written da code for little endian and later realized dat the uC am working with is big endian, as a result am not able to read boot sector and the program shows error 'NOT_FAT32'. Is thr any way to change uC from big endian mode to little endian mode!!!

         Plz help....

 

0 Kudos

975 Views
vicky07
Contributor I
I got the solution to my problem.
0 Kudos

975 Views
gustavod
Contributor III

 

The FAT File System of freescale with some bug fixes was posted on:

http://code.google.com/p/brtos/downloads/list

 

Now supports up to 512 MB and the list function is working correctly.

The corruption of files was also fixed.

 

Best Regards,

Gustavo

0 Kudos

975 Views
Darryl42
Contributor I

SIr,

 I downloaded your latest Fat file system for use in logging data.  In that circumstance it has a problem with the cluster calculation when opening a file larger than 8K for write.  The calculation u16Temporal =fileSize % (Sector_Size<<4) gives a sector index from 0-15 when it instead should be 0-63.  Using a u16 for the intermediate value, also poses an inherent 512Meg size limit.

    This problem only happens when opening an existing file for writing.  You can open a new file, write 500K to it close it and read it fine.  But I do lots of appends, and then it corrupts the file system.

 

In FAT_FileOpen() line 662

        u16Temporal=(INT16U)FAThandle->WHandler.File_Size % (FAThandle->u16FAT_Sector_Size<<4);
        FAThandle->WHandler.ClusterIndex= u16Temporal/FAThandle->u16FAT_Sector_Size;
Change this to

        u32Temporal=FAThandle->WHandler.File_Size % (FAThandle->u16FAT_Sector_Size<<6);
         FAThandle->WHandler.ClusterIndex= u32Temporal/FAThandle->u16FAT_Sector_Size;

0 Kudos

975 Views
gustavod
Contributor III

Darryl42,

 

Thank you for this bug correction. However, right now i'm using a better FAT file system implementation. This new file system supports FAT32 and directory structures. You can download the code in this links:

 

Coldfire JM128 Demo:

http://brtos.googlecode.com/files/TWR-LCD-FatFS.rar

 

Coldfire QE128 Demo:

http://brtos.googlecode.com/files/BRTOS%20CFV1%20SD%20Card%20%2B%20FatFS.rar

 

0 Kudos

975 Views
erooll
Contributor II
Another consideration is: If file name have letters in lowercase, then you will find a aditional entry similar to a long file entry in order to save file name in lowercase.
Maybe this is your case, i'll add two images with a directory entries, one have a entry with a file that have name and extension in uppercase(in directory entry sectors only have one entry), and other with the same file but have letters in lowercase(two entries for this file).


Message Edited by erooll on 2008-06-06 09:51 AM

Message Edited by erooll on 2008-06-06 09:56 AM
0 Kudos

975 Views
erooll
Contributor II
Lowercase
0 Kudos

975 Views
erooll
Contributor II
Hi jainabhs.
 
Now I understand your trouble, and off course, if you format SD card and write your file then we hope have only this file, but is posible that your computer still infected by some virus that usually writes files in SD card, or USB memory... etc, those files usually are hidden.
I recommend use a software tool like a Hexadecimal editor that allow see the context of your SDCard, and see sector where are allocated directory entries, maybe you could discover something in the mysterious entry.
I also use a SDformatter that format SD card in FAT16, but differs of formatter of OS(windows) that this formatter also erase memory in data space, all bytes are set to 0xFF.
 
If you want let me a email address in order to sent you this tools.
 
Regards
 

 
0 Kudos

975 Views
erooll
Contributor II
Hi.
actually I'm working with a SD and a implementation of FAT16-32 using a Coldfire V1 QE128, are you searching in FAT table?, or in Directory entry?, if file name is long, then by each file FAT generate various directories entries in order to store long name...
Only one of this entries have the information of file size, date of file, and first cluster of file.
 
0 Kudos

975 Views
jainabhs
Contributor I
Hi Erool,
Thanks for your reply.
I am not searching in FAT, I anm searching in directory entry.
Let me correct my question and let us not consider the case of long file names.
My quesry is, if there is only one file in SD card (after formatting it) and the filename is say 'test.cpp' then according to me I should find its entry at start (first entry) of root directory. But I find it after I add 32 bytes (at second entry) to root directory address calculated.
If the filename is exactly 8 chars (abcdefhg.txt) long, then I find it right at the first entry of root directory. i dont have to search it.
Please let me know why files with 8chars in name have their entry at the first entry of root directory and files with shorter name length have them at second entry, in case of there is only one file in SD card ?
My idea...
But as I understand now, I dont think there is any hard rule that defines location of entries in root directory. i think what I should rather do is , fetch 'RootDirMaxEntries' from SD card and search for desired filename throughout root directory.
Thanks in advance.
Abhishek Jain
0 Kudos

975 Views
ChrisJohns
Contributor I
Hi,

You will need to get the max. entries and search the whole directory. Consider adding 5 files f1.txt, f2.txt etc then you add your file you are interested in then you delete the f1.txt to f5.txt. Your file will be a the 6th entry or even further on. This is due to a deleted file having the first character changed. I cannot remeber what to. The directory entires are not shifted down in the directory table.

Regards
Chris
0 Kudos

975 Views
JimDon
Senior Contributor III
If you would llike to see some working sample code look here.
There is code to enum a directory, so I am sure this would help.

0 Kudos