cancel
Showing results for 
Search instead for 
Did you mean: 

SD card project

XLin.2
Associate II

I am developing project using SD card on custom board but had some difficulties, so I am learning by using the f746g-disco, the example project provided in CubeMX worked (except for Sandisk XC card), then I followed exactly this example (https://community.st.com/s/article/how-to-create-a-file-system-on-a-sd-card-using-stm32bubeide) to generate project using CubeMX, the generated project failed in 'SD_PowerOn'. What could be wrong?

9 REPLIES 9
Imen.D
ST Employee

Hello @XLin.2​ ,

Please share more details about to your post (error message, clock configuration, software/tools version used), this will help us, and community users answered you.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Perhaps also look at

STM32Cube_FW_F7_V1.17.0\Projects\STM32746G-Discovery\Applications\FatFs\FatFs_uSD

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
RRibe
Associate II
  • I made a project today with sd card and STM32F746G-DISCO using STM32CubeIDE version 1.12.1 and STM32CubeMX version 6.8.1 just following this tutorial.

https://community.st.com/s/article/how-to-create-a-file-system-on-a-sd-card-using-stm32bubeide

and don't forget to follow the tip of.

TKana.1

 (Community Member)

3 months ago

Actions for this Feed Item Comment

Made it work with couple of modifications:

1- Moved variables to global

move

"

/* USER CODE BEGIN 1 */

FRESULT res; /* FatFs function common result code */

uint32_t byteswritten, bytesread; /* File write/read counts */

uint8_t wtext[] = "STM32 FATFS works great!"; /* File write buffer */

uint8_t rtext[_MAX_SS];/* File read buffer */

/* USER CODE END 1 */

"

to

"

* USER CODE BEGIN PV */

FRESULT res; /* FatFs function common result code */

uint32_t byteswritten, bytesread; /* File write/read counts */

uint8_t wtext[] = "STM32 FATFS cali666siy great!"; /* File write buffer */

uint8_t rtext[_MAX_SS];/* File read buffer */

/* USER CODE END PV */

"

2- Changed 4B wide operation to 1B operation in "MX_SDMMC1_SD_Init()"

static void MX_SDMMC1_SD_Init(void)

{

 /* USER CODE BEGIN SDMMC1_Init 0 */

 /* USER CODE END SDMMC1_Init 0 */

 /* USER CODE BEGIN SDMMC1_Init 1 */

 /* USER CODE END SDMMC1_Init 1 */

 hsd1.Instance = SDMMC1;

 hsd1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;

 hsd1.Init.ClockBypass = SDMMC_CLOCK_BYPASS_DISABLE;

 hsd1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;

 hsd1.Init.BusWide = SDMMC_BUS_WIDE_1B; //Start with 1B instead 4B. Later "SD_Widebus_Enable" command makes it 4B

 hsd1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;

 hsd1.Init.ClockDiv = 0;

 /* USER CODE BEGIN SDMMC1_Init 2 */

 /* USER CODE END SDMMC1_Init 2 */

}

now it works OK. Tested with 4GB and 16GB FAT32 formatted uSD cards

XLin.2
Associate II

Thanks RRibe! It works on 746G-DISCO now. Just curious why 4 lanes didn't work, anyhow my custom board is 1 bit, I will try on it.

XLin.2
Associate II

I am still having problems with my custom board, which is Stm32H753, SD in 1 bit mode, Input clock 200Mhz, SDMMC2 interface as SD, with clock divide by (3+1), no transceiver. It always fail in SD_PowerON(). I traced it to SDMMC_CmdAppCommand()
_legacyfs_online_stmicro_images_0693W00000bj8snQAA.png, where it sends 0x37 and expects the same comes back from RESPCMDR registers. There was no timeout or CRC errors, just the RESPCMDR was 0.

I have attached a screen capture. I am not familiar with SD cards, please help.

The pins for SD are PD6(CLK), PD7(CMD), PB14(D0), all are high speed AF, with internal pull ups. I am using CubeMX 6.8 with H7 package 1.11.0.

RRibe
Associate II
XLin.2
Associate II

Still no luck yet. A question I have is about pins: Looking at the schematics of my board, it is in 1 bit SD mode. D1-D3 on the card slot side are left floating, should they be pulled? And for CLK/CMD/D0 are internal pullup (40Koms) enough?

AScha.3
Chief II

first -

  • use 1 bit mode
  • set pullups on all lines
  • set pin/port speed at medium or meduim/high (try)
  • use clock 100M div 1 (50 MHz) ...or lower.

If you feel a post has answered your question, please click "Accept as Solution".
wuxw
Associate

Have you enabled DMA for fatfs? If so, some comments need to be cancelled in sd_diskio.c.

/* USER CODE BEGIN enableSDDmaCacheMaintenance */
#define ENABLE_SD_DMA_CACHE_MAINTENANCE 1
/* USER CODE END enableSDDmaCacheMaintenance */

/* USER CODE BEGIN enableScratchBuffer */
#define ENABLE_SCRATCH_BUFFER
/* USER CODE END enableScratchBuffer */