Replacing FSRW with stdio (notes and questions)
Rayman
Posts: 14,665
Couldn't get FSRW to work in xmm-single or xmm-split modes although worked well in all other modes.
Because I really want xmm-split mode, I've replaced FSRW with stdio calls.
This turns out to be very easy to do.
Here's what I think I know:
You need to add this to the top of your main file:
You don't then need to call "mount" as somehow, somewhere this is done for us.
Next, where you want to open a file, say "filename.txt" for reading, do this:
And to read in data to a buffer, use fread:
Finally, just close the file:
Because I really want xmm-split mode, I've replaced FSRW with stdio calls.
This turns out to be very easy to do.
Here's what I think I know:
You need to add this to the top of your main file:
#include <stdio.h> #undef CALL_MOUNT extern _Driver _SimpleSerialDriver; extern _Driver _FileDriver; _Driver *_driverlist[] = { &_SimpleSerialDriver, &_FileDriver, NULL };
You don't then need to call "mount" as somehow, somewhere this is done for us.
Next, where you want to open a file, say "filename.txt" for reading, do this:
FILE* fp; fp=fopen("filename.txt","r");
And to read in data to a buffer, use fread:
fread(&buffer, 1,nbytes,fp);
Finally, just close the file:
fclose(fp)
Comments
When is the sd card actually mounted?
What happens if it fails to mount?
I have another question regarding the use of 2 SD cards... My QMP setup actually has 2 uSD cards, one of Rampage2 and one on QMP.
The way I've described above is for using the one on the Rampage2, because it uses the pins as defined in Rampage2x.cfg
But, suppose I want to use the other uSD card. Can I just explicitely call mount first?
Do I need to define CALL_MOUNT?
Is there a way to use both SD cards with this approach?
Since we're on the subject... Is there a limit on how many files I can have open on one sd card?
That would be the way I would expect it to be, and would be cleaner and allow
for more than one device if there was one.
Ex
FILE* fsd = sd_mount(DO ,CLK ,DI, CS);
You get a FILE* to use with C style file I/O
Tom
From what I can tell, you can have 8 files open at a time. However, three of the files are used by STDIN, STDOUT and STDERR, which leaves resources for 5 simultaneous SD files. Each SD file also requires some malloc space for buffers, so this could limit the number of files as well.
If I spent some time at it, I think I could make FSRW work for the second sd...
Dave
When I said you get a FILE* back for sd_mount to use I meant you would use it in fopen(), fread() etc
I am saying sd_mount would be clearer if it returned a FILE* .
I agree with Ray it is not very common to have more than one SD card however.
Just my feedback
Tom
No need to be sorry.
I stand corrected on the issue,
Tom
#undef CALL_MOUNT
Is this necessary?
sd_mount(DO, CLK, DI, CS) as shown in the examples I get
nothing on the SD card.
I was trying to create some files using fopen(filename,"w");
I tried it without sd_mount as a test and nothing happens.
Tom
Your board's .cfg file tells PropGcc which pins to use for SD card access...
my initial experiments with what Parallax announced last Monday.
Taking a peek it is set for ActivityBoard and CMM memory model
Tom
Andy didn't want to use the automated mounting. People who want to use the tutorials should stick to the script.
Ray
No. You can do anything you like. Let's not confuse people following the tutorials though.
_FileDriver.dfs_mount(Sd_miso ,Sd_clk ,Sd_mosi, Sd_cs);
and
dfs_mount(Sd_miso ,Sd_clk ,Sd_mosi, Sd_cs);
But, they are unrecognized...
I was hoping to use this to mount my other uSD (on different pins than in the Rampage2x.cfg file).
Looks like I need to call
uint32_t dfs_mount(_SD_Params* params);
after first creating an _SD_Params structure...
I think maybe it's simpler for me to use stdio the regular way and then figure out how to make fsrw work in xmm mode for the other usd card...
Is there a way to test that here?
I wouldn't change anything to add a second SD. I think it may only be me doing this...
And I'm leaning toward using FSRW for the second uSD....