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.

usb_dev_serial example - please explain how it is working

Other Parts Discussed in Thread: EK-TM4C1294XL

Hello!


I'd like to implement a 3rd (CDC) interface into my composite device which already have a raw HID and a DFU interface, both working. Unfortunately, I don't really understand the working principle of the usb_dev_serial example. I've got a couple of questions and I'd be grateful if someone will be able to answer it.

1. In the example, the comments indicate that there will be some kind of 'UART redirection' but I can't see anything like that. UART0 and PA0-PA1 pins are configured the same way like 'normal' UART. In addition, PA0-PA1 is connected to the ICDI interface to act as a debug UART. How the interface know that from now the ICDI debug interface is not needed because we intend to replace with CDC? I really don't get it.


2. I also don't understand what the CDC RXHandler and TXHandler are actually doing. In TXHandler, there is a comment

// Since we are using the USBBuffer, we don't need to do anything
// here.
//

but where are we using the USBBuffer, actually? The example is not echoing or sending anything..
In the RXHandler, there is a rather obscure part

// A new packet has been received.
        //
        case USB_EVENT_RX_AVAILABLE:
        {
            //
            // Feed some characters into the UART TX FIFO and enable the
            // interrupt so we are told when there is more space.
            //
            USBUARTPrimeTransmit(USB_UART_BASE);
            ROM_UARTIntEnable(USB_UART_BASE, UART_INT_TX);
            break;
        }

so we received something and now we force transmit some dummy bytes instead of reading out or what? I'm clueless.

Finally, the example blinks the blue (receive traffic) and green (transmit traffic) LED, to indicate that something happened. I'm using Minicom on Ubuntu, I can connect to ttyACM0 but when I press a key it seems that both LEDs blink at the very same time. Is it normal?


What would be useful is an explanation how USB CDC  actually relates to the UART peripherial. As far I know - after studying the USB lib UG, reading through e2e - there is no information which answers my questions.The example should have an echo functionality too, it would be much easier to understand what is going on and why.

  • Hello Greg,

    Do you mean the usb_dev_cserial example in ek-tm4c1294xl?

    Regards
    Amit
  • Hi Amit,

    no, I was referring to the usb_dev_serial example in the 'classic' Tiva LaunchPad (123GXL) example folder.

  • Here is another topic, apparently opened by someone who tried to walk in the same shoes:

    https://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/157379

  • Hello Greg

    Thanks for the clarification. To answer the questions asked

    1. The redirection is from the CDC channel on USB to UART0. For the specific use case of yours, its the application code that needs to be modified so that instead of a redirection, the application code can now process the data
    2. Since it is a redirection, so what is received on the USB CDC channel is processed in the RxHandler. For what is received from UART0 the CheckForSerialStateChange is used for transmission.

    Regards
    Amit
  • Okay, mystery solved. In the usb_dev_serial example - at least for me - it was not expressed enough that this is not just a simple serial communication example. What it actually does is acting like a bridge between the 'normal' UART0 and virtual CDC UART. You need to open 2 terminals, one should connect to the ICDI back UART and one should connect to the (hopefully) enumerated CDC virtual COM port. There you can send characters from terminal A to terminal B and vice versa by typing.

    If you just want a normal UART 'behaviour' using CDC, you can eliminate all UART sections from the code, you don't need UART peripherial/pins/interrupts/interrupt handlers whatsoever, only the the CDC Handlers (Control/Rx/Tx). If you want to send something to the host (PC) then you just need to write your data into the USBTxBuffer by calling USBBufferWrite(&USBTxBuffer, &your_dataarray, num_bytes_you_want_to_send) and that's all.

    To receive from the host, you need to add your read function to here:

    case USB_EVENT_RX_AVAILABLE:
            {
                // The received packet is in the Rx buffer
                // Read buffer with USBBufferRead
    
                your_read_function();
                break;
            }

    That's all :-)

  • Thank you Amit! I was just typing my solution when you replied.