cancel
Showing results for 
Search instead for 
Did you mean: 

How to include FatFS properly?

ÇSerp.1
Associate II

Hello, I want to write data to a SD card. When I want to include fatfs, in header files i get errors.

 

ff_gen_drv.h line 57 (typedef struct { uint8_t is_initialized[_VOLUMES];:( '_VOLUMES' undeclared here (not in a function)

sd_diskio.h line 35 (extern const Diskio_drvTypeDef SD_Driver;:( unknown type name 'Diskio_drvTypeDef'

sd_diskio.c line 70 (const Diskio_drvTypeDef SD_Driver =:( conflicting types for 'SD_Driver'; have 'Diskio_drvTypeDef'

fatfs.h line 36 (extern FATFS SDFatFS;:( unknown type name 'FATFS'

fatfs.h line 37 (extern FIL SDFile;:( unknown type name 'FIL'

 

I enabled SDIO and FatFS and generated the code.

In the code I deleted #include "fatfs.h" line in main.c. After that, I created 2 new files called "sd.c" and "sd.h" in /Core/User folder which i've created. 

 

SD.H file:

#ifndef USER_SD_H_
#define USER_SD_H_

#include "fatfs.h"

#endif /* USER_SD_H_ */

 

SD.C file:

#include "sd.h"

 

main.h file:

/* USER CODE BEGIN Includes */
#include "sd.h"
/* USER CODE END Includes */

 

I want to be able to include "fatfs.h" file in other files. Right now i am only able to include it in the .c files. When i want to include it in .h files, i get errors. How can i fix this?

3 REPLIES 3
Imen.D
ST Employee

Hello @ÇSerp.1 ,

The problem here seems to be related to the configuration of your project.

Look at the Include Paths settings and make sure that your project has the right include paths and the compiler knows the path to fatfs.h.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Hello @Imen.D 

I don't see any problems with the include paths. Here are my include paths and files:

 

Include paths:

Screenshot_39.png

 

Files:

Screenshot_40.png

 

 SD.h

Serp1_0-1704699233295.png

 

 

SD.c

Serp1_1-1704699243610.png

 

 

main.h

Serp1_2-1704699286749.png

 

Errors:

../Middlewares/Third_Party/FatFs/src/ff_gen_drv.h:57:42: error: '_VOLUMES' undeclared here (not in a function)

../FATFS/App/fatfs.h:36:8: error: unknown type name 'FATFS'

../FATFS/App/fatfs.h:37:8: error: unknown type name 'FIL'

../FATFS/Target/sd_diskio.h:35:14: error: unknown type name 'Diskio_drvTypeDef'

 

 

ÇSerp.1
Associate II

I also get errors if i move #include "fatfs.h" from main.c  to main.h. Normally, when i created the project, "fatfs.h" is already included in main.c. If I don't include "sd.h" file to "main.h" and just move the inclusion of "fatfs.h" from main.c to main.h, i get the same errors.