Skip to main content
TPier
Associate III
October 30, 2019
Solved

STM32F769 Discovery kit & FATFS

  • October 30, 2019
  • 3 replies
  • 980 views

In the frame of testing the STM32F7xx MCU, we test the file management capabilities of the STM32F769 Discovery kit. The configuration of the platform to access the SD card has been built with STM32CubeMX (FreeRTOS + FATFS).

The code for the test is the following:

 if ( result = f_mount(&SDFatFS, (TCHAR const*)"", 1) )
 {
 sprintf( message, "Mount failed (%d) !\r\n", result );
 sendMessage( message );
 while( 1 );
 }
 
// // Read file
 if( result = f_open (&SDFile, "/file.txt", FA_READ) )
 {
 sprintf( message, "Open failed (%d) !\r\n", result );
 sendMessage( message );
 while( 1 );
 }
 unsigned int bytes;
 if ( result = f_read (&SDFile, message, 64, &bytes) )
 {
 sprintf( message, "Read failed (%d) !\r\n", result );
 sendMessage( message );
 while( 1 );
 }
 sendMessage( "Content: " );
 sendMessage( message );
 sendMessage( "\r\n" );
 
 f_close(&SDFile);
 
 
 // Write file
 if ( result = f_mount(&SDFatFS, (TCHAR const*)"", 1) )
 {
 sprintf( message, "Remount failed (%d) !\r\n", result );
 sendMessage( message );
 while( 1 );
 }
 if( result = f_open (&SDFile, "/file.txt", FA_WRITE | FA_OPEN_APPEND) )
 {
 sprintf( message, "Reopen failed (%d) !\r\n", result );
 sendMessage( message );
 while( 1 );
 }
 if ( (result = f_write (&SDFile, "Hi man !", 8, &bytes)) == 0 )
 {
 sprintf( message, "%u bytes written.\r\n", bytes );
 sendMessage( message );
 }
 else
 {
 sprintf( message, "Write failed (%d) !\r\n", result );
 sendMessage( message );
 while( 1 );
 }
 
 f_close(&SDFile);
 
 if ( result = f_mount(0, (TCHAR const*)"", 1) )
 {
 sprintf( message, "Umount failed (%d) !\r\n", result );
 sendMessage( message );
 while( 1 );
 }
 
 sendMessage( "OK\r\n" );
 

Everything sounds to work correctly (witnessed by the messages on the console) but the file actually is unchanged.

I have no idea why and how to start the investigations. Has someone any experience or idea to solve this ?

Many thanks in advance.

Regards.

This topic has been closed for replies.
Best answer by TPier

Found the mistake : in STM32CubeMX, in the configuration of SDMMC2, link 2 DMAs to the MMC peripheral, one for RX and one for TX, in order to be able to write !

And do not forget to enable the related interrupts (for DMAs and SDMMC2).

Very instructive experience with STM32CubeMX !

Best regards.

3 replies

Tesla DeLorean
Guru
October 30, 2019

Caching?

Perhaps ensure all the file system / SDMMC related stuff is kept within DTCM RAM

Instrument DISKIO layer confirm writes to media are occurring, and are successful.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
TPier
TPierAuthor
Associate III
October 31, 2019

You are right ! The syncing with the disk is done in the close call. And as you can see in the code above, the return code of this call is not checked. I would have seen that it returns a "Disk error" :\

Still looking why ...

Many thanks.

TPier
TPierAuthorBest answer
Associate III
October 31, 2019

Found the mistake : in STM32CubeMX, in the configuration of SDMMC2, link 2 DMAs to the MMC peripheral, one for RX and one for TX, in order to be able to write !

And do not forget to enable the related interrupts (for DMAs and SDMMC2).

Very instructive experience with STM32CubeMX !

Best regards.