cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407VG - SDIO / FATFS - save file to an sd card

CFrom.1
Associate

Hi everyone,

Sorry for this “Error while parsing Rich Text Content�?, I got an error when publishing. I can't share the whole file.

Problem :

> Even the card is present or not, The SD card is mounted .

> I can’t write a file to the sd card.

Context :

I read a lot of books, documentations and tutorials, I can’t find a way to make it work.

From the STM IDE debugger, I can’t get rich errors as I find with Python or Javascript. This is why I’m asking help. Except with printf but this is only a personal comment to my terminal. What I mean it's... I cannot I have a feedback from a function error. I only can track variable value. I spend a lot of time on it but I cannot solve this basic issue.

Technical specifications :

Mac OS - 10.15.4 

CubeMX - 5.6.1

STM32 IDE - SDIO / FATFS

SD Card Board :

https://www.amazon.fr/Module-Lecteur-Carte-Double-Arduino/dp/B07MG4LZRW/ref=pd_rhf_se_p_img_12?_encoding=UTF8&psc=1&refRID=WJGA2Y1B8XK0H658VV8C

code

extern char SDPath[4];   /* SD logical drive path */
extern FATFS SDFatFS;    /* File system object for SD logical drive */
extern FIL SDFile;       /* File object for SD */
FIL myFile;
UINT myBytes; 
 
 if(f_mount(&SDFatFS, SDPath, 0) == FR_OK)
  {
	  HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);
 
 
 
	  if(f_open(&SDFile, "F7FILE2.TXT", FA_CREATE_ALWAYS | FA_WRITE) == FR_OK)
	  {
		HAL_GPIO_WritePin(GPIOD,GPIO_PIN_13, GPIO_PIN_SET);
 
		char myData[] = "Helllo ";
 
		if(f_write(&SDFile,myData, sizeof(myData), &myBytes) == FR_OK)
		{
 
			HAL_GPIO_WritePin(GPIOD,GPIO_PIN_15, GPIO_PIN_SET);
 
		}
		f_close(&SDFile);
	  }
	}
  else
  {
	  HAL_GPIO_WritePin(GPIOD,GPIO_PIN_14, GPIO_PIN_SET);
  }

Cube MX set-up :

1 - pin

0693W000001qSIQQA2.png

2 - FATFS configuration :

Only Physical drive were changed.

0693W000001qSIaQAM.png

3 - SDIO set-up :

0693W000001qSIpQAM.png

Please ask if you need more insight.

Thank you,

0 REPLIES 0