element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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
Software Application Development Standalone Baremetal Write/Read to 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 3 replies
  • Subscribers 328 subscribers
  • Views 865 views
  • Users 0 members are here
Related

Standalone Baremetal Write/Read to SD card

Former Member
Former Member over 9 years ago

Hi all,

I am trying to write/read to an SD card using a baremetal application.  I DO NOT want to format it as FAT32.  I simply want to do the simplest bare read/write possible.  I am using the Zynq 7Z02.

I've tracked it down to failing within the "readpolled" function call (a function in the xsdps.c file).  Within that file, it fails somewhere in here because apparently StatusReg & XSDPS_INTR_ERR_MASK == 1 (aka, read has failed):

do {
StatusReg = XSdPs_ReadReg16(InstancePtr-Config.BaseAddress,
tXSDPS_NORM_INTR_STS_OFFSET);
if (StatusReg & XSDPS_INTR_ERR_MASK) {
t/*
t * Write to clear error bits
t */
tXSdPs_WriteReg16(InstancePtr->Config.BaseAddress,
tttXSDPS_ERR_INTR_STS_OFFSET,
tttXSDPS_ERROR_INTR_ALL_MASK);
tStatus = XST_FAILURE;
tgoto RETURN_PATH;
t}
} while((StatusReg & XSDPS_INTR_TC_MASK) == 0);


I hope someone can help.  Below you'll find the code which initializes the SD card.
This is what I have so far:

uint8_t tSCR[8] __attribute__ ((aligned(32)));
uint8_t tReadBuff[64] __attribute__ ((aligned(32)));

XSdPs_Config *SdConfig;

int statusSdFlash = 0;
int readSd = 0;

// Check if card is in the socket

uint32_t StatusReg = XSdPs_GetPresentStatusReg(XPAR_XSDPS_0_BASEADDR);

if ((StatusReg & XSDPS_PSR_CARD_INSRT_MASK) == 0){
  return 1;tt// No disk
}

//Initialize the host controller

SdConfig = XSdPs_LookupConfig(XPAR_PS7_SD_0_DEVICE_ID);
tif (NULL == SdConfig){
ttreturn 1;
t}

statusSdFlash = XSdPs_CfgInitialize(&sd0Inst, SdConfig, SdConfig->BaseAddress);
t
if (statusSdFlash != XST_SUCCESS){
ttreturn 1;
t}

statusSdFlash = XSdPs_SdCardInitialize(&sd0Inst);
if (statusSdFlash != XST_SUCCESS){
treturn 1;
t}

statusSdFlash = XSdPs_Change_ClkFreq(&sd0Inst, 25000000/*XPAR_PS7_SD_0_SDIO_CLK_FREQ_HZ*/);
tif (statusSdFlash != XST_SUCCESS){
ttreturn 1;
t}

statusSdFlash = XSdPs_Select_Card(&sd0Inst);
tif (statusSdFlash != XST_SUCCESS){
ttreturn 1;
t}

statusSdFlash = XSdPs_Get_BusWidth(&sd0Inst, SCR);
tif (statusSdFlash != XST_SUCCESS){
ttreturn 1;
t}

statusSdFlash = XSdPs_Get_BusSpeed(&sd0Inst, ReadBuff);
tif (statusSdFlash != XST_SUCCESS){
ttreturn 1;
t}

if(ReadBuff[13] & HIGH_SPEED_SUPPORT){
tstatusSdFlash = XSdPs_Change_BusSpeed(&sd0Inst);
ttif (statusSdFlash != XST_SUCCESS){
tttreturn 1;
tt}
t}

statusSdFlash = XSdPs_Pullup(&sd0Inst);
tif (statusSdFlash != XST_SUCCESS){
ttreturn 1;
t}

if (SCR[1] & WIDTH_4_BIT_SUPPORT){
tstatusSdFlash = XSdPs_Change_BusWidth(&sd0Inst);
ttif (statusSdFlash != XST_SUCCESS){
tttreturn 1;
tt}
t}

statusSdFlash = XSdPs_SetBlkSize(&sd0Inst, XSDPS_BLK_SIZE_512_MASK);
tif (statusSdFlash != XST_SUCCESS){
ttreturn 1;
t}

statusSdFlash = XSdPs_ReadPolled(&sd0Inst, 1, 1, sdBuf);

tif (statusSdFlash != XST_SUCCESS){
ttreturn 1;
t}
}

//separate function
XSdPs_Config *XSdPs_LookupConfig(uint16_t DeviceId){

tXSdPs_Config *CfgPtr = NULL;
tint Index;

tXSdPs_Config XSdPs_ConfigTable[] =
t{
tt{
ttXPAR_XSDPS_0_DEVICE_ID,
ttXPAR_XSDPS_0_BASEADDR,
ttXPAR_XSDPS_0_SDIO_CLK_FREQ_HZ
tt}
t};
t
for (Index = 0; Index < XPAR_XSDPS_NUM_INSTANCES; Index++) {

if (XSdPs_ConfigTable[Index].DeviceId == DeviceId) {
tCfgPtr = &XSdPs_ConfigTable[Index];
tbreak;
t}
}
return CfgPtr;
}

  • Sign in to reply
  • Cancel
Parents
  • Former Member
    0 Former Member over 9 years ago

    Have you verified that your hardware design works with the SD Card interface with a known good application first? Is your SD clock set to the correct frequency. Have you set the SD WP and CD signals as required? 

     

    Since you are using a ZC702 board we are not as familiar with that SD Card interface as with the ZedBoard/MicroZed/PicoZed boards. You might want to try the Xilinx Community forums for more specific advice.

     

    -Gary

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

    I appreciate the response.  I looked at my build in Vivado and I do have the SD WP and CD signals set.  Should they be in "fast" mode?  They are currently in "slow" mode?  How can I tell what my SD clock frequency should be?

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

    I appreciate the response.  I looked at my build in Vivado and I do have the SD WP and CD signals set.  Should they be in "fast" mode?  They are currently in "slow" mode?  How can I tell what my SD clock frequency should be?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
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