We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi to all, i started to work on FAT file system on SD 1GB card. LPC2388 on MCB2300 board.
Just now i have completed my binary search on File system on SD card. Simply fopen, fread, fseek,etc.
Now i have to work on SD card using FAT file system. i went through so many web pages that didnt answer my question or i was not able to understand.
how to make a File allocating table on my SD Card? Some simple example can give me a good start...
my question is Whats the difference between Normal File system (which i have done on my SD card) and FAT File system?
And I had formatted the SD card on LAPTOP with the 2 options of FAT(Default) and FAT32. When i tried to use the card after i did format using FAT(Default) option, i was able to work with my code which i developed for SD card using normal File system.
But if format using FAT32 option, then while trying to initialize the card it says SD card un formatted.
So what its trying to say?
So by default my controller accept FAT12?
Can i use FAT32 on the same SD card for my same code in which i didnt give an option to recognize FAT32?
As i studied from the web source for FAT16, the clusters address divide my SD card in to sectors and gives back the location address to me(2^16 address)?
So on for FAT32?
So please give me some clear explanation how to start? And i gone through Wikipedia and all the sources so dont give me the link for wikipedia pls.
You don't want to receive Wiki links, but the question is: Have you _really_ read this page? en.wikipedia.org/.../File_Allocation_Table
1GB and max 32kB cluster size means how many clusters? 4096 clusters * 32kB is 128MB.
Any PC or microcontroller can create a FAT12, FAT16 or FAT32 file system. It is just a question of if the used source code supports it, and if the connected hardware needs it.
A camera can manage reasonably well with FAT16, since it generates few, but large, photos. This means that the waste will be small if you format the memory card with very large clusters.
But 65536 clusters of 32kB is still a limiting factor, since that would represent a limit of 2GB.
You might have noticed that older cameras (or MP3 players, ...) do not support FAT32 and can't be used with larger memory cards.
Next step up is of course to consider patens and licenses. Microsoft will _probably_ only be able to sue if you implement support for long file names. The alternative is to pay licensing fees.
-> However i cant fseek a data when i opened a file for writing?
So can a FAT fs fix this issue? <-
http://www.keil.com/support/man/docs/rlarm/rlarm_fseek.htm
Note
* Seeking within a file opened for "w" mode is currently unsupported.
Hi keil Enthu,
To better understand and control the SD-card on you embedded system, you need to learn a lot of things. There is no shortcut.
But in your situation, you might be able to treat something as a Black Box, and just use them until you encounter a related problem.
However, you must need to read the manual of RLARM, it is the basic requirement.
Only if he is actually using RLARM - which has not been mentioned before.
RLARM is certainly not necessary to implement a File System - including the MS FAT File Systems - on an SD Card.
Ok i take all your advice.
but if i get any simple or big doubt, to whom i can ask??
i can ask here and to you peoples only...:)
I dont want to make more no of threads by simply asking small small doubts(Even i try to figure out by my self) and wasting your time ...
Then my post may not be worthy to all. may give bore to the thread readers...
Thats why i wanted to make it as single and bulk...
Anyway i want to make this post as worth for me.
So in the chan's documents in which i went through, What they mean by Disk(Isn't not SD card)?
Whats that No of physical drive on SD card?
And on SD card also do we have physical drives?
Do we have to partition the SD card into no of physical drives?and how?
I was using RLARM only for my existing project(Binary search on SD card file system).
Are you going to implement a FATx file system yourself, or use an existing implementation?
If you are going to implement one - format the card in a PC and then read back the structures and analyze them. That should give you a lot of ideas about how a FAT file system works.
You are referring to elm-chan.org/.../00index_e.html aren't you?
You need to make this clear, as not everyone reading this thread will automatically know what you mean by "the chan's documents"
"So in the chan's documents in which i went through, What they mean by Disk (Isn't not SD card)?"
It uses the term "disk" generically to mean "the physical storage medium" - so that includes real disks, SD-Cards, or anything else.
This is much the same as the way that PCs view storage media like SD-Cards and USB sticks: they all appear as "drives", and it is (largely) irrelevant whether the "drive" is a real disk or not...
I think that may not be a good idea?
I seem to remember reading somewhere that you need to take care when formatting an SD-Card in a PC - or you can end up with an inappropriate format.
The disks come correctly formatted from the manufacturer - so don't mess with the formatting if at all poissible!
This is the classical concept already discussed above. Format with FAT16 and huge clusters, or FAT32 and small clusters. And a lot of MP3 players or cameras will not support FAT32, in which case they will reject a card that is default-formatted by a PC.
That is a good reason for formatting a card in the device it is intended to be used with.
If the goal is to decode data structures, then it is helpful to also test with the values generated by a PC. A number of cameras manages to generate incorrect file systems, where some fields either have incorrect values, or no values at all.
Hi to all, I trying to understand the FAT fs. So i made some efforts for that. now i am referring www.siwawi.arubi.uni-kl.de/.../
i made some changes on the code and i got some results :).
my code from main.c is:
FATFS *fs;/* Pointer to file system object */ DWORD fre_clust, fre_sect, tot_sect; DRESULT Disk; FRESULT res1; IoInit(); //Timer, UART and LED initialize xputs("\nFatFs module test monitor for LPC2388"); w1 = f_mount(0,fs); // mounting logical drive 0 xprintf("\r\nmount status %d",w1); // res = disk_initialize(0); // physical drive 0. But i dont know why // xprintf("\r\n Return value of diak_initilize() is %d",res); Disk = disk_status(0); // status if physical drive 0 xprintf("\r\n Return value of diak_status() is %x",Disk); // Get drive information and free clusters res1 = f_getfree("/Test.txt", &fre_clust, &fs); if (res1) put_rc(res1); xprintf("\r\n Retuen value of getfree() is %d",res1); // xprintf("\r\n Free Clusters %ld",fre_clust); // Get total sectors and free sectors tot_sect = (fs->max_clust - 2) * fs->csize; fre_sect = fre_clust * fs->csize; // Print free space in unit of KB (assuming 512B/sector) xprintf("%\r\nlu KB total drive space.\n" "%lu KB available.\n", fre_sect / 2, tot_sect / 2); // Open source file res1 = f_open(&file1, "Test.txt", FA_OPEN_EXISTING | FA_READ); if (res1) { put_rc(res1); } xprintf("\r\n status Opening Test1 file %d",res1); // Create destination file res1 = f_open(&file2, "b.txt", FA_CREATE_ALWAYS | FA_WRITE); if (res1) { put_rc(res1); } xprintf("\r\n status of opening b file %d",res1); // Copy source to destination for (;;) { res1 = f_read(&file1, Buff, sizeof(Buff), &br); if (res1 || br == 0) { put_rc(res1); xprintf("\r\n Reading status %d",res1); break; // error or eof } xprintf("\r\n Read sta %d",w1); res1 = f_write(&file2, Buff, br, &bw); if (res1 || bw < br) { put_rc(res1); xprintf("\r\n write status %d",res1); break; // error or disk full } xprintf("\r\n Write Sta %d",w1); } // Close all files f_close(&file1); f_close(&file2); // Unregister a work area before discard it f_mount(0, NULL);
i give the result here. FatFs module test monitor for LPC2388
mount status 0
Return value of diak_status() is MCI_INIT ok no timeout on CMD8 -> SD-Card>=Version 2.0 ACMD41 success -> SD-Card SC or HC SDSC detected MCI_Send_CSD result: 002f0032 5f5983bd edb7ff9f 964000a8 setting 4bit width success
rc=11 FR_NO_FILESYSTEM Retuen value of getfree() is 11MCI_INIT ok no timeout on CMD8 -> SD-Card>=Version 2.0 ACMD41 success -> SD-Card SC or HC SDSC detected MCI_Send_CSD result: 002f0032 5f5983bd edb7ff9f 964000a8 setting 4bit width success
rc=11 FR_NO_FILESYSTEM
status Opening Test1 file 11MCI_INIT ok no timeout on CMD8 -> SD-Card>=Version 2.0 ACMD41 success -> SD-Card SC or HC SDSC detected MCI_Send_CSD result: 002f0032 5f5983bd edb7ff9f 964000a8 I dont remember that i formatted SD card by either FAT32 or FAT Default.
But after the result i tried to format it again, but it using FAT32 but it says write protected. But i didnt make it as write protected.
So how can i remove this Write protected?
I dont know whats the MCI_Send_CSD result? What those values tell me?
Then i tried to fwrite a file and copy that file to another file. but i always failed. Y?
The way i am going on is correct or not? From Andy and per's lot of reply helped me to come to this level. But still i need more....
f_mkdir("0:sub1");
It says invalied drive. But
f_mkdir("1:sub1");
This one succeed. but is this a folder? like we create a new folder in Harddisk?
But i tried to read themon laptop. but no sign of them. However it says write protected, but creating root directory has been succeed?
pls. need help?
->I dont know whats the MCI_Send_CSD result? What those values tell me?<-
In the below thread
http://www.keil.com/forum/docs/thread15098.asp
Andy (Andy Neil) provided a link to
the free "simplified" version of the SD Card interface specification
www.sdcard.org/.../sdcard
Search this documentation with "SEND_CSD", you will found: The host issues SEND_CSD (CMD9) to obtain the Card Specific Data (CSD register), e.g. block length, card storage capacity, etc.
->So how can i remove this Write protected?<-
You need to find the related function/source code, study it, find out that, how it works, why it detects a "Write protected".
However, before you modify any lines of the source code, you must need to read the documentation.
You need to know that Andy and Per are very intelligent and experienced experts, everything they told you will need you to spend several days or weeks to study.
My level is much closer to you, and I suggest that, RLARM/RLFlash is good for NXP LPC23xx, you should use it, and treat everything you don't understand as a Black Box.
Hi to all:(
Still i am not able to get any success on anything even i tried so many options(changing in the code).
But the same results or not good results.
Still i am working on this because i believe i can get some help from you peoples.
All commends i tried but no results. I followed the flow of cmds. But same results.
from the elm-chan.org/.../dwrite.html DRESULT disk_write ( BYTE Drive, /* Physical drive number */ const BYTE* Buffer, /* Pointer to the write data (may be non aligned) */ DWORD SectorNumber, /* Sector number to write */ BYTE SectorCount /* Number of sectors to write */ );
Here what is SectorNumber. What value i should give here?
From the page www.sdcard.org/.../Simplified_Physical_Layer_Spec.pdf page no 89 gives me the details of received CSD values. But with my result of CSD doesn't match with that table.
MCI_Send_CSD result: 002f0032 5f5983bd edb7ff9f 964000a8
From this value how can i get my Sector address where i can f_write and f_read?
The 0th bit of CSD is reserved int the doc that should be 1. but in my result Which one is that reserved bit? Please reply for my all questions. If you leave any then i ill be blank always.
simply here i am trying to write a sector with some value.
FATFS fs; // Work area (file system object) for logical drive BYTE buffer[4096]; // file copy buffer disk_initialize(0); i = disk_status(0); xprintf("\r\nDisk status is :%d", i); for(i = 0; i < 10; i++) buffer[i] = i; i = disk_write(0, (const BYTE *)&buffer, 0xD2, 56); xprintf("\r\nWrite status is :%d", i);
This one gives the result MCI_INIT ok no timeout on CMD8 -> SD-Card>=Version 2.0 ACMD41 success -> SD-Card SC or HC SDSC detected MCI_Send_CSD result: 002f0032 5f5983bd edb7ff9f 964000a8 setting 4bit width success
Disk status is :0
Write status is :0 Should i give BLOCK_LEN before i read or write the Block?
The Basic thing still i dont know is after formatting the card how to read the clusters and sectors with without file system?
Please really i tried a lot. I need some point out from you to make it....
From when i started i am trying so many things but no progress. hard luck...
Do you have a disk_write() function for LPC2388?
i = disk_write(0, (const BYTE *)&buffer, 0xD2, 56);
For example: 0xD2, what is that?