cancel
Showing results for 
Search instead for 
Did you mean: 

SDCard with SDMMC on STM32H755ZI Nucleo

bramble
Associate III

Hi,

I've been trying to get a MicroSD card working with my H755 Nucleo for the last week. Tricky, isn't it?!

I started with a SPI SD-card interface but gave up on that after about several days of pain. My focus now is on interfacing via SDIO, using the SDMMC peripheral on H7 and FATFS with FreeRTOS. I've tried both 1- and 4-bit mode.

I have the card initialising OK in MX_SDMMC1_SD_Init(), but calls to f_mount() are failing in check_fs() (in ff.c) which returns FR_DISK_ERR (=4).

I've tried multiple different cards.

Interestingly I have been able to format a card, but it remains un-mountable, as well as when using an externally-formatted card.

I came across https://community.st.com/t5/stm32cubemx-mcus/stm32h7-how-to-use-sdmmc-with-mdma/m-p/220163  which contains a useful PDF which aims to fill the holes in AN5200 (whoever wrote the section around Figure 14 "MDMA end of data configuration with STM32CubeMx" seems to have lost interest just as they got to the interesting and important bit). That document is somewhat incomplete.

If anybody can point me towards a complete working example please, that would be great. By complete, I mean including the .ioc file as well as generated source, otherwise I've little chance of re-creating the solution in any maintainable way.

STM Staff, please would you sort out the documentation on this area? I think there's a need for a definitive set of instructions for SD Cards + FAT-FS, whereas currently I see a collection of incomplete documents and references to possible solutions from helpful developers in this community. You only have to look at all the questions asked by others to see how poorly documented this aspect of STM32 is.

I've attached my .ioc.

I'm sure I'll have done something silly or completely missed something that should be obvious - any help to identify the missing pieces would be  much appreciated.

Thank you!

 

1 ACCEPTED SOLUTION

Accepted Solutions
bramble
Associate III

Update on this issue which might help others in future.

I found this project on Git-Hub: SquadQuiz/NUCLEO-H755ZI-uSD-FatFS-DMA: ST MCU NUCLEO-H755ZI-Q Development board, Implementation of [SDMMC uSD + FatFs + DMA] with STM32CubeMX Code Generation . It provides a very complete step-by-step guide which should be useful for anyone using SDIO uSD cards on H755 Nucleo.

The key issue cause problems for me was confusion about these #defines in stm32h7xx_hal_sd.c:

 

#define SD_INIT_FREQ                   400000U   /* Initialization phase : 400 kHz max */
#define SD_NORMAL_SPEED_FREQ           25000000U /* Normal speed phase : 25 MHz max */
#define SD_HIGH_SPEED_FREQ             50000000U /* High speed phase : 50 MHz max */

 

I thought they'd do what the comments say, but that's not exactly right. I had left the GUI parameter "SDMMC clock divide factor" (see below) at its default value of 1, rather than 4 which I'm now using.

bramble_0-1739058764142.png

If you follow the logic in function HAL_SD_ConfigWideBusOperation() in stm32h7xx_hal_sd.c, it turns out that, if your uSD card is ultra-high speed, and if the value for "SDMMC clock divide factor" is less than that corresponding to SD_NORMAL_SPEED_FREQ, then the highlighted line of code is going to be hit, where hsd->Init.ClockDiv = <your GUI value, default = 1>

bramble_2-1739059224854.png

Putting this more plainly: The default value of "SDMMC clock divide factor" = 1 corresponds to a clock frequency that is very much faster than SD_NORMAL_SPEED_FREQ, and for an ultra-high-speed uSD that faster clock will be used, with SD_NORMAL_SPEED_FREQ and SD_HIGH_SPEED_FREQ being ignored.

Key take away => Don't leave "SDMMC clock divide factor" at its default value, and beware those #defines which are - in my opinion - not very well described in the code.

 

View solution in original post

1 REPLY 1
bramble
Associate III

Update on this issue which might help others in future.

I found this project on Git-Hub: SquadQuiz/NUCLEO-H755ZI-uSD-FatFS-DMA: ST MCU NUCLEO-H755ZI-Q Development board, Implementation of [SDMMC uSD + FatFs + DMA] with STM32CubeMX Code Generation . It provides a very complete step-by-step guide which should be useful for anyone using SDIO uSD cards on H755 Nucleo.

The key issue cause problems for me was confusion about these #defines in stm32h7xx_hal_sd.c:

 

#define SD_INIT_FREQ                   400000U   /* Initialization phase : 400 kHz max */
#define SD_NORMAL_SPEED_FREQ           25000000U /* Normal speed phase : 25 MHz max */
#define SD_HIGH_SPEED_FREQ             50000000U /* High speed phase : 50 MHz max */

 

I thought they'd do what the comments say, but that's not exactly right. I had left the GUI parameter "SDMMC clock divide factor" (see below) at its default value of 1, rather than 4 which I'm now using.

bramble_0-1739058764142.png

If you follow the logic in function HAL_SD_ConfigWideBusOperation() in stm32h7xx_hal_sd.c, it turns out that, if your uSD card is ultra-high speed, and if the value for "SDMMC clock divide factor" is less than that corresponding to SD_NORMAL_SPEED_FREQ, then the highlighted line of code is going to be hit, where hsd->Init.ClockDiv = <your GUI value, default = 1>

bramble_2-1739059224854.png

Putting this more plainly: The default value of "SDMMC clock divide factor" = 1 corresponds to a clock frequency that is very much faster than SD_NORMAL_SPEED_FREQ, and for an ultra-high-speed uSD that faster clock will be used, with SD_NORMAL_SPEED_FREQ and SD_HIGH_SPEED_FREQ being ignored.

Key take away => Don't leave "SDMMC clock divide factor" at its default value, and beware those #defines which are - in my opinion - not very well described in the code.