USB Raw on Kinetis microcontrollers...

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

USB Raw on Kinetis microcontrollers...

1,014 Views
dinofarina
Contributor II

Hello,

I'm thinking of using USB HID-RAW in a very defined application for establishing a communication mode (basically a message handler) between a Kinetis K24 device and a PC application.  I want to use the Kinetis Design Studio and Kinetis SDK tools if possible for the device-side implementation and LabVIEW for the PC application.  I've looked around quite a bit and haven't found any Freescale documents describing HID-RAW - everything points to "mouse" or "keyboard" and the complicated looking USB descriptor files associated with these types.  Conceptually, I know what I need the code to do and my thinking is that since I'm responsible for defining the packet contents for both the send and receive ends, why bother with the overhead of using a "mouse" or "keyboard" type when all I need is the "raw" packet?  Does anyone have any thoughts on this?

Thanks,

-Dino

Labels (2)
0 Kudos
4 Replies

701 Views
mjbcswitzerland
Specialist V

Hi

Take a look at C code for Teensy: USB Raw HID - for building custom USB devices

Regards

Mark

Kinetis: µTasker Kinetis support

K24: µTasker Kinetis TWR-K24F120M support

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 Kudos

701 Views
dinofarina
Contributor II

Thanks Mark. I have looked at that example very carefully – it’s helpful for sure. Though I was really hoping for something more relevant to Freescale’s microcontrollers and the Kinetis SDK…

-Dino

0 Kudos

701 Views
mjbcswitzerland
Specialist V

Hi Dino

In case you don't 'need' Freescale code you can also get USB-HID-RAW in the uTasker project.

This can be built with most IDEs, including KDS and CodeWarrior (CooCox, IAR, Keil, Greenhills etc.) and also combined with other classes as composite devices (eg. USB-MSD, USB-CDC etc.).

The code is processor independent and so builds and runs on any Kinetis part with USB and can be simulated in the uTasker Kinetis simulator for highest development efficiency.

As an example I just configured for the TWR-K24F120M and attached the binary - this enumerates as HID RAW device and can be tested with the application at the link. The PC program uses endpoint 2 to send 64 byte HID output reports and I set the IN report on endpoint 1 with a size of 32 (to be different) and just send back each report received to the PC host (just the first 32 bytes).

HID raw is very simple, whereby I have attached the required descriptors as header file. The following is the application layer implementation showing this example, although there are several choices for operation - with buffering or interrupt callbacks. I just set up the IN/OUT as a virtual bidirectional pair with a bit of rx buffering. I set a callback on successful IN frame delivery (non-buffered) which is useful for controlling the application sending fast data (to ensure that the PC polls it before the next is prepared) but don't actually use it in this example.

Initialisation:

    USBTABLE tInterfaceParameters; // table for passing information to driver

    QUEUE_HANDLE endpointNumber = 1;

    tInterfaceParameters.owner_task = TASK_USB; // USB task is woken on receptions

    tInterfaceParameters.usConfig = 0;

    tInterfaceParameters.usEndpointSize = HID_RAW_RX_SIZE; // endpoint queue size (2 buffers of this size will be created for reception)

    tInterfaceParameters.Endpoint = endpointNumber++; // the endpoint used by HID raw device for reception

    tInterfaceParameters.usb_callback = 0;

    tInterfaceParameters.queue_sizes.TxQueueSize = 0;

    tInterfaceParameters.queue_sizes.RxQueueSize = (2 * HID_RAW_RX_SIZE);// reception buffer with space for two complete HID raw messages

    tInterfaceParameters.Paired_RxEndpoint = endpointNumber++;

    tInterfaceParameters.INcallback = fnRawHIDPolled;

    USBPortID_HID_raw = fnOpen(TYPE_USB, 0, &tInterfaceParameters); // open the endpoints with defined configurations (initially inactive)

USB task:

    if (fnRead(USBPortID_HID_raw, ucRawData, HID_RAW_RX_SIZE) == HID_RAW_RX_SIZE) { // HID raw OUT reception

        fnWrite(USBPortID_HID_raw, ucRawData, HID_RAW_TX_SIZE); // send back on IN pipe

    }

Optional callback on IN polling completion:

static void fnRawHIDPolled(unsigned char ucEndpoint)

{ // dummy

}

That is about all the code needed to perform the configuration and echo, and the application can do its own other things by simply reading/writing the handle USBPortID_HID_raw.

Regards

Mark

Kinetis: µTasker Kinetis support

K24: µTasker Kinetis TWR-K24F120M support

USB User's Guide: http://www.utasker.com/docs/uTasker/USB_User_Guide.PDF

For the complete "out-of-the-box" Kinetis experience and faster time to market

0 Kudos

701 Views
dinofarina
Contributor II

Hi Mark,

Thank you very much for your detailed response and for the code! I’ll check out your code attachment and go from there.

-Dino

0 Kudos