SD card example for XMC 4500 Relax kit

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

cross mob
Not applicable
Hi,

Is there any example for XMC 4500 relax kit on how to use to SD card?

I have tried the following examples, which was designed for hexagonal kit:

FATFS003_Example1
FATFS003_Example2
SLTHA001_Example1
SLTHA002_Example1
SLTHA002_Example2

I used the migration option in Dave 3 to make the pin out suits for XMC4500 Relax kit. However, none of those works! Any suggestion?

Thanks
0 Likes
22 Replies
Not applicable
Hi,

I tried the USBBL001_USBMS001_Example 1 and did some modifications:

main.c:
Line 133: f_chdrive (0) //instead of 1
Line 136: DResult = f_mount(0, &myfsObject); //instead of 1

because the SD is configurated as drive 0 in FATFS004_0 App.

I hope it works for you, too!
Regards,
MTR
0 Likes
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
queksung wrote:
Hi,

Is there any example for XMC 4500 relax kit on how to use to SD card?

I have tried the following examples, which was designed for hexagonal kit:

FATFS003_Example1
FATFS003_Example2
SLTHA001_Example1
SLTHA002_Example1
SLTHA002_Example2

I used the migration option in Dave 3 to make the pin out suits for XMC4500 Relax kit. However, none of those works! Any suggestion?

Thanks


Please note that your SD card is non HC, as it is not supported. What is the error code feedback after mount()?

/* Mount the drive */
Result = mount(0, &myfsObject);
if(Result != DAVEApp_SUCCESS)
{
error = 1;
}
0 Likes
Not applicable
I do not understand. Elsewhere I have see official answer from Infineon that XMC4500 also works with SDHC cards in public and in writing. Does it mean that the SD controller is not a SDHC controller ? or does it mean that SDHC function was not implemented in this app ? Thanks very much.

I give the answer myself. XMC4500 is able to work with SDHC. The problem was something in software of this example.
0 Likes
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
You are RIGHT...:)

The Secure Digital/ MultiMediaCard interface (SDMMC) of the XMC4500 provides an interface between SD/SDIO/MMC cards and the AHB bus. The CPU is programmed to support SD, SDIO, SDHC and MMC cards, and can operate up to 48 MHz. The SDMMC module is able to transfer a maximum of 24 MB/sec for SD cards and 48 MB/sec for MMC cards.
0 Likes
Not applicable
Hi Travis.
I installed DAVE 3.1.2 and run example USBD_MS_Example1.
Detection as Mass Storage is ok... but transfer speed is too low (300KB / Sec)
On the contary commercial usb storage device has its speed as 10MB / Sec.
Document says that "The SDMMC module is able to transfer a maximum of 24MB/S for SD cards....."
UI Editor for SDMMC003 doesn't have any configuration for clock frequency.

Then how do I change clock frequency for that?

Best regards.
0 Likes
Not applicable
hy guys,
i'm working also with the xmc4500 board and i want to implement an SD Card for a datalogging application.
Do you know where I can find some examples for the SD-Card?

Best regards
0 Likes
Not applicable
I would also be very thankful if someone had an example to share.
0 Likes
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
canibalimao wrote:
I would also be very thankful if someone had an example to share.


Hi,

The latest DAVE4 release has already provided an App for SDMMC. Can you give it a try?

Best Regards
Travis
0 Likes
Not applicable
Travis wrote:
Hi,

The latest DAVE4 release has already provided an App for SDMMC. Can you give it a try?

Best Regards
Travis


Yes, the APP is there. I found it. The question is that I don't know how to mount the card.


EDIT: I've found and (hidden ???) help file with the following sample code:

 #include                  //Declarations from DAVE Code Generation (includes SFR declaration)

uint8_t send_data[1024];
uint8_t read_data[1024];
volatile uint32_t count;
volatile uint32_t delay;

SDMMC_BLOCK_ERASE_ADDRESS_t erase_address =
{
.start_address = 1004U,
.end_address = 1005U
};

int main(void)
{
DAVE_STATUS_t status;
SDMMC_BLOCK_STATUS_t sdmmc_status;
uint32_t buffer;
status = DAVE_Init(); /* Initialization of DAVE APPs */

sdmmc_status = SDMMC_BLOCK_Initialize(&SDMMC_BLOCK_0);

if (sdmmc_status == SDMMC_BLOCK_STATUS_SUCCESS)
{
do
{
send_data[count] = count;
} while (count++ < 1024);

sdmmc_status = SDMMC_BLOCK_WriteBlock(&SDMMC_BLOCK_0, send_data, 1004U, 2U);

if (sdmmc_status == SDMMC_BLOCK_STATUS_SUCCESS)
{
sdmmc_status = SDMMC_BLOCK_ReadBlock(&SDMMC_BLOCK_0, read_data, 1004U, 2U);

if (sdmmc_status == SDMMC_BLOCK_STATUS_SUCCESS)
{
for (count = 0; count < 1024; count++)
{
if(read_data[count] != send_data[count])
status = DAVE_STATUS_FAILURE;
}

sdmmc_status = SDMMC_BLOCK_Ioctl(&SDMMC_BLOCK_0, SDMMC_BLOCK_CTRL_TRIM, &erase_address);
sdmmc_status |= SDMMC_BLOCK_ReadBlock(&SDMMC_BLOCK_0, read_data, 1004U, 2U);

for (count = 0; count < 1024; count++)
{
if(read_data[count] != 0U)
status = DAVE_STATUS_FAILURE;
}
}

}
sdmmc_status |= SDMMC_BLOCK_Ioctl(&SDMMC_BLOCK_0, SDMMC_BLOCK_CTRL_EJECT, &buffer);
}

if((sdmmc_status != SDMMC_BLOCK_STATUS_SUCCESS) || (status != DAVE_STATUS_SUCCESS))
{
while(1)
{
DIGITAL_IO_ToggleOutput(&DIGITAL_IO_0);
for (delay = 0xFFFFFU; delay != 0U; delay--)
{
}
}
}

if(status == DAVE_STATUS_FAILURE)
{
/* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
XMC_DEBUG("DAVE APPs initialization failed\n");

while(1U)
{

}
}

/* Placeholder for user application code. The while loop below can be replaced with user application code. */
while(1U)
{

}
}
0 Likes
Not applicable
Hello,

where do you found the app? I use Dave 4.2.2 but I can't find the app.

Kind regards
Kurt
0 Likes
Not applicable
You must find 2 Beta APPS and install them. One is FATFS and the other (it's required by the first one) is, if I not wrong, SDMMC app, but you can confirm this when you try to compile the project.

If you can't find it tell me that I will confirm every name when I have my work computer in front of me.
0 Likes
Not applicable
Just to update the previus post with an example code, I've found another example code for the FATFS APP.

#include            //Declarations from DAVE Code Generation (includes SFR declaration)

int main(void)
{
FATFS fs; /* File system object (volume work area) */
FIL fil; /* File object */
FRESULT res; /* API result code */
UINT bw,br; /* Bytes written */
char buff[20];

DAVE_STATUS_t status;

status = DAVE_Init();

if(status == DAVE_STATUS_SUCCESS)
{
/* Register work area */
res = f_mount(&fs, "0", 1);

if (res == FR_OK)
{
/* Create a new directory */
res = f_mkdir("XMC4500");
if ((res == FR_OK) || (res == FR_EXIST))
{
/* Create a file as new */
res = f_open(&fil, "XMC4500/hello.txt", FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
if ((res == FR_OK) || (res == FR_EXIST))
{
/* Write a message */
res = f_write(&fil, "Hello, World!\r\n", 15, &bw);
if (res == FR_OK )
{
res = f_lseek(&fil, 0);
/* Read the buffer from file */
res = f_read(&fil, &buff[0], 15, &br);
if(res == FR_OK)
{
/* Go to location 15 */
res = f_lseek(&fil, 15);
if(res == FR_OK)
{
/* Add some more content to the file */
res = f_write(&fil, "\nWelcome to Infineon", 20, &bw);
if(res == FR_OK)
{
f_close(&fil);
}
}
}
}
}
}
}
}

while (1)
{
}

}


Remove the SD card and read the SD card content using any card reader.
It should consists:
1. Directory named "XMC4500"
2. Inside this directory a file named with "hello.txt"
The content within this file should be:
Hello world!
Welcome to Infineon


Hope this helps someone with the same issues I had.
0 Likes
User10215
Level 4
Level 4
First like received
Hi Kurt,

at first I was also confused about where the new Apps were. This thread here explains how to get the Apps you're missing:

http://www.infineonforums.com/threads/3810-Missing-Applications

Also bear in mind that the sd card app is a beta version and you can only find it in your "add new app"-window when "Hide beta versions" is unchecked!

If you need a file-system you can use the "FATFS"-App. An example can be found if you add the app and then right-click on it to select "APP Help". There is an example when you click on "Usage" in the following window.

Regards,
Niclas
0 Likes
Not applicable
SD_Block does not work in combination with fatfs if use sd mode. Why is it like that?
0 Likes
Not applicable
Basic FATFS use works for me when using FATFS v. 4.0.10 and SDMMC_BLOCK v. 4.0.10. See here: https://www.infineonforums.com/threads/4175-FATFS-problems-f_write-causes-FR_DISK_ERR
0 Likes
Not applicable
yes, thanks? are you using sd mode? My hardware is fixed to sd mode.
0 Likes
Not applicable
I am using SD mode, yes.
0 Likes
Not applicable
which dave version do you use? I am using dave 4.2.6 In my case, both of the apps are of version 4.0.10. I cannot select Sd mode at all, if FATFS is used? Please see picture.


2133.attach
0 Likes
Not applicable
It could be because you're using RTOS - SDMMC_BLOCK app doesn't support RTOS. Are you using a chip that supports SD mode?
0 Likes
Not applicable
No, i saw that you used dave 4.2.2. So I digged out dave_4_2_2_installer somewhere. Now I can generate the code with fatfs, sdmmc_block and rtos. I donot know yet if it is going to work. Thanks again.


Update: I used your main.c. I got error. The program stopped since a interrupt is active, and it uses the default handler ( i.e. endless loop).

update: I delete the rtos now. It works. So I think it was because the rtos is not initialized? I will try it and give feedback.

Thanks a lot for the help over weekday.


Update: There are problems with CMX_RTX port. See other posts about this issue.
0 Likes
Not applicable
I'm not sure what code you talk about - the code I posted doesn't depend on interrupts. But it seems you got everything figured out 🙂
0 Likes
User20173
Level 2
Level 2
First solution authored
removed post
0 Likes