4 Replies Latest reply on Dec 18, 2019 7:08 AM by PhMa_4608351

    How to select SD card using emFile? Dealing with multiple SD cards.

    PhMa_4608351

      Hello everyone.

       

      I currently have 2 SD cards connected to my development board and plan on having an additional 2 in the future. Although emFile can be configured to have multiple SD cards, I am not sure how to write to each one.

       

      This is an example of how I write to a text document in SD card 0:

       

      FS_Write(pFile[0], text, strlen(text));

       

      Where pFile[0] represents the text file inside the SD card. I cannot seem to find any argument in any of the emFile functions that allow me to choose which SD card I would like to write to, only ones which let me choose which files within the first SD card to write to. The answer is probably obvious and I am just being silly, but how do I select which SD card to write to?

       

      Thanks!

      - Phoenix

        • 1. Re: How to select SD card using emFile? Dealing with multiple SD cards.
          LePo_1062026

          Phoenix,

           

          Hopefully this can help.

           

          Configuring the additional SDs

          Double-click on your emFile component in TopDesign.  The "Configure" window will come up:

          Select "Number of SD cards" to a higher value.  For example "2".

           

          HW Port Assignment

          Go to your project's cydwr  "Pins" tab.  You'll see some addition SPI pins show up that need to be assigned to the second SD card.

          Make sure the proper ports are assigned to the HW or your second SD card.

           

          Accessing the other SD cards in Application SW

          Next:  When you want to access a different card, you select a different "UnitNum" in the qualified file name in the emFile API calls.

           

          A fully qualified file name looks like:

          [DevName:[UnitNum:]][DirPathList]Filename

           

          Len

          1 of 1 people found this helpful
          • 2. Re: How to select SD card using emFile? Dealing with multiple SD cards.
            PhMa_4608351

            So to retrieve the [DevName:[UnitNum:]] part I believe I can use:

             

            char sdVolName[4][12];     // Buffer that will hold the Volume names of 4 SD cards

            FS_GetVolumeName(0, &sdVolName[0][0], 12);

             

            To string together with the [DirPathList]Filename, would the full file name be:

            "VolumeName\\DIR\\FILE.TXT" ?

             

            Thanks Len,

            - Phoenix

            • 3. Re: How to select SD card using emFile? Dealing with multiple SD cards.
              LePo_1062026

              Phoenix,

               

              I've checked the "UM02001_emFile_V322c.pdf" which is the user guide for emFile.  I do not believe substituting the VolumeName for the DevName::[UnitNum:] will work.  You can try it.  If it works ... great!

               

              Note: They don't use "\\" as directory separators.  Only '\'.  The "\\" is used inside the double quotes because the '\' is considered an escape character.  Therefore => "VolumeName\\DIR\\FILE.TXT"  translates to   VolumeName\DIR\FILE.TXT  as a string.

               

              Len

              • 4. Re: How to select SD card using emFile? Dealing with multiple SD cards.
                PhMa_4608351

                Thanks for the help Len, I figured out how the path name works if anyone's interested.

                 

                The volume name of an SD card will usually end up looking like:  mmc:0:

                Where the integer represents the index of the SD card, in this case 0.

                 

                The user guide for SEGGER's emFile states that valid values for the volume name have the structure:  [DevName:[UnitNum:]]

                You do not need to use a "\" after the volume name, as the colons included in the volume name already separate itself from the path. The full path name for a file in a directory inside SD card 0 will look like:

                "mmc:0:DIR\FILE.TXT"  (assuming the DevName is "mmc")

                1 of 1 people found this helpful