Skip to content

Commit

Permalink
Fix drive enumeration for Storage API (#1363)
Browse files Browse the repository at this point in the history
***NO_CI***
  • Loading branch information
josesimoes authored Jun 13, 2019
1 parent 98f6e80 commit a32c7dc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
18 changes: 7 additions & 11 deletions targets/CMSIS-OS/ChibiOS/common/Target_Windows_Storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,18 @@ extern void PostManagedEvent(uint8_t category, uint8_t subCategory, uint16_t dat
// the drive indexes have to be used instead of fixed drive letters because a target can have one or more
// and those have to follow the sequence that is used in ChibiOS FatFS wrappers
// SD Card (or SPI) is 1st and USB MAS is 2nd (if SD Card is enabled)
#if defined(HAL_USE_SDC) && defined(HAL_USBH_USE_MSD)
// this is also mapped in the FatFS configuration
#if defined(HAL_USE_SDC)

#define SD_CARD_DRIVE_INDEX "0"
#define SD_CARD_DRIVE_INDEX "0:"
#define SD_CARD_DRIVE_INDEX_NUMERIC (0)
#define USB_MSD_DRIVE_INDEX "1"
#define USB_MSD_DRIVE_INDEX_NUMERIC (1)

#elif defined(HAL_USE_SDC) && !defined(HAL_USBH_USE_MSD)

#define SD_CARD_DRIVE_INDEX "0"
#define SD_CARD_DRIVE_INDEX_NUMERIC (0)
#endif

#elif !defined(HAL_USE_SDC) && defined(HAL_USBH_USE_MSD)
#if defined(HAL_USE_SDC)

#define USB_MSD_DRIVE_INDEX "0"
#define USB_MSD_DRIVE_INDEX_NUMERIC (0)
#define USB_MSD_DRIVE_INDEX "1:"
#define USB_MSD_DRIVE_INDEX_NUMERIC (1)

#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetRemovableSt
hbObj->SetObjectReference( NULL );

#if HAL_USE_SDC
bool sdCardEnumerated = false;

// is the SD card file system ready?
if(sdCardFileSystemReady)
{
Expand All @@ -77,6 +79,8 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetRemovableSt
#endif

#if HAL_USBH_USE_MSD
bool usbMsdEnumerated = false;

// is the USB mass storage device file system ready?
if(usbMsdFileSystemReady)
{
Expand Down Expand Up @@ -109,21 +113,28 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetRemovableSt
for(; driveIterator < driveCount; driveIterator++ )
{
// fill the folder name and path
switch(driveIterator)
{
case 0:
memcpy(workingDrive, INDEX0_DRIVE_PATH, DRIVE_PATH_LENGTH);
break;

case 1:
memcpy(workingDrive, INDEX1_DRIVE_PATH, DRIVE_PATH_LENGTH);
break;
#if HAL_USE_SDC
// is the SD card file system ready?
if(sdCardFileSystemReady && !sdCardEnumerated)
{
memcpy(workingDrive, INDEX0_DRIVE_PATH, DRIVE_PATH_LENGTH);

default:
// shouldn't reach here
NANOCLR_SET_AND_LEAVE(CLR_E_NOT_SUPPORTED);
break;
// flag as enumerated
sdCardEnumerated = true;
}
#endif

#if HAL_USBH_USE_MSD
// is the USB mass storage device file system ready?
if(usbMsdFileSystemReady && !usbMsdEnumerated)
{
memcpy(workingDrive, INDEX1_DRIVE_PATH, DRIVE_PATH_LENGTH);

// flag as enumerated
usbMsdEnumerated = true;
}
#endif

// dereference the object in order to reach its fields
hbObj = storageFolder->Dereference();
Expand Down

0 comments on commit a32c7dc

Please sign in to comment.