Skip to main content
Louie88
Senior
April 3, 2025
Solved

Using SD card in TouchGFX/FreeRTOS project

  • April 3, 2025
  • 2 replies
  • 718 views

Hello,

I created an app form my STM32H7474I-DISCO board to test SD card based on this example. I spent a couple of hours with porting it to H747I-DISCO board, but finally it worked: I could save and load a file from an SD Card.

I implemented the whole thing into my TouchGFX based project on same discovery board. I could build and run the project but when I tried to write a new file the SD Card was mounted fine but creating a new file failed with FR_NOT_READY (The physical drive cannot work) error.

uint32_t byteswritten;
 if(f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) != FR_OK)
 {
 Error_Handler();
 }
 else
 {
	 //Open file for writing (Create)
	 if(f_open(&SDFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
	 {
		 Error_Handler();
	 }
	 else
	 {
		 //Write to the text file
		 res = f_write(&SDFile, wtext, strlen((char *)wtext), (void *)&byteswritten);
		 if((byteswritten == 0) || (res != FR_OK))
		 {
			 Error_Handler();
		 }
		 else
		 {
			 f_close(&SDFile);
		 }
		}
 }

The same code, the same development board, the same SD card works fine if I have no TouchGFX nor FreeTOS. Is this some initializing/usage error or the same code cannot be run under TouchGFX nor FreeTOS?

Thanks,
Louis

2 replies