I want to use SD Card with FAT SL.
First, I tested FAT window example project, FAT_SL_and_CLI_Windows_Simulator. So I understand how it works. So I applied it to my system board(ARM) and checked it. Next, I make a initialization for SD Card, it works fine. They’re in same project.
But I don’t know how can I connect them. They’re working independently now…
I want use filesystem functions on my SD Card like dir, write, open, etc…
I’ve just reviewed that thread and am not sure what else to add.
You can reuse the RAM disk file and structures, and then re-implement the functions that actually perform the reading and writing to make use of your SD card read and write functions. That might be confusing though if you have a structure that says ‘RAM’ with read and write functions that use an SD card driver. I would therefore suggest taking a copy of the RAM disk files, then rename the file name, and the structures used within the file, so they are called something relevant to the SD card.
I’m sorry. My post was not enough to describe my situation and what I want.
I’ll describe my situation and question again.
The main question is how can I connect(or initialize) SD card for using in FAT SL file system like using RAM.
I did just initalize SD card hardware, and I can write something to SD card by SPI. This is not using FAT file system API, just reset and initalize SD card. So it is ready for use and wait.
I understood that the first step to use FAT file system is ‘init volume’.
How can I use init_volume function in FAT file system API for my SD card…
Something what I understand is wrong…? I don’t know how it works on SD card.
Is it possible using FreeROTS+FAT SL APIs on flash memory?
It is easy to use on the RAM. For example, I can copy something to another place by memcpy(). But it is different on flash memory…
So the code you have to initialize the SD card hardware would go in F_DRIVERINIT(), and the code to write data to the card will go in F_WRITESECTOR(). As you point out though, writing data to the card is more involved than writing to RAM so you will have to replace the memcpy() calls with the commands needed by the SD card controller over the SPI bus.
Can you be more specific about where the issue is, for example:
Is it that you don’t know the SPI commands necessary to read and write to the card, or
Is it that you don’t know how to arrange data on the SD card so it correctly represents the file system (because the data should be exactly as it is in the RAM disk memory array, just stored on the card rather than in RAM), or
Is it that you don’t know how to link your SD read/write functions into the portable layer of the SD card?
This is my situation… I want to use file system for flash memory(e.g. SD card). My embedded system use FreeRTOS 8.0, so I chose FreeRTOS_FAT_SL for file system on my board and bought license.
Unfortunately, this is the first time to develop file system to me. So I’m not familiar with it. Then I studied it and analyze ‘FAT_SL_and_CLI_Windows_Simulator’ project. But there is only codes for using RAM. I applied it to my embedded system. I made a some folders and files, and read & write something to those files in RAM on my board. But I don’t know how it applied to flash memory(SD card).
So I searched way of using flash memory because my purpose is using flash memory. I chose SD card and studied how can use it. Then I can initialize it with several CMDs by SPI communication. It forced block size to 512 bytes. But this is not related with file system, hardware was just initialized independently. I think that it is ready for use… and I know some CMDs for read or write sectors. perhaps, I can modify read or write sector functions in FAT for SD card.
I want to use file system on my SD card like using it on RAM. For example, if I input ‘dir’, file system return directory and file list in SD card to me. There are many functions in FreeRTOS FAT and I want to use them. But I don’t know how can initialize(or link?, connect?) file system on SD card. I want kinds of sequence or sample codes for initialization. or please tell me if I have misunderstood something…
Regards.
+) I think that I can use file system if it will be initialized. So please explain initialize sequence(or func) more specifically if you are okay…
So starting at the beginning, with initialisation, you have to provide an implementation of F_DRIVERINIT() to initialise the card before you can use it.
First get the RAM disk demo running on your target hardware. You may have to set the size of the RAM disk down to a couple of K bytes to fit it in the RAM you have available, so the file system won’t be usable, but that doesn’t matter it just needs to be compiling.
To do that you can use the Win32 simulator demo as a reference, just include the same files and configuration file.
Once it is compiling and running, step into the function vCreateAndVerifySampleFiles(). It in turn calls f_initvolume(). f_initvolume() passes in a single parameter, which is a pointer to the F_DRIVERINIT() function - which in this case is called ram_initfunc(). If you continue stepping through the code you will see the first line of fn_initvolume() is “mdrv = initfunc( 0 );” which is calling the function passed in as a parameter.
Step into initfunc() and you will find yourself in ram_initfunc(). The top of that function does some RAM disk initialisation - replace that with the code you say you have that initialises the SD card (assuming that is working).
ram_initfunc() then populates a structure with functions for reading and writing sectors - just leave those for now. You will have to come back and replace them with your own SD card read and write functions - but for now just get the code compiling and the SD card initialising.
So unlike the RAM disk, the SD card is a block device - so data can only be read or written in blocks (or sectors) or 512 bytes.
Rather than taking an address from the beginning of an array (as in the RAM disk) you take an address from the beginning of the SD card (sector 0). So to read an address you work out which sector the address falls within, and read the whole sector (from the start of the sector) to get a buffer that contains the data at the address you are actually interested in. Likewise when writing - read the whole sector back, modify the bytes you need to write to, then write the whole sector back to the disk.
I’m looking at that file and dont think the structure is needed at all because you can only have a single drive. The information in the structure can just be file scope variables.
// Declare an F_DRIVER structure at the top of the file.
static F_DRIVER my_driver;
So ram_initfunc() becomes sd_initfunc() and populated my_driver with the sd_readsector, sd_writesector, sd_getphy, sd_release and user_ptr members, just as you can see being done in ram_initfunct(). sd_initfunc() returns &my_driver.
sd_readsector() is the sd card version of ram_readsector(), sd_writesector() is the sd card version of ram_writesector, etc. These functions you will have to implement yourself using your SPI interface and the SD card commands to read and write sectors.
I’m looking at that file and dont think the structure is needed at all
because you can only have a single drive. The information in the structure
can just be file scope variables.
…like the attached file. A lot of the clutter, including the structure, is removed, leaving really just the init, read and write functions. Is that clearer?
I have understood way to connect file system and SD card. It is really helpful to me your helps.
I made new initialize, read, write, getphy functions for filesystem and f_initvolume() function returns ‘0’. I made it. Next, I tried to format my SD card. f_format() is worked well and return NO ERROR. So I can open, read and write example txt file.
But there is a problem…
My desktop PC or cell phone cannot read that SD Card. PC or cell phone say “this card did not formatted”.
So, I formatted SD card on PC and insert it to embedded board. My system recognize it formatted already. But Some error occure when it
try read or write file. The error is… response from SD card is not
returned accurately. SD card returns 0x00 first and 0xFE second and
then other values comming when it receive some command. But it returns only 0x00 and next is not come…
I don’t know why it happen.
It is works in embedded system but not work other system(PC, cell phone) when it formatted in embedded system.
On the contrary, it works in PC or cellphone when it formatted on PC,
but it does not work on embedded system. They were formatted FAT32 on both system.
One more question… attached files are master boot record of each
system.(It is little Endian) upper one is formatted by FreeRTOS FAT+SL and lower one is by PC. FAT size 32 is represented ‘0x00000D3A’(=973930496 sectors = about 464GB)
Hello, I am writing to the creator of this thread. I am doing something similar to you and if you read this, can you please provide some updates as to what is the progress of your work regarding SD card and FreeRTOS+FAT. I am working with SD card but in SD mode and I am very far off from what you have achieved. Looking forward to your help.
Hi. I read your another thread too and I can understand your condition.
Actually, My progress is same with my last post because I couldn’t find the reason of the problem and I should to do another work first(porting to another core).
It was finished the other works, so now I’ll try to use it again. I will make a TFTP system with SD card this time.
I think that you are almost finished. I can help you if you need. you can help me later too. We can be a good co-worker
Actually I am very far from where you have managed to reach. I am still struggling with how to read and write on the card and how is the addressing done and basic things like this.
Can you please tell me which micro-controller were you using for this matter ?
I really look forward to understand this all and hope I could learn from you a big deal.