cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple Calls to HAL_SD_WriteBlocks Results in timeout error

TCash.1
Associate III

Hello All,

I am having an issue interfacing an SD card to the STM23H7.

I am using the SDMMC1 with 4 bit wide bus. When testing HAL_SD_WriteBlocks , I can write and read from the card successfully at various lengths (different number of blocks). But I get an error when running 2 consecutive calls to HAL_SD_WriteBlocks.

status = HAL_SD_WriteBlocks(&hsd1, &datatest[0], 0, 2048/(512*2) , 1000);
status = HAL_SD_WriteBlocks(&hsd1, &datatest[0], 1,  2048/(512*2) , 1000);

The 2nd call returns HAL_ERROR because SDMMC_CmdWriteMultiBlock() returned 0x4 indicating a timeout error.

I tried spin locking on HAL_SD_GetCardState() between the 2 calls. But the state is forever stuck on "TRANSFER"

Any Ideas on what I could be missing would be much appreciated,

Thanks,

Trevor

2 REPLIES 2

Writing is an operation that completes long after the data is transmitted, expect to pend on the card having completed its work.

Make sure the DMA has completed, and that the FIFO has emptied to the card. If the STM32 side FIFO is still full the cards not going to be in a phase that accepts commands.

Reading is different, when you get the last byte in the buffer, you know it's done.

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

Hi Tesla, Thanks for the reply.

So to be clear the HAL_SD_WriteBlocks() function does not block until the write is finished?

I would expect that to be the case for sure with HAL_SD_WriteBlocks_IT and HAL_SD_WriteBlocks_DMA of course.

I'm not sure what would be the difference between HAL_SD_WriteBlocks and HAL_SD_WriteBlocks_IT if HAL_SD_WriteBlocks does not wait for entire write to finish.

What flag do I need to poll on to wait until HAL_SD_WriteBlocks() finishes? I tried HAL_SD_GetCardState().