Skip to main content
ÇSerp.1
Associate II
January 4, 2024
Question

How to include FatFS properly?

  • January 4, 2024
  • 3 replies
  • 3047 views

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

    Technical Moderator
    January 5, 2024

    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"".ThanksImen"
    ÇSerp.1
    ÇSerp.1Author
    Associate II
    January 8, 2024

    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
    ÇSerp.1Author
    Associate II
    January 8, 2024

    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.

    林彧_it
    Visitor II
    June 13, 2024

    我也遇到了此问题,可以试着将#include “ff_gen_drv.h”移动到sd_diskio.h,目前我这的报错已经消失且编译通过,这一操作对你来说也许可以解决问题

    Translation:

    I also encountered this problem. You can try to move #include "ff_gen_drv.h" to sd_diskio.h. At present, the error has disappeared and the compilation was successful. This operation may solve your problem.

    ÇSerp.1
    ÇSerp.1Author
    Associate II
    February 4, 2025

    Thank you for your reply. I can not try this at the moment but I will work on a project that requires sdio and i will get the problem again probably. I will see if this works later that.