SD Card on SPI in SAME70 Xplained + IO1 Explained

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all.

I need reconfigurate example for SD card from MCI to SPI on expand board IO1 Explained.

I only added CONF_BOARD_SPI and SD_MMC_SPI_MODE in conf_board.h and I removed SDIO_SUPPORT_ENABLE.

I have problem with sd_mmc_check(0). I don't know what I have to do else for switch SD card from mci to spi.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is different question. Default example is for MCI, not for SPI, and he has totaly another problem then me (I know it because I HAD the same problem with MCI). MCI works for me, SPI not.

Last Edited: Thu. Sep 14, 2017 - 12:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jackxl wrote:
he has totaly another problem then me 

and yet he has "totally the same" username as you ?!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I didn't notice, that previous question was mine. It is right...So, I can tell you, that this is realy different question...Don't discuss about "stupidity" and help me !

Last Edited: Fri. Sep 15, 2017 - 06:00 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I SOLVED it. Alone ! Again ! This forum is useless for me, but I give you my solution.

 

1) Add SPI Example from Example projects (File->New->Example Projects).

2) Add SD Card component from ASF with SPI settings

3) Add symbol ACCESS_MEM_TO_RAM_ENABLED to Project -> Properties -> Symbol

4) Add FatFS service from ASF

5) This will be in main()

 

char test_file_name[] = "0:sd_mmc_test20170921_1049.txt";

Ctrl_status status;

FRESULT res;

FATFS fs;

FIL file_object;

// Initialize the sleep manager

sleepmgr_init();

/* Initialize the SAM system. */

sysclk_init();

board_init();

 

///* Initialize the console UART. */

configure_console();

 

ioport_set_pin_dir(SPI0_NPCS1_GPIO,IOPORT_DIR_OUTPUT);

ioport_set_pin_mode(SPI0_NPCS1_GPIO,IOPORT_MODE_PULLUP) ;

ioport_set_pin_level(SPI0_NPCS1_GPIO,true);

 

spi_master_initialize();

pmc_enable_periph_clk(ID_SPI0);

sd_mmc_init();

6) Comment or remove definition of SD_MMC_0_CD_GPIO in .._xplained.h

7) Then add this code to main(), but only do..while cycle is necessary

while (1)

{

printf("Please plug an SD, MMC or SDIO card in slot.\n\r");

 

/* Wait card present and ready */

do {

status = sd_mmc_test_unit_ready(0);

if (CTRL_FAIL == status) {

printf("Card install FAIL\n\r");

printf("Please unplug and re-plug the card.\n\r");

while (CTRL_NO_PRESENT != sd_mmc_check(0)) {

}

}

} while (CTRL_GOOD != status);

 

printf("Mount disk (f_mount)...\r\n");

memset(&fs, 0, sizeof(FATFS));

res = f_mount(LUN_ID_SD_MMC_0_MEM, &fs);

if (FR_INVALID_DRIVE == res) {

printf("[FAIL] res %d\r\n", res);

goto main_end_of_test;

}

printf("[OK]\r\n");

 

printf("Create a file (f_open)...\r\n");

test_file_name[0] = LUN_ID_SD_MMC_0_MEM + '0';

res = f_open(&file_object,

(char const *)test_file_name,

FA_CREATE_ALWAYS | FA_WRITE);

if (res != FR_OK) {

printf("[FAIL] res %d\r\n", res);

goto main_end_of_test;

}

printf("[OK]\r\n");

 

printf("Write to test file (f_puts)...\r\n");

if (0 == f_puts("Test SD/MMC stack\n", &file_object)) {

f_close(&file_object);

printf("[FAIL]\r\n");

goto main_end_of_test;

}

printf("[OK]\r\n");

f_close(&file_object);

printf("Test is successful.\n\r");

 

main_end_of_test:

printf("Please unplug the card.\n\r");

while (CTRL_NO_PRESENT != sd_mmc_check(0)) {

}

}

8) Only this will be in conf_board.h:

 

#define CONF_BOARD_UART_CONSOLE

#define SD_MMC_SPI_MODE
/** SPI MACRO definition */
#define CONF_BOARD_SPI

/** Spi Hw ID . */
#define SPI_ID          ID_SPI0

/** SPI base address for SPI master mode*/
#define SPI_MASTER_BASE      SPI0

9) Edit sd_mmc_spi_card_init(void) in sd_mmc.c and add this ioport_set_pin_level(SPI0_NPCS1_GPIO,false); under line driver_send_clock();

This is the most important of this project. If you don't add this line, you newer will have response from SD card and you will stuck on drive_send_cmd.

Last Edited: Thu. Sep 21, 2017 - 10:42 AM