SDIO+DMA+FATFS for STM32L476RG (CubeMX 4.25.0+MCU pack 1.11.0)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-04-30 11:23 PM
Dear friends,
I have an issue with uSD reading and writing in DMA mode (How ever I am able to read and write data on SD card when dma template is off). I used CubeMX to configure♯
but it did not work for me ''out of the box''.My CubeMX version is 4.25.0 and L4 MCU package is 1.11.0.
Could you point out what I am doing wrong in configuration or in my code or if it is CubeMX issue, could you please advice me how to solve it?
I found some topics related to SDIO and DMA configuration and tried to implement them :https://community.st.com/0D50X00009XkVtKSAV
?https://community.st.com/0D50X00009Xkf5gSAB
?https://community.st.com/0D50X00009XkYIGSA3
?Below you find screen shots with my settings and my SW4STM32 project including CubeMX file.
My MCU setup:
My CubeMX configuration:
1) Clock
2)Clock factor
3)NVIC
4)DMA
5)Pin configuration
6)FatFS (sector size)
7)DMA template enabled
#fatfs-sdio #stm32l476 #sdio-dma #sd-card #sdio+dma+fatfs #stm32l4-sdioSolved! Go to Solution.
- Labels:
-
SDIO-SDMMC
-
STM32L4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-05-11 02:20 AM
Finally, I get it worked with CubeMX 4.25 and MCU pack 1.0!
The list of issues:
1) Missing line in time configuration
RCC_OscInitStruct.PLL.PLLM = 1; //Missed line
2) Change according to
Kirshin.Evgeny
‌https://community.st.com/0D50X00009XkVtKSAV
3) Change according to
Vasiliev.Alexander
‌https://community.st.com/0D50X00009XkVtKSAV
4) I suggest to use short filenames written in lower case letters.
I will update the git repository I mentioned behind.
Thanks a lot to
Kirshin.Evgeny
‌ andVasiliev.Alexander
‌. You help deserves a beer;)Best regards,
Dmitry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-05-01 07:48 AM
Hi Dmitry,
What exactly is not working?
Are you using RTOS? I have my code running on top of the FREERTOS, generated by CubeMX (same project).
I do not have a separate demo-project, but I can share the files I modified (attached). The fatfs.c is modified to use RTC time for files.
My initialization procedure is as follows:
SD_Initialize(); if(BSP_SD_IsDetected()) { if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) == FR_OK) { sd_mounted = 1; } }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
Where:
static void SD_Initialize(void) { if (isInitialized == 0) { BSP_SD_Init(); BSP_SD_ITConfig(); if(BSP_SD_IsDetected()) { isInitialized = 1; } } }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
I also attached some screenshots, where I found differences between yours and my project configuration in CubeMX.
As you can see, I have SDMMC1 48MHz clock and SDMMCCCLK clock divider is set to 0. The DMA priority is Very High, but I don't think this should be an issue. Also, I don't use internal pull-ups since I have them externally. Finally, I enabled long filenames support in FatFs.
I hope this helps.
________________ Attachments : fatfs.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hxey&d=%2Fa%2F0X0000000b0h%2FyMkSYkSe_W_2WqOT_wnYOkxueK4JxgIZ8ReXGAzJfak&asPdf=falsestm32l4xx_it.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hxet&d=%2Fa%2F0X0000000b0c%2FhpgKXCq_kBop4KsnaEqnD_4KNP63To1lsk21BCsiXE0&asPdf=falsebsp_driver_sd.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hxf3&d=%2Fa%2F0X0000000b0g%2F6EaBfDqo7rAttRKkcZtW54xDBML2v566cm2Ttm6xJ3U&asPdf=false- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-05-01 05:23 PM
,
,
Dear Evgeny,
Thank you very much for such quick and informative reply.
I corrected all my settings according to yours, but I still have the problem with sd card reading.
Regarding to your questions:
1) First, I am able to access an sd card (read/write) with switch off dma template option.
2) In the beginning, I did not use freertos and made a corrections according to your advice in the topic
https://community.st.com/0D70X000006SiUGSA0
, and the problem was a dma read or write timeout, because I did not receive a callbacks (HAL_SD_RxCpltCallback or HAL_SD_TxCpltCallback).3) Now, I am trying to run sd card reading in rtos, but the program does not start. I thought that it could be lack of ram memory for task. I changed the task stack size from 128 to 256 and even to 512, but it did not help.
Do you know what could be the problem?
My task is just:
,[CODE]
void StartDefaultTask(void const * argument)
,
{,
, /* init code for FATFS */,
, MX_FATFS_Init(),, /* USER CODE BEGIN 5 */
,
, /* Infinite loop */,
, for(,,),
, {,
, , ,HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin),,
, , , osDelay(100),,
, },
}[/CODE]
Could I ask you to share your freertos settings and nvic related to sd card reading?
Thank you in advance for your response.
Best regards,
Dmitry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-05-02 09:12 AM
Hi Dmitry,
If you set a breakpoint in your task, does it stop there? If not, it might be an issue with task priorities (although, you have only one task?) Also, have a look at heap size.
Here are the screenshots of the settings from my project.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-05-03 10:24 AM
Dear Evgeny,
Thanks a lot for your support. I did a corrections according to your screen shots.
I found out that freezed program start was caused by error in timer configuration. I changed the input for sd card clock to PLLQ with 40MHz and it partially works now (I am able to blink a led in freertos:)).
Another thing is that my f_mount function with mount later option
f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) returns FR_OK and it is a good sign,
however if I select f_mount(&SDFatFS, (TCHAR const*)SDPath, 1)
it returns FR_DISK_ERR.
Below you could see a code that generates an error:
fmt = check_fs(fs, bsect); /* Load sector 0 and check if it is an FAT-VBR as SFD */
if (fmt == 2 || (fmt < 2 && LD2PT(vol) != 0)) { /* Not an FAT-VBR or forced partition number */ for (i = 0; i < 4; i++) { /* Get partition offset */ pt = fs->win + (MBR_Table + i * SZ_PTE); br[i] = pt[PTE_System] ? ld_dword(pt + PTE_StLba) : 0; } i = LD2PT(vol); /* Partition number: 0:auto, 1-4:forced */ if:)
i--; do { /* Find an FAT volume */ bsect = br[i]; fmt = bsect ? check_fs(fs, bsect) : 3; /* Check the partition */ } while (LD2PT(vol) == 0 && fmt >= 2 && ++i < 4); } if (fmt == 4) return FR_DISK_ERR; /* An error occured in the disk I/O layer */Today evening I will try to debug it and write you back with my results tomorrow. If you have any suggestions, please write me back. I appreciate your help.
Best regards,
Dmitry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-05-10 04:11 PM
Dear Evgeny,
I am sorry for the delay in response.
I rewrite the bsp_driver_sd.c according to FatFs_uSD_DMA_RTOS for l476g-eval. I downgrade my CubeMX from 4.25 to 4.24 and change my CubeMX settings according to your screen shots, but I still did not solve the issue.
I created project on GitHub:
https://github.com/uid17/uSD_DMA_RTOS_STM32l476RG
I appreciate any suggestions and commits of you and community.
Thank you in advance.
Best regards,
Dmitry.
P.S.
I also found the recommendation of
Vasiliev.Alexander
in the topic I will try it today.‌- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-05-11 02:20 AM
Finally, I get it worked with CubeMX 4.25 and MCU pack 1.0!
The list of issues:
1) Missing line in time configuration
RCC_OscInitStruct.PLL.PLLM = 1; //Missed line
2) Change according to
Kirshin.Evgeny
‌https://community.st.com/0D50X00009XkVtKSAV
3) Change according to
Vasiliev.Alexander
‌https://community.st.com/0D50X00009XkVtKSAV
4) I suggest to use short filenames written in lower case letters.
I will update the git repository I mentioned behind.
Thanks a lot to
Kirshin.Evgeny
‌ andVasiliev.Alexander
‌. You help deserves a beer;)Best regards,
Dmitry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-05-11 09:36 AM
I am glad you solved your problem.
Was the issue only in one line to set the PLLM?
Which toolchain/compiler are you using?
Long file names with capitals work for me (there is a setting in FatFs configuration to enable long file name support).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-05-11 10:26 AM
Hello
dmitry.kochubey
,About the missing PLLM code generation for STM32L4 Series, this issue is fixed with the new version 4.1.
Best Regards,
Imen
Thanks
Imen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-05-11 02:45 PM
Dear Evgeny,
I am using SW4STM32 + GCC. Regarding to the issues in the beginning I had to fix time config, then I modify bsp according to your advice and finally I also had the same issue as
Vasiliev.Alexander
‌ and I fixed it according his suggestions. Long file names with capitals work for me as well but I write this recommendation for beginners in order to reduce effect of file names on sd reading process.Best regards,
Dmitry.