Shop OBEX P1 Docs P2 Docs Learn Events
Replacing FSRW with stdio (notes and questions) — Parallax Forums

Replacing FSRW with stdio (notes and questions)

RaymanRayman Posts: 14,665
edited 2013-05-14 12:47 in Propeller 1
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:
#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

  • RaymanRayman Posts: 14,665
    edited 2013-05-13 09:03
    Now, here's my questions:

    When is the sd card actually mounted?
    What happens if it fails to mount?
  • RaymanRayman Posts: 14,665
    edited 2013-05-13 09:14
    In my defense, I merely copied that from the "filetest.c" demo...
  • RaymanRayman Posts: 14,665
    edited 2013-05-13 09:45
    Actually, I sometimes write it that way too.... It's instructive to hear a point of view on this though. Maybe I'll try to remember this.

    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?
  • tdlivingstdlivings Posts: 437
    edited 2013-05-13 10:01
    It would be better if sd_mount needed to be called and returned a FILE*
    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
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-05-13 10:24
    Rayman wrote: »
    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?
    I believe you can only use one SD card at a time. In theory, you could mount a card, use it for a while, unmount it, and then mount the other card. However, I don't think there is an unmount function.

    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.
  • RaymanRayman Posts: 14,665
    edited 2013-05-13 10:27
    Thanks. Guess I will have to get FSRW working in xmm-split mode if I want to have access to both uSD cards at the same time then...
  • RaymanRayman Posts: 14,665
    edited 2013-05-13 10:36
    I don't know if I'd change anything... Use of multiple SD is probably a rare thing.
    If I spent some time at it, I think I could make FSRW work for the second sd...
  • tdlivingstdlivings Posts: 437
    edited 2013-05-13 12:05
    David Betz wrote: »
    sd_mount mounts the filesystem. It doesn't open a file. You need to use fopen for that.

    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
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-05-13 12:23
    sd_mount should not return a FILE pointer. Even if it did, that would not be sufficient to support more than one SD card. Currently there is only one volume descriptor struct. We would need one for each SD card. We would also need a prefix to distinguish one SD card from another, like we use for FullDuplexSerial ( FDS: ), or SimpleSerial ( SSER: ). SD files use a null prefix, which makes it more natural for specifying file names. If we used a prefix for SD files you would have to specify it when opening a file, such as fopen("SD1:myfile.txt", "r"). However, to support multiple SD cards we would need to use unique prefixes. Or another possibility is to include the prefix in the path, such as /sd1/file1.txt or /sd2/file2.txt. The prefix or device pathname could be passed as an additional parameter to the mount routine.
  • tdlivingstdlivings Posts: 437
    edited 2013-05-13 12:41
    Dave
    No need to be sorry.
    I stand corrected on the issue,

    Tom
  • RaymanRayman Posts: 14,665
    edited 2013-05-13 13:24
    I'm still wondering about this line:
    #undef CALL_MOUNT

    Is this necessary?
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-05-13 13:34
    No, you don't need"#undef CALL_MOUNT". It was present in the original filetest.c code in case you needed to explicitly call the mount function. In that case the #undef was changed to #define, and one of the pre-defined pin definitions would be used, or a custom pin definition could be defined.
  • tdlivingstdlivings Posts: 437
    edited 2013-05-13 18:41
    Been experimenting with the SD card code an unless I execute
    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
  • RaymanRayman Posts: 14,665
    edited 2013-05-13 18:44
    What are you using for your "board" setting?
    Your board's .cfg file tells PropGcc which pins to use for SD card access...
  • tdlivingstdlivings Posts: 437
    edited 2013-05-13 19:09
    Using SimpleIDE and Simpletools with all the defaults, I changed nothing for
    my initial experiments with what Parallax announced last Monday.
    Taking a peek it is set for ActivityBoard and CMM memory model

    Tom
  • jazzedjazzed Posts: 11,803
    edited 2013-05-13 19:52
    David Betz wrote: »
    Maybe they have the Activity Board configuration file setup wrong. You shouldn't need the mount call.

    Andy didn't want to use the automated mounting. People who want to use the tutorials should stick to the script.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-05-14 06:08
    So, does that mean, when you are using 0-9-xx, even in project view, you have to do a manual sd_mount()? This is a big change, hopefully all these changes will be documented, and show what is different from SimpleIDE 0-8-5.

    Ray
  • jazzedjazzed Posts: 11,803
    edited 2013-05-14 06:21
    Rsadeika wrote: »
    So, does that mean, when you are using 0-9-xx, even in project view, you have to do a manual sd_mount()?

    No. You can do anything you like. Let's not confuse people following the tutorials though.
  • RaymanRayman Posts: 14,665
    edited 2013-05-14 11:55
    How do you call sd_mount explicitly? (without using simpletools.h)
  • RaymanRayman Posts: 14,665
    edited 2013-05-14 11:58
    Ok, I tried :

    _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...
  • RaymanRayman Posts: 14,665
    edited 2013-05-14 12:27
    Ok, this is starting to look like a real pain...

    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...
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-05-14 12:44
    The file driver currently contains only one volume descriptor struct, so it can only support one SD card right now. It would not be too hard to add a second volume descriptor, and then modify the mount routine to use it. The standard unix/linux way of handling multiple volumes is to specify a path for each volume. So the first volume could be mounted at the root directory, and the second one could be at /sd2. Or we could use drive letters, such as C: and D: like in Windows. The Windows method is actually a better fit for how PropGCC handles different device drivers.
  • RaymanRayman Posts: 14,665
    edited 2013-05-14 12:47
    With fsrw, when you mount, you can look at the return value to see if mount was successful.
    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....
Sign In or Register to comment.