cancel
Showing results for 
Search instead for 
Did you mean: 

FATFS Failure with FreeRTOS

EthanMankins
Senior

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");

 

  

1 ACCEPTED SOLUTION

Accepted Solutions
EthanMankins
Senior

I have solved the hard fault by changing task priority; however, I fail f_open() and f_mount() with a NO_FILE_SYSTEM, even after f_mkfs() succeeds.

View solution in original post

2 REPLIES 2
EthanMankins
Senior

I have solved the hard fault by changing task priority; however, I fail f_open() and f_mount() with a NO_FILE_SYSTEM, even after f_mkfs() succeeds.


@EthanMankins wrote:

I have solved the hard fault by changing task priority; 


Great - so please mark that as the solution:

https://community.st.com/t5/community-guidelines/help-others-to-solve-their-issues/ta-p/575256

 


@EthanMankins wrote:

however, I fail f_open() and f_mount() with a NO_FILE_SYSTEM, even after f_mkfs() succeeds.


New thread for that:

https://community.st.com/t5/stm32-mcus-embedded-software/fatfs-rtos/td-p/750564