AnsweredAssumed Answered

FATFs Using USB Mass Storage Key

Question asked by JC Lebreton on Feb 28, 2018
Latest reply on Mar 5, 2018 by JC Lebreton

Hi,
I've been playing around with FatFs for about 1 mounth now. 
I succefully used SDMMC and SPI protocol to save and read data from an SD card.

 

I order to improve the system (it's a improvement for the project) 
We decided to add an UDB Mass Storage Key. (approx 8Giga)

 

I found this : [FATFs] Opening file on USB stick returns FR_DISK_ERR 
And it describe exaclty my error.
I'm able to mount the USB stick but I couldn't f_open() it. 

 

 

most of my code is a copy paste of the example provided by ST.
I copy what i made at the end of the message. 

 

if some of you have or had the same issue could you provide me some help. or in other case explain me more precisely what smrtkai describes in the post i link at the begining.

 

thanks in advance

 

edit : forget to say that i m working with an STM32H743zi on a nucleo board

 

------

if(FATFS_LinkDriver(&USBH_Driver, "") ==0)
{

MX_USB_HOST_Init();

while(1)
{
/* USB Host Background task */
MX_USB_HOST_Process();

/* Mass Storage Application State Machine */
switch(Appli_state)
{
case APPLICATION_START:
FS_FileOperations(); <-- I got issues here
Appli_state = APPLICATION_IDLE;
break;

case APPLICATION_IDLE:
default:
break;
}
}
}
else
{
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_SET); //put it on if linkdriver fail
}

 

 

static void FS_FileOperations(void)
{
FRESULT res; /* FatFs function common result code */
uint32_t byteswritten;
uint8_t wtext[] = "This is STM32 working with FatFs + USB/FS"; /* File write buffer */

 

/* Register the file system object to the FatFs module */
if(f_mount(&USBHFatFS, "", 0) == FR_OK)
{

/* Create and Open a new text file object with write access */
res = f_open(&USBHFile, "STM32.TXT", FA_CREATE_NEW); <- Biggest issue is here
datasend(res);
if(res == FR_OK)
{
/* Write data to the text file */
res = f_write(&USBHFile, wtext, sizeof(wtext), (void *)&byteswritten);

if((byteswritten > 0) && (res == FR_OK))
{
/* Close the open text file */
f_close(&USBHFile);
//HAL_GPIO_WritePin(GPIOB,GPIO_PIN_7,GPIO_PIN_SET); //Led de debug pour confimer la bonne fermeture du fichier
return;
}
}

}
/* Error */
// HAL_GPIO_WritePin(GPIOB,GPIO_PIN_14,GPIO_PIN_SET); //Led de debug pour confimer la bonne fermeture du fichier
}

Outcomes