2024-12-03 04:05 PM - edited 2024-12-03 04:05 PM
I am using the STM32H7B3I-DK for my project. I am trying to integrate uSD card usage with a touchgfx program. I have gotten a simple write to a file working on a non rtos project; however, when I use it in my project with RTOS I keep getting a hard fault. I had to make the SDMMC have a clock divider of 2 to get it to work on non-rtos. Are there some conflicts with FreeRTOS that I need to be considering?
Here is the code I am using in both:
FRESULT res; /* FatFs function common result code */
UINT byteswritten, bytesread; /* File write/read counts */
uint8_t wtext[] = "STM32 FATFS works great!"; /* File write buffer */
uint8_t rtext[_MAX_SS];/* File read buffer */
[...]
BYTE work[4096]; // Work area for formatting
/* USER CODE BEGIN 5 */
printf("Starting\r\n");
if(f_mount(&SDFatFS, (TCHAR const*)SDPath, 1) != FR_OK)
{
printf("Failed to mount -- Formatting\r\n");
if (f_mkfs(SDPath, FM_FAT32, 0, work, sizeof(work)) != FR_OK) {
printf("Failed to format SD card.\r\n");
return;
} else {
printf("SD card formatted to FAT32 successfully.\r\n");
}
}
//Open file for writing (Create)
if(f_open(&SDFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
{
printf("Failed on open\r\n");
}
else
{
//Write to the text file
res = f_write(&SDFile, wtext, strlen((char *)wtext), (void *)&byteswritten);
if((byteswritten == 0) || (res != FR_OK))
{
printf("Failed on write\r\n");
}
else
{
f_close(&SDFile);
}
}
f_mount(&SDFatFS, (TCHAR const*)NULL, 0);
printf("Done\r\n");