cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_SD_WriteBlocks_DMA - not writing or succeeding

jagauthier
Associate III

When attempting to write to an SD card with HAL_SD_WriteBlocks_DMA() I expect the data to be written and then the card status to change to HAL_SD_CARD_TRANSFER. However, that never happens.

Here's a short snippet of code I am using (this is pretty much all of it)

 __disable_irq();
 SDCardState = HAL_SD_GetCardState(&hsd1);
 HALState = HAL_DMA_GetState(&hdma_sdmmc1);
 serprintf("First: State: %i", SDCardState);
 serprintf("HAL First: State: %i", HALState);
 
 HAL_SD_WriteBlocks_DMA(&hsd1, Buffer_Block_Tx, WR_ADDR, BLOCK_SIZE);
 HALState = HAL_DMA_GetState(&hdma_sdmmc1);
 serprintf("After Write HAL State: %i", HALState);
 SDCardState = HAL_SD_GetCardState(&hsd1);
 serprintf("After Write State: %i", SDCardState);
 
 HALState_old = HAL_DMA_GetState(&hdma_sdmmc1);
 SDState_old = HAL_SD_GetCardState(&hsd1);
 
 while (1) {
	 HALState = HAL_DMA_GetState(&hdma_sdmmc1);
	 SDCardState = HAL_SD_GetCardState(&hsd1);
	 if (HALState_old != HALState || SDState_old != SDCardState) {
		 serprintf("HAL State: %i", HALState);
		 serprintf("State: %i", SDCardState);
		 HALState_old = HALState;
		 SDState_old = SDCardState;
	 }

My output is this:

First: State: 4
HAL First: State: 1
After Write HAL State: 2
After Write State: 6

Card status is stuck at HAL_SD_CARD_RECEIVING and DMA status is stuck at HAL_DMA_STATE_BUSY indefinitely.

I've disabled interrupts. I've lowered my clock multiple times.

I'm not sure what else could cause this. 

3 REPLIES 3
TDK
Guru

> I've disabled interrupts.

Don't do that. Interrupts are used in DMA mode to signal the end of the transfer and update relevant state info.

Could be some other issue as well, the HAL SD drivers are not awesome, but disabling interrupts will 100% make it not work.

If you feel a post has answered your question, please click "Accept as Solution".

Okay, thanks. I was disabling interrupts because I read that was how to make it work without using DMA. It didn't occur to me they would be an integral part of using DMA.

Sadly, it did not really make a difference.

Disabling interrupts would get it to work without DMA. With DMA, should not need to disable them.
If you feel a post has answered your question, please click "Accept as Solution".