cancel
Showing results for 
Search instead for 
Did you mean: 

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

Javier1
Principal

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)

we dont need to firmware by ourselves, lets talk
1 ACCEPTED SOLUTION

Accepted Solutions
Javier1
Principal

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)

we dont need to firmware by ourselves, lets talk

View solution in original post

7 REPLIES 7
Javier1
Principal

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);

we dont need to firmware by ourselves, lets talk
Javier1
Principal

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)

we dont need to firmware by ourselves, lets talk
Laurens
Associate II

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 


@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

we dont need to firmware by ourselves, lets talk

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

 

I just realised i provided a link to the Code in the post, no gusrantees that Will world for you tough

we dont need to firmware by ourselves, lets talk

aha great i will try it out. Thanks a lot