cancel
Showing results for 
Search instead for 
Did you mean: 

Writing multiple blocks to SD card fails

Ivan Ivan
Associate II
Posted on August 02, 2017 at 14:19

Hello. I am developing application that involves writing multiple blocks (of 512 bytes) to SD card. It is a part of USB MSC application, multiblock operations are required for correct and fast functioning. A 

BSP_SD_WriteBlocks() recommended routine hangs when writing several blocks. Reading multiple blocks performs OK, writing single block also is fine, but multiple blocks write transmission fails. 

My code is simple:

BSP_SD_WriteBlocks((uint32_t *)buf, blk_addr, blk_len, 1000);

uint32_t state1 = PERSONAL_SD_GetCardState();

uint32_t error1 = PERSONAL_SD_GetCardError() ;

//HANGS HERE

while (BSP_SD_GetCardState() != SD_TRANSFER_OK)

{

}

I have added two subroutines to stm32746g_discovery_sd.h to understand what is happening with card:

uint32_t

PERSONAL_SD_GetCardState

(void) {

return ( (uint32_t)(HAL_SD_GetCardState(&uSdHandle) ) );

}

uint32_t

PERSONAL_SD_GetCardError

(void) {

return uSdHandle.ErrorCode;

}

During debug:

state1 gets assigned to 6 , which is 'Card is receiving operation information'. (I am expecting it to be 1, or card ready)

error1 gets assigned to 8 , which is 'Data timeout' (I am expecting it to be SDMMC_ERROR_NONE, or 0)

How can I overcome this issue and make sd card correctly accept several blocks in one operation?

#sdio #stm32f746-disco #sd-card
3 REPLIES 3
Ivan Ivan
Associate II
Posted on August 03, 2017 at 08:07

Seems like I should construct my own subroutine that writes multiple blocks using a direct access to registers.

Does someone have an example of this code? Share it, please...

STM32F746NGH MCU's reference manual has quite vague instructions on how to do this (p. 1208) (CMD24, I need CMD25), and it covers only single block writing (which works OK with HAL code)

yassine jmili
Associate
Posted on June 26, 2018 at 01:07

Hello everybody,

I have some issue by using the read multiple block cmd, some data is corrupted.

T_U32 ReadBlock(T_U8* SrcData, T_U32 BlockAdd , T_U32 NumberOfBlocks )

{

 HAL_DMA_Start_IT(hsd->hdmarx, (uint32_t)&hsd->Instance->FIFO, BlockAdd , (uint32_t)(BlockSize * NumberOfBlocks)/4);

if(this->SD_Card.CardType != CARD_SDHC_SDXC)

{

BlockAdd *= 512U;

}

SDIO_ConfigData()

SDMMC_CmdBlockLength(registers, BLOCKSIZE); 

BLOCKSIZE=512;

if(NumberOfBlocks > 1U)

{

StatusRead = SDMMC_CmdReadMultiBlock(registers, BlockAdd);

}

else

{

StatusRead = SDMMC_CmdReadSingleBlock(registers, BlockAdd);

}

It's necessary to send the 

CmdBlockLength command after the SDMMC_CmdReadMultiBlock ,or it must change the BLOCKSIZE parameter  to NumberOfBlocks * BlockSize within the CmdBlockLength.

thanks  

Posted on June 26, 2018 at 01:09

I note that the 

ReadSingleBlock command is worked !!