-
-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix simultaneous use of SDcard and USB MSD #1523
Conversation
Hi @martin-kuhn, I'm nanoFramework bot. A human will be reviewing it shortly. 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Thanks for the fix. 👍
@martin-kuhn have you tested this code with the following variations? 🤔
|
Yes, I checked all of the four possibilities:
|
Are you sure that you're not getting a Null on 3. Instead of am empty collection? |
With no device inserted I get an Windows.Storage.StorageFolder array of length 0 (as you can see in the picture). If there's only one device, then the array has length 1 and for two devices it has length 2. |
@@ -73,6 +73,7 @@ HRESULT Library_win_storage_native_Windows_Storage_StorageFolder::GetRemovableSt | |||
uint32_t driveCount = 0; | |||
char workingDrive[sizeof(DRIVE_PATH_LENGTH)]; | |||
uint16_t driveIterator = 0; | |||
bool busy = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think this busy
flag is needed. The sdCardEnumerated
and usbMsdEnumerated
should take care of this.
I've just tested your fix without it and it seems to be working as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested it quickly without the busy flag. It is needed anyway. Without the busy flag, both if conditions of the SDcard and the USB MSD are true because they are both ready and not enumerated at the beginning. So they get executed both in the first iteration of the loop and then the workingDrive of the SD card gets overwritten by the workingDrive of the USB MSD. This means that in both iterations the same device (the second one, which is the USB MSD) is mounted. So you'll end up with an array which has two StorageFolders but they are exactly the same.
I would have preferred to use the enumerated flags instead of an additional busy flag, but this is not possible because if you use only one drive, the other one is not defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting for your comment on the busy
flag. 😃
Thanks for your solution. I came to the same one yesterday, but I dropped it because of this: |
That shouldn't be a problem. The SD_CARD_DRIVE_INDEX_NUMERIC is set to 1 or 0 according to the defines on what's being used. |
Ok, I see. So USB_MSD_DRIVE_INDEX_NUMERIC is set to 0 when HAL_USE_SDC is not defined. Great! |
Ah, that's already the case. I didn't see that, sorry :) |
I don't think that check is required. If the file systems aren't ready the drive count will be 0 and that code block is never entered. |
Can you please squash all these so the changes being made here are clearer? |
I cleaned up the code with some small changes (instantiation of StorageFolder was there twice, maxDriveCount fixed). It's tested and it works in all of the 4 possibilities. |
|
finished 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
The Windows.Storage library allows file operations on SD cards and USB MSD.
Motivation and Context
With the present code, it is only possible to use either the SD card or the USB MSD but not both at the same time. To get this to work, small changes were necessary.
How Has This Been Tested?
This has been tested on a custom STM32F427 based board with an SD card slot and an USB Host port. With the FileAccess sample from the GitHub repo, which has been adjusted to use two removable devices, the functionality could be verified.
Types of changes
Checklist: