Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
8 years ago

sd-card interface on de1-soc board

hello

I want to interface with sd card on de1-soc board, but I want to interface with nios2 on qys. After the generator, I made the pin assignment of the sd card in the qsf file to the gpio port pin (since the original sd card was supposed to be used in the hps area), I tried to run it using eclipse after compiling and it does not work. Can not connect sd card interface to gpio in the area of ​​hps? The program shown below is a program in eclipse but can not be operated. Please, please solve it. I have connected the SD card module to the gpio port pin. Additionally, the contents of the qsf file are uploaded. gpio port pin.

qsf file

set_location_assignment PIN_AC23 -to SD_CMD

set_location_assignment PIN_AD24 -to SD_DAT[0]

set_location_assignment PIN_AE23 -to SD_DAT[1]

set_location_assignment PIN_AE24 -to SD_DAT[2]

set_location_assignment PIN_AF25 -to SD_DAT[3]

set_location_assignment PIN_AB21 -to SD_CLOCK

set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to SD_CMD

set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to SD_DAT[0]

set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to SD_DAT[1]

set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to SD_DAT[2]

set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to SD_DAT[3]

set_instance_assignment -name IO_STANDARD "3.3-V LVTTL" -to SD_CLOCK

eclipse# include <stdio.h># include <system.h># include <Altera_UP_SD_Card_Avalon_Interface.h>

short int sd_fileh, sd_fileh2, att;

char buffer[512] = "WELCOME TO THE INTERFACE!!\r\n\0";

char data[512];

int i,pixel,att3;

int main()

{

printf("SD Card Access Test\n");

alt_up_sd_card_dev *sd_card_dev = alt_up_sd_card_open_dev(ALTERA_UP_SD_CARD_AVALON_INTERFACE_0_NAME);

if(sd_card_dev != 0)

{

if(alt_up_sd_card_is_Present())

{

if(alt_up_sd_card_is_FAT16())

printf("Card is FAT16\n");

else

printf("Card is not FAT16\n");

sd_fileh = alt_up_sd_card_fopen("test1.txt", true);

if(sd_fileh < 0)

printf("Problem creating file. Error %i", sd_fileh);

else

{

printf("SD Accessed Successfully, writing data...\n");

int index = 0;

while (buffer[index] != '\0')

{

alt_up_sd_card_write(sd_fileh, buffer[index]);

}

printf("Writing Done!\n");

printf("Closing File 1...\n");

alt_up_sd_card_fclose(sd_fileh);

}

sd_fileh2 = alt_up_sd_card_fopen("test2.txt", false);

if(sd_fileh2 < 0)

printf("Problem creating file. Error %i", sd_fileh2);

else

{

printf("SD Accessed Successfully, reading data...\n");

printf("Data read from the Text file = \n");

for(i=0;i<12;i++)

{

data = alt_up_sd_card_read(sd_fileh);

printf("%c",data);

}

printf("\nClosing file...");

alt_up_sd_card_fclose(sd_fileh2);

printf("Done!\n");

}

}

}

return 0;

}

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I am just about to do this on my de1-SoC and have not yet tried it, but as far as I can tell your pin assignments are completely wrong. Here are the pins from the documentation, you should verify that you are reading the document from the de1-soc not the de1

    Signal Name FPGA Pin No.

    HPS_SD_CLK PIN_A16

    HPS_SD_CMD PIN_F18

    HPS_SD_DATA[0] PIN_G18

    HPS_SD_DATA[1] PIN_C17

    HPS_SD_DATA[2] PIN_D17

    HPS_SD_DATA[3] PIN_B16
    • Shikha's avatar
      Shikha
      Icon for New Contributor rankNew Contributor

      Hello,

      I am trying to interface SD card on DE1 Soc board, I have done the above PIN assignments:

      Signal Name FPGA Pin No.

      HPS_SD_CLK PIN_A16

      HPS_SD_CMD PIN_F18

      HPS_SD_DATA[0] PIN_G18

      HPS_SD_DATA[1] PIN_C17

      HPS_SD_DATA[2] PIN_D17

      HPS_SD_DATA[3] PIN_B16

      How ever in eclipse window, I have written code to detect SD card and I am using function "alt_up_sd_card_is_Present()" from the driver code. It does not return true value and on debugging I understood that Auxiliary Status Register ASR register bit 1 is always 0.( bit 1 indicates if an SD Card is present in the SD card socket).

      And bit 0 is 1 which indicates if the last command sent to the core was valid

      I am stuck here, can some one please help me in understanding the problems?