cancel
Showing results for 
Search instead for 
Did you mean: 

HI, I have STM32L476RG nucleo board. I have interface a SD card using SDMMC. I could not connect to the card.

HMaje.1
Associate III

HI, I have STM32L476RG nucleo board. I have interface a SD card using SDMMC. I have configured SDMMC as 4bit mode with TX, RX in DMA mode. I have configured FATFS. I have given 47K pull up to DO to D3 and CMD line. I am using CUbeMX 5.5.0. The FATFS version is R0.12c.

0690X00000BwcW5QAJ.jpgWhen I generate the code and compile, I get error of

void HAL_SD_AbortCallback(SD_HandleTypeDef *hsd)

weak void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)

weak void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)

as defined twice in BSP_driver_SD.c and stm32l4xx_hal_sd.c

SO I commented in BSP_driver_SD.c and the code complied.

I flashed the code in my nucleo-l476RG board.

the code is as below

MX_GPIO_Init();

 MX_DMA_Init();

 MX_RTC_Init();

 MX_SDMMC1_SD_Init();

 MX_USART2_UART_Init();

 MX_FATFS_Init();

 /* USER CODE BEGIN 2 */

 res = BSP_SD_Init();

 if(res != FR_OK)

 {

   Error_Handler();

 }

 res = f_mount(&SDFatFS, (TCHAR const*)SDPath, 0);

 if(res != FR_OK)

 {

   Error_Handler();

 }

 if(f_open(&SDFile, "L4.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)

 {

  printf("Failed to open Write file\r\n");

 }

 else

 {

  printf("Opened Write file successfully\r\n");

  //Write data to text file

  res = f_write(&SDFile, wtext, strlen((char *)wtext), (void *)&byteswritten);

  if((byteswritten == 0) || (res != FR_OK))

  {

   printf("Failed to write file!\r\n");

  }

but on ruuning the code, I am getting

Failed to open Write file

Please can you help with the configuration and code.

Thanks,

Hitesh

  else

  {

   printf("File written successfully\r\n");

   printf("Write Content: %s\r\n", wtext);

  }   

  f_close(&SDFile);

 }

but the

8 REPLIES 8
HMaje.1
Associate III

I uploaded the below hex file STM32L476RG_NUCLEO_TEST_SDMMC_001.hex and I am getting

Core=80000000, 80 MHz     CPUID 410FC241 DEVID 415 REVID 1007                                                                                              

Cortex M4 r0p1                STM32L475xx, L476xx or L486xx                                                                                                    

C0000000 00000000 00000000 10110021 11000011 00000000                                                                                                       

FPU-S Single-precision only HCLK=80000000                                                                                                                    

APB1=80000000                      APB2=80000000                                                                                                                    

MCLK=4000000                                                                                                                     

FatFs Testing (87030)                                                                                                            

SystemCoreClock: 80000000                                                                                                        

Mounting FatFs                                                                                                                   

Switch to 4-Bit                                                                                                                  

R 8192 1 (00000002)                                                                                                            

res = 13 f_getfree                                                                                                               

Infinite loop...  

Nothing is written on the SD card.

How large is the card? Is it using EXFAT or NTFS?

Try a FAT formatted card of 32GB or less.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Check also wiring and socket. I'm using quality PCB, and wiring only several inches long, and uniform.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks for the post.

I have FAT32 card of 16 GB size.

Yes have checked the connection several time and found OK. The length of wire is also 110 mm.

I have been reading post for SD card issue and seems many are facing the issue.

The posts of problems with SD card, posted, are old. Does the problem with cubeMX code (latest one) for SD card still persist?

I have just switched to ST micro controllers. have been successful with RTC,ADC, RTC Alarm, LCD. but I wanted to store this data ( as my application is data logger with GSM Connectivity) I am unable to interface my nucleo-L476RG to SD card.

>>The posts of problems with SD card, posted, are old. Does the problem with cubeMX code (latest one) for SD card still persist?

Not a Cube Jockey here, I've got no doubt it is still packed with bugs, the demo was written directly with HAL and has been tested on the target hardware. It was provided as a "known to work" example, so issues with HW vs SW could be delineated. There is likely some other hardware/electrical conflict on the board.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks,

I will once again re-check my electrical connections.

Or the socket/board. I have generally used WaveShare/ViewTool sockets, and short schmartboard jumper wires, these bite a lot harder/reliably on the the pin edges than dupont wires. More akin to the metallic bond you get with wire-wrap.

https://www.waveshare.com/micro-sd-storage-board.htm

https://www.waveshare.com/SD-Storage-Board.htm

https://schmartboard.com/jumper-wires/

I've used these on NUCLEO 64 and 144 boards. And I have some custom dongle/hat boards to the NUCLEO-144

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
HMaje.1
Associate III

I have programmed by nucleo-L476RG board from STM32Cube_FW_L4_V1.15.0 ( provided by STM)

D:\en.stm32cubel4_v1-15-0\STM32Cube_FW_L4_V1.15.0\Projects\STM32L476G-EVAL\Applications\FatFs\FatFs_uSD_Standalone

the f_open function creates the a text file STM32.txt in my SD card. but f_write function return error. SO f_write is not working.

Since I am able to create a STM32.TXT in my SD card, I assume my electrical connections are OK. Also I am getting SDMMC_CK as 24MHZ on the oscilloscope.

(SDMMC_CK = SDMMCCLK / [CLKDIV + 2])

MY SD card is FAT32 format 16GB SDHC.