cancel
Showing results for 
Search instead for 
Did you mean: 

FATFS_LinkDriverEx(.....) returns error

HAHA
Associate II

code generated for stm32l0xx with FAT option ticked, generates following stub, I believe missing the equal sign in if condition:

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

{

 uint8_t ret = 1;

 uint8_t DiskNum = 0;

 if(disk.nbr < _VOLUMES)

 {

  disk.is_initialized[disk.nbr] = 0;

  disk.drv[disk.nbr] = drv;

  disk.lun[disk.nbr] = lun;

  DiskNum = disk.nbr++;

  path[0] = DiskNum + '0';

  path[1] = ':';

  path[2] = '/';

  path[3] = 0;

  ret = 0;

 }

 return ret;

}

5 REPLIES 5

>> I believe missing the equal sign in if condition

No, C arrays indexes are ZERO based

/**
  * @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; 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
HAHA
Associate II

exactly my point, when volume is equal 1 (you only have one volume) the 0 is not less than 0.

HAHA
Associate II

sorry my above comment is not right, there must be something else causing this function to be called two times, and only the second time the condition is not met, hence an error returned.

HAHA
Associate II

My fault, I was calling the function two times. Call to this function was already included in auto generated code in the FAT init.

void MX_FATFS_Init(void)
{
 /*## FatFS: Link the USER driver ###########################*/
 retUSER = FATFS_LinkDriver(&USER_Driver, USERPath);
 /* USER CODE BEGIN Init */
 /* additional user code for init */
 /* USER CODE END Init */
}

Yes, it's not re-entrant, perhaps there are better ways of doing this, ST just did something very simple to meet their immediate needs, not necessarily production ready.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..