2021-09-23 09:13 AM
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.
2021-09-24 11:43 AM
> 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.
2021-09-24 12:43 PM
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.
2021-09-24 12:52 PM