Skip to main content
willcfj
Associate III
October 24, 2018
Question

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

  • October 24, 2018
  • 42 replies
  • 8799 views

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

    This topic has been closed for replies.

    42 replies

    BGavr.3
    Associate
    October 25, 2018

    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
    willcfjAuthor
    Associate III
    October 26, 2018

    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
    October 26, 2018

    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
    willcfjAuthor
    Associate III
    October 27, 2018

    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
    willcfjAuthor
    Associate III
    October 26, 2018

    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

    Tesla DeLorean
    Guru
    October 26, 2018

    >>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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    willcfj
    willcfjAuthor
    Associate III
    October 27, 2018

    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

    Tesla DeLorean
    Guru
    October 27, 2018

    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Lukasz Przenioslo
    Associate III
    October 27, 2018

    With my current state of the design, I cannot get the eMMC working beyond 8 Mhz clock (still using only 1 data wire for now).

    0690X000006CGhVQAW.jpg

    willcfj
    willcfjAuthor
    Associate III
    October 27, 2018

    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

    Tesla DeLorean
    Guru
    October 27, 2018

    I don't use CubeMX, it is a time saving tool that wastes time in my universe.

    I'm using the HAL examples as a basis for the things, and have Polled and DMA variants working on assorted STM32 platforms, non-RTOS. I can also support eMMC (4-128GB modules tested), and have validated functionality out to 200-400GB cards. Got a lot of time and resources invested, so code only being shared with clients.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    willcfj
    willcfjAuthor
    Associate III
    October 27, 2018

    Clive:

    OK, understand your situation, thanks.

    will

    Lukasz Przenioslo
    Associate III
    October 27, 2018
    Hi Will,
    You are right, my cables are really bad. But at this point, i need it to work at any speed and with any data signals. Also, I was able to use 4 data bits thanks to Clive's help on a Nucleo board. Just could not bring the rest 3 signals to my current PCB because the pins are already in use by other peripherals. I am also looking forward to the next pcb revision, with series resistors and 4 data lines.
    T J
    Senior III
    October 27, 2018

    they are very thick wires, do you have any wirewrap wire ?

    too hard to retro fit... which eMMC chip are you using ?

    I can whip up a daughter board for you...

    willcfj
    willcfjAuthor
    Associate III
    November 1, 2018

    Just to let folk know: I'm still working on the root issue. I have confirmed that the stall is because there is no DMA happening at all, not because the DMA finished and the end isn't somehow being flagged. I also need a DMA-driven DAC for this project. Since I am pretty sure the "something basic" I'm missing has to do with DMAs, I'm going to fiddle withe the simpler peripheral (the DAC over SDMMC) to see what is wrong. Hopefully any lesson learned from the DAC DMA setup wil be applicable to the SDMMC DMA setup.

    will