cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with STM32F7 SDMMC DMA READ

anonymous.8
Senior II
Posted on December 31, 2016 at 00:27

Hi, all, I have a STM32F7 Discovery board (chip is

STM32F746NGH6

). I have implemented my own SDMMC layer  (bare metal, no HAL or ported STD peripheral libraries. It is working very nicely using polled mode for SD card reads, but I want to use DMA reads. I cannot get it to work, more specifically it hangs in the SDWaitRead() function after the DMA transfer has been set up. I have established that the SDIO_IRQHandler() and DMA2_Stream3_IRQHandler() interrupt handlers are never being fired so there is some issue with the interrupts.

I have attached my code here. And also, for comparison, I have attached my working SDReadBlocksPolled() function as well, so I know my basic SDMMC access technique works well. As an aside you may note that in order to send a Command to the SD card, I have boiled all the superfluous bloated HAL code down to two lines only using direct register access as per this example :

   SDMMC1->ARG = (U32)BLOCK_SIZE;

   SDMMC1->CMD = SDMMC_CMD_SHORT_NOWAIT_NOWAIT_CPSMENABLE(SD_CMD_SET_BLOCKLEN_CMD16);

where SDMMC_CMD_SHORT_NOWAIT_NOWAIT_CPSMENABLE is a simple macro thus:

&sharpdefine SDMMC_CMD_SHORT_NOWAIT_NOWAIT_CPSMENABLE(CMD)  (0x440 | CMD)  // 0b10001000000 | CMD

I have similar macros for

&sharpdefine SDMMC_CMD_NORESP_NOWAIT_NOWAIT_CPSMENABLE(CMD) (0x400 | CMD)  // 0b10000000000 | CMD and

&sharpdefine SDMMC_CMD_LONG_NOWAIT_NOWAIT_CPSMENABLE(CMD)   (0x4C0 | CMD)  // 0b10011000000 | CMD

Similarly I have boiled the Datapath State Machine setting code down to three lines thus:

   // Configure the SD DPSM (Data Path State Machine)

   // Set the SDIO Data TimeOut and DataLength and DCTRL (Data Control) values

   SDMMC1->DTIMER = SD_DATATIMEOUT;

   SDMMC1->DLEN   = NumberOfBlocks * BLOCK_SIZE;

   SDMMC1->DCTRL |= SDMMC_DCTRL_TOSDIO_512_BLOCK_MODE_DTEN;

These simple techniques lead to much easier to write and read SDMMC code, in my opinion. I might add that I have the luxury of not being under any deadline, so I can take the time to really understand how the registers work and also don't have to worry about portability, so this coding technique is very efficient, now I have figured it out. And the best part it doesn't depend on the HAL bloatware, or any other libraries.

Any help you can give to identify the problems I am having with my DMA version of SDReadBlocks() would be much appreciated. Thanks.

#sdmmc #stm32f7-dma-sdio-sdmmc-requests
7 REPLIES 7
anonymous.8
Senior II
Posted on December 31, 2016 at 00:54

OK, silly me. I just found the problem. The IRQ handlers were copy/pasted from an earlier STM32F4 code base where the SD peripheral is called SDIO, whereas on the SMT32F7, it is called SDMMC1 (or 2).

So the name of the SD IRQ handler was wrong. My code had it as

void

SDIO_IRQHandler(void), whereas it should have been

void

SDMMC1_IRQHandler(void).

I made that change and now it works.

In any case, anyone is free to use my stripped down SDMMC code if they wish. It should run more efficiently too as it uses direct register access, instead of a multitude of bloat layers.
Posted on January 02, 2017 at 09:58

Hi

Harrison.David.002

‌,

Thank you for posting your findings and how you fixed the issue, it is good to hear that it was solved

-Nesrine-

We are looking for your wishes about our STM32 products,ecosystem and community:

https://community.st.com/community/stm32-community/stm32-forum/blog/2016/12/30/2017-stm32-wish-list

Lars Rademacher
Associate II
Posted on February 13, 2017 at 17:07

Hi David,

would you be willing to provide the whole code of your SD Card driver (all functions you introduced in your header files)?

I would like to test your driver, because i am experiencing many difficulties with the Cube drivers.

Best regards

Lars

Posted on February 13, 2017 at 17:12

Yes, eventually. I am still struggling with SD card writes which are still not working, either in polled or DMA mode. However, you would take my code, as is, with no support, and it is not MISRA compliant. I will let you know on this thread once it is complete enough.

Posted on February 13, 2017 at 19:09

Hi David,

thank you. As i mentioned, it would be for testing purpose only, so no support etc. is necessary.

Best regards

Lars

Posted on March 30, 2017 at 23:14

I am having issues with the cube driver as well.  What I found was in:

file:  stm32f7xx_hal_sd.c

function:  HAL_SD_WriteBlocks(...)

The while (!..) loop (around line 755) that does the FIFO poll seems to have issues.  The first check below tests the FIFO half full flag (SDMMC_FLAG_TXFIFOHE).  I found if I changed that to the empty flag (SDMMC_FLAG_TXFIFOE) then it now successful writes and creates directories.  It seems to be overrunning the FIFO causes a fatal exception.

AVI-crak
Senior
Posted on March 31, 2017 at 14:39

Use bitbucket.org for the free publication of a program code.

The compressed archive suits for the checked decisions at a final stage.