cancel
Showing results for 
Search instead for 
Did you mean: 

FatFs - SDMMC - STM32H7

JC Lebreton
Associate II
Posted on February 21, 2018 at 16:20

Hi,

I have the problem that many of us have as seen on the number of post on the forum. Unfortunatly for me nobody have the same issue as i have!

Let s point out first what i'm trying to do.

I'm on a small project of data gathering. Of course I need to store the data somewhere and the card won't have acces to LoraWan or any similar network. So the only idea i got was using an USB stick or an SD card. I came with the idea to use an SD card for its small size. If some of you think it's easier to implement USB stick we can explore this option.

 

OK. this settled, let me explain what i did at the moment.

I try the code given by ST and adafruit, where they are using the SPI connection with the SD card. But i don't really like this technique.

So i try with the Cube to implement the SDMMC (1bit bus at the moment) and FatFs interface for an SD card. (configuration of the Cube on attachement).

I then create a projet on eclipse and try so stuff.

I use the function BSP_SD_Init(), wich result in a succes

I then try functions lie : f_mount(), 

FATFS_LinkDriver(&SD_Driver, SDPath),

f_mount()... But none of them seems to work!

I'm totaly lost... 

Do I have to Initialise more things? 

Do I have to complete .c files? like sd_diskio.c ?

well, if some of you have some clue or some working sample code it will be awesome.

Best regards,

JC

15 REPLIES 15
Posted on April 21, 2018 at 15:07

Hi JC!

Would you be able to share your test-project for the Nucleo here? I'm also struggling with the H7 and SD-card, and am starting to suspect I'm somehow doing something completely stupid and a working demo-project would be helpful!

Thanks a lot,

Michael

Posted on April 21, 2018 at 17:00

I'll need to pull together a releasable build.

0690X00000604UkQAI.jpg

For the sockets I can recommend the VIEWTOOL and OPEN-SMART

https://www.ebay.com/itm/New-Blue-Silver-Micro-SD-TF-Card-Breakout-Transfer-Board-Module-MB102-DIY-YG/122073672724

 
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 21, 2018 at 20:03

Clive, may I ask what value you are using for the SD clock divider (i.e. at what frequency are you running the card)? I noticed an interesting behavior in my code: when I use a very low divider value (0 to 5), and hence a high frequency, it completely fails to initialize the card (HAL_SD_Init() returns an error). I suspected that this might be due to my messy wiring (also I did not yet desolder SB116 and SB117) and therefore increased the clock divider. Starting at 6 (corresponding to just 6 MHz bus frequency) the call to HAL_SD_Init() succeeds but then the FatFS calls f_mkfs() returns FR_DISK_ERR ('A hard error occurred in the low level disk I/O layer').

Do you still have your working Nucleo+SD-Card combo assembled? I know this is asking for a lot but could you try to run my test application on your board and see whether it works for you? I attached the project (GCC Makefile project) to this post, it also includes a compiled elf-file in the build folder. The app prints debug information over the ST-Link Uart with 115200 baud. Note also that it tries to format your SD-Card so please be careful!

Thanks again for your help!

Michael

________________

Attachments :

fatfs_simple.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hxfc&d=%2Fa%2F0X0000000b0n%2FMSiyiQNwI94p0_m7AX6qEpb7QN8okxqLfrKiryQNBFI&asPdf=false
Posted on April 21, 2018 at 20:46

The STM32 get more complex and confusing clock routing as time progress. The SDMMC clocks at 200 MHz. Down stream code limits ClockDiv based on card type. I would not call MKFS, and in fact during initial bring up do read-only operation. In ff_conf.h I disable MKFS and enable EXFAT and LFN support.

I have two NUCLEO-H743ZI boards wired up, and also an STM32H743I-EVAL, but the latter has the bus transceiver and a bit more complicated interface for higher speed cards. Don't have the Nucleo boards with me, and not looking to do a destructive test on my cards. I will do a static review of what you have provided.

Posted a file CRC function here.

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

 

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

 

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

 
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 22, 2018 at 18:50

Ah that's interesting! Seems then that the corresponding description in CubeMX is wrong:

SDMMCCLK clock divide factor

ClockDiv must be between 0 and 255.

Parameter Description:

SDMMC_CK = SDMMCCLK / [CLKDIV + 2]. The output clock frequency can vary between 187 KHz and 24 MHz. It is advised to keep the default ClockDiv value (0) to have a maximum SDMMC_CK frequency of 24 MHz.

Anyway, the good news is that I got it working at least in 1bit mode (I'm kind of embarrassed that I didn't try this earlier...) so I'm strongly suspecting some signal integrity issues here due to my long and messy wiring  Will try a different SD socket breakout and shorter wires soon and report back here.

Thanks again for your helpful support Clive!

Posted on April 30, 2018 at 12:36

Hello Michael,

Thanks for rising this issue.

It will be fixed next release.