cancel
Showing results for 
Search instead for 
Did you mean: 

SDMMC on STM32 L476 L4

electronic tobi
Associate II
Posted on June 26, 2018 at 13:02

Hello,

I struggle to get SDMMC running.

I have a Discovery F4, I use the SDIO Module, open CubeMX, enable SDIO, gpio_input card detect, 2 dma (rx,tx) + interrupt

my code is simple

...

fres = f_mount(&_FileSys, SDPath, 1);

if (fres == FR_OK)

{

fres = f_open(&_File, 'TEST2.TXT', FA_READ);

if (fres == FR_OK)

{

..etc.

I can write to the card... works fine

But I also have a nucleo L476, when I do the same, enable SDMMC,dma...

it doesn't even mount the card

FR_DISK_ERR

I tested different clock sources, dividers, with dma , without dma

I wired the thing 3 times.

Did I miss something?

Is the there a big difference between the L4 and F4 / SDIO and SDMMC?

CubeMX 4.0 (+ L4 1.0)

TrueSTUDIO 9.0.1

Attached is the not working code for the L4

update:

the old CubeMX 4.21 works with the nucleo L476

The example without Cube from the current reposity package works also.

But the CubeMX 4.26 still doesn't 1 or 2 dma channels... whatever I try, allways

FR_DISK_ERR

.

#sdio-dma #sdmmc #sdio #l476 #dma-sdmmc

Note: this post was migrated and contained many threaded conversations, some content may be missing.
9 REPLIES 9
Posted on June 26, 2018 at 13:42

You might want to start using the example code in the HAL trees, it works better

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 26, 2018 at 13:55

hmm I'm not sure what you mean,

should I try to port the application code from a different L4 board to my nucleo ?

Posted on June 26, 2018 at 14:45

>>should I try to port the application code from a different L4 board to my nucleo ?

Might be a shorter path than fighting with broken code, it is the approach I used. Easier to take working code and pivot.

STM32Cube_FW_L4_V1.12.0\Projects\STM32L476G-EVAL\Applications\FatFs\FatFs_uSD_Standalone

There are several others, and ones implementing DMA

With CubeMX code you'd want to make sure the IRQs and call-backs are plumbed properly

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 29, 2018 at 16:45

thanks for the answer, yes the example just need some tweaks and then its working,

formating, writing, all works fine, I removed some code to get a better view...

but I'm still not able do the same with CubeMX, I guess the example is old and uses old bsp files, while the code from CubeMX seems different, for example the CardDetect in the example must be low, in the new files musst be high.

Currently I think there is something wrong how cubemx build the template or the bsp file isn't correct.

I mean, the discovery F4 works without a problem.

regards

Imen.D
ST Employee
Posted on July 02, 2018 at 15:50

Hello

t.greifenberg

 ,

I raised this issue internally to CubeMx team for check and come back to you.

With Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Posted on July 11, 2018 at 22:07

Hi, I'm also trying and failing to incorporate SDMMC with a Cube-generated project (specifically for the L476RG). Have you made any progress on converting from the HAL example?

Posted on July 12, 2018 at 11:15

Hello Forest,

yes I 'found' a workaround in the Forum

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

you need to do what is suggested in the first post and then remove the weak functions like suggested in one of the last posts.

But this is only a workaround the problem is that stm doesn't generate usable bsp files for the L4 , if you regenerate code with cube you must do the steps again.

With my sd card module I need also the internal pullups.

You can also take a look here

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

somewhere on the bottom are github links but since I got it working I didn't tested the solutions in this thread.

I hope that stm fix the problems around the sd card and dma code soon.

You can use my ioc attached to this post to generate a project

________________

Attachments :

L4CubeNEW.ioc.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxQX&d=%2Fa%2F0X0000000axt%2FDRB_32IbDNt1DEC7iPjK7iYLEs_nnSkGhka7EV50F2s&asPdf=false
Posted on July 12, 2018 at 19:06

Thanks for the links and .ioc -- they were very helpful!

Here's a question for anyone --

I get an error when calling FATFS_LinkDriver(&SD_Driver, SDPath) as shown in the HAL example. Looking further I find that this can be traced to FATFS_LinkDriverEx() in ff_gen_drv.c ---

(sorry, I don't know how to format code here)

uint8_t FATFS_LinkDriverEx(const Diskio_drvTypeDef *drv, char *path, uint8_t lun)

{

uint8_t ret = 1;

uint8_t DiskNum = 0;

if(disk.nbr < _VOLUMES)  // Right here is the root of the problem. disk.nbr in my case is 1 and _VOLUMES is also 1. Should this be <= _VOLUMES instead, or should these values be different?

{

disk.is_initialized[disk.nbr] = 0;

disk.drv[disk.nbr] = drv;

disk.lun[disk.nbr] = lun;

DiskNum = disk.nbr++;

path[0] = DiskNum + '0';

path[1] = ':';

path[2] = '/';

path[3] = 0;

ret = 0;

}

return ret;

}
Posted on July 13, 2018 at 09:05

do you call the fatfs_link with your own code?

Because in your main you only need to use f_mount, f_open,f_write,f_read, f_close

link is getting called in some basic function