This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LPC2148 usb controller

I use usb controller in Lpc2148. I get example code from keil website in HID class. I need adapt InReport up to 64 byte( InReport[0],InReport[1]....,InReport[64]) for send more data but I donn't good enough in C programming. How can I do? pleas give code. How can I develop application software in the host side. I need Visual Basic 6
thanks you

Parents
  • Hi, sure here it is :)
    const BYTE USB_ConfigDescriptor[] = {
    /* Configuration 1 */ USB_CONFIGUARTION_DESC_SIZE, /* bLength */

    USB_CONFIGURATION_DESCRIPTOR_TYPE, /*bDescriptorType */ WBVAL( /* wTotalLength */ USB_CONFIGUARTION_DESC_SIZE + USB_INTERFACE_DESC_SIZE + HID_DESC_SIZE + USB_ENDPOINT_DESC_SIZE + USB_ENDPOINT_DESC_SIZE ), 0x01, /* bNumInterfaces */ 0x01, /* bConfigurationValue */ 0x00, /* iConfiguration */ USB_CONFIG_BUS_POWERED /*|*/ /* bmAttributes */
    /*USB_CONFIG_REMOTE_WAKEUP*/, USB_CONFIG_POWER_MA(100), /* bMaxPower */
    /* Interface 0, Alternate Setting 0, HID Class */ USB_INTERFACE_DESC_SIZE, /* bLength */ USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType */ 0x00, /* bInterfaceNumber */ 0x00, /* bAlternateSetting */ 0x02, /* bNumEndpoints */ USB_DEVICE_CLASS_HUMAN_INTERFACE,/* bInterfaceClass */ HID_SUBCLASS_NONE, /* bInterfaceSubClass */ HID_PROTOCOL_NONE, /* bInterfaceProtocol */ 0x5C, /* iInterface */
    /* HID Class Descriptor */
    /* HID_DESC_OFFSET = 0x0012 */ HID_DESC_SIZE, /* bLength */ HID_HID_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL(0x0100), /* 1.00 */ /* bcdHID */ 0x00, /* bCountryCode */ 0x01, /* bNumDescriptors */ HID_REPORT_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL(HID_REPORT_DESC_SIZE), /* wDescriptorLength */
    /* Endpoint, HID Interrupt In */ USB_ENDPOINT_DESC_SIZE, /* bLength */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ USB_ENDPOINT_IN(1), /* bEndpointAddress */ USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */ WBVAL(0x0040), /* wMaxPacketSize */ 0x20, /* 32ms */ /* bInterval */
    /* Endpoint, HID Interrupt Out */ USB_ENDPOINT_DESC_SIZE, /* bLength */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ USB_ENDPOINT_OUT(1), /* bEndpointAddress */ USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */ WBVAL(0x0040), /*wMaxPacketSize // = 64 0x20, /* 32ms */ /* bInterval */
    /* Terminator */ 0 /* bLength */
    };

Reply
  • Hi, sure here it is :)
    const BYTE USB_ConfigDescriptor[] = {
    /* Configuration 1 */ USB_CONFIGUARTION_DESC_SIZE, /* bLength */

    USB_CONFIGURATION_DESCRIPTOR_TYPE, /*bDescriptorType */ WBVAL( /* wTotalLength */ USB_CONFIGUARTION_DESC_SIZE + USB_INTERFACE_DESC_SIZE + HID_DESC_SIZE + USB_ENDPOINT_DESC_SIZE + USB_ENDPOINT_DESC_SIZE ), 0x01, /* bNumInterfaces */ 0x01, /* bConfigurationValue */ 0x00, /* iConfiguration */ USB_CONFIG_BUS_POWERED /*|*/ /* bmAttributes */
    /*USB_CONFIG_REMOTE_WAKEUP*/, USB_CONFIG_POWER_MA(100), /* bMaxPower */
    /* Interface 0, Alternate Setting 0, HID Class */ USB_INTERFACE_DESC_SIZE, /* bLength */ USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType */ 0x00, /* bInterfaceNumber */ 0x00, /* bAlternateSetting */ 0x02, /* bNumEndpoints */ USB_DEVICE_CLASS_HUMAN_INTERFACE,/* bInterfaceClass */ HID_SUBCLASS_NONE, /* bInterfaceSubClass */ HID_PROTOCOL_NONE, /* bInterfaceProtocol */ 0x5C, /* iInterface */
    /* HID Class Descriptor */
    /* HID_DESC_OFFSET = 0x0012 */ HID_DESC_SIZE, /* bLength */ HID_HID_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL(0x0100), /* 1.00 */ /* bcdHID */ 0x00, /* bCountryCode */ 0x01, /* bNumDescriptors */ HID_REPORT_DESCRIPTOR_TYPE, /* bDescriptorType */ WBVAL(HID_REPORT_DESC_SIZE), /* wDescriptorLength */
    /* Endpoint, HID Interrupt In */ USB_ENDPOINT_DESC_SIZE, /* bLength */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ USB_ENDPOINT_IN(1), /* bEndpointAddress */ USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */ WBVAL(0x0040), /* wMaxPacketSize */ 0x20, /* 32ms */ /* bInterval */
    /* Endpoint, HID Interrupt Out */ USB_ENDPOINT_DESC_SIZE, /* bLength */ USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ USB_ENDPOINT_OUT(1), /* bEndpointAddress */ USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */ WBVAL(0x0040), /*wMaxPacketSize // = 64 0x20, /* 32ms */ /* bInterval */
    /* Terminator */ 0 /* bLength */
    };

Children
  • Ok, I think this looks better

    const BYTE USB_ConfigDescriptor[] = {

    /* Configuration 1 */

    USB_CONFIGUARTION_DESC_SIZE, /* bLength */

    USB_CONFIGURATION_DESCRIPTOR_TYPE, /*DescriptorType */

    WBVAL( /* wTotalLength */

    USB_CONFIGUARTION_DESC_SIZE +

    USB_INTERFACE_DESC_SIZE +

    HID_DESC_SIZE +

    USB_ENDPOINT_DESC_SIZE +

    USB_ENDPOINT_DESC_SIZE ), 0x01, /* bNumInterfaces */

    0x01, /* bConfigurationValue */

    0x00, /* iConfiguration */

    USB_CONFIG_BUS_POWERED /*|*/ /* bmAttributes */

    /*USB_CONFIG_REMOTE_WAKEUP*/, USB_CONFIG_POWER_MA(100), /* bMaxPower */

    /* Interface 0, Alternate Setting 0, HID Class */

    USB_INTERFACE_DESC_SIZE, /* bLength */

    USB_INTERFACE_DESCRIPTOR_TYPE, /*bDescriptorType */

    0x00, /* bInterfaceNumber */

    0x00, /* bAlternateSetting */

    0x02, /* bNumEndpoints */

    USB_DEVICE_CLASS_HUMAN_INTERFACE,/* bInterfaceClass */

    HID_SUBCLASS_NONE, /* bInterfaceSubClass */

    HID_PROTOCOL_NONE, /* bInterfaceProtocol */ 0x5C, /* iInterface */
    /* HID Class Descriptor */

    /* HID_DESC_OFFSET = 0x0012 */

    HID_DESC_SIZE, /* bLength */

    HID_HID_DESCRIPTOR_TYPE, /* bDescriptorType */

    WBVAL(0x0100), /* 1.00 */ /* bcdHID */

    0x00, /* bCountryCode */

    0x01, /* bNumDescriptors */

    HID_REPORT_DESCRIPTOR_TYPE, /* bDescriptorType */

    WBVAL(HID_REPORT_DESC_SIZE),/* wDescriptorLength */

    /* Endpoint, HID Interrupt In */ USB_ENDPOINT_DESC_SIZE, /* bLength */

    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */

    USB_ENDPOINT_IN(1), /* bEndpointAddress */

    USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */

    WBVAL(0x0040), /* wMaxPacketSize */

    0x20, /* 32ms */ /* bInterval */

    /* Endpoint, HID Interrupt Out */

    USB_ENDPOINT_DESC_SIZE, /* bLength */

    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */

    USB_ENDPOINT_OUT(1), /* bEndpointAddress */

    USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */

    WBVAL(0x0040), /* wMaxPacketSize */ // = 64

    0x20, /* 32ms */ /* bInterval */

    /* Terminator */

    0 /* bLength */
    };
    Doug

  • How about using approporiate code formatting, as per the instructions above the text input window ?

    const BYTE USB_ConfigDescriptor[] = {
    
    /* Configuration 1 */
    
    USB_CONFIGUARTION_DESC_SIZE, /* bLength */
    
    USB_CONFIGURATION_DESCRIPTOR_TYPE, /*DescriptorType */
    
    WBVAL( /* wTotalLength */
    
    USB_CONFIGUARTION_DESC_SIZE +
    
    USB_INTERFACE_DESC_SIZE +
    
    HID_DESC_SIZE +
    
    USB_ENDPOINT_DESC_SIZE +
    
    USB_ENDPOINT_DESC_SIZE ), 0x01, /* bNumInterfaces */
    
    0x01, /* bConfigurationValue */
    
    0x00, /* iConfiguration */
    
    USB_CONFIG_BUS_POWERED /*|*/ /* bmAttributes */
    
    /*USB_CONFIG_REMOTE_WAKEUP*/, USB_CONFIG_POWER_MA(100), /* bMaxPower */
    
    /* Interface 0, Alternate Setting 0, HID Class */
    
    USB_INTERFACE_DESC_SIZE, /* bLength */
    
    USB_INTERFACE_DESCRIPTOR_TYPE, /*bDescriptorType */
    
    0x00, /* bInterfaceNumber */
    
    0x00, /* bAlternateSetting */
    
    0x02, /* bNumEndpoints */
    
    USB_DEVICE_CLASS_HUMAN_INTERFACE,/* bInterfaceClass */
    
    HID_SUBCLASS_NONE, /* bInterfaceSubClass */
    
    HID_PROTOCOL_NONE, /* bInterfaceProtocol */ 0x5C, /* iInterface */
    /* HID Class Descriptor */
    
    /* HID_DESC_OFFSET = 0x0012 */
    
    HID_DESC_SIZE, /* bLength */
    
    HID_HID_DESCRIPTOR_TYPE, /* bDescriptorType */
    
    WBVAL(0x0100), /* 1.00 */ /* bcdHID */
    
    0x00, /* bCountryCode */
    
    0x01, /* bNumDescriptors */
    
    HID_REPORT_DESCRIPTOR_TYPE, /* bDescriptorType */
    
    WBVAL(HID_REPORT_DESC_SIZE),/* wDescriptorLength */
    
    /* Endpoint, HID Interrupt In */ USB_ENDPOINT_DESC_SIZE, /* bLength */
    
    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
    
    USB_ENDPOINT_IN(1), /* bEndpointAddress */
    
    USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */
    
    WBVAL(0x0040), /* wMaxPacketSize */
    
    0x20, /* 32ms */ /* bInterval */
    
    /* Endpoint, HID Interrupt Out */
    
    USB_ENDPOINT_DESC_SIZE, /* bLength */
    
    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */
    
    USB_ENDPOINT_OUT(1), /* bEndpointAddress */
    
    USB_ENDPOINT_TYPE_INTERRUPT, /* bmAttributes */
    
    WBVAL(0x0040), /* wMaxPacketSize */ // = 64
    
    0x20, /* 32ms */ /* bInterval */
    
    /* Terminator */
    
    0 /* bLength */
    };
    

  • Yeah I suppose thats better I didnt noticed that :) thanks

  • Your Configuration descriptor set is fine.
    I had jumped to wrong conclusion...
    OK, I reconsider on your previous post.

    "the last thing on the bus was a "GET DESCRIPTOR FROM INTERFACE"

    Humm.. then isn't it Get_Descriptor( HID_REPORT )?

    bmRequestType: 0x81   (IN from interface)
    bRequest     : 0x06   (GetDescriptor)
    wValue       : 0x2200 (HID REport, report ID = 0)
    wIndex       : 0x0000 (interface 0)
    

    "after that it turns to "BULK OR INTERRUPT TRANSFER" but it always appear one "Sucess" and the next report is "Not Supported".

    Is it the first Input report? What is the direction of the transfer?
    If so, the enumeration finishes successfully.

    What do you mean "Not Supported"?

    Tsuneo

  • Tsuneo
    Like I said on my previous post I've donwloaded the sniffer you suggested. The software Im working on is the Keil HID example which is one their website. I've changed the code accoding to your posts. I think like you've said enumeration works fine, the majority of the reports are in.

    The "not supported" message I get using the sniffer and it comes every other report after enumeration. I dont think this message causes any harm cause I've tested the original software and it shows just the same msg as the altered version.
    Still trying to figure this out,
    Doug

  • Hi
    I was wondering, don't I have to configure the endpoint in the usbcfg? The code says there's a wizard for that but just cant find it. Does anybody know ?
    Doug

  • "Don't I have to configure the endpoint in the usbcfg?"

    I don't think so.
    If there is anything to modify on usbcfg.h, it's USB_EP_EVENT

    usbcfg.h
    
    #define USB_EP_EVENT        0x0003
    

    This constant works as a mask to the Events Callback function table in usbuser.c
    Please note, the logical endpoint number (joined IN and OUT) is applied here.

    usbuser.c
    
    #define P_EP(n) ((USB_EP_EVENT & (1 << (n))) ? USB_EndPoint##n : NULL)
    
    /* USB Endpoint Events Callback Pointers */
    void (* const USB_P_EP[16]) (DWORD event) = {
      P_EP(0),
      P_EP(1),
      P_EP(2),
      P_EP(3),
      P_EP(4),
      P_EP(5),
      P_EP(6),
      P_EP(7),
      P_EP(8),
      P_EP(9),
      P_EP(10),
      P_EP(11),
      P_EP(12),
      P_EP(13),
      P_EP(14),
      P_EP(15),
    };
    

    Fortunately in this case, the USB_EndPoint1 has been already enabled for EP1 IN. Then, no specific modification for EP1 OUT is required.

    Tsuneo

  • As we've observed on the sniffer, the enumeration seems to finish successfully.
    To confirm it, run these tests.

    Confirmation of Enumeration
    a) Windows Device Manager
    In the USB development, you should often summon up Device Manager.
    This is a tip to ease the procedure.

    1) Copy these two lines to a blank text file, and rename the file to, for example, DevManager.bat (any .bat will do)

    set devmgr_show_nonpresent_devices=1
    start devmgmt.msc
    


    2) Double click DevManager.bat, and Device Manager comes up.

    (Note) When you select 'Show hidden devices' from 'View' menu, you can see all device instances, even if it isn't currently connected. This function is convenient to clean up the device instances for lost devices.

    - Under 'Human Interface Device', can you see the device instance for your board?
    - Does the property window of the instance (double click the instance) show any trouble?

    b) USBView (or UVCView)
    USBView and UVCView are MS tool to show how Windows recognize the USB devices.

    The source code of the USBView is included in the WinDDK.
    C:\WINDDK\3790.1830\src\wdm\usb\usbview\

    MS distribute free WinDDK on this page.
    "Download the Windows Server 2003 SP1 DDK [236 MB ISO file]"
    www.microsoft.com/.../default.mspx

    SiLabs distributes USBView.exe on their KnowledgeBase page.
    See the right pane of this article for usbview.zip.
    "VID/PID/Descriptor Recovery"
    "
    "
    www.microsoft.com/.../WDKpkg.mspx

    - Can you see the descriptors of your device properly on the USBView screen?

    c) USB compliance test
    The USB compliance test (USBCV) is a good tool to debug the enumeration code, even if you don't apply the USB logo program of USB.org.

    USBCV R1.3
    www.usb.org/.../

    When you run this tool, attach PS/2 mouse to your PC.
    USB mouse (and keyboard) doesn't work while this tool is running.
    Laptop PC is a good platform to run this app, because it usually has PS/2 pointing device.
    Also, a high-speed hub has to be connected between your PC and the device.

    - Run Ch9 and HID test on USBCV

    Tsuneo

  • Tsuneo
    I've downloaded the win DDK and also the VC++ 9.0. I tried to compile with VC++ and had no luck. The compiler says it can't compile "enum.c".

    Also I've checked the site you posted " is broken. Could you put the software somewhere I can download or tell me in which compiler the software will compile with?

    As to the third thest, I don't have a high speed hub so that won't work.

    I've done a couple tests maybe this will give you a hint of what might be:
    On

     void USB_EndPoint1 (DWORD event) {
    
      switch (event) {
        case USB_EVT_IN:
          GetInReport();
              IO1SET = 1 << 20;
          USB_WriteEP(0x81, InReport, sizeof(InReport));
          break;
    
       case USB_EVT_OUT:
       IO1SET = 1 << 19;
          USB_ReadEP(0x01, OutReport);
          SetOutReport();
          break;
    
      }
    })
    


    I wrote code so that it sets leds 19 and 20 if events IN and OUT occur. The led 20 which represents event in is always set but the led 19 event OUT never gets set.
    So I went back and tried to use only InReport size of 64 and left the OutReport the ogirinal. The keil original code sends value on InReport[1] =0x01 so on my win application I've put a flag to show that it receives. The flag was never set.

    I forgot to mention but on item a) of your post I did all the things that you've mentioned and Windows sees my device as a HID and it doesn't say its not working properly or anything of that sort.

    I'm not sure but could there be a problem on my win application? It works fine with the keil example, even if I only change the InReport to 64 bytes the outreport still works fine. Im thinking no because its the device that tells the host how its configuration but Im not 100% sure.

    Doug.

  • I've downloaded usbview.
    Doug

  • This is what I get on the USBView

    Device Descriptor:
    bcdUSB:             0x0110
    bDeviceClass:         0x00
    bDeviceSubClass:      0x00
    bDeviceProtocol:      0x00
    bMaxPacketSize0:      0x40 (64)
    idVendor:           0x0000
    idProduct:          0x0000
    bcdDevice:          0x0100
    iManufacturer:        0x04
    0x0409: "Keil Software"
    iProduct:             0x20
    0x0409: "Keil MCB2140 HID"
    iSerialNumber:        0x42
    0x0409: "DEMO00000000"
    bNumConfigurations:   0x01
    
    ConnectionStatus: DeviceConnected
    Current Config Value: 0x01
    Device Bus Speed:     Full
    Device Address:       0x01
    Open Pipes:              1
    
    Endpoint Descriptor:
    bEndpointAddress:     0x81
    Transfer Type:   Interrupt
    wMaxPacketSize:     0x0040 (64)
    bInterval:            0x20
    
    Configuration Descriptor:
    wTotalLength:       0x0029
    bNumInterfaces:       0x01
    bConfigurationValue:  0x01
    iConfiguration:       0x00
    bmAttributes:         0x80 (Bus Powered )
    MaxPower:             0x32 (100 Ma)
    
    Interface Descriptor:
    bInterfaceNumber:     0x00
    bAlternateSetting:    0x00
    bNumEndpoints:        0x01
    bInterfaceClass:      0x03 (HID)
    bInterfaceSubClass:   0x00
    bInterfaceProtocol:   0x00
    iInterface:           0x5C
    0x0409: "HID"
    
    HID Descriptor:
    bcdHID:             0x0100
    bCountryCode:         0x00
    bNumDescriptors:      0x01
    bDescriptorType:      0x22
    wDescriptorLength:  0x001B
    
    Endpoint Descriptor:
    bEndpointAddress:     0x81
    Transfer Type:   Interrupt
    wMaxPacketSize:     0x0040 (64)
    bInterval:            0x20
    
    Endpoint Descriptor:
    bEndpointAddress:     0x01
    Transfer Type:   Interrupt
    wMaxPacketSize:     0x0040 (64)
    bInterval:            0x20
    

    Doug

  • I've got the InReport working, the flag I put finally was set ! :D It was a problem with my application.

    Now to the OutReport the kit doesn't even get a USB_EVT_OUT. I suppose the problem is also on the win application but I haven't found out what it is.
    Doug

  • The output of USBView on your post is fine.
    It is confirmed that the enumeration finishes successfully.

    "I've downloaded the win DDK and also the VC++ 9.0. I tried to compile with VC++ and had no luck."

    WinDDK is distributed with its own C compiler.

    To compile USBView on WinDDK,
    1) Select one of environment which fits to your OS version (Win XP/2k/2k3)
    - Start button > Development Kits > Windows DDK 3790.1830 > Build Environments > WinXP [/ Win Server 2k3 / Win2k] > Free build
    - DOS window pops up.

    2) Move to usbview directory and build it
    > cd src\wdm\usb\usbview
    > build -cZg

    It is documented in "Building a Sample Driver" section of WinDDK help.

    "As to the third thest, I don't have a high speed hub so that won't work."

    I think you have.
    "USB2.0 hub" is a High-Speed hub :-)

    "Now to the OutReport the kit doesn't even get a USB_EVT_OUT. I suppose the problem is also on the win application but I haven't found out what it is."

    When you aren't sure which side the problem lies on, the firmware or the host app, look at the USB traffic.

    In this case,
    - Step execute your host app around WriteFile
    - If you see nothing on the sniffer (or hardware bus analyzer), the host app is the culprit.
    - If you see expected URB (USB Request Block), but it doesn't finish, the firmware is the culprit.

    For this purpose, any software sniffer will do.

    I recommend you SourceUSB in my above post, because this (and BusHound) is the only software sniffer which can catch erroneous enumeration process. Other software sniffers fail to show the enumeration process when it doesn't complete.
    However, once the enumeration finishes, you can use any software sniffer for debug.

    Free, open-source:
    SnoopyPro sourceforge.net/.../

    Commercial, 1-month eval:
    HHD USB Monitor www.hhdsoftware.com/.../usb-monitor.html
    etc.

    Tsuneo

  • Tsuneo
    the problem is on the win application. To fix that wouldnt In the case I need to write a driver, does anybody have code for an application written in C++ that compiles with Builder C++? It woold save me a lot of time plus I dont know how to write a driver...
    Thanks for all the help
    Doug

  • This HID component is written in Delphi, but also compatible to BCB (Borland C++ Builder).

    "Human Interface Device controller suite" by Robert Marquardt
    www.soft-gems.net/index.php
    - Compatible with Delphi 4 to 6 and BCB (tested with BCB 6 Trial).

    Tsuneo