CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

USB not indicating correct number of string descriptors

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jaka



Joined: 04 May 2014
Posts: 35
Location: Finland

View user's profile Send private message

USB not indicating correct number of string descriptors
PostPosted: Sun May 04, 2014 8:39 am     Reply with quote

Hello All,

Just registered to this forum. I've been using CCS for some time on various projects and so far I've been able to solve problems just by searching this forum. Now I've encountered a problem that seems not to be reported earlier.

Yesterday I was trying to find out a solution to a known problem (with no luck). If you have a composite USB HID device with 2 joysticks, Windows only uses name of first device for both devices. This has been discussed here before and is likely to be a Windows problem.

I came across a tool called SimpleHidWrite http://janaxelson.com/hidpage.htm#tools, which allows some debugging with Hid devices. This tool recognizes both devices with correct names from the composite USB device. There is also an info button, which allows to see more information from the selected HID device. It shows VID/PID, serial number, report sizes and all strings from the device. All the strings are shown as they should, but after them there are garbage strings, up to 255. It seems as the number of strings reported by the device is not correct, and when requesting strings that do not exist, incorrect data is sent by the PIC.

In the examples, there is line
Code:
#define USB_STRING_DESC_COUNT sizeof(USB_STRING_DESC_OFFSET)

which clearly defines USB_STRING_DESC_COUNT to indicate number of stored strings. However, this doesn't seem to have any effect. The USB_STRING_DESC_COUNT is not used in any usb related source files, and omitting it or defining it to some other number doesn't have any effect (the compiled HEX files are identical).

The problem is not just related to my own code, I tested with ex_usb_mouse and it showed similar behavior: Like this. This was tested with CCS version 5.019 and Windows 7.

The problem is not that critical (devices work OK, names show up correctly in windows device manager), but I think it would be nice that the number of strings is shown correctly.

Regards,
jaka
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Sun May 04, 2014 12:42 pm     Reply with quote

That line is a 'left over' from the older USB driver. Not used in the current driver.
The descriptor count, doesn't change with multiple devices. Look at the KB/mouse example.
jaka



Joined: 04 May 2014
Posts: 35
Location: Finland

View user's profile Send private message

PostPosted: Sun May 04, 2014 8:11 pm     Reply with quote

The string descriptor count can vary. The CCS examples have only 3 strings (language, manufacturer, product). My composite device has 6 strings; serial number and separate names for both interfaces in addition to the before mentioned 3. All 6 strings show up us they should, but after them begin the garbage strings on SimpleHidWrite.

On comparison, I tested some other devices, a PS2 gamepad adapter (implemented with a Cypress µC) and a barcode reader. They both show manufacturer and product strings correctly, and no garbage after those. But then I tested Pickit2 and Pickit3, they also show garbage so the same 'feauture' seems to be in Microchip USB stack also. But then again I saw a screenshot from SimpleHidWrite on Microchip forum and there was no garbage. Strange..
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Mon May 05, 2014 2:08 am     Reply with quote

Yes, the number of string descriptors can vary, but it doesn't directly have any relation to the number of devices. You can have exactly the same number of descriptors with one device, or five (if you want). You specify which string is to be used for the device, in the interface descriptor index.
jaka



Joined: 04 May 2014
Posts: 35
Location: Finland

View user's profile Send private message

PostPosted: Mon May 05, 2014 8:30 am     Reply with quote

Ok, maybe I formulated the topic badly. The only thing I'm wondering is if I can get rid of those garbage strings.

I just guessed that it those are shown because PIC doesn't report the number of strings available. Or it just replies to queries of strings that do not exist.
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Mon May 05, 2014 11:02 am     Reply with quote

It actually sounds to me as if the code you are using is trying to read beyond the number of devices being implemented, or one of the descriptor indexes contains a number beyond the end of the actual array (or an index exists beyond the number of entries).
jaka



Joined: 04 May 2014
Posts: 35
Location: Finland

View user's profile Send private message

PostPosted: Mon May 05, 2014 12:18 pm     Reply with quote

But the same code doesn't get garbage strings from some other USB devices I tested. So I think it could be fixed in PIC FW. But it might not be worth the effort and/or increased code size..
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Mon May 05, 2014 12:31 pm     Reply with quote

Which is why I said:
"or one of the descriptor indexes contains a number beyond the end of the actual array (or an index exists beyond the number of entries)."
This would be down to the entries in your tables.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Tue May 06, 2014 12:14 am     Reply with quote

I wonder if what you have run into is related to the issue I ran into some time ago with the PICKIT2 - it would crash / prevent startup of my video editor and even caused the dxdiag utility to fail. Unplugging the PicKit2 from the usb port fixed the problem. See my original post www.ccsinfo.com/forum/viewtopic.php?t=44471

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
rksjbeck



Joined: 10 Sep 2009
Posts: 3
Location: Atlanta, GA

View user's profile Send private message

I know what you are talking about
PostPosted: Tue Jan 13, 2015 6:35 pm     Reply with quote

Yes, the CCS implementation will respond to any string descriptor request, even if it is an offset that doesn't have any data there. As someone pointed out, there was a time when the stack used the size of the offset array, but now it doesn't.
If you are still having this problem, let me know.
There is a pretty simple patch to the USB stack that fixes the problem.
jaka



Joined: 04 May 2014
Posts: 35
Location: Finland

View user's profile Send private message

PostPosted: Sun Jan 25, 2015 6:27 am     Reply with quote

I am still having this 'problem'. I did try to look the USB stack code to fix the behavior, but couldn't figure out how to do it in reasonable time.

I would like to try out the patch, would be very nice to get this sorted out.
rksjbeck



Joined: 10 Sep 2009
Posts: 3
Location: Atlanta, GA

View user's profile Send private message

Here you go, the len of 0 is really the important part
PostPosted: Tue Jan 27, 2015 6:11 pm     Reply with quote

In the module usb.c go to the "void usb_Get_Descriptor() " function and under the "case USB_DESC_STRING_TYPE: //3" change that entire case statement to :

Code:
case USB_DESC_STRING_TYPE: //3
  USB_stack_status.getdesc_type=USB_GETDESC_STRING_TYPE;
  if(usb_ep0_rx_buffer[2] > (sizeof(USB_STRING_DESC_OFFSET) -1))
  {
    usb_getdesc_ptr = 0;
    usb_getdesc_len = 0;
  }
  else
  {
    usb_getdesc_ptr=USB_STRING_DESC_OFFSET[usb_ep0_rx_buffer[2]];
    usb_getdesc_len=USB_STRING_DESC[usb_getdesc_ptr];
  }

// Original Code
// usb_getdesc_ptr=USB_STRING_DESC_OFFSET[usb_ep0_rx_buffer[2]];
// usb_getdesc_len=USB_STRING_DESC[usb_getdesc_ptr];
// End Original Code

  break;
jaka



Joined: 04 May 2014
Posts: 35
Location: Finland

View user's profile Send private message

PostPosted: Wed Jan 28, 2015 12:38 pm     Reply with quote

The patch works like a charm! Thanks rksjbeck, you're the man!
jaka



Joined: 04 May 2014
Posts: 35
Location: Finland

View user's profile Send private message

PostPosted: Sun Feb 22, 2015 10:29 am     Reply with quote

Even with the patch applied, Hid Device Exerciser tool shows that the device has 255 strings. Some other commercial devices show the value correctly.

The tool is available here: http://janaxelson.com/files/HidTest.zip

I did some experimenting and changed this line from patch
Code:

   usb_getdesc_len = 0;

to
Code:

   usb_getdesc_len = -1;


I don't know if this is a proper way to do it, but now the Hid Device Exerciser tool shows the amount of strings correctly.
jaka



Joined: 04 May 2014
Posts: 35
Location: Finland

View user's profile Send private message

PostPosted: Tue Sep 15, 2015 12:06 pm     Reply with quote

I recently renewed my CCS maintenance and found that the garbage string problem has been fixed on Feb 6, 2015. (from usb.c file) Quite soon after the solution was posted here!

Hid Device Exerciser still shows that device has 255 strings, but that's not too much of annoyance.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group