cancel
Showing results for 
Search instead for 
Did you mean: 

FatFs on SDMMC1 configured by CubeMX not working with DMA (F722)

Lars Beiderbecke
Senior III
Posted on April 17, 2018 at 18:46

I'm using FatFs on SDMMC1 configured by CubeMX (v.4.23) on a STM32F722. Everything runs perfectly fine.

But when I activate DMA by

  • enabling DMA template in FatFs
  • creating DMA channel for SDMMC1 RX and TX
  • enabling the DMA and SDMMC1 interrupts

I can see that the code in sd_diskio.c has changed, and two IRs have been generated.

But the mounting and/or reading of the SD card fails.

This worked with v.4.22 (even without creating DMA channels), but now doesn't.

What is missing here?

#fatfs #dma
1 ACCEPTED SOLUTION

Accepted Solutions

It's working for me now.

In CubeMX, you have to enable DMA mode, but then also manually create DMA TX and RX streams, and enable SDMMC1, DMA TX, and DMA RX interrupts.

No more problems for me, at least when using a soldered uSD connector (not a breakout board).

View solution in original post

14 REPLIES 14
Lars Beiderbecke
Senior III
Posted on April 18, 2018 at 21:06

I upgraded to CubeMX v4.25 with firmware v1.11, as people said it would work out of the box with that version. Alas, not for me.

Most code changes suggested here in the forum are already present in the code generated by CubeMX. The BSP_SD_Init() was also fixed. As suggested here, I tried both AXI and TCM interface, but no go.

Right now my setup looks like the one in the SDIO+DMA+FatFs+CubeMX PDF that was posted here somewhere, except for the code changes. I'm also using SDMMC1 and only 1 wire right now.

Nothing works, the f_mount always fails. Are there any other guides on how to configure DMA with CubeMX? Are there other requirements? Or code changes needed for v.4.25 code?

Posted on April 20, 2018 at 17:30

Hello

pub

,

Please refer to

https://community.st.com/0D50X00009bMM8bSAG

and

https://community.st.com/0D50X00009XkXgUSAV

discussion, this may help you.

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on April 21, 2018 at 13:34

Thanks for the reply, but I had the correction already applied.  In fact, the lastest CubeMX has this problem fixed.

Without DMA, FatFs is working fine for me, but with DMA the f_mount fails.

Posted on April 26, 2018 at 18:34

Hello

pub

,

You may refer to this discussion

https://community.st.com/0D50X00009XkVtKSAV

.

Hope this helps you.

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on April 26, 2018 at 18:57

@ST

Wouldn't it be a better goal for CubeMX to output viable code from the outset, then we'd not have to triage a stream of time wasting issues? Please light a fire under the team, and have people focus on validating output. Whatever method of validating the code that is currently being employed needs to be tightened up, and someone needs to review why these things are being missed, or how they were missed.

I know CubeMX is a complex project, I know teams don't scale well, I know these things take time and skill, but a lot of these problems are of your own creation. The resistance to external facing bug tracking and code submission seem to compound the problems.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on July 04, 2018 at 03:08

I would like to add my voice to Clive.  STM32H7 Series MCU package as of the last version 1.2.0 has completely broken FatFs when used with FreeRTOS and DMA.  The only thing that works is the example project application in 1.2.0 which, if one wants to use, has to be carefully extracted from the repository and then carefully built upon to add other functions.  Trying to diff compare the project example with the CubeMX generated code is an exercise in futility as there are a number of astonishing differences.  If attempts are made to implement code differences things go south with the middleware in some very unexpected places.  If STM wants to replicate the issues do the following:

With a windows 10 machine (64 bit in my case but I am certain it does not matter) and CubeMX V 4.26.0 with STM32H7 V1.2.0 build a BSP for STM32H743i_Eval board.  Enable the peripherals as well as FatFs, FreeRTOS, and LWIP.   Generate the code.  Use the section of main from C:\STM32Cube\Repository\STM32Cube_FW_H7_V1.2.0\Projects\STM32H743I_EVAL\Applications\FatFs\FatFs_uSD_DMA_RTOS for FSOperations and other initialization as needed for the SD card.  If it works (which I am certain it will not) please post the project so we can all figure out what we are doing wrong. 

I just ran into the same issue with cubeMX 5.1.0. As soon I disable "use DMA template" in fatfs it works. Otherwise not! It doesn't seem that anybody fixed anything. At least not right. Very frustrating!

It's working for me now.

In CubeMX, you have to enable DMA mode, but then also manually create DMA TX and RX streams, and enable SDMMC1, DMA TX, and DMA RX interrupts.

No more problems for me, at least when using a soldered uSD connector (not a breakout board).

EKirs
Associate II

I have similar issues with the CubeMX and CubeIDE (that includes CubeMX).

After updating CubeMX and regenerating the code, my previous fix for STM32L4+SDMMC+FreeRTOS+FatFs+DMA does not work anymore. It looks like ST made an attempt to correct the issue (and probably corrected for some MCUs, but not for L4). Too bad, neither newly generated code nor my previous fix work at the moment. Some posts above are for MCUs with 2 dedicated channels for TX and RX. The L4 MCU I am using has only one dedicated DMA channel, so I am wondering how to address this problem...

Also, if ST promotes the CubeMX application, why can't they make their Cube firmware packages with all the examples generated by CubeMX (with addition of some code if necessary and *.ioc files provided)? If it is done this way, there wouldn't be any concerns of matching the working "cube" examples with the (not working) code generated by CubeMX application.