Skip to main content
Javier1
Principal
May 6, 2021
Solved

USB Mass storage device+ SD card + FATFS (fatfs breaks my code)

Howdy, im very new with filesystems and SD cards in general.

I am trying to develop a system that can manage files from a SD card (images ) and also interface between the PC and the SD card trough USB.

0693W00000ANbCFQA1.png0693W00000ANbAnQAL.png 

I managed to get my stm32f4-discovery working with an USB mass storage device and a SD card conected via SDIO.

It works but my stm32f4 blindly writes and reads the sd card when USB mass storage asks for it.

I want my stm32f4 to be able to search folders and read/write files from the SD card also ,so i am trying (unsuccesfully) to add the FATFS middleware.

I find tutorials about USB+SD card and FATFS+SD card but not all of them together.

Am i trying to do something weird here?

res=f_mount(&SDFatFS, (TCHAR const*)SDPath, 0);//this returns FR_OK
 	HAL_Delay(200);
 
//Open file for writing (Create)
res=f_open(&SDFile, "F7FILE2.TXT", FA_CREATE_ALWAYS | FA_WRITE);//this returns FR_NO_FILESYSTEM

my code (github)

This topic has been closed for replies.
Javier1
Javier1Best answer
Principal
May 11, 2021

So... my issue was not declaring the SIO detection pin in cubeMX

https://community.st.com/s/question/0D53W00000mlP0wSAE/detectsdio-in-cubemx-no-solution

Now it works (sometimes)

hit me up in https://www.linkedin.com/in/javiermuñoz/

7 replies

Javier1
Javier1Author
Principal
May 7, 2021

From youtube: https://www.youtube.com/watch?v=sVgKUhkwnAQ

Mutex Embedded - Education

hace 7 horas

Hi Javi, Check you MX_FATFS_Init() Make sure it is called properly beforehand.

@Mutex Embedded - Education  hi :), what do you mean by properly? The autogenerated code in cubemx places it right before my code:

/* Initialize all configured peripherals */ 
MX_GPIO_Init(); 
MX_DMA_Init(); 
MX_USB_DEVICE_Init(); 
MX_SDIO_SD_Init(); 
MX_FATFS_Init(); 
 
/* USER CODE BEGIN 2 */ 
//5. File Operations 
res=f_mount(&SDFatFS, (TCHAR const*)SDPath, 0); HAL_Delay(200); 
 //Open file for writing (Create) 
res=f_open(&SDFile, "F7FILE2.TXT", FA_CREATE_ALWAYS | FA_WRITE);

hit me up in https://www.linkedin.com/in/javiermuñoz/
Javier1
Javier1AuthorBest answer
Principal
May 11, 2021

So... my issue was not declaring the SIO detection pin in cubeMX

https://community.st.com/s/question/0D53W00000mlP0wSAE/detectsdio-in-cubemx-no-solution

Now it works (sometimes)

hit me up in https://www.linkedin.com/in/javiermuñoz/
Visitor II
March 11, 2024

Dear @Javier1 I am working on a simmilar project and i cannot get the usb msc working with fatfs. Is ther a possiblility that you can share your working code?

Thanks in advance 

Javier1
Javier1Author
Principal
March 13, 2024

@Laurens wrote:

Dear @Javier1 I am working on a simmilar project and i cannot get the usb msc working with fatfs. Is ther a possiblility that you can share your working code?

Thanks in advance 


sorry, long time has passed, no clue, maybe come back if you figure it out and paste a link

hit me up in https://www.linkedin.com/in/javiermuñoz/
Visitor II
March 14, 2024

Thank you for the response. If i figured it out i will post it here.