cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 SDMMC standalone mode (no RTOS): Works polled, not with DMA

willcfj
Senior

Hi, pretty sure this is a newbie type question. I'm using the SDMMC interface on an STM32L476. Right now it is just wired to a Nucleo board so I can do some benchmarking before committing it to a layout. I'm using STM32CubeMX and following the example in section 3.3 of UM1721 (Fatfs on CubeMX). After learning the hard way pullup resistors *are* necessary (some other posts said not), I am able to talk to a card, but only if I use polled mode ("Use DMA Template" set to disable in STM32CubeMX Fatfs settings). When enabled, the code hangs in the sd_diskio_dma.c SD_Read() routine right after the BSP_SD_ReadBlocks_DMA() call.

The note for "Use DMA Template" says to ensure that DMAs are properly configured but no more info. In the SDMMC configuration I've tried tried selecting SDMMC1 and then both SDMMC1_TX_SDMMC1_RX. I always get the stall. I am sure there i something basic I'm missing, but been at it for a couple days now and deciding to ask. Since this seems a very basic "follow the app note", rationalizing it might be useful for others too.

I've only recently migrated from the basic StcPeriph libraries to STMCube, starting with the LL routines, this is my attempt using HAL.

will

42 REPLIES 42
BGavr.3
Associate II

check out these videos, they helped me when setting up SDMMC using CubeMX

https://www.youtube.com/watch?v=Y5UMTGQDmog&t=141s

His channel is very helpful

willcfj
Senior

Bojan:

Thanks for the link. Good watching. I've tried a few of the suggestions short of going all the back to the 1.21 release (the firmware is up to 1.27 now). I'll report back once I find a way to get things working.

will

BGavr.3
Associate II

Np Will

Also if you think the issue might be hardware related I would suggest using breakout boards similar to this one

https://www.sparkfun.com/products/13743?_ga=2.202773905.1818468449.1540488118-2054388973.1537370868

These are really cheap and speed up prototyping alot.

The newer firmware shouldn't really be much of an issue, I just recently set up SDMMC with the new firmware on the STM32L476 just by following his videos

willcfj
Senior

Thanks Bojan, just need to do some more fiddling. The release notes for CubeMX 4.24 claim to have fixed the issue which is after the videos were made. I'm running 4.26 now, just behind the current 4.27 release. I need to do some timeline unraveling to see what parts of the video may still be needed. I'm pretty confident on the hardware (6 wires and 5 resistors!) especially given all works well in polled IO mode. I did have the same issue of comms not working well at 24MHz as noted in the videos.

I did run my performance test in polled mode and it looks good. I need a sustained 1Mbps and am getting close to 17Mbps even with a 6MHz clock. Hopefully I can get the full 24MHz once I get a real board layout and not wires wire-wrapped to a Nucleo board! :)

I'll note how it goes as I get it figured out.

will

>>Hopefully I can get the full 24MHz once I get a real board layout and not wires wire-wrapped to a Nucleo board!

Should be able to get north of 50 MHz on any given MicroSD card

0690X000006CGatQAG.jpg

Don't recall the numbers for the L4/L4+, but gotten 30 MB/s (240 Mbps) read speeds off materially similar socket/wiring arrangements.

Write big aligned blocks.

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

Bojan:

The board I got a while back was the Adafruit one that had an SPI-wired SD card and LCD to warm me up for another project for which SPI-based SD card comms was fine. They are handy. For this test I already had reader sockets left over from that project so opted to just sky-wire it (see picture in post to Clive below). I didn't have pullups on any lines after reading some posts saying they wern't necessary. Seeing scope traces made me wonder. It took a couple days to get to the right combination of pullups plus non-DMA to finally see things working. I'm getting there, just taking a bit longer than I had expected.

will

willcfj
Senior

Clive:

That is some serious speed. My sky wires are even shorter (see picture) and I was seeing some not-so-great signals and errors at 24MHz. I'm not terribly worried just yet, I'm sure a good layout will help considerably. That is good to know, though.

I've been wondering if my DMA-not-working issue may be something that STMCube32MX didn't have quite right specifically with the STM32F476, but see that you are using the exact same chip/board? Can I ask what revision CubeMX software/drivers you are using and FatFS/SDMMC settings you used? I'm sure there is something simple I am overlooking as a new CubeMX user. I'm mostly a hardware guy and only recently moved up from the bare bones SdtPeriph class libraries.

will

One can certainly do a much better job with a PCB design. The trace lengths on some of ST's EVAL boards are longer than I'd like. @Community member​ is working on some socket dongles for the NUCLEO-144 series that plug in compactly on the back-side. @Community member​ made a eMMC dongle when we were working on that.

Keeping trace lengths short and equal is desirable. For short runs, 27 or 33R series resistors should be used to stop ringing (backing off slew rate also helps), and 33 or 47K pull-up at the socket for the data and command lines.

In retrospect I should have used the shorter schmartboard wires for the SDMMC rather than the SPI, but it photographs well, works well, and can be handed around a conference table without getting broken, or in a car ride to/from home in a box. I've used wire-wrap a lot in the past, and that is more reliable than the dupont wires people use for bread boarding.

https://schmartboard.com/wire-jumpers/

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

Clive:

The jumper set I have doesn't look as nice as those. Wire wrap has worked well for me and I stockpiled a lot a long time ago, so still using it! If I can use jumpers I do, but often the thing I'm trying to wire up doesn't have posts like the SD card connector, so wire wrapping one end and soldering the other works out nicely. The hardware guy in me says use series resistors for slew rate control, but probably should listen to the firmware guy and use built-in slew rate control of the micro! :)

Back to the original problem though, could you please share your CubeMX settings for FatFS and SDMMC? Are you using DMA mode and/or RTOS maybe? I'd really like to get DMA mode working.

will