USB mass storage and charging

Hi,

My product uses the nrf52840 chip with NCS 2.7 and has a USB mass storage function.

I would like to implement a feature as below 

1. When the USB is connected to the charger, it will directly display "Charging".

2. When the USB is connected to the PC, it will display the "Charging only" and "Mass Storage" option, if user select "Charging only" then the same as item 1,if  select "Mass Storage" then connect to the PC as a mass storage device.

How to handle the USB part when  connect to the charger or the PC? (Base on the example  zephyr\samples\subsys\usb\mass).

  • Hi Jason,

    I am afraid the USB Mass sample doesn't readily support what you want to do. The sample is setup so that the Mass Storage Class (MSC) is enabled before main(), and there is no way to hide it from the host.

    We haven't tried this before, but there are some APIs in the USB Next stack that might help you:

    usbd_register_class()
    usbd_unregister_class()
    usbd_shutdown()
    usbd_init()
    usbd_enable()

    The idea is to initially not expose the MSC to the host. After the choice is made, if the MSC is needed, shutdown the USB stack, add the MSC, and re-enabled the USB stack.

    You can enable the USB Next stack and try this.

    Hieu

Related