cancel
Showing results for 
Search instead for 
Did you mean: 

STM3210E-EVAL + SDIO

hitsumen
Associate II
Posted on August 23, 2013 at 11:16

Good day,

Have anybody make it work? I tried the example from:

...\STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\SDIO\uSDCard

But it does not work. I mean reading, writing functions.. I could only read the capacity, blocksize, RCA and cardtype.

I tried it with 2 cards. The first one is 8GB SDHC kingston card, the second is 2GB not SDHC one. Both the same results. 

This code should work, but it does not:

Status = SD_WriteBlock(buffer, address, 512);

Status = SD_WaitWriteOperation();

while(SD_GetStatus() != SD_TRANSFER_OK); 

From sdhc 8 gb card i get this info:

Capacity: 3504 MB; // Why not 8GB? 

Blocksize: 512;

RCA: 3350;

Cardtype: 2.

With 2GB card I get the capacity of 2GB..

But still board does not work with write and read functions..

4 REPLIES 4
Posted on August 23, 2013 at 14:13

The ST implementations have several issues

Use 32-bit linear byte addressing, rather than block addressing, limiting access below 4GB

Don't send blocking size to SDHC cards
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hitsumen
Associate II
Posted on August 23, 2013 at 15:54

Is there any code example of that?

Is there any never version of libraries? I use the 3.5.

There are some mistakes in that library?

Posted on August 23, 2013 at 16:12

I've fixed up F2/F4 implementations, and posted some, but not the F1.

No 3.5.0 is the latest for the F1, but the issues are endemic across all the SDIO examples.

There are some inconvenient truths in there, it demonstrates a sub-set of functionality, and isn't very robust.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 23, 2013 at 16:25

This addressed some of the issues on the F2/F4, I've ignored the single block functions, and just use multiple blocks with a parameter of 1. The code also makes assumptions that sectors are always 512 bytes.

// FIXED Version where ReadAddr is in BLOCKS NOT BYTES, permits SDHC media >4GB
SD_Error SD_ReadMultiBlocksFIXED(uint8_t *readbuff, uint32_t ReadAddr, uint32_t BlockSize, uint32_t NumberOfBlocks)
{
SD_Error errorstatus = SD_OK;
TransferError = SD_OK;
TransferEnd = 0;
StopCondition = 1;
SDIO->DCTRL = 0x0;
if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
BlockSize = 512;
else
ReadAddr *= BlockSize; // Convert to Bytes for NON SDHC
/*!< Set Block Size for Card */
SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) BlockSize;
SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_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(SD_CMD_SET_BLOCKLEN);
if (SD_OK != errorstatus)
{
return(errorstatus);
}
SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
SDIO_DataInitStructure.SDIO_DataLength = NumberOfBlocks * BlockSize;
SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4;
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);
/*!< Send CMD18 READ_MULT_BLOCK with argument data address */
SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)ReadAddr;
SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_READ_MULT_BLOCK;
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(SD_CMD_READ_MULT_BLOCK);
if (errorstatus != SD_OK)
{
return(errorstatus);
}
SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
SDIO_DMACmd(ENABLE);
SD_LowLevel_DMA_RxConfig((uint32_t *)readbuff, (NumberOfBlocks * BlockSize));
return(errorstatus);
}

See also

http://blog.frankvh.com/2011/09/04/stm32f2xx-sdio-sd-card-interface/

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..