cancel
Showing results for 
Search instead for 
Did you mean: 

Problem using CubeMX 4.24 + FatFs R012.c + SDMMC1 with nucleo L476RG

Posted on March 08, 2018 at 00:58

Hi everyone,

Since a couples days ago I'm trying to set a project in which I can use a micro SD card using the nucleo board L476RG. I'm using CubeMX 4.24 and the HAL library 1.11 for L4 for making all the settings and I also checked the example that is provided for the L476 eval board. I think that all the settings are right, I compare it with the example and it is almost equal. Some captures from cubeMX:

0690X0000060A0FQAU.png

0690X0000060A0QQAU.png

0690X0000060A0UQAU.png

0690X00000609axQAA.png

0690X0000060A0ZQAU.png

0690X00000609xlQAA.png

0690X00000609xmQAA.png

0690X0000060A0eQAE.png

0690X00000609wuQAA.png

After doing all the configurations I generated the code, So I copied some parts of the example and added to my code. I started with this:

if(retSD == 0)

{

if(BSP_SD_Init() != HAL_OK)

{

Error_Handler();

}

res = f_mkfs(SDPath, FM_ANY, 0, workBuffer, sizeof(workBuffer));

if (res != FR_OK)

{

Error_Handler();

}

}

But the function

f_mkfs

always returned FR_DISK_ERROR. So I check the forum and I find that changing the name of the SD callback functions could help to avoid the error. So I changed from sd_diskio.c:

//void BSP_SD_ReadCpltCallback(void)

void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)

{

ReadStatus = 1;

}

//void BSP_SD_WriteCpltCallback(void)

void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)

{

WriteStatus = 1;

}

And I comment those functions from bsp_driver_sd.c.

After did that, the SD_WRITE function works and the

f_mkfs

returned FR_OK, also I can mount the unit but when I tried to open or create a file the function reaches the timeout and return error. I found that the RxCallback is never reached when the f_open function is called.

0690X0000060A0tQAE.png

I'm not sure, but I think that there is an error with the DMA configuration or maybe could be a harware error, here is a picture of the board with the adapter:

See Attachements 29105

Attached to this post is the code for SW4STM If there is other way to set the FatFs I'll be glad to receive all the suggestions. If you need any additional info don't hesitate to request. Thank you so much!!

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on March 09, 2018 at 17:48

Hi

Turvey.Clive

,

Thank you so much for your fast reply. In fact I checked other forum and I found that you could configure the polled mode in the FatFs button by disabling the DMA template in the IPs instances:

0690X0000060A3dQAE.png

In polled mode works fine, in fact I didn't change any of my code and it works in the first attempt (even with my handmade micro SD adapter ) and for my application is enough. However, the DMA configuration let me a doubt: why the Tx mode reaches the interrupt but the Rx don't. Hope that ST CubeMx team could fix it!

View solution in original post

4 REPLIES 4
Posted on March 08, 2018 at 02:39

Not sure I would have taken this approach.

The code in bsp_driver_sd.c clashes with some of the code in sdmmc.c

SD_DMAConfigRx() in bsp_driver_sd.c configures the wrong DMA channel and interrupt

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

Did get this to build in Keil last night via a donor project template, and instrumented via SWV

Was able to get it to work in polled mode, but do think there are some issues with DMA. There is a lot of code to support DMA differently on the L4Rx platforms (L4+) where I do have working DMA based code, but I can't pin down in the code flow where it would start/configure a DMA transfer here, which is why it stalls and doesn't see an interrupt at the other end.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 09, 2018 at 17:48

Hi

Turvey.Clive

,

Thank you so much for your fast reply. In fact I checked other forum and I found that you could configure the polled mode in the FatFs button by disabling the DMA template in the IPs instances:

0690X0000060A3dQAE.png

In polled mode works fine, in fact I didn't change any of my code and it works in the first attempt (even with my handmade micro SD adapter ) and for my application is enough. However, the DMA configuration let me a doubt: why the Tx mode reaches the interrupt but the Rx don't. Hope that ST CubeMx team could fix it!

feuerwolf
Senior
Posted on March 20, 2018 at 14:19

you can find my DMA example Code here:

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