2015-04-08 06:40 AM
Hi,
I am trying to do a memory stick reading in the STM32F4-Discovery board.In order to test it, I am running the application example located in the following path:STM32Cube\Repository\STM32Cube_FW_F4_V1.5.0\Projects\STM32F4-Discovery\Applications\FatFs\FatFs_USBDiskMy problem is that I am getting the following error when I try to open a file: (File: ff.c Function: find_volume())/* Find an FAT partition on the drive. Supports only generic partitioning, FDISK and SFD. */ bsect = 0; fmt = check_fs(fs, bsect); /* Load sector 0 and check if it is an FAT boot sector as SFD */ if (fmt == 1 || (!fmt && (LD2PT(vol)))) { /* Not an FAT boot sector or forced partition number */ UINT i; DWORD br[4]; for (i = 0; i < 4; i++) { /* Get partition offset */ BYTE *pt = fs->win.d8+MBR_Table + i * SZ_PTE; br[i] = pt[4] ? LD_DWORD(&pt[8]) : 0; } i = LD2PT(vol); /* Partition number: 0:auto, 1-4:forced */ if (i) i--; do { /* Find an FAT volume */ bsect = br[i]; fmt = bsect ? check_fs(fs, bsect) : 2; /* Check the partition */ } while (!LD2PT(vol) && fmt && ++i < 4); }if (fmt == 3) return FR_DISK_ERR; /* An error occured in the disk I/O
layer */ if (fmt) return FR_NO_FILESYSTEM; /* No FAT volume is found */I tried to format my memory stick, but it still is not working.What ''FR_DISK_ERR /* An error occured in the disk I/O
'' means?Do you have any clues?Thanks in advance! #i-have-a-clue2015-04-08 07:03 AM
What ''FR_DISK_ERR /* An error occured in the disk I/O'' means? Do you have any clues?
That the read command sent to the USB stick via check_fs(fs, bsect); failed. Go look at the abstraction layer in diskio.c, instrument it if needed, and see what read command were sent and if they succeeded. Signs point to they didn't.
2015-04-08 10:14 AM
I went deeper in the code trying to find where the error is being generated and I reached the following:
DRESULT USBH_read(BYTE *buff, DWORD sector, UINT count){ DRESULT res = RES_ERROR; MSC_LUNTypeDef info; USBH_StatusTypeDef status = USBH_OK; DWORD scratch [_MAX_SS / 4]; if ((DWORD)buff & 3) /* DMA Alignment issue, do single up to aligned buffer */ { while ((count--)&&(status == USBH_OK)) { status = USBH_MSC_Read(&HOST_HANDLE, 0, sector + count, (uint8_t *)scratch, 1); if(status == USBH_OK) { memcpy (&buff[count * _MAX_SS] ,scratch, _MAX_SS); } else { break; } } } else { status = USBH_MSC_Read(&HOST_HANDLE, 0, sector, buff, count); } if(status == USBH_OK) { res = RES_OK; } else { USBH_MSC_GetLUNInfo(&HOST_HANDLE, 0, &info); switch (info.sense.asc) { case SCSI_ASC_LOGICAL_UNIT_NOT_READY: case SCSI_ASC_MEDIUM_NOT_PRESENT: case SCSI_ASC_NOT_READY_TO_READY_CHANGE: USBH_ErrLog (''USB Disk is not ready!''); res = RES_NOTRDY; break; default:res = RES_ERROR;
break; } } return res;}If you look a little deeper, in the function called to obtain the error source (USBH_MSC_GetLUNInfo());USBH_StatusTypeDef USBH_MSC_GetLUNInfo(USBH_HandleTypeDef *phost, uint8_t lun, MSC_LUNTypeDef *info){ MSC_HandleTypeDef *MSC_Handle = (MSC_HandleTypeDef *) phost->pActiveClass->pData; if(phost->gState == HOST_CLASS) { USBH_memcpy(info,&MSC_Handle->unit[lun], sizeof(MSC_LUNTypeDef)); return USBH_OK; } else {return USBH_FAIL;
}}Anyone knows something which may help me?Thanks in advance!2015-04-08 11:39 AM
In fact, the variable used in the switch have the value 0x00, which is:
#define SCSI_ASC_NO_ADDITIONAL_SENSE_INFORMATION 0x00
#define SCSI_ASC_LOGICAL_UNIT_NOT_READY 0x04#define SCSI_ASC_INVALID_FIELD_IN_CDB 0x24#define SCSI_ASC_WRITE_PROTECTED 0x27#define SCSI_ASC_FORMAT_ERROR 0x31#define SCSI_ASC_INVALID_COMMAND_OPERATION_CODE 0x20#define SCSI_ASC_NOT_READY_TO_READY_CHANGE 0x28#define SCSI_ASC_MEDIUM_NOT_PRESENT 0x3A