Stm32+ USB. Skipping messages

Creating a device based on stm32, which would connect to a Windows computer as a HID device. To write a program on stm32, I use the cubemx+keil bundle. It is necessary to organize a simple transmission of packets of 11 bytes. The report descriptor is given below:

__ALIGN_BEGIN static uint8_t CUSTOM_HID_ReportDesc_FS[USBD_CUSTOM_HID_REPORT_DESC_SIZE] __ALIGN_END =
{
  /* USER CODE BEGIN 0 */
   0x06, 0x00, 0xff,              //    USAGE_PAGE (Generic Desktop)
    0x09, 0x01,                    //   USAGE (Vendor Usage 1)
    // System Parameters
    0xa1, 0x01,                    //   COLLECTION (Application)
    0x85, 0x01,                    //   REPORT_ID (1)
    0x09, 0x01,                    //   USAGE (Vendor Usage 1)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0xFF,                    //   LOGICAL_MAXIMUM (1)
    0x75, 11,                    //   REPORT_SIZE (8)
    0x95, 8,                       //   REPORT_COUNT (4)
    0xb1, 0x82,                    //   FEATURE (Data,Var,Abs,Vol)
    0x85, 0x01,                    //   REPORT_ID (1)
    0x09, 0x01,                    //   USAGE (Vendor Usage 1)
    0x91, 0x82,                    //   OUTPUT (Data,Var,Abs,Vol)

    0x85, 0x02,                    //   REPORT_ID (4)
    0x09, 0x02,                    //   USAGE (Vendor Usage 4)
    0x75, 11,                    //   REPORT_SIZE (8)
    0x95, 8,                       //   REPORT_COUNT (4)
    0x81, 0x82,                    //   INPUT (Data,Var,Abs,Vol)
  /* USER CODE END 0 */ 
  0xC0    /*     END_COLLECTION              */

};

I ran into a problem with this plan. When transmitting more than one packet per second, there is a chance that the whole packet will not be sent. For example, here I wrote a test the program.

uint8_t dataTest[50][11]; //Объявление переменных, естественно,
uint8_t flag=0;           //сделано в нужном месте
    for(uint8_t i=0;i<50;i++)for(uint8_t j=0;j<11;j++)dataTest[i][j]=i; //Заполнение начальными значениями
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */       
        while(USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, dataTest[flag++], 11)!=USBD_OK);
        if(flag==50)flag=0;
        HAL_Delay(500); 
  }
  /* USER CODE END 3 */
}

I hook up with the Saleae analyzer to the USB bus and see the following picture. Eleven bytes of "sevens" were transmitted, eleven bytes of "eights" were transmitted, then eleven bytes of "tens"were transmitted. In the response program on the computer, the same thing. What can be associated with the transition of the stm to the next element of the array, without even waiting for the transfer of the previous one?

 0
Author: Nowsan, 2018-05-29

1 answers

I did not understand what was the root of the problem, but I solved it as follows. Added a simple implementation of the confirmation of the reception of the packet by the computer, after which the MC proceeds to send the next message from its buffer.

 0
Author: Nowsan, 2018-06-09 05:40:42