Skip to content

This repository contains code and instructions to implement a USB Host CDC driver on the TI Tiva C (TM4C123G) MCU

Notifications You must be signed in to change notification settings

remixed123/tiva-c_usb_host_cdc_driver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Tiva C USB Host CDC Driver Readme

This driver currently only supports send data out the Tiva C USB Port to a device. If you requiring receive data, then you will need to update the code, which should be relatively simple once the enumeration takes place. This code is custom, so you may need to play around with it a bit to get enumeration working, as it depends on how your CDC device has set up its interfaces and endpoints. CDC devices can vary in this respect.

The contents of this document and the source code was originally posted on Texas Instrument's Tiva C E2E support forum - http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/294099

USB Background Information

If you are only starting out with USB embedded host work, I suggest the following resources.

Code Review

Included in the respository is the following code files

  • usbhcdc.c and usbhcdc.h - this is the USB Host CDC driver that has been developed
  • usbhostenum.c - this is one the main usb host libraries that comes with Tivaware. I needed to make some changes to this code, as I discovered a few bugs. When I last checked on the 5/1/2014, TI had not got around to resolving this bug yet. You will need to check this your self to see whether has been resolved. The bugs are discussed here - http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/296947.aspx

Code Changes Required

You will need to add the following to usbhost.h

extern const tUSBHostClassDriver g_sUSBHostCDCClassDriver;

Here are some of the important points for the program code. I suggest starting with one of the examples provided with Tivaware or TI-RTOS for a similar device. And then altering it to your needs.

mainprogram.c

// USB Headers
#include "usblib/usblib.h"
#include "usblib/host/usbhost.h"
#include "usblib/host/usbhcdc.h"

// A list of available Host Class Drivers, we only add CDC driver
static tUSBHostClassDriver const * const usbHCDDriverList[] = {
    &g_sUSBHostCDCClassDriver,
    &USBCDCH_eventDriver
};

Add this to where you initialise the your USB CDC

void USBCDCH_init(Void)
{
:
:

    // Initialize the USB stack for host mode. 
    USBStackModeSet(0, eUSBModeForceHost, NULL);

    // Register host class drivers 
    USBHCDRegisterDrivers(0, usbHCDDriverList, numHostClassDrivers);

    // Open an instance of the CDC host driver 
    CDCInstance = USBHCDCDriveOpen(0, CDCCallback);
:
:
}

Add this to your main program loop

// Call the USB stack to keep it running.
USBHCDMain();

Use something like this to send data out the bulk output

void singlePacket(tUSBHCDCInstance *psCDCInstance)
{

:
:
     int byteCount = 0;
     byteCount = USBHCDCWrite(psCDCInstance, packetPtr, totalSize);
:
:
}

About

This repository contains code and instructions to implement a USB Host CDC driver on the TI Tiva C (TM4C123G) MCU

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published