This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C123FH6PM: USB: dinamically add and remove CDC devices to composite USB device

Part Number: TM4C123FH6PM

Hello!

As a part of my design I need to create device wich uses CAN bus to connect to other devices and USB to connect to host. This device should add CDC device for each CAN device connected to, and remove it then disconnected. 

As I read spmu297e document, I see the USBDCDCCompositeInit() function to add composite device, and USBDCDCTerm() for shuting down, but there are a note: "This function should not be called if the CDC device is part of a composite device and instead the USBDCompositeTerm() function should be called for the full composite device." But I do not need to shut down whole composite device, but only one CDC device, how to do it?

Thank you!

  • Hello Oleg,

    I am not sure that is really possible by USB standards. I haven't heard of a setup like that. The way USB works for Composite is that on connection, the Composite port enumerates by sharing information via Descriptors about every port of the Composite device that is present. This is only done on the initial connection & enumeration, and so there would be no means to update this afterwards beyond re-enumerating. So if you terminated a CDC port, the host would still expect it to be there and could try and connect to it without the device's knowledge. This cannot be resolved unless the enumeration is started over again and the device tells the host a new descriptor with the correct number of ports.

    I would instead recommend doing a disconnection so the host is not connected to the CDC port, but it is available for future connections instead. This way it is not in use, but it is available under the right circumstances. I feel like that is the best solution here, but of course repeated re-enumeration is an option as well if you feel that is best fit for your system depending on how often the situation occurs.

    Best Regards,

    Ralph Jacobi

  • OK, maybe I should not shut down the devices, as disconnection from CAN is abnormal situation, but I need to add CDC devices one by one as they are appear on the bus. Is it possible? I need this as I need to see which device uses which port, the devices has no built in identification.

  • Hello Oleg,

    My first thought would be to do something like... you enumerate initially indicating you have x number of CDC devices - which would be your maximum amount - but then don't connect with them. Just make the indicator they are present. That way the host machine knows additional connections can be made.

    Then as needed connect and disconnect them based on CAN connections. This way the descriptors don't need to be updated but you are able to connect additional CDC ports as needed as well as have the option to disconnect USB CDC ports too.

    Best Regards,

    Ralph Jacobi

  • The problem is host machine should know when device is connected, and see COM port appeared/

  • Hello Oleg,

    I am not really familiar with this sort of use case. I think perhaps the alternative would be to use Suspend and Resume type commands for handling this, but really I'm not familiar with an application where a composite device wants to add and remove new CDC ports after initial enumeration like you are describing.

    Best Regards,

    Ralph Jacobi