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

How to keep my HID from permanently sending data

Hi there!
I've set up an HID which works fine with HIDClient.exe: it gets polled every 32ms (as per the descriptor), it receives and sends decent data. However, what I'm aiming at is something like:

1. Most of the time, the HID doesn't transfer any data
2. I set the HID to some kind of "Data Transfer mode". In this mode, it reacts to commands sent by the PC.
In a first attempt I'm trying to have the device transmit data at certain device-specific events. So I've set up a buffer which my device can fill. More specifically, I've changed usbuser.c:

Keil's example usbuser.c:

void USB_EndPoint1 (U32 event) {
  switch (event) {
    case USB_EVT_IN:
      GetInReport();
      USB_WriteEP(HID_EP_IN, &InReport, sizeof(InReport));
      break;
    case USB_EVT_OUT:
      ...
      break;
  }
}

My usbuser.c:

void USB_EndPoint1 (U32 event) {
  switch (event) {
    case USB_EVT_IN:
      while ((HID_BufferCtr>0) && (HID_BufferCtr<HID_BUFFER_SIZE)) {
        HID_BufferCtr--;
        InReport = HID_InBuffer[HID_BufferCtr];
        USB_WriteEP(HID_EP_IN, &InReport, sizeof(InReport));
      }
      break;
    case USB_EVT_OUT:
      ...
      break;
  }
}


What happens is that as soon as I increase HID_BufferCtr beyond 0, I get kicked out of the USB. Actually, HID_BufferCtr is even 1, so not even the amount of data changed from Keil's example. So what's the dramatic difference? All I'm doing is write some U8 to InReport, and afterwards it's the same call to USB_WriteEP.
I'd love to attach a USBlyzer log, but can't find the option. The log goes roughly like:

2* PnP Query Device Relations - Removal Relations (issued - failed)
2* PnP Query Device Relations - Ejection Relations (issued - failed)
4* PnP Query Device Relations - Removal Relations (issued - issued - failed - failed)
4* PnP Query Device Relations - Ejection Relations (issued - issued - failed - failed)
3* PnP Surprise Removal (issued - succeeded - issued)
2* URB Bulk or Interrupt Transfer (issued - canceled)
3* PnP Surprise Removal (issued - succeeded - succeeded)
3* PnP Remove Device (issued - succeeded - issued)
2* URB Abort Pipe (issued - failed)
3* PnP Remove Device (issued - succeeded - succeeded)

Now I can't imagine what in my changed code could cause the bus to disconnect me. Are there any ideas? Thanks in advance!

Best wishes,
Peter

  • As of your code, the problem lies in the "while" loop.
    Once USB_WriteEP() passes a packet in USB_EndPoint1(USB_EVT_IN), another USB_WriteEP() call is not allowed, until next USB_EndPoint1(USB_EVT_IN) callback.

    > 1. Most of the time, the HID doesn't transfer any data

    It's a usual usage of HID. Rather, Keil HID example is unusual.
    See these posts,
    http://www.keil.com/forum/15613/
    24-Sep-2009 17:48 GMT
    26-Sep-2009 03:46 GMT

    Tsuneo