lpc1342 USB examples

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

lpc1342 USB examples

864 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bhallett on Tue Jan 26 10:34:35 MST 2010
Hello all,

Does anyone know of any example code for USB support which uses the LPC1342 microcotroller? If not, does anyone know if in order to support USB on this microcontroller that an OS is required?

Regards

B
0 Kudos
Reply
10 Replies

770 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by domen on Mon Feb 21 10:08:06 MST 2011
I agree with KTownsend, license restrictions are really silly for the examples.

You could have a healthy community of people that would improve/fix them.
But the current state, where I can't publish the code, and the bugs (with fixes) I've reported weren't even merged... well... why do I even bother.
0 Kudos
Reply

770 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ktownsend on Tue Feb 02 09:37:04 MST 2010

Quote: NXP_USA
We are working on a tiny version of the USB HID example. It will use the CMSIS header files to declare the peripheral registers, but it will leave out the CMSIS SystemInit setup code. It will compile to less than 1kB.



I'd definately be glad to see that.  I like the ROM-based drivers (they take about 5 minutes to get working), but being limited to a single report is a significant limitation, even if you can vary the length.  If you want full control over the report descriptor, the Keil examples are kind of bloated for simple HID though (especially for a 32KB part).  If NXP is able to provide something with a smaller overall footprint, that would definately be welcome.  A lightweight CDC example would probably make a lot of engineers happy as well, but obviously HID is more relevant for real-world product development.

I've also been avoiding the Keil code because of license issues.  I'm not able to distribute anything using it in code form according to license details at the top of the files.  Hopefully anything made by NXP won't have the same limitation.
0 Kudos
Reply

770 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_USA on Mon Feb 01 12:32:36 MST 2010

Quote: bhallett
Thanks for the info NXP_USA, thats been a great help.

Do you know of any examples that do not use the CSMIS package?

Regards

Barry



We are working on a tiny version of the USB HID example. It will use the CMSIS header files to declare the peripheral registers, but it will leave out the CMSIS SystemInit setup code. It will compile to less than 1kB.

-Dave
0 Kudos
Reply

770 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Sun Jan 31 10:50:56 MST 2010
You'd never guess how happy one could be just seeing abcdef... in a notepad window

I changed the usb_hid example from the EmbeddedArtists package to get a working USB keyboard. This will be used to create a custom human interface using buttons and rotary encoders.

All that had to be done was to change the USB descriptors, create an InReport  with 8 bytes and some sample code to simulate key presses.
Note that I did not yet change the bInterval in the endpoint descriptor so the interrupt function is called at a 32 ms interval. In the "Device Class Definition for HID" document from usb.org the example descriptos in appendix E.6 use 10 ms. I guess that 31 keypress/release events per second is enough - if not I can always try the 10 ms to get 100 events per second.

If anyone wants to play around with the keyboard code then just have a look at the changed I made below.

Regards,

Rob

src/demo.h: changed definition of InReport into InReport[8]

src/demo.c: changed definition of InReport into InReport[8] 
            changed GetInReport function to put (and remove) keys in InReport[2] at regular intervals
            
src/hiduser.c: changed HID_GetReport to get the full InReport[] buffer into EP0Buf[]

src/usbdesc.c: changed the HID Report descriptor to identify a keyboard device:

        /* HID Report Descriptor */
        const uint8_t HID_ReportDescriptor[] = {
          HID_UsagePage(HID_USAGE_PAGE_GENERIC),
          HID_Usage(HID_USAGE_GENERIC_KEYBOARD),
          HID_Collection(HID_Application),
            HID_UsagePage(HID_USAGE_PAGE_KEYBOARD),
            HID_UsageMin(0xe0),
            HID_UsageMax(0xe7),
            HID_LogicalMin(0),
            HID_LogicalMax(1),
            HID_ReportSize(1),
            HID_ReportCount(8),
            HID_Input(HID_Data | HID_Variable | HID_Absolute),
            HID_ReportCount(1),
            HID_ReportSize(8),
            HID_Input(HID_Constant),
            HID_ReportCount(5),
            HID_ReportSize(1),
            HID_UsagePage(HID_USAGE_PAGE_LED),
            HID_UsageMin(1),
            HID_UsageMax(5),
            HID_Output(HID_Data | HID_Variable | HID_Absolute),
            HID_ReportCount(1),
            HID_ReportSize(3),
            HID_Output(HID_Constant),
            HID_ReportCount(6),
            HID_ReportSize(8),
            HID_LogicalMin(0),
            HID_LogicalMax(101),
            HID_UsagePage(HID_USAGE_PAGE_KEYBOARD),
            HID_UsageMin(0),
            HID_UsageMax(101),
            HID_Input(HID_Data | HID_Array),
          HID_EndCollection,
        };

               In the USB_ConfigDescriptor[] enabled the USB_CONFIG_REMOTE_WAKEUP in the bmAttributes field
               and changed the InterfaceSubClass and InterFaceProtocol in HID_SUBCLASS_NONE and HID_PROTOCOL_KEYBOARD.
               also changed bcdHID in the intefacedescriptor into 0x0101 instead of 0x0100
               and the wMaxPacketSize in the endpoint is set to 8 (was 4)

src/demo.c: add simulated keypresses in the GetInReport function:

        void GetInReport (void) {
            static unsigned counter = 0;
            static unsigned keycode = 0x04;

            switch(counter++) {
            case 1: InReport[2] = keycode++;
                    if(keycode > 0x1d) keycode = 0x04; // Rotate back from Z to A
                    break;
            case 3: InReport[2] = 0;
                    break;
            case 16:counter = 0;
                    break;
            }
          return;
        }
0 Kudos
Reply

770 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Fri Jan 29 13:02:44 MST 2010
Pawel,

usbview is showing (what I think) to be correct:

bcdUSB:             0x0200
bDeviceClass:         0x03
bDeviceSubClass:      0x01
bDeviceProtocol:      0x01
bMaxPacketSize0:      0x40 (64)
idVendor:           0x1FC9
idProduct:          0x0003
bcdDevice:          0x0100
iManufacturer:        0x01
0x0409: "NXP SEMICOND "
iProduct:             0x02
0x0409: "LPC13xx USB HID "
iSerialNumber:        0x03
0x0409: "DEMO00000000"
bNumConfigurations:   0x01
I also tried to make it a regular (i.e. non Boot Device with subclass = 0) bur that did not make a difference. Also spent some more time in reading the USB spec, I did not change the Report descriptor so that could also be a problem.

The device manager of Vista reports it with the compatibility Ids set to: USB/Class_03&SubClass_00&Prot_00. I still have to check if that is the same when the Report descriptor is changed but I decided to spend more time on reading the USB specs first.

Rob
0 Kudos
Reply

770 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by elektrknight on Thu Jan 28 15:33:32 MST 2010
Hi,

I would first check what the USBView is showing, look for:

bcdUSB
bDeviceClass
bDeviceSubClass
bDeviceProtocol
bMaxPacketSize

It will tell you what Windows think about your device.
Pawel

USBView link
http://msdn.microsoft.com/en-us/library/cc748123.aspx
0 Kudos
Reply

770 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Thu Jan 28 14:09:58 MST 2010
Ok, I've downloaded the examples and tested the HID example.
I wanted to create my own special keyboard device and changed the subclass and the protocol in the usbdesc.c (HID_SUBCLASS_BOOT, HID_PROTOCOL_KEYBOARD) and also changed the InReport to contain 4 bytes but Windows does not recognise my device as a keyboard.

I've use the Snoopy USB monitoring program and I do see that the subclass and protocol are sent as expected but that's all - the device still shows as a standard HID device and not a keyboard device in Windows.
I must ne missing from reading the USB spec (I was reading the Device Class Definition for Human Interface Devices (HID) v 1.11)

Any help is welcome.

Rob
0 Kudos
Reply

770 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by elektrknight on Thu Jan 28 13:51:19 MST 2010
Hi Barry,

Try  LPC13xxSampleSoftware -
http://ics.nxp.com/support/documents/microcontrollers/zip/code.bundle.lpc13xx.keil.zip

The USB examples in LPC13xxSampleSoftware use some CMSIS files but it
just startup_LPC13xx.s and system_LPC13xx.c and a bunch of macros.

I think it would simple to decouple it completely from CMSIS.
In fact this is more or less what I did in LPC13xxSampleSoftware
GCC port available here:

http://code.google.com/p/32bitmicro/wiki/LPC13xxSampleSoftware

BTW LPC1342 is supported out of the box in GCC port, all you need to
do is to set variable in the Makefile:

TARGET_MCU=lpc1342

Cheers,
Pawel
0 Kudos
Reply

770 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bhallett on Thu Jan 28 07:02:37 MST 2010
Thanks for the info NXP_USA, thats been a great help.

Do you know of any examples that do not use the CSMIS package?

Regards

Barry
0 Kudos
Reply

770 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NXP_USA on Tue Jan 26 10:57:48 MST 2010

Quote: bhallett
Hello all,

Does anyone know of any example code for USB support which uses the LPC1342 microcotroller? If not, does anyone know if in order to support USB on this microcontroller that an OS is required?

Regards

B



The complete NXP example package available on the www.nxp.com/lpcxpresso-support page has five USB example projects in it. Two of them use the on-chip ROM driver and three are examples ported to LPCXpresso from one of our 3rd party tool vendors. These are all set up to run on the LPC1343, but they should run similarly on the LPC1342. The Mass Storage Class examples will require modification because the LPC1342 has less memory and cannot hold as many MSC device sectors.
0 Kudos
Reply