Shop OBEX P1 Docs P2 Docs Learn Events
C3 and SD — Parallax Forums

C3 and SD

RsadeikaRsadeika Posts: 3,837
edited 2014-01-24 11:16 in Propeller 1
I was just testing out my C3 board, just to see if it still works, and I tried too get the SD mounted, how is that being done now days. It seems like the sd_mount() is not working for me. Is that in the documentation some where?

Ray
«1

Comments

  • jazzedjazzed Posts: 11,803
    edited 2013-12-08 15:44
    Rsadeika wrote: »
    I was just testing out my C3 board, just to see if it still works, and I tried too get the SD mounted, how is that being done now days. It seems like the sd_mount() is not working for me. Is that in the documentation some where?

    Ray
    API Documentation for sd_mount is in Simple Libraries, simpletools.

    I recommend formatting your SD card or doing an error check.

    Error-Check: Insert SD card into PC. Right click on it (windows) and choose properties. Click Tools tab, and run Error-Checking.

    My SD card would not work until I did error-check.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-12-08 16:02
    Thanks jazzed.
    Out of curiosity, which of the Parallax boards support XMM-SINGLE External RAM and XMM-Split ... modes, I just tried using those on the C3, and was not successful. It seemed like before everything use too work so smoothly, now it is...

    Is SimpleIDE becoming a tool just for the Activity and PropBOE boards? To use all the other boards you have too go through all kinds of contortions... I better shut up before I am asked to leave.

    Ray
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-12-08 16:04
    The documentation says that sd_mount is only for SD cards with a simple 4-pin interface. A C3 board uses 5 pins. So how does this work with a C3 board.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-12-08 16:14
    I even dug up the Dave Hein filetest.c program, and that does not work anymore, something must of changed in <sys/sd.h>. Hopefully on Monday Parallax will be announcing a new IDE for all the other boards.

    Ray
  • jazzedjazzed Posts: 11,803
    edited 2013-12-08 16:15
    Rsadeika wrote: »
    Thanks jazzed.
    Out of curiosity, which of the Parallax boards support XMM-SINGLE External RAM and XMM-Split ... modes, I just tried using those on the C3, and was not successful. It seemed like before everything use too work so smoothly, now it is...

    Is SimpleIDE becoming a tool just for the Activity and PropBOE boards? To use all the other boards you have too go through all kinds of contortions... I better shut up before I am asked to leave.

    Ray
    No one will ask you to leave. :)

    You're my best customer.

    As I said before, Simple Libraries are not compiled for xmm-single and xmm-split. You can compile them yourself by opening the libraries you care about and selecting xmm-single then compile, and xmm-split then compile.

    Parallax wanted Simple View for the education program. Maybe we can convince Andy to precompile all versions of libraries for distribution (with a Makefile).
  • jazzedjazzed Posts: 11,803
    edited 2013-12-08 16:19
    Dave Hein wrote: »
    The documentation says that sd_mount is only for SD cards with a simple 4-pin interface. A C3 board uses 5 pins. So how does this work with a C3 board.
    That's a case where the default driver must be used as described here:
    https://sites.google.com/site/propellergcc/documentation/libraries#TOC-Console-and-File-system-driver-initialization

    Andy doesn't cover the C3 board in his tutorials.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-08 16:28
    Rsadeika wrote: »
    Thanks jazzed.
    Out of curiosity, which of the Parallax boards support XMM-SINGLE External RAM and XMM-Split ... modes, I just tried using those on the C3, and was not successful. It seemed like before everything use too work so smoothly, now it is...

    Is SimpleIDE becoming a tool just for the Activity and PropBOE boards? To use all the other boards you have too go through all kinds of contortions... I better shut up before I am asked to leave.

    Ray
    The C3 supports xmmc, xmm-single, and xmm-split. It was the reference platform when these modes were developed. However, your program needs to fit in the selected mode. For xmmc and xmm-split this means that the code must be < 1MB. For xmm-split the data must be < 64k. For xmm-single the code and data together must be < 64k.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-08 16:48
    Rsadeika wrote: »
    Thanks jazzed.
    Out of curiosity, which of the Parallax boards support XMM-SINGLE External RAM and XMM-Split ... modes, I just tried using those on the C3, and was not successful. It seemed like before everything use too work so smoothly, now it is...

    Is SimpleIDE becoming a tool just for the Activity and PropBOE boards? To use all the other boards you have too go through all kinds of contortions... I better shut up before I am asked to leave.

    Ray
    The C3 is the only Parallax board that supports any XMM mode unless you count the XMMC support for >32k EEPROMs or the SD card. The EEPROM support is pretty good but the SD card support is slow because it is forced to use 512 byte cache lines to match the size of an SD sector.

    The C3 should support all of the XMM modes assuming that the program you're trying to run fits. The main problem with fitting is with XMM-SINGLE where the entire program and data must fit in < 64k (the size of the two SRAM chips on the C3).
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-12-08 18:30
    Rsadeika wrote: »
    I even dug up the Dave Hein filetest.c program, and that does not work anymore, something must of changed in <sys/sd.h>. Hopefully on Monday Parallax will be announcing a new IDE for all the other boards.
    Ray,

    I tried building filetest.c under SimpleIDE, and it failed for me with an unresolved symbol "getcnt". Is this the error you're getting? I changed "getcnt()" to "CNT", and it works OK. Select "C3F" for the board type in SimpleIDE.

    Dave
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-08 19:39
    Dave Hein wrote: »
    Ray,

    I tried building filetest.c under SimpleIDE, and it failed for me with an unresolved symbol "getcnt". Is this the error you're getting? I changed "getcnt()" to "CNT", and it works OK. Select "C3F" for the board type in SimpleIDE.

    Dave
    C3F is fine if you're planning to use XMMC mode but it won't work for XMM-SINGLE or XMM-SPLIT. The "F" in C3F means "flash only".
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-12-09 02:22
    I am trying to create a minimal program to mount the SD, and write something to it. The below program compiles, but that is all that it does. I must be missing some important piece of code, but I do not know what that is.

    Ray
    /*
      test.c
    */
    #include "simpletools.h"
    #include <dirent.h>
    #include <sys/sd.h>
    
    FILE *sp;
    
    void mount()
    {
       print("Load and mount SD: \n");
        _SD_Params* mountParams = (_SD_Params*)-1;
    
        static _SD_Params params =
        {
            AttachmentType: _SDA_SerialDeMUX,
            pins:
            {
                SerialDeMUX:
                {
                    MISO: 10,    // The pin attached to the SD card's MISO or DO output
                    CLK:  11,    // The pin attached to the SD card's CLK or SCLK input
                    MOSI: 9,     // The pin attached to the SD card's MOSI or DI input
                    CLR:  25,    // The pin attached to the counter's reset/clear pin
                    INC:  8,     // The pin attached to the counter's clock/count pin
                    ADDR: 5,     // The SD card's demux address (the counter's count)
                }
            }
        };
        mountParams = &params;
    }
    
    
    int main()
    {
      // Add startup code here.
      mount();
    
      sp = fopen("test1.txt", "w");
      
     
      while(1)
      {
        // Add main loop code here.
        sp = fopen("test1.txt", "a");
        fwrite("TEST\r\n",1,6,sp);
    //    print("This is a test line\n");
        fclose(sp);
        pause(5000);
        
      }  
    }
    
    
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-12-09 06:42
    Ray,

    You are missing a few key pieces of code in your program. At the beginning of your program add the following lines:
    #include <stdio.h>
    
    extern _Driver _SimpleSerialDriver;
    extern _Driver _FileDriver;
    
    /* This is a list of all drivers we can use in the
     * program. The default _InitIO function opens stdin,
     * stdout, and stderr based on the first driver in
     * the list (the serial driver, for us)
     */
    _Driver *_driverlist[] = {
      &_SimpleSerialDriver,
      &_FileDriver,
      NULL
    };
    
    At the end of your mount routine add this:
        mountParams = &params;
        uint32_t mountErr = dfs_mount(mountParams);
        if (mountErr)
        {
            printf("Mount error: %d\n", mountErr);
            exit(1);
        }
    
    That should fix your program.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-12-09 08:13
    Thanks Dave, that did the trick.

    Since the C3 is an orphan, in terms of C support, I think I will have to create a C3.c file, and start putting in the necessary drivers as they become available. I will probably have to do the same thing(DNA.c) with the DNA-RTC board, another orphan, also. Having the drivers file added in for compile time will also allow me to use an XMM mode without any problems, I hope. "Back to the Future"...

    Ray
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-12-09 08:31
    It seems like it would be a good idea to add a more complete version of sd_mount to the tutorials library, especially since Parallax sells the C3 in their online store. It could be called sd_mount_expanded that would take 8 parameters, where the first one would define whether the interface is simple, serial or parallel. Or there could be two additional routines called sd_mount_serial and sd_mount_parallel, which would be used for the other two types of interfaces.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-12-09 08:49
    OK, now I just got to my first hurdle. When I ran the new setup in CMM mode, it worked as expected. When I switched it to XMMC mode, the SD did not get mounted (error 6). Now, I guess the other option is to run fsrw26.spin through the spin2cpp program, and then use the result of that for access to the SD. I guess I will have two mount scenarios, mount() for a CMM mode, and an sdfs_mount() for the XMMC mode. I think that will not get to confusing.

    Ray
  • jazzedjazzed Posts: 11,803
    edited 2013-12-09 08:51
    Actually, leaving out the sd_mount call entirely fixes the problem as long as you follow the example on the link I mentioned in post #7.

    In that case the mount is handled automatically thanks to David Betz. I was never able to convince Andy to use that method though.

    Ray, can you run any program from XMMC ?
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-09 09:02
    Rsadeika wrote: »
    Since the C3 is an orphan, in terms of C support, I think I will have to create a C3.c file, and start putting in the necessary drivers as they become available.
    The C3 is not supposed to be an orphan. As I said earlier, it was the reference platform we used when we first started working on PropGCC. I'll have to try the SD support to see what might be going wrong. Originally the SD driver was part of the C3 cache driver but was separated out at some point. Maybe that introduced this problem. Anyway, it's supposed to work and we'll fix it to make it work.
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-12-09 10:31
    Ray, you might want to try getting the filetest.c program to work first, and then use the relevant code from it for your application. If you look at the beginning of filetest.c you'll see the following comments:
    // The loader will automatically initialize the pin settings for the SD card
    // if the board CFG file contains the SD pin description, and the ELF file
    // contains the symbol table (i.e., the -s option was not specified).
    // Otherwise, the mount function can be called by defining CALL_MOUNT and one
    // one of the board types listed below.  You can also specify your own SD pin
    // configuration by editing one of the examples that most closely matches your
    // specific board.
    
    As long as you select either C3 or C3F for the board type you shouldn't have to perform the mount yourself.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-12-09 11:12
    @jazzed, I can run programs in XMMC, like a blinker program.

    @Dave, I can run filetest.c in CMM mode, but in XMMC mode the SD does not get mounted.
    you shouldn't have to perform the mount yourself.
    That is what I thought, but when I tried it that way the SD was not mounted.

    Ray
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-12-09 11:17
    Post your code and the *.side file.
  • jazzedjazzed Posts: 11,803
    edited 2013-12-09 13:44
    This example from post #7 works fine for me with C3 board type C3F and CMM or XMMC mode.

    This one does not use Simple Libraries.
    /**
     * @file file.c
     * This is the main file program start point.
     */
    #include <stdio.h>
    #include <propeller.h>
    
    extern _Driver _SimpleSerialDriver;
    extern _Driver _FileDriver;
    
    /* This is a list of all drivers we can use in the
     * program. The default _InitIO function opens stdin,
     * stdout, and stderr based on the first driver in
     * the list (the serial driver, for us)
     */
    _Driver *_driverlist[] = {
      &_SimpleSerialDriver,
      &_FileDriver,
      NULL
    };
    
    /**
     * Main program function.
     */
    void main(void)
    {
        char name[20];
        FILE *fp1;
    
        waitcnt(CLKFREQ+CNT); // pause for terminal to open
    
        sprintf(name,"Test"); // test file name
        printf("Opening file '%s'.\n", name);
    
        if((fp1=fopen(name,"w+"))==0) {
            printf("Can't open file %s.\n",name);
        }
        else {
            printf("File was opened.\n");
            fclose(fp1);
        }
        while(1);
    }
    
    This one does use Simple Libraries.
    /**
     * @file file.c
     * This is the main file program start point.
     */
    #include "simpletools.h"
    
    extern _Driver _NullDriver;
    extern _Driver _FileDriver;
    
    /* This is a list of all drivers we can use in the
     * program. The default _InitIO function opens stdin,
     * stdout, and stderr based on the first driver in
     * the list (the serial driver, for us)
     */
    _Driver *_driverlist[] = {
      &_NullDriver,
      &_FileDriver,
      NULL
    };
    
    /**
     * Main program function.
     */
    void main(void)
    {
        char name[80] = "Test.txt";
        FILE *fp1;
    
        putStr("Opening file ");
        putLine(name);
    
        if((fp1=fopen(name,"r"))==0) {
            putStr("Can't open file ");
            putLine(name);
        }
        else {
            fread(name, 1, 80, fp1);
            putLine("File was opened.\n");
            putLine(name);
            fclose(fp1);
        }
        while(1);
    }
    
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-09 20:22
    I'm not sure why you aren't able to get filetest working on the C3. Here is the output that I got when I tried running it in XMMC mode using the C3F cache driver under release_1_0.
    propeller-load -bc3f filetest.elf -r -t
    Propeller Version 1 on /dev/cu.usbserial-A8004ILf
    Patching __cfg_sdspi_config1 with 090a0b13
    Patching __cfg_sdspi_config2 with 19080005
    Loading the serial helper to hub memory
    10392 bytes sent                  
    Verifying RAM ... OK
    Loading cache driver 'c3_cache_flash.dat'
    1620 bytes sent                  
    Loading program image to flash
    38556 bytes sent                  
    Loading .xmmkernel
    1736 bytes sent                  
    [ Entering terminal mode. Type ESC or Control-C to exit. ]
    Commands are help, cat, rm, ls, ll, echo, cd, pwd, mkdir and rmdir
    
    > ls
    propsd        ~1.tra        test2.bas     trashe~1      spotli~1
    blink.bas     test.bas      autorun.pex
    
    > cat blink.bas
    10 high(15)
    15 for x=1 to 10
    20 toggle(15)
    30 pause(500)
    40 next x
    
    > 
    
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-12-10 01:32
    Since the top three "C" gurus say it is working for them...

    I am going to see if I can figure this out for myself, I am most certain that it is some minute detail that I overlooked that is causing the problem. After all it used to work before without any problems, sorry about the big fuss.

    While I am doing that I will have to give some more thought as to the best way to get "C" drivers for the other things on the C3 board, like A/D conversion, maybe some functional servos, and what else? Oh, have them work in XMM mode. I am still looking for way to access cogs in XMM mode, something a lay person can understand and work with.

    Ray
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-12-10 05:49
    I did some more testing of the filetest.c program, and I got it to work as expected. The habit that I got myself into is, I start all my projects in Simple View, which means the project uses simpletools.h, and that does not mix well with some programs like filetest.c. And using that approach you will not get anything too work in XMM mode, maybe a blinker program will work.

    Simpletools has a lot of time saving functions, maybe at some point they will be added to propeller.h, and then you would be able to use the XMM mode without any problems. As an example, I have been using fwrite() to write to the SD, in Simple View, now I do not know if that is strictly simpletools function or is it available without simpletools. It is almost like you are going to have two sets of tools, and two learning strategies, once you move to Project View status then you will have to learn how too use a new set of tools. I guess in a nutshell simpletools is not a subset propeller.h.

    Now I am not so sure about SimpleIDE, maybe SimpleIDE should just be Simple View, and have a separate IDE for the regular "C" programming.

    Ray
  • jazzedjazzed Posts: 11,803
    edited 2013-12-10 06:52
    One of the examples I gave uses simpletools.h. It works fine.
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-12-10 06:58
    Ray, the problem isn't with "Simple View" versus "Project View", but it has to do with how sd_mount works. I tried running the "SD with Tests" example program on my C3, and ran into problems like you did. Since the sd_mount function only supports a simple 4-pin SD interface it doesn't work with C3. I commented out the call to sd_mount, and relied on the loader to initialize the file driver by specifying C3F as the "Board Type". Of course, you have to switch to project view to do this.

    However, just setting the board type is not enough. You also have to have the file driver in your file list. You can either define your own driver list, which would include the serial driver and the file driver, or you can add the file driver by calling add_driver. I wasn't aware of the add_driver routine before, but that's how sd_mount does it.

    I replaced the call to sd_mount in "SD with Tests" with the following code, and it works!
    #ifdef CALL_SD_MOUNT
      int erc = sd_mount(DO, CLK, DI, CS);        // Mount SD card
    #else
      int erc = 0;
      extern _Driver _FileDriver;
      add_driver(&_FileDriver);
    #endif
    
    If you have a board with a simple 4-pin SD interface you could define CALL_SD_MOUNT along with SO, CLK, DI and CS, and you don't need to tell SimpleIDE your board type. However, if your board does not have a simple 4-pin SD interface you must select your board type in SimpleIDE, and don't define CALL_SD_MOUNT. Or you could write your own mount routine, which is what filetest.c does.

    I realize this is very confusing. I think the confusion could be reduced if the sd_mount routine accommodated the serial and parallel SD interface types in addition to the simple interface type.

    EDIT: So I'm suggesting that sd_mount have 8 parameters, where the first parameter is the interface type, and the remaining 7 parameters are used to convey the pin numbers and CS selection value. If the first parameter doesn't match either the simple, serial or parallel values sd_mount could just call add_driver without calling dfs_mount, and it would rely on the loader to initialize the file system.
  • RsadeikaRsadeika Posts: 3,837
    edited 2013-12-10 08:26
    @jazzed, I tried your simpletools example, I just copy/paste into a Simple View Project, and the SD had a test.txt file, when I ran the program it came up with a "Can't open file". So, I am not sure what happened there. I did notice that when some files get created by one program, sometimes a different program cannot open the file. That happened with C3 test that I did using filetest.c, once I formatted the SD then the program ran as expected. Is this a new problem showing up, some files are getting corrupted for some reason?

    Ray
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-10 08:39
    I think sd_mount must be a part of the simple tools library. It isn't part of the standard PropGCC library. Instead, there is a function called dfs_mount that will allow any of the CS protocols to be used including the one implemented on the C3.
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-12-10 08:55
    Yes, sd_mount is in the simple tools library. On my Windows machine it is in Documents/SimpleIDE/Learn/"Simple Libraries"/Utility/libsimpletools/source/sddriverconfig.c. I've attached it below. I think my previous post explained what the problem is.

    After thinking about it for a while this could be fixed by allowing sd_mount to have a variable number of parameters. If four parameters are specified it would configure for a simple interface like it currently does. If 6 parameters are specified it will configure for a serial SD interface, and if 7 parameters are specified it would configure for parallel. If no parameters are specified it would use the configuration set by the loader. Doing it this way will allow sd_mount to be backwards compatible with the current use for a simple serial interface.
    c
    c
    705B
  • jazzedjazzed Posts: 11,803
    edited 2013-12-10 09:27
    Did you Error-Check (or chkdsk) your SDCard like I suggested earlier ?

    I'm not sure about this, but it may be necessary to add a null driver entry to the list like below for using simpletools.h .
    I'll update the code listing.
    /**
     * @file file.c
     * This is the main file program start point.
     */
    #include "simpletools.h"
    
    
    extern _Driver _NullDriver;
    extern _Driver _FileDriver;
    
    
    /* This is a list of all drivers we can use in the
     * program. The default _InitIO function opens stdin,
     * stdout, and stderr based on the first driver in
     * the list (the serial driver, for us)
     */
    _Driver *_driverlist[] = {
      &_NullDriver,
      &_FileDriver,
      NULL
    };
    


    Rsadeika wrote: »
    @jazzed, I tried your simpletools example, I just copy/paste into a Simple View Project, and the SD had a test.txt file, when I ran the program it came up with a "Can't open file". So, I am not sure what happened there. I did notice that when some files get created by one program, sometimes a different program cannot open the file. That happened with C3 test that I did using filetest.c, once I formatted the SD then the program ran as expected. Is this a new problem showing up, some files are getting corrupted for some reason?

    Ray
Sign In or Register to comment.