element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Avnet Boards Forums
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Avnet Boards Forums
  • More
  • Cancel
Avnet Boards Forums
MicroZed Hardware Design Problem using SD card
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Avnet Boards Forums to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 5 replies
  • Subscribers 314 subscribers
  • Views 642 views
  • Users 0 members are here
Related

Problem using SD card

Former Member
Former Member over 10 years ago

Hi there,

I need some advice.  I am trying to use a SD card on a MicroZed board.  The board is loaded with a bare bones Zynq processor system all configured as per the board support package defaults.  I have booted linux on this board from that card before so know it is electrically all OK.  I am now just working on a basic SD card read and write using the Xilinx driver, no file system at this stage.  The code I am using is:

XSdPs_Config * sd0Cfg = XSdPs_LookupConfig(XPAR_PS7_SD_0_DEVICE_ID);//XPAR_PS7_SD_0_BASEADDR

int err = XSdPs_CfgInitialize(&sd0Inst, sd0Cfg, sd0Cfg->BaseAddress);

if(err == XST_SUCCESS)

{

err = XSdPs_SdCardInitialize(&sd0Inst);

if(err == XST_SUCCESS)

{

err = XSdPs_ReadPolled(&sd0Inst, 1, 1, buf);



}

}


The problem I have is that  XSdPs_SdCardInitialize fails UNLESS I step through it where it passes.  The problem happens somewhere in this code of  XSdPs_SdCardInitialize:

/*

* Send ACMD41 while card is still busy with power up

*/

while ((RespOCR & XSDPS_RESPOCR_READY) == 0) {

Status = XSdPs_CmdTransfer(InstancePtr, CMD55, 0, 0);

if (Status != XST_SUCCESS) {

Status = XST_FAILURE;

goto RETURN_PATH;

}



/*

* 0x40300000 - Host High Capacity support & 3.3V window

*/

Status = XSdPs_CmdTransfer(InstancePtr, ACMD41,

(XSDPS_ACMD41_HCS | XSDPS_ACMD41_3V3), 0);

if (Status != XST_SUCCESS) {

Status = XST_FAILURE;

goto RETURN_PATH;

}



/*

* Response with card capacity

*/

RespOCR = XSdPs_ReadReg(InstancePtr->Config.BaseAddress,

XSDPS_RESP0_OFFSET);



}

If I allow the processor to run to the first line of this code, then single step through it, then run again it succeeds!  It seems the only way it can fail is if one of the calls to XSdPs_CmdTransfer fails.  Not sure why they fail at full speed but OK on single stepping.

I have also tried changing the clock frequency to 25MHz and changing the pins slew rate to fast.  With the clock frequency the SD Init function seems to pass most times but the SD read function still fails every time.

Any advice would be greatly appreciated.  I will add any other information required if you ask.


Thanks

  • Sign in to reply
  • Cancel
  • zedhed
    0 zedhed over 10 years ago

    Hi ashesman,

    Any reason why you need SD card access without using an operating system?

    It seems that others have come across similar challenges in getting this to work under baremetal execution.  Have you already reviewed these other forum threads?

    http://microzed.org/content/standalone-sd-card-sdio

    http://microzed.org/content/sd-card-example-design-using-standalone

    Regards,

    -Kevin

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to zedhed

    Hi Kevin,

    Yes, I have read the threads.  There is one note in there about changing the SDIO and GPIO pins around which I did not quite understand.

    I am using an operating system, but not one that just works with this SDIO controller.  I am using FreeRTOS and its supported fat file system.  I will replace the ram disk implementation with SD card.  But, for now I can not even read a block from the card.  Once I can read and write to the card then I will use the OS.

    A little frustrating that the standard BSP and Vivado block automation do not just work to configure the SDIO and driver to just work.  I am sure it can be fixed...

    Cheers

    Ashley

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago

    Update:  I tried using the Xilinx fat fs and it works perfectly.  It uses the SDIo driver functions so I can follow my way through the low level driver layer and find the answer in there.  It calls a few more functions during init than I did so will see what I can do...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago

    For future reference, the file diskio.c in the xilinx fat file system has the answer in it.  You can use the following code to bare metal init and read from a SD card but it would make mmore sense to just use diskio.c and diskio.h to init and read etc.





    XSdPs sd0Inst;

    u8 buf[520];



    #define HIGH_SPEED_SUPPORT 0x01

    #define WIDTH_4_BIT_SUPPORT 0x4



    int SD0Init(void)

    {

    u8 SCR[8] __attribute__ ((aligned(32)));

    u8 ReadBuff[64] __attribute__ ((aligned(32)));



    XSdPs_Config *SdConfig;



    /*

    * Check if card is in the socket

    */

    u32 StatusReg = XSdPs_GetPresentStatusReg(XPAR_XSDPS_0_BASEADDR);

    if ((StatusReg & XSDPS_PSR_CARD_INSRT_MASK) == 0)

    {

    // No disk

    return 1;

    }

    else

    {

    if (StatusReg & XSDPS_PSR_WPS_PL_MASK)

    {

    // Not write protected

    }

    else

    {

    // Write protected

    }

    }



    u3000

    /*

    * Initialize the host controller

    */

    SdConfig = XSdPs_LookupConfig(XPAR_PS7_SD_0_DEVICE_ID);

    if (NULL == SdConfig)

    {

    return 1;

    }



    int Status = XSdPs_CfgInitialize(&sd0Inst, SdConfig, SdConfig->BaseAddress);

    if (Status != XST_SUCCESS)

    {

    return 1;

    }



    Status = XSdPs_SdCardInitialize(&sd0Inst);

    if (Status != XST_SUCCESS)

    {

    return 1;

    }



    Status = XSdPs_Change_ClkFreq(&sd0Inst, 25000000/*XPAR_PS7_SD_0_SDIO_CLK_FREQ_HZ*/);

    if (Status != XST_SUCCESS)

    {

    return 1;

    }



    Status = XSdPs_Select_Card(&sd0Inst);

    if (Status != XST_SUCCESS)

    {

    return 1;

    }



    Status = XSdPs_Get_BusWidth(&sd0Inst, SCR);

    if (Status != XST_SUCCESS)

    {

    return 1;

    }



    Status = XSdPs_Get_BusSpeed(&sd0Inst, ReadBuff);

    if (Status != XST_SUCCESS)

    {

    return 1;

    }



    if(ReadBuff[13] & HIGH_SPEED_SUPPORT)

    {

    Status = XSdPs_Change_BusSpeed(&sd0Inst);

    if (Status != XST_SUCCESS)

    {

    return 1;

    }

    }



    Status = XSdPs_Pullup(&sd0Inst);

    if (Status != XST_SUCCESS)

    {

    return 1;

    }



    if (SCR[1] & WIDTH_4_BIT_SUPPORT)

    {

    Status = XSdPs_Change_BusWidth(&sd0Inst);

    if (Status != XST_SUCCESS)

    {

    return 1;

    }

    }



    Status = XSdPs_SetBlkSize(&sd0Inst, XSDPS_BLK_SIZE_512_MASK);

    if (Status != XST_SUCCESS)

    {

    return 1;

    }



    }



    void main_blinky( void )

    {

    print("Readyr
    ");



    int err = SD0Init();

    if(err == XST_SUCCESS)

    {

    print("SD Init Passedr
    ");

    err = XSdPs_ReadPolled(&sd0Inst, 1, 1, buf);

    if(err == XST_SUCCESS)

    {

    print("SD Card Read Passedr
    ");

    }

    else

    {

    print("SD Card Read Failedr
    ");

    }

    }

    else

    {

    print("SD Init Failed!");

    }


    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • zedhed
    0 zedhed over 10 years ago

    Hi Ashley,

    Thanks for responding back with what worked for you so that the community can benefit from this knowledge.

    Regards,

    -Kevin

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube