2024-01-18 04:22 AM
Hello, i am trying to make a file with a text on a SD card without success.
I followed this tutorial:
But i have a stm32h743zit6 and it is a bit different.First, I can't configure DMA on SDMMC in stm32cubemx.
I've configured the pins of the stm to the pins slot i have in my board (Is a custom board made by me using this microcontroller and the sd card slot.)
I activated in cubemx: DMA (I think it is not necessary), SDMMC, FATFS, GPIO and freertos (for threads in the future).
Then, i wrote a simple code shown in the tutorial:
/* USER CODE BEGIN 1 */
FRESULT res; //Fatfs function common result code
uint32_t byteswritten, bytesread; // File writes/read counts
uint8_t wtext[]= "PRUEBA ESCRITURA"; //Buffer de escritura de archivo
uint8_t rtext[_MAX_SS]; //Lectura de buffer de fichero
/* USER CODE END 1 */
/* USER CODE BEGIN 2 */
if(f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) != FR_OK)
{
printf("Error mount\r\n");
}
else
{
printf("mount correct \r\n");
if(f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, rtext, sizeof(rtext)) != FR_OK)
{
printf("Error make file\r\n");
}
else
{
printf("File created \r\n");
//Open file for writing (Create)
if(f_open(&SDFile, "Prueba_para_ficheros.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
{
printf("Error writing\r\n");
}
else
{
printf("File opened \r\n");
//Write to the text file
res = f_write(&SDFile, wtext, strlen((char *)wtext), (void *)&byteswritten);
printf("Writing in file\r\n");
if((byteswritten == 0) || (res != FR_OK))
{
}
else
{
printf("File closed\r\n");
f_close(&SDFile);
}
}
}
}
f_mount(&SDFatFS, (TCHAR const*)NULL, 0);
/* USER CODE END 2 */
I have an error doing f_mkfs, and the program does not do the opening or writing thing.
Can anyone tell me what it could be happening here? Any ideas?
Thank you so much!
2024-04-16 01:49 AM
Hello @rubenles
You can refer to this application provided in the STM32CubeH7 firmware. It demonstrates how to create text files on an SD card using the FatFS middleware component and FreeRTOS. The application is working on STM32H743I-EVAL board.
If your question is answered, please close this topic by clicking "Accept as Solution".