Question to USB Experts, Please Help : USB HID device serial number transfer does not work

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
RDo78147
Posts: 1
Joined: 07 May 2020 09:34

Question to USB Experts, Please Help : USB HID device serial number transfer does not work

#1 Post by RDo78147 » 07 May 2020 11:03

Hello forum
why is the serial number string not available.
Here is my USB descriptor

Code: Select all

module USBdsc

const USB_VENDOR_ID as word = 0x1177
const USB_PRODUCT_ID as word = 0x0010
const USB_SELF_POWER as char = 0x80           ' Self powered 0xC0,  0x80 bus powered
const USB_MAX_POWER as char = 50              ' Bus power required in units of 2 mA
const HID_INPUT_REPORT_BYTES as char = 64
const HID_OUTPUT_REPORT_BYTES as char = 64
const EP_IN_INTERVAL as char = 1
const EP_OUT_INTERVAL as char = 1

const USB_INTERRUPT as char = 1
const USB_TRANSFER_TYPE as char = 0x03        '0x03 Interrupt
const USB_HID_IN_EP as char = 1
const USB_HID_OUT_EP as char = 1
const USB_HID_RPT_SIZE as char = 33

structure device_descriptor
    dim bLength as char               ' bLength         - Descriptor size in bytes (12h)
    dim bDescriptorType as char       ' bDescriptorType - The constant DEVICE (01h)
    dim bcdUSB as word                ' bcdUSB          - USB specification release number (BCD)
    dim bDeviceClass as char          ' bDeviceClass    - Class Code
    dim bDeviceSubClass as char       ' bDeviceSubClass - Subclass code
    dim bDeviceProtocol as char       ' bDeviceProtocol - Protocol code
    dim bMaxPacketSize0 as char       ' bMaxPacketSize0 - Maximum packet size for endpoint 0
    dim idVendor as word              ' idVendor        - Vendor ID
    dim idProduct as word             ' idProduct       - Product ID
    dim bcdDevice as word             ' bcdDevice       - Device release number (BCD)
    dim iManufacturer as char         ' iManufacturer   - Index of string descriptor for the manufacturer
    dim iProduct as char              ' iProduct        - Index of string descriptor for the product.
    dim iSerialNumber as char         ' iSerialNumber   - Index of string descriptor for the serial number.
    dim bNumConfigurations as char    ' bNumConfigurations - Number of possible configurations
end structure

const device_dsc as device_descriptor = (
  0x12,                   ' bLength
  0x01,                   ' bDescriptorType
  0x0200,                 ' bcdUSB
  0x00,                   ' bDeviceClass
  0x00,                   ' bDeviceSubClass
  0x00,                   ' bDeviceProtocol
  8,                      ' bMaxPacketSize0
  USB_VENDOR_ID,          ' idVendor
  USB_PRODUCT_ID,         ' idProduct
  0x0100,                 ' bcdDevice
  0x01,                   ' iManufacturer
  0x02,                   ' iProduct
  0x03,                   ' iSerialNumber
  0x01                    ' bNumConfigurations
)

' Configuration 1 Descriptor
const configDescriptor1 as byte[41] = (
    ' Configuration Descriptor
    0x09,                   ' bLength             - Descriptor size in bytes
    0x02,                   ' bDescriptorType     - The constant CONFIGURATION (02h)
    0x29,0x00,              ' wTotalLength        - The number of bytes in the configuration descriptor and all of its subordinate descriptors
    1,                      ' bNumInterfaces      - Number of interfaces in the configuration
    1,                      ' bConfigurationValue - Identifier for Set Configuration and Get Configuration requests
    0,                      ' iConfiguration      - Index of string descriptor for the configuration
    USB_SELF_POWER,         ' bmAttributes        - Self/bus power and remote wakeup settings
    USB_MAX_POWER,          ' bMaxPower           - Bus power required in units of 2 mA

    ' Interface Descriptor
    0x09,                   ' bLength - Descriptor size in bytes (09h)
    0x04,                   ' bDescriptorType - The constant Interface (04h)
    0,                      ' bInterfaceNumber - Number identifying this interface
    0,                      ' bAlternateSetting - A number that identifies a descriptor with alternate settings for this bInterfaceNumber.
    2,                      ' bNumEndpoint - Number of endpoints supported not counting endpoint zero
    0x03,                   ' bInterfaceClass - Class code
    0,                      ' bInterfaceSubclass - Subclass code
    0,                      ' bInterfaceProtocol - Protocol code
    0,                      ' iInterface - Interface string index

    ' HID Class-Specific Descriptor
    0x09,                   ' bLength         - Descriptor size in bytes.
    0x21,                   ' bDescriptorType - This descriptor's type: 21h to indicate the HID class.
    0x01,0x01,              ' bcdHID          - HID specification release number (BCD).
    0x00,                   ' bCountryCode    - Numeric expression identifying the country for localized hardware (BCD) or 00h.
    1,                      ' bNumDescriptors - Number of subordinate report and physical descriptors.
    0x22,                   ' bDescriptorType - The type of a class-specific descriptor that follows
    USB_HID_RPT_SIZE,0x00,  ' wDescriptorLength - Total length of the descriptor identified above.

    ' Endpoint Descriptor
    0x07,                   ' bLength - Descriptor size in bytes (07h)
    0x05,                   ' bDescriptorType - The constant Endpoint (05h)
    USB_HID_IN_EP or 0x80,  ' bEndpointAddress - Endpoint number and direction
    USB_TRANSFER_TYPE,      ' bmAttributes - Transfer type and supplementary information
    0x40,0x00,              ' wMaxPacketSize - Maximum packet size supported
    EP_IN_INTERVAL,         ' bInterval - Service interval or NAK rate

    ' Endpoint Descriptor
    0x07,                   ' bLength - Descriptor size in bytes (07h)
    0x05,                   ' bDescriptorType - The constant Endpoint (05h)
    USB_HID_OUT_EP,         ' bEndpointAddress - Endpoint number and direction
    USB_TRANSFER_TYPE,      ' bmAttributes - Transfer type and supplementary information
    0x40,0x00,              ' wMaxPacketSize - Maximum packet size supported
    EP_OUT_INTERVAL         ' bInterval - Service interval or NAK rate
)

structure hid_report_descriptor
  dim report as byte[USB_HID_RPT_SIZE]
end structure

const hid_rpt_desc as hid_report_descriptor = (
  (0x06, 0x00, 0xFF,      ' Usage Page = 0xFF00 (Vendor Defined Page 1)
  0x09, 0x01,             ' Usage (Vendor Usage 1)
  0xA1, 0x01,             ' Collection (Application)
  ' Input report
  0x19, 0x01,             ' Usage Minimum
  0x29, 0x40,             ' Usage Maximum
  0x15, 0x00,             ' Logical Minimum (data bytes in the report may have minimum value = 0x00)
  0x26, 0xFF, 0x00,       ' Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255)
  0x75, 0x08,             ' Report Size: 8-bit field size
  0x95, HID_INPUT_REPORT_BYTES,' Report Count
  0x81, 0x02,             ' Input (Data, Array, Abs)
  ' Output report
  0x19, 0x01,             ' Usage Minimum
  0x29, 0x40,             ' Usage Maximum
  0x75, 0x08,             ' Report Size: 8-bit field size
  0x95, HID_OUTPUT_REPORT_BYTES,' Report Count
  0x91, 0x02,             ' Output (Data, Array, Abs)
  0xC0)                   ' End Collection
  )

'Language code string descriptor
structure str1
  dim bLength as char
  dim bDscType as char
  dim wString as word[1]
end structure

const strd1 as str1 = (
  4,
  0x03,
  (0x0409)
)

'Manufacturer string descriptor
structure str2
  dim bLength as char
  dim bDscType as char
  dim wString as word[4]
end structure

const strd2 as str2 = (
  10,           'sizeof this descriptor string
  0x03,
  ("R","W","D","V")
)

'Product string descriptor
structure str3
  dim bLength as char
  dim bDscType as char
  dim wString as word[19]
end structure

const strd3 as str3 = (
  40,           'sizeof this descriptor string
  0x03,
  ("K","e","e","p","P","o","w","e","r","_","I","n","t","e","r","f","a","c","e")
)
          'Serial Number string descriptor
structure str4
  dim bLength as char
  dim bDscType as char
  dim wString as word[1]
end structure

const strd4 as str4 = (
  10,           'sizeof this descriptor string
  0x03,
  ("6")
)

'Array of configuration descriptors
dim USB_config_dsc_ptr as ^const byte[1]

'Array of string descriptors
dim USB_string_dsc_ptr as ^const byte[4]

sub procedure USB_Init_desc()

implements
  sub procedure USB_Init_desc()
    USB_config_dsc_ptr[0] = @configDescriptor1
    USB_string_dsc_ptr[0] = ^const byte(@strd1)
    USB_string_dsc_ptr[1] = ^const byte(@strd2)
    USB_string_dsc_ptr[2] = ^const byte(@strd3)
    USB_string_dsc_ptr[3] = ^const byte(@strd4)
  end sub
end.

for the serial number i have added the following to the descriptor

Code: Select all

'---------------------------------------------------------------------
 const device_dsc as device_descriptor = (
 ...
 ...
  0x03,                   ' iSerialNumber    (Default = 0x00)
  
'--------------------------------------------------------------------
  
         'Serial Number string descriptor
structure str4
  dim bLength as char
  dim bDscType as char
  dim wString as word[1]
end structure

const strd4 as str4 = (
  10,           'sizeof this descriptor string
  0x03,
  ("6")
)

'--------------------------------------------------------
  'Array of string descriptors
dim USB_string_dsc_ptr as ^const byte[4]

sub procedure USB_Init_desc()

implements
  sub procedure USB_Init_desc()
    USB_config_dsc_ptr[0] = @configDescriptor1
    USB_string_dsc_ptr[0] = ^const byte(@strd1)
    USB_string_dsc_ptr[1] = ^const byte(@strd2)
    USB_string_dsc_ptr[2] = ^const byte(@strd3)
    USB_string_dsc_ptr[3] = ^const byte(@strd4) 
  end sub
The device works, but the 3rd string for the serial number does not come

Code: Select all

         ===>Device Descriptor<===
bLength:                           0x12
bDescriptorType:                   0x01
bcdUSB:                          0x0200
bDeviceClass:                      0x00  -> This is an Interface Class Defined Device
bDeviceSubClass:                   0x00
bDeviceProtocol:                   0x00
bMaxPacketSize0:                   0x08 = (8) Bytes
idVendor:                        0x1177 = Hitachi Communication Technologies, Ltd.
idProduct:                       0x0010
bcdDevice:                       0x0100
iManufacturer:                     0x01
     English (United States)  "RWDV"
iProduct:                          0x02
     English (United States)  "KeepPower_Interface"
iSerialNumber:                     0x03
*!*ERROR:  No String Descriptor for index 3!
bNumConfigurations:                0x01

The problem was solved in 2007.
viewtopic.php?f=97&t=26036&p=129379#p129379
the library is still available, but does not work (anymore)

That was 10 years ago. Has the limitation to 3 string description meanwhile been lifted in Mikrobasic PRO?

Or did I make a mistake when adding the descriptor that I do not recognize?
Would someone check that please


Thanks a lot
Reinhold

Post Reply

Return to “mikroBasic PRO for PIC General”