This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Switch USB Class between MSC and CDC in runtime

Does anyone know how to switch usb between msc and cdc dynamically when uisng Keil USB Stack? Not the composite mode.

  • It is possible but it is not simple.

    Simplest way would be to use two completely separate projects one for MSC, other for CDC and then make a bootloader or a piece of code that would run each of them depending on whatewer makes the switch beweeen MSC and CDC.

    Second way is more complex, it would reduce the code size as there would not be two separate projects containing complete USB stack. This would mean you choose MSC or CDC as default device and make it as if it were the only device, then you at runtime replace all descriptors with other device (there are provisions for that in Keil USB stack) if other class is required but there are also some internal things that need to be handled in this case and this would require some investigation. These additional things that need to be done are intitalization of another class when switch is done, and mapping endpoint events to threads belonging to other class when switch is done.

    So, basically second way is almost impossible or very time consuming, and first way would be preferred of course doubling code size for complete project.