2018-03-07 03:58 PM
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:
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.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 29105Attached 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!!
Solved! Go to Solution.
2018-03-09 09:48 AM
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:
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!
2018-03-07 05:39 PM
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
2018-03-08 11:10 AM
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.
2018-03-09 09:48 AM
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:
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!
2018-03-20 06:19 AM
you can find my DMA example Code here: