Skip to main content
Cezar Chirila
Associate II
February 27, 2018
Question

STM32F446 FatFS Adafruit BSP drivers

  • February 27, 2018
  • 5 replies
  • 1730 views
Posted on February 27, 2018 at 12:49

Hi! 

I am trying to use an SD card with the STM32F446RE (using Attolic TrueSTUDIO) but I cannot seem to figure out what I am doing wrong. 

I get this error:

FatFS\sd_diskio.h:57:14: error: unknown type name 'Diskio_drvTypeDef'

But in sd_diskio.h file I have already included 'ff_gen_drv.h'. Here is how my sd_diskio.h file looks like:

/* Define to prevent recursive inclusion -------------------------------------*/

#ifndef __SD_DISKIO_H

#define __SD_DISKIO_H

/* Includes ------------------------------------------------------------------*/

#include 'stm32_adafruit_sd.h'

#include 'ff_gen_drv.h'

/* Exported types ------------------------------------------------------------*/

/* Exported constants --------------------------------------------------------*/

/* Exported functions ------------------------------------------------------- */

extern const Diskio_drvTypeDef SD_Driver;

#endif /* __SD_DISKIO_H */

And ff_gen_drv.h file:

/* Define to prevent recursive inclusion -------------------------------------*/

#ifndef __FF_GEN_DRV_H

#define __FF_GEN_DRV_H

#ifdef __cplusplus

extern 'C' {

#endif

/* Includes ------------------------------------------------------------------*/

#include 'sd_diskio.h'

#include 'ff.h'

#include 'stdint.h'

#include 'diskio.h'

/* Exported types ------------------------------------------------------------*/

/**

* @brief Disk IO Driver structure definition

*/

typedef struct

{

DSTATUS (*disk_initialize) (BYTE); /*!< Initialize Disk Drive */

DSTATUS (*disk_status) (BYTE); /*!< Get Disk Status */

DRESULT (*disk_read) (BYTE, BYTE*, DWORD, UINT); /*!< Read Sector(s) */

#if _USE_WRITE == 1

DRESULT (*disk_write) (BYTE, const BYTE*, DWORD, UINT); /*!< Write Sector(s) when _USE_WRITE = 0 */

#endif /* _USE_WRITE == 1 */

#if _USE_IOCTL == 1

DRESULT (*disk_ioctl) (BYTE, BYTE, void*); /*!< I/O control operation when _USE_IOCTL = 1 */

#endif /* _USE_IOCTL == 1 */

}Diskio_drvTypeDef;

/**

*

* @brief Global Disk IO Drivers structure definition

*/

typedef struct

{

uint8_t is_initialized[_VOLUMES];

const Diskio_drvTypeDef *drv[_VOLUMES];

uint8_t lun[_VOLUMES];

volatile uint8_t nbr;

}Disk_drvTypeDef;

/* Exported constants --------------------------------------------------------*/

/* Exported macro ------------------------------------------------------------*/

/* Exported functions ------------------------------------------------------- */

uint8_t FATFS_LinkDriver(const Diskio_drvTypeDef *drv, char *path);

uint8_t FATFS_UnLinkDriver(char *path);

uint8_t FATFS_LinkDriverEx(const Diskio_drvTypeDef *drv, char *path, BYTE lun);

uint8_t FATFS_UnLinkDriverEx(char *path, BYTE lun);

uint8_t FATFS_GetAttachedDriversNbr(void);

#ifdef __cplusplus

}

#endif

#endif /* __FF_GEN_DRV_H */

Anyone has any idea what is going on?

    This topic has been closed for replies.

    5 replies

    Cezar Chirila
    Associate II
    February 27, 2018
    Posted on February 27, 2018 at 12:52

    Whoopsie, I think the problem was this line in ff_gen_drv.h:

    #include 'sd_diskio.h'

    I do however now get in main errors regarding all file functions such as

    'undefined reference to `FATFS_LinkDriver''

    Andrew Neil
    Super User
    February 27, 2018
    Posted on February 27, 2018 at 13:57

    That sounds like a Linker error - not compiler error?

    So that usually means that you haven't included the source or precompiled library which contains the definitions

    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Andrew Neil
    Super User
    February 27, 2018
    Posted on February 27, 2018 at 13:59

    For FatFs documentation & support, see: 

    http://elm-chan.org/fsw/ff/00index_e.html

     - in particular, note the 'Resources' section at the end of the page.

    http://elm-chan.org/fsw/ff/bd/

      
    A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
    Tesla DeLorean
    Guru
    February 27, 2018
    Posted on February 27, 2018 at 16:52

    Review how this project builds/functions and then port that into the F446 trees

    STM32Cube_FW_F4_V1.19.0\Projects\STM32F413ZH-Nucleo\Applications\FatFs\FatFs_uSD

    I don't use Atollic, but Keil, I've built and fixed implementations based on the Adafruit SD for the F4, F7 and L4 Nucleos

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Cezar Chirila
    Associate II
    February 27, 2018
    Posted on February 27, 2018 at 18:12

    I have managed to get it working. I used the example told by @Clive One and the FatFs driver provided in the STM32Cube directory. The problem was that I instantiated the FatFS module using CubeMX and for some reason, something wasn't adding up.