lawrence_jeff

Launchpad USB example and documentation additions/labs

69 posts in this topic

For those of you attempting to build USB devices I put together some Launchpad examples as well as a lab type walkthrough of how to create custom devices (mainly HID)

 

Included

 

1) Examples ported to the Launchpad  - Mouse, Keyboard, Composite

2) Updated HID header file with additional device and usage types

3) A new device type called usbdhidcustom - This allows you to make new devices with minimal code changes

4) A complete document in lab type format where you build a volume control device, a gamepad and a keyboard + mouse

5) Completed projects to go with the labs

 

 

 

 

 

StellarisWare.zip

reaper7, juani_c, timotet and 7 others like this

Share this post


Link to post
Share on other sites

For those of you attempting to build USB devices I put together some Launchpad examples as well as a lab type walkthrough of how to create custom devices (mainly HID)

 

Included

 

1) Examples ported to the Launchpad  - Mouse, Keyboard, Composite

2) Updated HID header file with additional device and usage types

3) A new device type called usbdhidcustom - This allows you to make new devices with minimal code changes

4) A complete document in lab type format where you build a volume control device, a gamepad and a keyboard + mouse

5) Completed projects to go with the labs

Thanks!

Share this post


Link to post
Share on other sites

For those of you attempting to build USB devices I put together some Launchpad examples as well as a lab type walkthrough of how to create custom devices (mainly HID)

 

Included

 

1) Examples ported to the Launchpad  - Mouse, Keyboard, Composite

2) Updated HID header file with additional device and usage types

3) A new device type called usbdhidcustom - This allows you to make new devices with minimal code changes

4) A complete document in lab type format where you build a volume control device, a gamepad and a keyboard + mouse

5) Completed projects to go with the labs

Hi Jeff,

I had a question about hid. I wish to transfer 64 bytes of data back and forth between the PC and Stellaris. In such a case what Usage Page/Usage would allow this? I'm still trying to get a grasp of USB HID. It seems interesting.

Share this post


Link to post
Share on other sites

Check out these links

 

http://www.waitingforfriday.com/index.php/USB_Generic_HID_Open_Source_Framework_for_Atmel_AVR_and_Windows

http://www.waitingforfriday.com/index.php/Open_Source_Framework_for_USB_Generic_HID_devices_based_on_the_PIC18F_and_Windows

 

Once you have an OS side applicaton it should be a matter of just using my examples with a customized descriptor (You can dig through the PIC code above to find the descriptor those examples use). If I get a chance I can try to update my examples to include one of these (I think it would be similair to the volume control example except you would make it a generic device and you would have to write the OS side code to send/recieve instead of relying on the HID volume driver included in the OS)

 

Jeff

Share this post


Link to post
Share on other sites

Check out these links

 

http://www.waitingforfriday.com/index.php/USB_Generic_HID_Open_Source_Framework_for_Atmel_AVR_and_Windows

http://www.waitingforfriday.com/index.php/Open_Source_Framework_for_USB_Generic_HID_devices_based_on_the_PIC18F_and_Windows

 

Once you have an OS side applicaton it should be a matter of just using my examples with a customized descriptor (You can dig through the PIC code above to find the descriptor those examples use). If I get a chance I can try to update my examples to include one of these (I think it would be similair to the volume control example except you would make it a generic device and you would have to write the OS side code to send/recieve instead of relying on the HID volume driver included in the OS)

 

Jeff

Hell.. that is perfect! Thanks a ton for the quick response. I just did the volume example and it was a no-brainer. 

Share this post


Link to post
Share on other sites

I am getting 75 errors when I try to build the USB libraries (Step 10 in your writeup).  Most are coming from usbhidcustom.c, and are all along the lines of -

#20 identifier "bool" is undefined usbdhidcustom.c /usblib/device line 385, external location: C:\ti\TivaWare_C_Series-1.0\driverlib\usb.h C/C++ Problem

 

When I look at the referenced lines in the code, the majority of them are on comment lines, which makes no sense to me.  I'm building this for the Tiva, not the Stellaris, don't know if that might be the problem.

 

Also, I'm getting an error that appears to be due to a bug in CCS v5.4.  The example projects you include were configured for V4.9.5 of the ARM compiler.  CCS will not allow you to build them because there isn't a compatible version of the compiler installed (I have 5.0.4 and 5.0.6 available).  The problem is, if you change the compiler version, CCS throws a builder error and it is not possible to fix without having CCS v5.3 or older installed from what I found here - http://e2e.ti.com/support/development_tools/code_composer_studio/f/81/t/226067.aspx

 

Any ideas??
 

Share this post


Link to post
Share on other sites

The fact that your error references C:\ti\Tivaware indicates you are using the wrong software

 

These were developed before Tivaware so you need to use Stellarisware (per the requirements section in the PDF in my zip)

 

So download and install stellarisware to C:\Stellarisware - first option on this page http://www.ti.com/tool/sw-lm3s (make sure you get the one that mentions LM4f)

Update the files in that directory with the version in the zip

Follow the instructions in the PDF - I just went through them with 5.4 and I didn't change the compiler options from 4.9.5 and they still built fine.

 

In general you shouldn't have to change anything from the PDF - except for my note above that for a TIVA in the code you need to force Device mode

Share this post


Link to post
Share on other sites

Yes, that would likely work.  However, I'm not attempting to just follow your examples, I am attempting to update them for Tivaware.  I do not have, nor do I intend to purchase a Stellaris.  I realize that the Tiva is essentially a re-branded Stellaris and that code compiled for the Stellaris will work, with a few exceptions, on the Tiva.  However, since I am just starting out with the TI products myself I would prefer not to even begin with a deprecated product or codebase.  I think I have most of the necessary changes worked out, and I plan on following the advice from the TI forum on using CCS 5.3 to fix the compiler error as soon as I have a free moment to do so, and then pulling the project back into CCS 5.4.  Hopefully that will fix the compiler error and I can move on to the error messages when attempting to compile the libraries.  I think the handful of errors I am getting in host/usbhidkeyboard might have to do with one or more of the modified files included in your package.  I have not tried compiling the stock library to see if it generates the same errors.  I'll compare your files to the Tivaware and Stellarisware originals, and see if I can correct the issues.

 

What has me particularly confused though is that 90% of the line numbers that are throwing errors in usbdhidcustom.c when attempting to compile the libraries are on lines that contain nothing but a comment???  If I'm not mistaken, the compiler should ignore any line that begins with a "//", so what could possibly cause it to generate an "identifier ******** undefined" error on those lines?

 

I'll keep digging and hopefully figure it out through trial and error and google.  The more I hammer away at this problem, the more I'll start to pick up on the code style in general.  I learn much faster that way than trying to read and absorb from the manuals, datasheets, and books.  Once (if??) I get everything functional, I'll drop you an update.  If you have any suggestions on what might be causing the errors on the comment lines, that would be helpful.

 

Thanks!

Share this post


Link to post
Share on other sites

I would still recommend installing stellarisware and using the instructions to get familiar with the process of using CCS and compiling the library there are lots of little gotchas that can burn lots of time (it would also let you see how it behaves when it works as expected) stellarisware is just a directory tree so you can have it installed in parallel with Tivaware and just delete it when you get comfortable and are ready to tackle Tivaware (which is almost exactly the same except they changed all the variable types)

 

Either way if you do port any of the stuff over please drop me a copy if you don't mind..

Share this post


Link to post
Share on other sites

Ok, working on reconciling your custom usbhid.h and usb-ids.h with the Tivaware ones.  usbhid.h was easy, but I have a question on usb-ids.h.  0x000D is assigned to USB_PID_CUSTOM in your usb-ids.h file.  It wasn't used in the original Stellarisware package.  However, in Tivaware, it is assigned to USB_PID_COMP_HID_HID.

 

Any ideas how to handle the conflict?  I haven't looked to see what USB_PID_COMP_HID_HID is used by in the Tivaware package yet, but I would hazard a guess I probably shouldn't reassign it to USB_PID_CUSTOM or it will end up breaking something.  Can I assign USB_PID_CUSTOM to 0x000E without breaking your code, or will I need to make other modifications as well?  0x000C isn't assigned in the Tivaware usb-ids.h file, so the USB_PID_GAMEPAD entry should be fine.

 

Once I get that taken care of, I'll move on to trying to get your example code working with Tivaware.

Share this post


Link to post
Share on other sites

One of the main reasons I created my framework was to support the lack of composite HID support in the framework, I'm guessing that is what USB_PID_COMP_HID_HID stands for. Just feel free to either use that value instead of USB_PID_CUSTOM or if you want just assign PID_CUSTOM to an unused value.

 

Product IDs really don't matter they just need to be unique per device you create (and across any examples you install) since the OS caches it and can get confused if the same PID is used for multiple devices.

 

Also I did manage to port my files over to Tivaware this weekend - I can try to post the new files to github tonight.

Share this post


Link to post
Share on other sites

That would be great.  I've nearly got the library compiling correctly.  Fixed all the variable type errors, down to two warnings and two errors.  One error is with the USBHIDCompositeInit call, which now requires a third variable passed (tCompositeEntry *psCompEntry) which I'm not sure how to handle, and the line directly above it referring to PrivateHIDData I haven't been able to fix.  It looks like PrivateHIDData has been renamed to PrivateData, but when I do so in the code, I get an error #515 a value of type "tHIDInstance *" cannot be assigned to an entity of type "tHIDInstance".

 

The two warnings I'm getting are

#515-D a value of type "unsigned long (*)(void *, unsigned long, unsigned long, void *)" cannot be assigned to an entity of type "tUSBCallback" on the pfnRxCallback and pfnTxCallback lines.

Share this post


Link to post
Share on other sites

Ok, reading through the migration document, looks like the PrivateData call isn't needed anymore, so I commented it out.  I just put in a 0 for CompEntry for the moment, and the library compiled with just the warnings about tUSBCallback.  I was able to get the usb_dev_volume example to compile as well with the same warning.  I'd load it to my board and see if it works, but I don't have it with me....  I look forward to your updated package as well, I'm guessing it fixes the issues better than mine does :)

Share this post


Link to post
Share on other sites

Thank you!  Took a small amount of tweaking, but I was able to get everything compiled and working.  You had the includes for the Volume example pointed to ek-lm4f232 rather than the ek-tm4c123gxl and Tivaware 1.0 rather than 1.1, but that was easily corrected.

Share this post


Link to post
Share on other sites

Never mind, I just realized that for this to work the way I want it too, I'm going to have to significantly restructure my code.  Your Volume example won't keep up with the 125Hz polling rate for USB HID devices, and I need to hit that for the smooth mouse/trackball input.  Hmmmm, more research.  I think I'll have to look into to how to set it up to send a single report for the entire composite HID device like you suggested. The rest of the code is coming along nicely though :)

Share this post


Link to post
Share on other sites

@@lawrence_jeff - Well, I have had some limited success now!  I have the Launchpad showing up as a dual gamepad and mouse, my code to scan the GPIO pins works the way I want it to, down to one last problem.  It may show up, and is reading input, but the input isn't making it to the computer??  If I pull a pin to ground that corresponds to a button press on one of the gamepads, I can see in the debugger that the correct value is in the report array, but when I look at the gamepad control panel, the corresponding button does not show up as being pressed.  Not sure what isn't working and not sure where to look to find it.  My code seems to be functioning as intended, so I'm guessing something in the USB stack isn't working correctly.  If you would be willing to take a look at my custom HID code and see if maybe I missed something, it would be greatly appreciated.

usbdhidmame.zip

Share this post


Link to post
Share on other sites

At a glance I don't follow the first report - the comments say 12 bits of buttons followed by 4 bits of padding (to end up an even 2 bytes). However you declare 8 buttons/bits not 12 

 

ReportSize(1),

ReportCount(8),

 

and then pad that with 4 bits for a total of 12 bits (not at an even byte boundary).

Share this post


Link to post
Share on other sites

@@lawrence_jeff - I didn't update the comments, I reduced the button count to 8, as I am going to use the JTAG pins for the other four and was attempting to reduce complexity for debugging.  The 4bit padding is temporarily commented out and I reduced the report count to 8.

Share this post


Link to post
Share on other sites

@@lawrence_jeff - I didn't update the comments, I reduced the button count to 8, as I am going to use the JTAG pins for the other four and was attempting to reduce complexity for debugging.  The 4bit padding is temporarily commented out and I reduced the report count to 8.

 

Sorry I should have looked more closely - so if you do this as individual reports they are all 4 bytes (for example the gamepad is 1 byte reportID, 1 byte of buttons and 2 bytes of axes so 4 bytes total

 

But in your header file you declare the size to be 1 byte

 

#define CUSTOMHID_REPORT_SIZE       1

 

You need this to be 4.

Share this post


Link to post
Share on other sites

@@lawrence_jeff - knew I had to be missing something stupid....  Now the question is, what do I do when the reports for the various devices are of different lengths?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now