This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52840 USB MSC and app_sdcard block device sharing - MSC only enumerates once with USB Hub

Hello all!

I'm finding a lot of what I'm able to do with the nRF52840 mostly straight forward, especially with the wealth of examples included with the SDK. I'm currently working on a project where my end goal is this:

- While USB is connected to a host, present a USB Mass Storage Class device that exposes the SD Card, which is formatted with FAT32.
- While the USB is disconnectedthe application will access the SD Card and use it's data for operations.

I've mostly got it working, but with one snag: the Mass Storage Device only shows up on the host's side once, when I'm using it through my USB hub on my desk here. My USB hub is one of those models that have the ability to toggle individual ports on and off via a hardware switch. When using that switch everything works exactly as you'd expect, up until the second time it's switched on. My application closes down the fatfs access (`disk_uninitialize(0)`) upon seeing that USB has power, similarly to the way the MSC example treats the QSPI block device. The USB event handler calls `app_usbd_enable()` and then `app_usbd_start()` once the APP_USBD_EVT_POWER_READY event comes through. Things look all happy from the application's end. If I turn on verbose logging for the USB modules, there's definitely a heap of transfers going back and forth, but Windows never even seems to notice I've attached a USB device. (I'm using Nirsoft's usb_log_view, Thesycon's Usb Descriptor Dumper, and have the windows device manager open. None of them register the attachment)

I spent all evening being sure it's something wrong with my code, sharing the sdcard block device, etc. Until on a whim, I decided to try unplugging and re-plugging in my USB cable. Lo and behold, the application behaves exactly as I would expect it to. No matter the number of times I reconnect it, the USB device always shows back up, applications handle the events the same, and everything seems peachy.

So it seems the case with my switch on my USB hub seems to (I hope!) be a severe edge case! I'm just worried it might mean something else is wrong that could bite me in the future.

Does anyone have any insight with USB of something that I'm missing here? Is there a physical difference between a switch that cuts the VBus line (my guess is it leaves the D+/- lines, and GND untouched?) and reconnecting the cable?

Thank you all!

Some notes about my environment: nRF52840, custom board, using arm gcc 2019 q2, targeting C++17/C11, SDK 17.0, DEBUG is defined, not using a soft device.

Parents Reply Children
No Data
Related