Skip to main content
HAHA
Associate II
November 16, 2022
Question

FATFS_LinkDriverEx(.....) returns error

  • November 16, 2022
  • 5 replies
  • 1480 views

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;

}

This topic has been closed for replies.

5 replies

Tesla DeLorean
Guru
November 16, 2022

>> 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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
HAHA
HAHAAuthor
Associate II
November 16, 2022

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

HAHA
HAHAAuthor
Associate II
November 16, 2022

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
HAHAAuthor
Associate II
November 16, 2022

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 */
}

Tesla DeLorean
Guru
November 16, 2022

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..