Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 5, 3 & 1 Forum Discussions

PhMa_4608351
Level 2
Level 2
First like received First like given

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

0 Likes
1 Solution
Len_CONSULTRON
Level 9
Level 9
500 solutions authored 1000 replies posted 750 replies posted

Phoenix,

Hopefully this can help.

Configuring the additional SDs

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

pastedImage_0.png

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.

pastedImage_0.png

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

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

4 Replies
Len_CONSULTRON
Level 9
Level 9
500 solutions authored 1000 replies posted 750 replies posted

Phoenix,

Hopefully this can help.

Configuring the additional SDs

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

pastedImage_0.png

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.

pastedImage_0.png

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

Len
"Engineering is an Art. The Art of Compromise."

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

0 Likes

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

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

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")