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

They wrote back!

Case#: 00081057

Subject: SDMMC DMA non RTOS code sample needed

Status: Solution Proposed

Description:

Hi,

Sorry for the 'sanity' loss.. I agree it can be frustrating... ST is working on, won't happen in the next several months, the .ioc for the examples in the cube library. I, as you, have to do the same thing. I do the trial on error to get the configuration of the peripheral, then move the application/IT/callback code into the generated cubemx file. Sorry, but this is how it's currently done.

I searched the L4 cube database, for SDMMC issues. There was one back in 2018 with the DMA and a single block transfer where the error callback timeout. But this was fixed. Make sure your'e using ver 1.14.

One thing to check, there are other DMA examples, no RTOS in the cube L4... take a look at one, there are some for the SPI. This will show you the flow. With DMA and peripheral, the sync needs to be done.... the DMA starts before you enable the peripheral. The difference with Normal DMA and circular DMA, the count is auto loaded in circular DMA... so in your case you will have two DMA, SPI to memory and memory to SDCard. You won't be able to DMA directt to SDCARD. There are large pauses on the write/read seek in SD cards....

When streaming DMA, I use large buffer, the HC ISR of the DMA to start the write to the SDcard, the TC for the 2nd half of the buffer. The buffer will need to be large. ST DMA does not do chaining, so you use single buffer and the HC/TC counts for the ping-pong.

I have not done a SD CARD recently, but the class of the card (NAND) has an affect on the seek time, thus the pause time when writing... So be aware of this.

When it comes to FREERTOS, it uses the systick for it's tick, TIM6 is used for the HAL tick which is used in the delay(), the callback timeouts. So yes keep them separate. When it comes to ISR priorities, in FreeRTOS all are level 5, some are set to level 15... The DMA ISR can be at the same priority as the peripheral ISR... both are not happening at the same time unless you are doing normal, but the data is moved by that time... it's the starting where they synching needs to occur...

You should not be getting trapped in while(1) with error callback.

Sorry, not much help, no 'silver' bullet... just some thoughts

Best Regards,

ST Tech Support M1

Please visit ST Customer Support Portal for further information.

https://my.st.com/ols#/ols/editrequest/00081057

willcfj
Senior

Beachmiles:

Bummer, not much of an answer in terms of guidance unforutnately, but was worth a try... I've been spending time again on this project for a good part of my day today, but still no luck. I did migrate to STM32CubeIDE which looks to have been a mistake. Two crashes so far during code re-generation and for both crashes it completely tashed all my source files. For the first one, I did't lose anything, for the second i lost about 2 hours of work. Not getting off to a good start. Grumble, grumble.

will

Hello, do you need it with DMA or without ?