2021-09-09 12:51 AM
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:
with FreeRTOS:
the 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!
Solved! Go to Solution.
2021-09-21 06:21 AM
Hello @KaoChin
You can refer to the following application that exploits the features offered by FatFs with the microSD drive in RTOS configuration mode :
This could help you.
BeST Regards,
Walid
2021-09-21 06:21 AM
Hello @KaoChin
You can refer to the following application that exploits the features offered by FatFs with the microSD drive in RTOS configuration mode :
This could help you.
BeST Regards,
Walid
2021-10-05 02:31 AM
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