cancel
Showing results for 
Search instead for 
Did you mean: 

The function f_read of FATFS reads nothing when FreeRTOS is used.

KaoChin
Associate

My mcu is H743, the MDMA is enable for SD. The FATFS is used to operate file system. CubeMX is used to generate template code.

Without the FreeRTOS, both of the FATFS functions f_write() and f_read () work correctly. But when the FreeRTOS is used, f_write works correctly(is checked by PC card reader) but f_read() get nothing (all of datas are 0x00).

the result without FreeRTOS is shown as following:

without FreeRTOS:

0693W00000DmdYAQAZ.jpgwith FreeRTOS:

0693W00000DmdY5QAJ.jpgthe test code for FATFS is show as follow:

void sd_test(){
printf("\r\n ****** FatFs Example ******\r\n\r\n");
    /*##-1- Register the file system object to the FatFs module ##############*/
	
	retSD = f_mount(&fs, SDPath, 1);
	if(retSD)
	{
		printf(" mount error : %d \r\n",retSD);
		Error_Handler();
	}
	else
		printf(" mount sucess!!! \r\n"); 	
	/*##-2- Create and Open new text file objects with write access ######*/
	retSD = f_open(&fil, filename, FA_CREATE_ALWAYS	 | FA_WRITE);
	if(retSD){
		printf(" open file error : %d\r\n",retSD);
	}
			
	else{
			printf(" open file sucess!!! \r\n"); 	
	}
			
	/*##-3- Write data to the text files ###############################*/
	retSD = f_write(&fil, wtext, sizeof(wtext), (void *)&byteswritten);
	if(retSD){
			printf(" write file error : %d\r\n",retSD);
	}
			
	else
	{
		printf(" write file sucess!!! \r\n");
		printf(" write Data : %s\r\n",wtext);
	}
	/*##-4- Close the open text files ################################*/
	retSD = f_close(&fil);
	if(retSD)
		printf(" close error : %d\r\n",retSD);
	else
		printf(" close sucess!!! \r\n");
	/*##-5- Open the text files object with read access ##############*/
	delay_ms(1000);
	retSD = f_open(&fil, filename, FA_READ);
	if(retSD){
		printf(" open file error : %d\r\n",retSD);		
	}
			
	else
		printf(" open file sucess!!! \r\n");
	/*##-6- Read data from the text files ##########################*/
	retSD = f_read(&fil, rtext, sizeof(rtext), (UINT*)&bytesread);
	if(retSD){
		printf(" read error!!! %d\r\n",retSD);
	}			
	else
	{
		printf(" read sucess!!! \r\n");
		printf(" read Data : %s\r\n",rtext);
	}
	/*##-7- Close the open text files ############################*/
	retSD = f_close(&fil);
	if(retSD) {
		printf(" close error!!! %d\r\n",retSD);
	}
			
	else
		printf(" close sucess!!! \r\n");
}

Please give me advice or guide me to debug it. Thank you very much. Best Wishes!

1 ACCEPTED SOLUTION

Accepted Solutions

Hello @KaoChin​ 

You can refer to the following application that exploits the features offered by FatFs with the microSD drive in RTOS configuration mode :

  • Projects\STM32H743I-EVAL\Applications\FatFs\FatFs_uSD_DMA_RTOS

This could help you.

BeST Regards,

Walid

View solution in original post

2 REPLIES 2

Hello @KaoChin​ 

You can refer to the following application that exploits the features offered by FatFs with the microSD drive in RTOS configuration mode :

  • Projects\STM32H743I-EVAL\Applications\FatFs\FatFs_uSD_DMA_RTOS

This could help you.

BeST Regards,

Walid

Hello @KaoChin​ 

Please click on Select as Best if my post fully answered your question. This will help other customers with the same issue to find the solution faster

BeST Regards,

Walid