This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430 HID Packets Out of Order

Other Parts Discussed in Thread: MSP430F6638

I've been working on a communication protocol to configure devices. I am using an MSP430F6638 as the processor and HID as the interface. For the most part it works great but there have been some intermittent errors. Some of the 64 byte HID packets are out of order. Upon further testing it appears that as the device is sending packets, occasionally one will go "missing". Immediately after the next packet arrives at the PC the "missing" one can be read.

I am using HIDAPI from signal11 (I am using https://github.com/trezor/cython-hidapi for my testing right now) and Windows 7 (I've also run my script in Linux with same results).

Key points I've noticed:

  • If "missing" packet is the last one in a transmission block, no amount of waiting will make it show up. 
  • It appears that the "missing" packet is always available to read after the next transmission block starts
  • If its in the middle of a transmission block it will appear after n+1

The following is my TX code on the MSP.

 

static char out_buf_index = 0;

void usb_flush(void){
  char error;
  uint16_t bytesSent, bytesReceived;
set_LED(Warn3, 1);//debug
  if(out_buf_index > 0){
packet_cnt++; //debug
    while (USBHID_intfStatus(HID0_INTFNUM, &bytesSent, &bytesReceived) & kUSBHID_waitingForSend) //Wait till last tx is finished
      __no_operation();
    if(x_send){
usb_out_buf_y[0] = packet_cnt; //debug
      error = hidSendDataInBackground((unsigned char*)usb_out_buf_y, out_buf_index +1, HID0_INTFNUM, 0xFFFF); //Send
      usb_out_buf_x[1] = '\0';
      
      if(error == 0){
        x_send = 0;
      }
      else
        //usb_out_buf_y[0] = '\0'; //Clear other buffer //debug
        usb_out_buf_y[1] = '\0'; //Clear other buffer
    }
    
    else{
usb_out_buf_x[0] = packet_cnt; //debug
      error = hidSendDataInBackground((unsigned char*)usb_out_buf_x, out_buf_index+1, HID0_INTFNUM, 0xFFFF); //Send
      usb_out_buf_y[0] = '\0';
      
      if(error == 0){
        x_send = 1;
      }
      else
        //usb_out_buf_x[0] = '\0'; //Clear other buffer //debug
        usb_out_buf_x[1] = '\0'; //Clear other buffer
    }
    
    out_buf_index = 0;
  }
  else
    _NOP();
set_LED(Warn3, 0);//debug
}

EDIT: Fixed some wording

 

  • Did some testing with Wireshark and USBPcap. Captures also show flipped frames.

    Added ~2ms delay before each write and it doesn't have this issue so far. Problem is that makes total first connect time with software > 30 seconds. And some other operations could take 5-15 min for the user instead of  1.5 min.

    Does raw HID require a minimum time between TX frames? I didn't see any mention of it on the TI Programmers_Guide_MSP430_USB_API.pdf

    Any insight is appreciated

**Attention** This is a public forum