2020-12-31 02:25 AM
Hi,
Iam using a STM32F746 DISCO Board to use SDMMC in a TOUCHGFX Application but Iam not able to get past if(f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, rtext, sizeof(rtext)) != FR_OK) function. It gives error here. Even If I comment this section and reach fopen command it returns FR_DISK_ERR.
However When I simply run the standalone SDMMC example ,it works and writes data to SD card.
Why is that the same example does not work with Touchgfx application?
The only difference I could see is of Clock speed between two applications. One is at 50Hz & other is at 48Hz.
Im Prototyping my project on disco board before I go into custom design. Kindly help!!
Solved! Go to Solution.
2021-01-02 04:26 AM
Hi,
I got it working using FREE RTOS & SDMMC. The mounting of the SD Card needs to be done inside MX_FATFS_Init();
void MX_FATFS_Init(void)
{
/*## FatFS: Link the SD driver ###########################*/
retSD = FATFS_LinkDriver(&SD_Driver, SDPath);
/* USER CODE BEGIN Init */
/* additional user code for init */
f_mount(&SDFatFS, (TCHAR const*)SDPath, 0);
/* USER CODE END Init */
}
It is strange that mounting needs to be done here and not in the RTOS Task.
After Mounting it in the Init function, You can open and write the file inside the RTOS Task like shown below
FRESULT res; /* FatFs function common result code */
uint32_t byteswritten, bytesread; /* File write/read counts */
uint8_t wtext[] = "welcome!"; /* File write buffer */
//uint8_t rtext[_MAX_SS];/* File read buffer */
//f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, rtext, sizeof(rtext));
res = f_open(&SDFile, "test.TXT", FA_CREATE_ALWAYS | FA_WRITE);
res = f_write(&SDFile, wtext, strlen((char *)wtext), (void *)&byteswritten);
f_close(&SDFile);
This is just an example.
I hope it helps others too.
2020-12-31 03:52 AM
Try compare your code with GitHub - argandas/STM32F746G-DISCO_TouchGFX_Demo-1: Demo code for STM32F746G-DISCO board using TouchGFX
And where you call if(f_mkfs((TC ? As you can see on example this need separate thread ... SDTask in demo
2021-01-01 03:07 AM
Hi,
I created a new task and tried doing the same thing in the new created task . All I did was copied the sdcard example code in another task . But still its not working.
2021-01-02 04:26 AM
Hi,
I got it working using FREE RTOS & SDMMC. The mounting of the SD Card needs to be done inside MX_FATFS_Init();
void MX_FATFS_Init(void)
{
/*## FatFS: Link the SD driver ###########################*/
retSD = FATFS_LinkDriver(&SD_Driver, SDPath);
/* USER CODE BEGIN Init */
/* additional user code for init */
f_mount(&SDFatFS, (TCHAR const*)SDPath, 0);
/* USER CODE END Init */
}
It is strange that mounting needs to be done here and not in the RTOS Task.
After Mounting it in the Init function, You can open and write the file inside the RTOS Task like shown below
FRESULT res; /* FatFs function common result code */
uint32_t byteswritten, bytesread; /* File write/read counts */
uint8_t wtext[] = "welcome!"; /* File write buffer */
//uint8_t rtext[_MAX_SS];/* File read buffer */
//f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, rtext, sizeof(rtext));
res = f_open(&SDFile, "test.TXT", FA_CREATE_ALWAYS | FA_WRITE);
res = f_write(&SDFile, wtext, strlen((char *)wtext), (void *)&byteswritten);
f_close(&SDFile);
This is just an example.
I hope it helps others too.