Skip to main content
Visitor II
September 9, 2021
Solved

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

  • September 9, 2021
  • 1 reply
  • 2072 views

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!

    This topic has been closed for replies.
    Best answer by Walid ZRELLI

    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

    1 reply

    Visitor II
    September 21, 2021

    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

    Visitor II
    October 5, 2021

    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