STM32 – Creating a File System on a SD card

Published: 11 December 2020
on channel: STMicroelectronics
48,609
487

Find out more information:
https://bit.ly/32F746GDISCOVERY
https://bit.ly/STM32CubeIDE-yt
https://bit.ly/FatFSinfo

In this video we will explain you how to create a file system on a SD card using STM32 and ST Toolsets. This is useful for data logging type of application where you need to write data files on an external media like a SD card.

Introduction: 0:00
Board used: 2:32
Beginning of exercise: 2:54
Live Demo: 11:40

Code available here: http://www.st.com/content/dam/AME/202...

/* USER CODE BEGIN 1 */
FRESULT res; /* FatFs function common result code */
uint32_t byteswritten, bytesread; /* File write/read counts */
uint8_t wtext[] = "STM32 FATFS works great!"; /* File write buffer */
uint8_t rtext[_MAX_SS];/* File read buffer */
/* USER CODE END 1 */
...
/* USER CODE BEGIN 2 */
if(f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) != FR_OK)
{
Error_Handler();
}
else
{
if(f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, rtext, sizeof(rtext)) != FR_OK)
{
Error_Handler();
}
else
{
//Open file for writing (Create)
if(f_open(&SDFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
{
Error_Handler();
}
else
{



//Write to the text file
res = f_write(&SDFile, wtext, strlen((char *)wtext), (void *)&byteswritten);
if((byteswritten == 0) || (res != FR_OK))
{
Error_Handler();
}
else
{



f_close(&SDFile);
}
}
}
}
f_mount(&SDFatFS, (TCHAR const*)NULL, 0);
/* USER CODE END 2 */


Watch video STM32 – Creating a File System on a SD card online without registration, duration hours minute second in high quality. This video was added by user STMicroelectronics 11 December 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 48,609 once and liked it 487 people.