cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746 Discovery USB Mass Storage Class FATFS f_mount successfully but f_open file failed..

Karan 123
Senior

Hi,

I have working on below setup.

Hardware :

STM32F746G Discovery board

USB Thumb Drive 16/32 GB.

Tool Chain:

STMCubeMX

Repository -> STM32Cube_FW_F7_V1.11.0

Keil uVision 5 Demo VersionSTM32_USB_3

Application_start , Application_Disconnect and f_mount works 

case APPLICATION_START:

HAL_GPIO_WritePin (LD1_GPIO_Port,LD1_Pin,GPIO_PIN_SET);

case APPLICATION_DISCONNECT:

  HAL_GPIO_WritePin (LD1_GPIO_Port,LD1_Pin,GPIO_PIN_RESET);

 if(f_mount(&USBDISKFatFs, (TCHAR const*)USBHPath, 0) != FR_OK)

 {

 Error_Handler();

 }

But failed to f_open file -> then further to f_write and f_read and f_close.

Please help me resolve this issue .

Which Repository version is stable for STM32Cube_FW_F7_Vx.xx.xx for FATFS,exFAT , USB MSC , SDCard . ?

Thanks ..

--

Gurpreet Singh

3 REPLIES 3

Start with DISKIO layer, read/write functions must work flawlessly for top level code to succeed.

For Keil, makes sure you have an adequate stack allo​cation in startup_stm32xxxx.s

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

Hi,

Thanks for update..

"Start with DISKIO layer, read/write functions must work flawlessly for top level code to succeed."

Is this a bug or what STM32Cube ?

Any Stable Version of STM32Cube..?

What I have to do with diskio.c and diskio.h?

#include "diskio.h"
#include "ff_gen_drv.h"
 
#if defined ( __GNUC__ )
#ifndef __weak
#define __weak __attribute__((weak))
#endif
#endif
 
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
extern Disk_drvTypeDef  disk;
 
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
 
/**
  * @brief  Gets Disk Status
  * @param  pdrv: Physical drive number (0..)
  * @retval DSTATUS: Operation status
  */
DSTATUS disk_status (
	BYTE pdrv		/* Physical drive number to identify the drive */
)
{
  DSTATUS stat;
 
  stat = disk.drv[pdrv]->disk_status(disk.lun[pdrv]);
  return stat;
}
 
/**
  * @brief  Initializes a Drive
  * @param  pdrv: Physical drive number (0..)
  * @retval DSTATUS: Operation status
  */
DSTATUS disk_initialize (
	BYTE pdrv				/* Physical drive nmuber to identify the drive */
)
{
  DSTATUS stat = RES_OK;
 
  if(disk.is_initialized[pdrv] == 0)
  {
    disk.is_initialized[pdrv] = 1;
    stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]);
  }
  return stat;
}
 
/**
  * @brief  Reads Sector(s)
  * @param  pdrv: Physical drive number (0..)
  * @param  *buff: Data buffer to store read data
  * @param  sector: Sector address (LBA)
  * @param  count: Number of sectors to read (1..128)
  * @retval DRESULT: Operation result
  */
DRESULT disk_read (
	BYTE pdrv,		/* Physical drive nmuber to identify the drive */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	        /* Sector address in LBA */
	UINT count		/* Number of sectors to read */
)
{
  DRESULT res;
 
  res = disk.drv[pdrv]->disk_read(disk.lun[pdrv], buff, sector, count);
  return res;
}
 
/**
  * @brief  Writes Sector(s)
  * @param  pdrv: Physical drive number (0..)
  * @param  *buff: Data to be written
  * @param  sector: Sector address (LBA)
  * @param  count: Number of sectors to write (1..128)
  * @retval DRESULT: Operation result
  */
#if _USE_WRITE == 1
DRESULT disk_write (
	BYTE pdrv,		/* Physical drive nmuber to identify the drive */
	const BYTE *buff,	/* Data to be written */
	DWORD sector,		/* Sector address in LBA */
	UINT count        	/* Number of sectors to write */
)
{
  DRESULT res;
 
  res = disk.drv[pdrv]->disk_write(disk.lun[pdrv], buff, sector, count);
  return res;
}
#endif /* _USE_WRITE == 1 */
 
/**
  * @brief  I/O control operation
  * @param  pdrv: Physical drive number (0..)
  * @param  cmd: Control code
  * @param  *buff: Buffer to send/receive control data
  * @retval DRESULT: Operation result
  */
#if _USE_IOCTL == 1
DRESULT disk_ioctl (
	BYTE pdrv,		/* Physical drive nmuber (0..) */
	BYTE cmd,		/* Control code */
	void *buff		/* Buffer to send/receive control data */
)
{
  DRESULT res;
 
  res = disk.drv[pdrv]->disk_ioctl(disk.lun[pdrv], cmd, buff);
  return res;
}
#endif /* _USE_IOCTL == 1 */
 
/**
  * @brief  Gets Time from RTC
  * @param  None
  * @retval Time in DWORD
  */
__weak DWORD get_fattime (void)
{
  return 0;
}
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
 

Stack Allo​cation in startup_stm32746xx.s as below:

0690X00000DC9adQAD.png0690X00000DC9aYQAT.png

>>Is this a bug or what STM32Cube ? Any Stable Version of STM32Cube..?

I don't use Cube. The robot is only as competent as the people feeding it boiler plate.

>>What I have to do with diskio.c and diskio.h?

You have posted a top level abstraction ST uses, you want to be testing\evaluating the "usb_diskio_whatever.c" files, and ensuring that you can in fact reliably read and write blocks from the block storage device. It must be able to recover the same data written to the block previously, and not corrupt other/surrounding blocks.

You need to understand the nature of the failure that FatFs subsequently FR_DISK_ERR (or whatever) in order to be able to remediate the problem.

Stack/Heap look plenty large. On the F7 I'd recommend using the DTCMRAM when using DMA, otherwise you'll need to manage the cache-coherency more explicitly

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