cancel
Showing results for 
Search instead for 
Did you mean: 

SDMMC + FATFS saving logs

iyed_hamdi
Associate II

Hello @ST Community 

I am using STM32F769I-disco to save real time data in SD card with SDMMC2 & FATFS. The sensor value are type float. 
The problem is that there are saving data in the file of SD card but the screen freeze.
this is the code that i am using:

 

 

 

static void MX_SDMMC2_SD_Init(void) { /* USER CODE BEGIN SDMMC2_Init 0 */ /* USER CODE END SDMMC2_Init 0 */ /* USER CODE BEGIN SDMMC2_Init 1 */ /* USER CODE END SDMMC2_Init 1 */ hsd2.Instance = SDMMC2; hsd2.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING; hsd2.Init.ClockBypass = SDMMC_CLOCK_BYPASS_DISABLE; hsd2.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE; hsd2.Init.BusWide = SDMMC_BUS_WIDE_1B; hsd2.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE; hsd2.Init.ClockDiv = 0; /* USER CODE BEGIN SDMMC2_Init 2 */ /* USER CODE END SDMMC2_Init 2 */ } char wGlobalText[500]; char rtext[512]; void init_sd_card(void) { // Initialiser le chemin de la carte SD sprintf(SDPath, "0:/"); // Monter la carte SD if (f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) != FR_OK) { Error_Handler(); // Erreur lors du montage du système de fichiers return; } // Vérifier si le fichier "STM32.TXT" existe if (f_open(&SDFile, "ST.TXT", FA_OPEN_EXISTING | FA_READ) != FR_OK) { // Le fichier n'existe pas, le créer if (f_open(&SDFile, "ST.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { Error_Handler(); // Erreur lors de la création du fichier } else { f_close(&SDFile); // Fermer le fichier après la création } } else { f_close(&SDFile); // Fermer le fichier s'il a été ouvert avec succès } //creer ou ouvrir le 2eme fichier /* if (f_open(&SDFile, "id.TXT", FA_OPEN_EXISTING | FA_READ) != FR_OK) { // Le fichier n'existe pas, le créer if (f_open(&SDFile, "id.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { Error_Handler(); // Erreur lors de la création du fichier } else { printf("File 'id.TXT' created successfully.\n"); f_close(&SDFile); // Fermer le fichier après la création } } else { f_close(&SDFile); // Fermer le fichier s'il a été ouvert avec succès }*/ // Démonter le système de fichiers f_mount(&SDFatFS, (TCHAR const*)NULL, 0); } void write_data_to_file(void) { FRESULT res; uint32_t byteswritten; //char wtext[100]; // Augmentez la taille du buffer si nécessaire // Formater les données à écrire avec l'horodatage // Formatage de la chaîne avec snprintf snprintf(wGlobalText, sizeof(wGlobalText), "fTT1: %d.%d; fHT1: %d.%d; fTT3: %d.%d; fHT3: %d.%d; fHabs1: %d.%d; fHabs3: %d.%d; fD: %d.%d; fCUS: %d.%d\n", (int)fTT1,(int)(100*fabs(fTT1)-100*((int)fabs(fTT1))), (int)fHT1,(int)(100*fabs(fHT1)-100*((int)fabs(fHT1))), (int)fTT3,(int)(100*fabs(fTT3)-100*((int)fabs(fTT3))), (int)fHT3,(int)(100*fabs(fHT3)-100*((int)fabs(fHT3))), (int)fHabs1,(int)(100*fabs(fHabs1)-100*((int)fabs(fHabs1))), (int)fHabs3,(int)(100*fabs(fHabs3)-100*((int)fabs(fHabs3))), (int)fD,(int)(100*fabs(fD)-100*((int)fabs(fD))), (int)fCUS,(int)(100*fabs(fCUS)-100*((int)fabs(fCUS)))); //snprintf(wGlobalText, sizeof(wGlobalText), //"fTT1: %d.%d\n",(int)fTT1,(int)(100*fTT1-100*((int)fTT1))); // Monter la carte SD if (f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) != FR_OK) { return; } // Ouvrir le fichier pour ajouter des données res = f_open(&SDFile, "ST.TXT", FA_OPEN_APPEND | FA_WRITE); if (res != FR_OK) { f_mount(&SDFatFS, (TCHAR const*)NULL, 0); // Démonter le système de fichiers en cas d'erreur return; } // Ajouter des données au fichier res = f_write(&SDFile, wGlobalText, strlen(wGlobalText), &byteswritten); // Fermer le fichier f_close(&SDFile); // Démonter le système de fichiers f_mount(&SDFatFS, (TCHAR const*)NULL, 0); } /* void write_data_to_second_file(void) { FRESULT res; uint32_t byteswritten; char wtext[100] = "id"; // Données à écrire dans le deuxième fichier // Monter la carte SD if (f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) != FR_OK) { Error_Handler(); // Erreur lors du montage du système de fichiers return; } // Ouvrir le fichier pour ajouter des données res = f_open(&SDFile, "id.TXT", FA_OPEN_APPEND | FA_WRITE); if (res != FR_OK) { Error_Handler(); // Erreur lors de l'ouverture du fichier pour ajout f_mount(&SDFatFS, (TCHAR const*)NULL, 0); // Démonter le système de fichiers en cas d'erreur return; } // Ajouter des données au fichier res = f_write(&SDFile, wtext, strlen(wtext), &byteswritten); if (res != FR_OK || byteswritten == 0) { Error_Handler(); // Erreur lors de l'écriture dans le fichier } else { printf("Data appended to 'id.TXT' successfully.\n"); } // Fermer le fichier f_close(&SDFile); // Démonter le système de fichiers f_mount(&SDFatFS, (TCHAR const*)NULL, 0); }*/ void read_data_from_file(const char* filename) { FRESULT res; uint32_t bytesread; // Monter la carte SD if (f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) != FR_OK) { Error_Handler(); // Erreur lors du montage du système de fichiers return; } // Ouvrir le fichier pour lire res = f_open(&SDFile, filename, FA_READ); if (res != FR_OK) { Error_Handler(); // Erreur lors de l'ouverture du fichier pour lecture f_mount(&SDFatFS, (TCHAR const*)NULL, 0); // Démonter le système de fichiers en cas d'erreur return; } // Lire les données du fichier res = f_read(&SDFile, rtext, sizeof(rtext) - 1, &bytesread); // Laisser de l'espace pour le caractère nul if (res != FR_OK || bytesread == 0) { Error_Handler(); // Erreur lors de la lecture du fichier } else { // Ajouter un caractère nul à la fin du buffer pour le traitement en tant que chaîne rtext[bytesread] = '\0'; } // Fermer le fichier après lecture f_close(&SDFile); // Démonter le système de fichiers f_mount(&SDFatFS, (TCHAR const*)NULL, 0); }
View more

 

 

when i run the code this message appear in console :

Memory Programming ...

Opening and parsing file: ST-LINK_GDB_server_a14188.srec

  File          : ST-LINK_GDB_server_a14188.srec

  Size          : 971.65 KB

  Address       : 0x08000000

Erasing memory corresponding to segment 0:

Erasing internal memory sectors [0 4]

Erasing memory corresponding to segment 1:

Erasing external memory sectors [0 11]

Download in Progress:

File download complete

Time elapsed during download operation: 00:00:11.518

Verifying ...

Download verified successfully

Shut



Thanks you guys.



3 REPLIES 3
SHs
ST Employee

Hello @iyed_hamdi ,

Could you please provide a more detailed description of the issue you are encountering? Specifically, in which function does the code execution halt, and what is the return value of the instruction at that point? This information will enable me to assist you more effectively in resolving the problem.

Thank you.

 

Please close this topic by clicking on “Accept as solution" button if it fully answered your question.

HI, 
When we configure the SDMMC2 mode with an SD size of 1 byte, the file is created, and the data is saved to the SD card, but the screen freezes. However, when I change the SD size to 4 bytes, the screen displays data and its contents as usual, but no files are created or data saved. Additionally, when I use debug mode, the software becomes stuck in the file stm32f7xx_it.c exaactly in this function

[15:49] Abir Mejri void MemManage_Handler(void) { /* USER CODE BEGIN MemoryManagement_IRQn 0 */ /* USER CODE END MemoryManagement_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ /* USER CODE END W1_MemoryManagement_IRQn 0 */ } }

 

SHs
ST Employee

Hello @iyed_hamdi ,

Thank you for bringing this matter to our attention, this issue has already been identified and reported in this thread:

Please close this topic by clicking on “Accept as solution" button if it fully answered your question.