AnsweredAssumed Answered

STM32F4-Discovery - problem with USB OTG

Question asked by dzikowski.bartlomiej on Dec 16, 2012
Latest reply on Dec 19, 2012 by sutherland.hugh
Hi,
I have a problem with usb. My board is set as a device. On PC I have an application, which was programmed in C#. I want to change the state of the diodes on Discovery with the press of appropriate keys.
The communication work good, but I can only send 72 packages of data, so I can press key 72 times and when I press key one more, the communication is suspended. I can't find the place in my code, where there is a fault.
I don't know too, what I should make with PD5 (OverCurrent) and PC0 (PowerOn)?

Settings of GPIO and RCC:
RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_GPIOAEN, ENABLE);
GPIO_InitTypeDef GPIO_Settings;
GPIO_Settings.GPIO_Mode = GPIO_Mode_AF;
GPIO_Settings.GPIO_OType = GPIO_OType_PP;
GPIO_Settings.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_11 | GPIO_Pin_12;
GPIO_Settings.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Settings.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOA, &GPIO_Settings);
GPIO_Settings.GPIO_OType = GPIO_OType_OD;
GPIO_Settings.GPIO_Pin =  GPIO_Pin_10;
GPIO_Settings.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOA, &GPIO_Settings);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_OTG_FS);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_OTG_FS);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_OTG_FS);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_OTG_FS);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_OTG_FS);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

Descriptors (Configuration, interface, HID, endpoints):
__ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_END =
{
  0x09, /* bLength: Configuration Descriptor size */
  USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
  USB_HID_CONFIG_DESC_SIZ,  /* wTotalLength: Bytes returned */
  0x00,
  0x01,         /*bNumInterfaces: 1 interface*/
  0x01,         /*bConfigurationValue: Configuration value*/
  0x00,         /*iConfiguration: Index of string descriptor describing the configuration*/
  0xE0,         /*bmAttributes: bus powered and Support Remote Wake-up */
  0x32,         /*MaxPower 100 mA: this current is used for detecting Vbus*/
    
  /************** Descriptor of Joystick Mouse interface ****************/
  /* 09 */
  0x09,         /*bLength: Interface Descriptor size*/
  USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/
  0x00,         /*bInterfaceNumber: Number of Interface*/
  0x00,         /*bAlternateSetting: Alternate setting*/
  0x02,         /*bNumEndpoints*/
  0x03,         /*bInterfaceClass: HID*/
  0x01,         /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
  0x02,         /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
  0,            /*iInterface: Index of string descriptor*/
  /******************** Descriptor of Joystick Mouse HID ********************/
  /* 18 */
  0x09,         /*bLength: HID Descriptor size*/
  HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
  0x11,         /*bcdHID: HID Class Spec release number*/
  0x01,
  0x00,         /*bCountryCode: Hardware target country*/
  0x01,         /*bNumDescriptors: Number of HID class descriptors to follow*/
  0x22,         /*bDescriptorType*/
  HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
  0x00,
  /******************** Descriptor of endpoint ********************/
  /* 27 */
  0x07,          /*bLength: Endpoint Descriptor size*/
  USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/
  HID_IN_EP,     /*bEndpointAddress: Endpoint Address (IN) (from device to host)*/
  0x03,          /*bmAttributes: Interrupt endpoint*/
  HID_IN_PACKET, /*wMaxPacketSize: 2 Byte max */
  0x00,
  0x0A,          /*bInterval: Polling Interval (10 ms)*/
  /* 34 */
  
  0x07,          /*bLength: Endpoint Descriptor size*/
  USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/
  HID_OUT_EP,    /*bEndpointAddress: Endpoint Address (OUT)*/
  0x03,          /*bmAttributes: Interrupt endpoint*/
  HID_OUT_PACKET,/*wMaxPacketSize*/
  0x00,
  0x0A,          /*bInterval: Polling Interval (10 ms)*/
  /* 41 */
} ; /* CustomHID_ConfigDescriptor */

Function which read the data:
static uint8_t  USBD_HID_DataOut (void  *pdev,
                               uint8_t epnum)
{
    if (epnum == HID_OUT_EP)
    {
        if (((USB_OTG_CORE_HANDLE*)pdev)->dev.out_ep[epnum].xfer_count > 0)
        {
            /* USB data will be immediately processed, this allow next USB traffic being NAKed till the end of the application Xfer */
            if (((USB_OTG_CORE_HANDLE*)pdev)->dev.device_status == USB_OTG_CONFIGURED)
            {
  
                //USB_OTG_ReadPacket(pdev, NULL, HID_OUT_PACKET);
                USBD_USR_DataOut(Buffer, HID_OUT_PACKET);
                /* Prepare Out endpoint to receive next packet */
                DCD_EP_PrepareRx(pdev, HID_OUT_EP, Buffer, HID_OUT_PACKET);
            }
        }
    }
    return USBD_OK;
}

Outcomes