cancel
Showing results for 
Search instead for 
Did you mean: 

STM3210VE, 8G SD card , SDIO 4bits bus, DMA mode-STOne-32,help me please

linkai1020
Associate II
Posted on September 17, 2010 at 03:07

STM3210VE, 8G SD card , SDIO 4bits bus, DMA mode-STOne-32,help me please

26 REPLIES 26
Posted on May 17, 2011 at 14:07

Is R/W SDHC card by SDIO in DMA 4bits mode not s

table

?

Are you sure the high capacity cards use the same protocol as the older/slower cards? I'm pretty these cards won't work in classic readers either.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
linkai1020
Associate II
Posted on May 17, 2011 at 14:07

thanks for your reply,

This code can judge the type of cards...and i readed the spec: Part_1_Physical_Layer_Simplified_Specification_Ver3.01_Final_100518.pdf

and

SD_SDIO_specsv1.pdf

The Process

 of the code is right for the spec..

And all of the Response for the CMD is right...

  /* CMD8: SEND_IF_COND --------------------------------------------------------*/

  /* Send CMD8 to verify SD card interface operating condition */

  /* Argument: - [31:12]: Reserved (shall be set to '0')

               - [11:8]: Supply Voltage (VHS) 0x1 (Range: 2.7-3.6 V)

               - [7:0]: Check Pattern (recommended 0xAA) */

  /* CMD Response: R7 */

  SDIO_CmdInitStructure.SDIO_Argument = SD_CHECK_PATTERN;

  SDIO_CmdInitStructure.SDIO_CmdIndex = SDIO_SEND_IF_COND;

  SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;

  SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;

  SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;

  SDIO_SendCommand(&SDIO_CmdInitStructure);

  errorstatus = CmdResp7Error();

  if (errorstatus == SD_OK)

  {

    CardType = SDIO_STD_CAPACITY_SD_CARD_V2_0; /* SD Card 2.0 */

    SDType = SD_HIGH_CAPACITY;

  }

  else

  {

    /* CMD55 */

    SDIO_CmdInitStructure.SDIO_Argument = 0x00;

    SDIO_CmdInitStructure.SDIO_CmdIndex = SDIO_APP_CMD;

    SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;

    SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;

    SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;

    SDIO_SendCommand(&SDIO_CmdInitStructure);

    errorstatus = CmdResp1Error(SDIO_APP_CMD);

  }

linkai1020
Associate II
Posted on May 17, 2011 at 14:07

I am crazy.who can tell me some c

lue

?
linkai1020
Associate II
Posted on May 17, 2011 at 14:07

越�?�越晕乎了。。。真是的,这问题�?�的,SANDISK的8G SDHC�?�,�?�尔能写,但是文件里�?�大部分的数�?�都是错的。。晕。。。2G的完全正确

Nickname12657_O
Associate III
Posted on May 17, 2011 at 14:07

Dear lin,

I will be back to you soon, i need to investigate the case and reproduce it first.

Cheers,

STOne-32.

linkai1020
Associate II
Posted on May 17, 2011 at 14:07

//Now i describe my code to you,and i think there are some bugs in the

//examples which come from st.

SD_Error SD_PowerON(void)

{

  SD_Error errorstatus = SD_OK;

  uint32_t response = 0, count = 0;

  bool validvoltage = FALSE;

  uint32_t SDType = SD_STD_CAPACITY;

  uint8_t i = 0;

  /* Power ON Sequence -------------------------------------------------------*/

  /* Configure the SDIO peripheral */

  SDIO_InitStructure.SDIO_ClockDiv = SDIO_INIT_CLK_DIV; /* HCLK = 72MHz, SDIOCLK = 72MHz, SDIO_CK = HCLK/(178 + 2) = 400 KHz */

  SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising;

  SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable;

  SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;

  SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_1b;

  SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;

  SDIO_Init(&SDIO_InitStructure);

  /* Set Power State to ON */

  SDIO_SetPowerState(SDIO_PowerState_ON);

  /* Enable SDIO Clock */

  SDIO_ClockCmd(ENABLE);

  /* CMD0: GO_IDLE_STATE -------------------------------------------------------*/

  /* No CMD response required */

  SDIO_CmdInitStructure.SDIO_Argument = 0x0;

  SDIO_CmdInitStructure.SDIO_CmdIndex = SDIO_GO_IDLE_STATE;

  SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_No;

  SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;

  SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;

  

// it will be TimeOut  if i don't add this,It needs 74 clocks here

//according to the SD spec 

//

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

  {

  SDIO_SendCommand(&SDIO_CmdInitStructure);

  errorstatus = CmdError();

  }

  if (errorstatus != SD_OK)

  {

    /* CMD Response TimeOut (wait for CMDSENT flag) */

    return(errorstatus);

  }

  /* CMD8: SEND_IF_COND --------------------------------------------------------*/

  /* Send CMD8 to verify SD card interface operating condition */

  /* Argument: - [31:12]: Reserved (shall be set to '0')

               - [11:8]: Supply Voltage (VHS) 0x1 (Range: 2.7-3.6 V)

               - [7:0]: Check Pattern (recommended 0xAA) */

  /* CMD Response: R7 */

  SDIO_CmdInitStructure.SDIO_Argument = SD_CHECK_PATTERN;

  SDIO_CmdInitStructure.SDIO_CmdIndex = SDIO_SEND_IF_COND;

  SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;

  SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;

  SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;

  SDIO_SendCommand(&SDIO_CmdInitStructure);

  errorstatus = CmdResp7Error();

  if (errorstatus == SD_OK)

  {

    CardType = SDIO_STD_CAPACITY_SD_CARD_V2_0; /* SD Card 2.0 */

    SDType = SD_HIGH_CAPACITY;

  }

  else

  {

    /* CMD55 */

    SDIO_CmdInitStructure.SDIO_Argument = 0x00;

    SDIO_CmdInitStructure.SDIO_CmdIndex = SDIO_APP_CMD;

    SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;

    SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;

    SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;

    SDIO_SendCommand(&SDIO_CmdInitStructure);

    errorstatus = CmdResp1Error(SDIO_APP_CMD);

  }

  /* CMD55 */

  SDIO_CmdInitStructure.SDIO_Argument = 0x00;

  SDIO_CmdInitStructure.SDIO_CmdIndex = SDIO_APP_CMD;

  SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;

  SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;

  SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;

  SDIO_SendCommand(&SDIO_CmdInitStructure);

  errorstatus = CmdResp1Error(SDIO_APP_CMD);

  /* If errorstatus is Command TimeOut, it is a MMC card */

  /* If errorstatus is SD_OK it is a SD card: SD card 2.0 (voltage range mismatch)

     or SD card 1.x */

  if (errorstatus == SD_OK)

  {

    /* SD CARD */

    /* Send ACMD41 SD_APP_OP_COND with Argument 0x80100000 */

    while ((!validvoltage) && (count < SD_MAX_VOLT_TRIAL))

    {

      /* SEND CMD55 APP_CMD with RCA as 0 */

      SDIO_CmdInitStructure.SDIO_Argument = 0x00;

      SDIO_CmdInitStructure.SDIO_CmdIndex = SDIO_APP_CMD;

      SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;

      SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;

      SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;

      SDIO_SendCommand(&SDIO_CmdInitStructure);

      errorstatus = CmdResp1Error(SDIO_APP_CMD);

      if (errorstatus != SD_OK)

      {

        return(errorstatus);

      }

      SDIO_CmdInitStructure.SDIO_Argument = SD_VOLTAGE_WINDOW_SD | SDType;

      SDIO_CmdInitStructure.SDIO_CmdIndex = SDIO_SD_APP_OP_COND;

      SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;

      SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;

      SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;

      SDIO_SendCommand(&SDIO_CmdInitStructure);

      errorstatus = CmdResp3Error();

      if (errorstatus != SD_OK)

      {

        return(errorstatus);

      }

      response = SDIO_GetResponse(SDIO_RESP1);

      validvoltage = (bool) (((response >> 31) == 1) ? 1 : 0);

      count++;

    }

    if (count >= SD_MAX_VOLT_TRIAL)

    {

      errorstatus = SD_INVALID_VOLTRANGE;

      return(errorstatus);

    }

    if (response &= SD_HIGH_CAPACITY)

    {

      CardType = SDIO_HIGH_CAPACITY_SD_CARD;

    }

  }/* else MMC Card */

  return(errorstatus);

}
linkai1020
Associate II
Posted on May 17, 2011 at 14:07

//I cannot open the bbs this morning,Now it's ok.I can go on.

//In this function,It have be right since i add some code followed:

static SD_Error FindSCR(uint16_t rca, uint32_t *pscr)

{

  uint16_t delay_time = 0;

  uint32_t index = 0;

/************************/

//  uint32_t temp = 0, temp_go  = 0;

/************************/

  SD_Error errorstatus = SD_OK;

  uint32_t tempscr[2] = {0, 0};

  /* Set Block Size To 8 Bytes */

  /* Send CMD55 APP_CMD with argument as card's RCA */

  SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)8;

  SDIO_CmdInitStructure.SDIO_CmdIndex = SDIO_SET_BLOCKLEN;

  SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;

  SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;

  SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;

  SDIO_SendCommand(&SDIO_CmdInitStructure);

  errorstatus = CmdResp1Error(SDIO_SET_BLOCKLEN);

  if (errorstatus != SD_OK)

  {

    return(errorstatus);

  }

  /* Send CMD55 APP_CMD with argument as card's RCA */

  SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;

  SDIO_CmdInitStructure.SDIO_CmdIndex = SDIO_APP_CMD;

  SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;

  SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;

  SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;

  SDIO_SendCommand(&SDIO_CmdInitStructure);

  errorstatus = CmdResp1Error(SDIO_APP_CMD);

  if (errorstatus != SD_OK)

  {

    return(errorstatus);

  }

  SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;

  SDIO_DataInitStructure.SDIO_DataLength = 8;

  SDIO_DataInitStructure.SDIO_DataBlockSize = SDIO_DataBlockSize_8b;

  SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;

  SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;

  SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;

  SDIO_DataConfig(&SDIO_DataInitStructure);

  /************************/// It needs sometimes.

  for(delay_time = 0 ; delay_time < 20 ;delay_time++)

  {

   __nop();

  }

  /************************/

  /* Send ACMD51 SD_APP_SEND_SCR with argument as 0 */

  SDIO_CmdInitStructure.SDIO_Argument = 0x0;

  SDIO_CmdInitStructure.SDIO_CmdIndex = SDIO_SD_APP_SEND_SCR;

  SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;

  SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;

  SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;

  SDIO_SendCommand(&SDIO_CmdInitStructure);

  errorstatus = CmdResp1Error(SDIO_SD_APP_SEND_SCR);

  if (errorstatus != SD_OK)

  {

    return(errorstatus);

  }

/*******************************/

 //temp = SDIO->STA;//清除STA标志�?,�?�测试用

 //temp_go = temp + 1;

/*******************************/

  while (!(SDIO->STA & (SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DBCKEND | SDIO_FLAG_STBITERR)))

  {

    if (SDIO_GetFlagStatus(SDIO_FLAG_RXDAVL) != RESET)

    {

      *(tempscr + index) = SDIO_ReadData();

      index++;

/*********************/// It need jump out.

   if(2 == index)

   {

    break;

   }

/*********************/

    }

  }

  if (SDIO_GetFlagStatus(SDIO_FLAG_DTIMEOUT) != RESET)

  {

    SDIO_ClearFlag(SDIO_FLAG_DTIMEOUT);

    errorstatus = SD_DATA_TIMEOUT;

    return(errorstatus);

  }

  else if (SDIO_GetFlagStatus(SDIO_FLAG_DCRCFAIL) != RESET)

  {

    SDIO_ClearFlag(SDIO_FLAG_DCRCFAIL);

    errorstatus = SD_DATA_CRC_FAIL;

    return(errorstatus);

  }

  else if (SDIO_GetFlagStatus(SDIO_FLAG_RXOVERR) != RESET)

  {

    SDIO_ClearFlag(SDIO_FLAG_RXOVERR);

    errorstatus = SD_RX_OVERRUN;

    return(errorstatus);

  }

  else if (SDIO_GetFlagStatus(SDIO_FLAG_STBITERR) != RESET)

  {

    SDIO_ClearFlag(SDIO_FLAG_STBITERR);

    errorstatus = SD_START_BIT_ERR;

    return(errorstatus);

  }

  /* Clear all the static flags */

  SDIO_ClearFlag(SDIO_STATIC_FLAGS);

  *(pscr + 1) = ((tempscr[0] & SD_0TO7BITS) << 24) | ((tempscr[0] & SD_8TO15BITS) << 8) | ((tempscr[0] & SD_16TO23BITS) >> 8) | ((tempscr[0] & SD_24TO31BITS) >> 24);

  *(pscr) = ((tempscr[1] & SD_0TO7BITS) << 24) | ((tempscr[1] & SD_8TO15BITS) << 8) | ((tempscr[1] & SD_16TO23BITS) >> 8) | ((tempscr[1] & SD_24TO31BITS) >> 24);

  return(errorstatus);

}
linkai1020
Associate II
Posted on May 17, 2011 at 14:07

And i found some problems when i use the 2G SD_Card:

f_open( );f_write( );f_close(); ---->I must write this functions together,otherwise there will be some wrong data in the file.like this:

Write_Something()

{

f_open( ...);

f_write( ...);

f_close(....);

}

It will be wrong if it be writed followed:

Write_Something()

{

f_open( ...);

delay(sometimes);//or do otherthings

f_write( ...);

delay(sometimes);//or do otherthings

f_close(....);

}
linkai1020
Associate II
Posted on May 17, 2011 at 14:07

Many e

ngineer

s in china said that they have various problems when using the ''SDIO+4bit+DMA''mode.''Some cards cannot R/W in this mode'',they said.

So,most of them choose the ''SPI'' mode,

But i cann't,I must s

olve this problem....