2018-03-03 05:37 AM
Hello.
I've tried to test sdcard with fatfs on STM32F411RE on NUCLEO-F411RE board.
I don't have a compleat 100% sure hardware or software, so I'm struggling to debug if its a software or hardware issue.
I've read trough some topics hear, one with issue with sd initialization (but it seams that in my version this issue is already resolved).
I've tripple cheked all the connections and when the card is not in the socket I get fast resposne.
I've generated the code from stm32cubemx, and added a custom code:
/* Initialize all configured peripherals */
MX_GPIO_Init(); MX_SDIO_SD_Init(); MX_FATFS_Init(); /* USER CODE BEGIN 2 */ FRESULT res; FATFS SDFatFs; /* File system object for SD disk logical drive */ FIL MyFile; /* File object */ res = f_mount(&SDFatFs, (TCHAR const*)SDPath, 0); if (res != FR_OK) while(1); res= f_open(&MyFile, ''STM32.TXT'', FA_CREATE_ALWAYS | FA_WRITE); if (res != FR_OK) while(1); /* USER CODE END 2 */f_mount is ok, but f_open after around 30s gives back an FR_DISK_ERR . When there is no card in the socket I'm getting fast FR_NOT_READY return.
When exacuting f_open the funcion stucks on line 3050 from ff.c
fmt = check_fs(fs, bsect); /* Load sector 0 and check if it is an FAT-VBR as SFD */
It check_fs returns 4 code back and then f_open returns with FR_DISK_ERR
The only thing I did is change some SDIO pins to other options, and setup the clock. I'v tried with SDIO divider up to 96 and it didn't resolve my issue.
Am i forgetting about something? I know that the socket is on jumper wires, but at 250khz clock it should work... Of course tried few cards, tried to use f_mkfs to format card....
I'm software I'm using:
Attolic True studio v9.0
STM32Cube FW_F4 V1.19.0
FatFs R0.12cSTM32Cube 4.24#fatfs-sdio #sdio #stm32f411re #nucleo-f411re #fatfs-r0.12c #nucleo-f411 #stm32f4Solved! Go to Solution.
2018-03-11 05:00 AM
OK, I've resolved the issue.
The reason it not working was that I've didn't setup the DMA controller to work, and the standard SDIO communication works trough DMA.
Solution is for:
Attolic True studio v9.0
STM32Cube FW_F4 V1.0
FatFs R0.12c STM32Cube 4.24You have to manually in STM32Cube:
1. Add a DMA Stream for RX and TX
2. Add IRQ for SDIO (not sure if its requierd)
3. Optionally enable internally pull-ups on all lines except sdio_clk. The card works with only internal pull-ups without any problems at almost full speeds.
In you're code at the bottom of sd_diskio.c add:
Those are proper names for week functions for DMA completed callbacks.
And card started to work. I've also tried to use a pooling mode (disable DMA in FatFs configuration in stm32cube), but that way only reading from the card worked, and writing resulted in some fatal errors I've didn't care to debug. Default is that DMA is enabled. You can switch it here:
My test code in main looks like this:
I've attached my 100% working project. You can get wiring from the first post, I've used an SD to MicroSD adapter as a socket. Works like a charm.
________________ Attachments : sd_diskio.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hxim&d=%2Fa%2F0X0000000b24%2FCfrBCww.zTuYDZafHYoigwgocFRfOaruTl6_w0ZT9N4&asPdf=falsemain.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hxt1&d=%2Fa%2F0X0000000b22%2F9.FrdqHYC556x8JTZti_xO1.VCvM97dRaDk3CTNpWhM&asPdf=falsewiring.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxuD&d=%2Fa%2F0X0000000b21%2FDjAlqwnWO2VeZOkx2C4QUJ71sNlLdQeIoCjxBQnSRCA&asPdf=falsesdiodma.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxuI&d=%2Fa%2F0X0000000b25%2F.t4D8Xaq6h0rLIMciJeL54GVhIX50YGYB7cp_OSz24I&asPdf=false2018-03-05 07:01 AM
Hi!
I faced a similar problem when working with an F407 board. Initially i thought that there was something wrong with the code generation but i was wrong. I solved the problem once i slowed down the clocks after reading this in the manual.
I think you should decrease the SDIOCLK to around 25MHz (16 MHz worked for me) and then give it a try.
Hope this helps.
2018-03-11 05:00 AM
OK, I've resolved the issue.
The reason it not working was that I've didn't setup the DMA controller to work, and the standard SDIO communication works trough DMA.
Solution is for:
Attolic True studio v9.0
STM32Cube FW_F4 V1.0
FatFs R0.12c STM32Cube 4.24You have to manually in STM32Cube:
1. Add a DMA Stream for RX and TX
2. Add IRQ for SDIO (not sure if its requierd)
3. Optionally enable internally pull-ups on all lines except sdio_clk. The card works with only internal pull-ups without any problems at almost full speeds.
In you're code at the bottom of sd_diskio.c add:
Those are proper names for week functions for DMA completed callbacks.
And card started to work. I've also tried to use a pooling mode (disable DMA in FatFs configuration in stm32cube), but that way only reading from the card worked, and writing resulted in some fatal errors I've didn't care to debug. Default is that DMA is enabled. You can switch it here:
My test code in main looks like this:
I've attached my 100% working project. You can get wiring from the first post, I've used an SD to MicroSD adapter as a socket. Works like a charm.
________________ Attachments : sd_diskio.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hxim&d=%2Fa%2F0X0000000b24%2FCfrBCww.zTuYDZafHYoigwgocFRfOaruTl6_w0ZT9N4&asPdf=falsemain.c.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hxt1&d=%2Fa%2F0X0000000b22%2F9.FrdqHYC556x8JTZti_xO1.VCvM97dRaDk3CTNpWhM&asPdf=falsewiring.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxuD&d=%2Fa%2F0X0000000b21%2FDjAlqwnWO2VeZOkx2C4QUJ71sNlLdQeIoCjxBQnSRCA&asPdf=falsesdiodma.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxuI&d=%2Fa%2F0X0000000b25%2F.t4D8Xaq6h0rLIMciJeL54GVhIX50YGYB7cp_OSz24I&asPdf=false2018-03-11 05:19 AM
Thank You, but as I've mentioned I've tried to lower the clock of SDIO. Tried values to 250kHz. But I've resolved the issue, I'll post the solution within few minutes.
2019-08-04 10:59 AM
@Jakub: Thanks for not only asking a good question, but also being so nice to post the solution.
Your screenshots helped me compare the differences between my configuration and a working configuration, and with that I got it to work. Using DMA was the key :)
2019-11-13 11:53 PM
Thanks! Jakub Lasinski
I just change pins to pull-up and all my problems solved.
2020-12-02 02:05 AM
unfortunately it doesn't work on STM32Cube_FW_F4_V1.25.2 and standard example STM324xG_EVAL\Applications\FatFs\FatFs_uSD\Src (2017 year) is without stm32cubeide support too...
2020-12-02 04:48 AM
Very helpful post. Thanks alot.
2020-12-02 05:42 AM
unfortunately for stm32cubeide 1.5.0 this solution doesn't work. And FatFS via CubeMX on STM32Cube_FW_F4_V1.25.2 too. But very old example STM324xG_EVAL\Applications\FatFs\FatFs_uSD\Src from 2017 year works via Keil.
2020-12-02 05:51 AM
I have cube 1.5.0 and it works perfectly