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 TM4C123

Hi,

I was trying to create a virtual COM port to communicate a tm4c123 uC with my pc (via UART), to make a simple echo program, so i took a look to TI´s usb_dev_serial example. I spent a day trying to understand how this code works, but it´s to complicated. Searching for internet i found i readable and understandable code, but it doesn´t work. I would like to modificate the usb_dev_serial example to get something like this (which is the understundable code):

#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_uart.h"
#include "inc/hw_sysctl.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/interrupt.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"
#include "driverlib/rom.h"
#include "usblib/usblib.h"
#include "usblib/usbcdc.h"
#include "usblib/device/usbdevice.h"
#include "usblib/device/usbdcdc.h"
#include "utils/ustdlib.h"
#include "utils/uartstdio.h"
#include "usb_structs.h"
#include "usbconfig.h"

// UART configuration for uartstdio library
void ConfigureUART(void)
{
// Enable the GPIO Peripheral used by the UART.
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

// Enable UART0
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

// Configure GPIO Pins for UART mode.
ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

// Use the internal 16MHz oscillator as the UART clock source.
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

// Initialize the UART for console I/O.
UARTStdioConfig(0, 115200, 16000000);
}

// This is the main application entry function.
int main(void)
{
// Set the clocking to run from the PLL at 50MHz
ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

// Enable the GPIO port that is used for the on-board LED.
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

// Enable the GPIO pins for the LED (PF2 & PF3).
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3|GPIO_PIN_2);

// Initialise UART for debug
ConfigureUART();

// Initialise USBCDC for VCP.
USBInit();

while(1)
{
SysCtlSleep();
}
}

// Data handler for RX channel
void RxDataHandler()
{
uint32_t numbytes;
uint8_t data[32];
numbytes = USBBufferDataAvailable(&RxBuffer);
USBBufferRead(&RxBuffer, data, numbytes);
USBBufferFlush(&RxBuffer);
USBBufferWrite(&TxBuffer, data, numbytes);
}

Is there a way to make something like this?

I already have the usbconfig and usb_structs libraries, but i don´t know why they don´t work. I´m working with ccs 6.1.

Hope someone could help me!

Thanks!

  • Hello Denis

    The method you have shown is clearly not the way to develop Virtual COM port over USB. I would refer you back to the TivaWare example code. That code has been utilized by a lot of customers to implement Virtual COM port applications.

    A simpler method would be to use a USB Bulk Device if all you need to do is data exchange.
  • Hi Amit! Thank you very much for replay!!

    Here is the thing... What i´m trying to do is to create a Virtual COM port to in first place talk with my pc, but then what i want to do is to connect tiva uc to a Raspberry pi. So here is my question:

    If i go for a bulk transfer (which is easier to understand for me)... Will i need a special driver for the raspberry?

    It came to my mind that if i implement a virtual COM port on Tiva side, then in Raspberry side things are not going to be dificult (no need of a driver).

    What i can not understand of the usb_dev_serial example is where (int handler) i can add my own code (read/write data)

    Thanks again for replay! Hope you understand me, english is not my first language.

    Best regards!

  • Hello Denis,

    Of course, for a bulk device you would need different drivers. If you want to the virtual COM port, then you would need to modify the usb_dev_serial example as required by the data communication protocol between TM4C and Raspberry Pi. The example code provided is a template for development.
  • Hi Amit!

    Thanks for reply! I already solve the problem. I try 2 differnts thinks and both works!

    First, and after some time thinking i was able to modify the usb_dev_serial example and could read/write data from/to the raspberry pi. The only "problem" is the extensive program that left after doing this.

    Second, I made a simple UART (with interruption) program, and directly connect the USB debug port of LaunchPad to a USB port of the Raspberry... And for my surprice the Raspberry recognize the virtual COM port without any driver installation (that was the thing that push me to the usb_dev_serial example).

    Now I have to alternatives to explore and see which is better, but i think i will use the second method.

    Thanks once again Amit for your help!

    Best regards!

  • Hello Denis

    So you are still using the UART0 over the debug cable for the COM port application. Nice.