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

STM32F103 USB HID using Endpoints (no answer from EP1)

Hi Guys,
I sit for days on my USB transfer. I work with a STM32F103C8 microcontroller.
I want to build a transmission with 2 endpoints to transfer my Data from the (GUI) Host.
My problem are the endpoints. I can not get data from the endpoint.
It is the KEIL USB Library...

Here some code snippets:

//********************************Defines****************************************

#define USB_POWER           0
#define USB_IF_NUM          1
#define USB_EP_NUM          2
#define USB_MAX_PACKET0     8
#define USB_DBL_BUF_EP      0x0040

#define USB_POWER_EVENT     0
#define USB_RESET_EVENT     1
#define USB_SUSPEND_EVENT   0
#define USB_RESUME_EVENT    0
#define USB_WAKEUP_EVENT    0
#define USB_SOF_EVENT       0
#define USB_ERROR_EVENT     0
#define USB_EP_EVENT        0x0003
#define USB_CONFIGURE_EVENT 0
#define USB_INTERFACE_EVENT 1
#define USB_FEATURE_EVENT   0

#define USB_CLASS           1
#define USB_HID             1
#define USB_HID_IF_NUM      0
#define USB_MSC             0
#define USB_MSC_IF_NUM      0
#define USB_AUDIO           0
#define USB_ADC_CIF_NUM     0
#define USB_ADC_SIF1_NUM    1
#define USB_ADC_SIF2_NUM    2
#define USB_CDC             0
#define USB_CDC_CIF_NUM     0
#define USB_CDC_DIF_NUM     1
#define USB_CDC_BUFSIZE     64


//***************************My Buffer Variables************************************
uint8_t InReport[64];
uint8_t  OutReport[64];

I get no call interrupt at this point

void USB_EndPoint1 (U32 event) {

 GPIOB->BSRR |=(1<<1); //Set PB1 only for debuging with Osziloscope

  switch (event) {
  case USB_EVT_IN:
  GetInReport();
  USB_WriteEP(0x81, InReport, sizeof(InReport));
  break;

  case USB_EVT_OUT:
  USB_ReadEP(0x01, OutReport);
  SetOutReport();
  break;
  }
GPIOB->BSRR |=(1<<17); //Clear PB1 only for debuging with Osziloscope
}


const U8 HID_ReportDescriptor[] = {
  HID_UsagePageVendor( 0x00                     ),
  HID_Usage          ( 0x01                     ),
  HID_Collection     ( HID_Application          ),

    HID_LogicalMin   ( 0                        ),  //value range: 0 - 0xFF
    HID_LogicalMaxS  ( 0xFF                     ),
    HID_ReportSize   ( 8                        ),  // 8 bits
    HID_ReportCount  ( 0x40   ),
    HID_Usage        ( 0x01                     ),
    HID_Input        ( HID_Data | HID_Variable | HID_Absolute ),
    HID_ReportCount  ( 0x40  ),
    HID_Usage        ( 0x01                     ),
    HID_Output       ( HID_Data | HID_Variable | HID_Absolute ),
    HID_ReportCount  ( 0x40 ),
    HID_Usage        ( 0x01                     ),
    HID_Feature      ( HID_Data | HID_Variable | HID_Absolute ),

  HID_EndCollection,
};

/* USB Standard Device Descriptor */
const U8 USB_DeviceDescriptor[] = {
  USB_DEVICE_DESC_SIZE,              /* bLength */
  USB_DEVICE_DESCRIPTOR_TYPE,        /* bDescriptorType */
  WBVAL(0x0200), /* 2.00 */          /* bcdUSB */
  0x00,                              /* bDeviceClass */
  0x00,                              /* bDeviceSubClass */
  0x00,                              /* bDeviceProtocol */
  USB_MAX_PACKET0,                   /* bMaxPacketSize0 */
  WBVAL(0xC251),                     /* idVendor */
  WBVAL(0x1C01),                     /* idProduct */
  WBVAL(0x0100), /* 1.00 */          /* bcdDevice */
  0x01,                              /* iManufacturer */
  0x02,                              /* iProduct */
  0x03,                              /* iSerialNumber */
  0x01                               /* bNumConfigurations: one possible configuration*/
};

const U8 USB_ConfigDescriptor[] = {
//Configuration 1
  USB_CONFIGUARTION_DESC_SIZE,       /* bLength */
  USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType */
  WBVAL(USB_CONFIGUARTION_DESC_SIZE + HID_DESC_SIZE + USB_INTERFACE_DESC_SIZE + USB_ENDPOINT_DESC_SIZE + USB_ENDPOINT_DESC_SIZE),   // wTotalLength
  0x01,                              /* bNumInterfaces */
  0x01,                              /* bConfigurationValue: 0x01 is used to select this configuration */
  0x00,                              /* iConfiguration: no string to describe this configuration */
  USB_CONFIG_BUS_POWERED,                       /* bmAttributes */
  USB_CONFIG_POWER_MA(100),          /* bMaxPower, device power consumption is 100 mA */

// 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 */
  0,                            /* bInterfaceSubClass */
  0,                            /* bInterfaceProtocol */
  0,                           /*iInterface*/


//HID Class Descriptor
  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 */
  0x40,0x00,                        /* wMaxPacketSize */
  0x01,          /* 32ms */          /* bInterval */    //0x20


//Endpoint, HID Interrupt out
        USB_ENDPOINT_DESC_SIZE,            /* bLength */
  USB_ENDPOINT_DESCRIPTOR_TYPE,      /* bDescriptorType */
  USB_ENDPOINT_OUT(1),                /* bEndpointAddress */
  USB_ENDPOINT_TYPE_INTERRUPT  ,       /* bmAttributes */
  0x40,0x00,                            /* wMaxPacketSize */
  0x01,          /* 32ms */          /* bInterval *///0x20


/* Terminator */
  0                                  /* bLength */
};



//************************************************************************************
The USB Sniffer shows the correct port setting. But why the endpoint interrupt is not executed?
I see data packets (every 1ms) at the USB data pin on the oscilloscope.
But unfortunately, the device receives nothing...
Who can help me in the initialization?
I have read many Theards, but it does not work ..

Best Regards
Peter

Parents
  • Hey Tsuneo,

    cool that you responded so quickly =) I've read many reports from you.
    All are really excellent.

    Yes, I want to build a bidirectional connection to the host.(An example in C++ .Net).
    It should act like a UART connection.
    In and Out connection with interrupt mode at 64 byte per frame.
    I have changed the example (C:\Keil\ARM\Boards\Keil\MCBSTM32\USBHID) and added the endpoint 1.
    I guess it works so far. Further up the thread is a report from the USB connection device.
    I do not know if everything is correct. But you can see the Report from USB Sniffer.

    But I know now that I need only one endpoint, because this IN and Out support.
    I'll change it now in my firmware.

    Thats the .net GUI Interface:

    
    unsigned char OutputPacketBuffer[65];
    unsigned char InputPacketBuffer[65];
    
    
    private: System::Void get_set_data_from_device(System::Object^ sender, System::EventArgs^  e){
    
      DWORD BytesWritten = 0;
      DWORD BytesRead = 0;
    
    
    InputPacketBuffer[0] = 0;
    OutputPacketBuffer[0] = 0;
    
    OutputPacketBuffer[1] = 0x00;  //Some Values in my send buffer
    OutputPacketBuffer[2] = 0x01;  //Some Values in my send buffer
    OutputPacketBuffer[3] = 0x01;  //Some Values in my send buffer
    
    
    
    WriteFile(WriteHandle, &OutputPacketBuffer, 64, &BytesWritten, 0); //Sending process
    ReadFile(ReadHandle, &InputPacketBuffer, 64, &BytesRead, 0);       //Receiving process
    
    InputPacketBuffer[1]; //Some data from my Device at the endpoint IN
    InputPacketBuffer[2]; //Some data from my Device at the endpoint IN
    InputPacketBuffer[3]; //Some data from my Device at the endpoint IN
    
    }
    

    The problem is, that i never received or sends some data to or from my Device (STM32F103C8)....
    Just *** =(

    Beste Regards
    Peter

Reply
  • Hey Tsuneo,

    cool that you responded so quickly =) I've read many reports from you.
    All are really excellent.

    Yes, I want to build a bidirectional connection to the host.(An example in C++ .Net).
    It should act like a UART connection.
    In and Out connection with interrupt mode at 64 byte per frame.
    I have changed the example (C:\Keil\ARM\Boards\Keil\MCBSTM32\USBHID) and added the endpoint 1.
    I guess it works so far. Further up the thread is a report from the USB connection device.
    I do not know if everything is correct. But you can see the Report from USB Sniffer.

    But I know now that I need only one endpoint, because this IN and Out support.
    I'll change it now in my firmware.

    Thats the .net GUI Interface:

    
    unsigned char OutputPacketBuffer[65];
    unsigned char InputPacketBuffer[65];
    
    
    private: System::Void get_set_data_from_device(System::Object^ sender, System::EventArgs^  e){
    
      DWORD BytesWritten = 0;
      DWORD BytesRead = 0;
    
    
    InputPacketBuffer[0] = 0;
    OutputPacketBuffer[0] = 0;
    
    OutputPacketBuffer[1] = 0x00;  //Some Values in my send buffer
    OutputPacketBuffer[2] = 0x01;  //Some Values in my send buffer
    OutputPacketBuffer[3] = 0x01;  //Some Values in my send buffer
    
    
    
    WriteFile(WriteHandle, &OutputPacketBuffer, 64, &BytesWritten, 0); //Sending process
    ReadFile(ReadHandle, &InputPacketBuffer, 64, &BytesRead, 0);       //Receiving process
    
    InputPacketBuffer[1]; //Some data from my Device at the endpoint IN
    InputPacketBuffer[2]; //Some data from my Device at the endpoint IN
    InputPacketBuffer[3]; //Some data from my Device at the endpoint IN
    
    }
    

    The problem is, that i never received or sends some data to or from my Device (STM32F103C8)....
    Just *** =(

    Beste Regards
    Peter

Children
  • On the host application,

    Count in the report ID byte for the nNumberOfBytesToWrite of WriteFile() and nNumberOfBytesToRead of ReadFile(), even if no report ID is used on the report descriptor. To send 64 bytes report of no report ID, 65 bytes (report ID: 0, and following 64 bytes report body) are exchanged.

    WriteFile(WriteHandle, &OutputPacketBuffer, 65, &BytesWritten, 0); //Sending process
    ReadFile(ReadHandle, &InputPacketBuffer, 65, &BytesRead, 0);       //Receiving process
    

    Tsuneo

  • Ah, on the device side,
    device receives / sends just 64 bytes report, without report ID.

    PC HID driver strips / adds the report ID: 0.

    Tsuneo