Hello there,
I've been playing around with the SD card examples trying to get this functionality to work for an ATMEL SAM4S Xplained Pro and I've looked at the code for a SAM3x module which has SDcard support (and same pinout effectively), RL/FS drivers for the SAM4S pro, but I have been unable to get the finit() function to correctly initialize the card; it always returns 1.
Below is the File_Config.c
// CPU clock #define CPU_CLK 12000000UL // </e> // <e>Memory Card Drive 0 // ====================== // Enable Memory Card Drive [M0:] #define MC0_EN 1 // <o>Bus Mode <0=>SD-Native <1=>SPI // Define Memory Card bus interface mode. // SD-Native mode needs MCI peripheral. // SPI mode uses SD Card in SPI mode. #define MC0_SPI 0 // <o>File System Cache <0=>OFF <1=>1 KB <2=>2 KB <4=>4 KB // <8=>8 KB <16=>16 KB <32=>32 KB // Define System Cache buffer size for file IO. // Increase this number for faster r/w access. // Default: 4 kB #define MC0_CASZ 4 // <e>Relocate Cache Buffer // Locate Cache Buffer at a specific address. // Some devices like NXP LPC23xx require a Cache buffer // for DMA transfer located at specific address. #define MC0_RELOC 1 // <o>Base address <0x0000-0xFFFFFE00:0x200> // Define the Cache buffer base address. // For LPC23xx/24xx devices this is USB RAM // starting at 0x7FD00000. #define MC0_CADR 0x7FD00000 // </e> // <q>FAT Journal // Enable FAT Journal in order to guarantee // fail-safe FAT file system operation. #define MC0_FSJ 1 // <q>Default Drive [M0:] // Used when Drive letter not specified #define MC0_DEF 1
The MCI_SAM4S.c driver, which is largely unchanged, with only the following modified:
#define __DRV_ID mci0_drv #define __HSMCICLK 12000000UL /* HSMCI peripheral clock frequency */ #define __CPUCLK 12000000UL /* CPU clock frequency */
The SD card code which is simple enough
static void init_card (void) { U32 retv = 1; while (retv != 0) { /* Wait until the Card is ready*/ retv = finit ("M0:"); if (retv == 1) { printf ("SD/MMC Init Failed\n\r"); printf ("Insert Memory card and press key...\n\r"); //getkey (); } else { printf ("SD/MMC Card is Unformatted\n\r"); } } if (fformat ("") == 0) { printf ("Memory Card Formatted.\n\r"); printf ("Card Label is %s\n\r","KEIL"); } else { printf ("Formatting failed.\n\r"); } } /*---------------------------------------------------------------------------- * Create a file and fill it with some text *---------------------------------------------------------------------------*/ void cmd_fill (char *par) { char *fname, *next; FILE *f; int i,cnt = 1000; // fname = get_entry (par, &next); // if (fname == NULL) { // printf ("\nFilename missing.\n"); // return; // } // if (next) { // par = get_entry (next, &next); // if (sscanf (par,"%d", &cnt) == 0) { // printf ("\nCommand error.\n"); // return; // } // } init_card(); f = fopen ("test.txt", "w"); /* open a file for writing */ if (f == NULL) { printf ("\nCan not open file!\n"); /* error when trying to open file */ return; } for (i = 0; i < cnt; i++) { fprintf (f, "This is line # %d in file %s\n", i, fname); } fclose (f); /* close the output file */ printf ("\nFile closed.\n"); }