Autor Tema: Problema con driver USB HID en Win7  (Leído 5253 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18310
    • MicroPIC
Problema con driver USB HID en Win7
« en: 28 de Junio de 2011, 08:10:04 »
Hola amigos. Tengo un dispositivo USB HID que se detecta, instala y funciona perfectamente en WinXP y en WinVista sin instalar driver alguno, ya que utiliza el genérico de Windows.

Sin embargo, necesito usarlo en Win7-32 y no consigo que furule. Me sale este error al intentar instalar el driver y luego se queda como Unknow Device.



¿Qué puedo hacer?

Gracias

Desconectado Suky

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 6758
Re: Problema con driver USB HID en Win7
« Respuesta #1 en: 28 de Junio de 2011, 10:30:52 »
C32, C30, C18, Hitech o CCS?
No contesto mensajes privados, las consultas en el foro

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18310
    • MicroPIC
Re: Problema con driver USB HID en Win7
« Respuesta #2 en: 28 de Junio de 2011, 11:41:39 »
CCS para PIC24F.

Gracias, Suky

Desconectado LABmouse

  • Moderadores
  • DsPIC30
  • *****
  • Mensajes: 3575
    • Juntos es mejor
Re: Problema con driver USB HID en Win7
« Respuesta #3 en: 28 de Junio de 2011, 11:48:36 »
Hola manolo, pruébate esto:

> Intenta compilar con otra versión de CCS.
> Intenta con otro cable USB, tal vez conseguir uno que sea 2.0 certificado. Esto lo dig porque tengo un analizador lógico que en XP no camina y en SEVEN si va de maravilla, la razón es que al parecer los driver de SEVEN gestionan el USB de manera mas eficiente, PERO! con un cable 1.0  los equipos que le conecto por USB a Seven no me funcionan.

Saludos!
« Última modificación: 28 de Junio de 2011, 11:52:20 por LABmouse »

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18310
    • MicroPIC
Re: Problema con driver USB HID en Win7
« Respuesta #4 en: 28 de Junio de 2011, 12:31:17 »
Pues lo de la versión de CCS lo acabo de intentar sin éxito. El proyecto originalmente está compilado con la 4.093, y lo he intentado compilar con la 4.119 y 4.120 que tengo instaladas y en ambas el micro se reinicia constantemente. Con la 4.084 que también tengo instalada no puedo compilarlo porque no todavía no incluía al 24FJ256GB106.

Y cables he probado 3, aunque no sé qué norma USB cumplen. Pero lo cierto es que siempre han funcionado bien estos cables con otros periféricos. E incluso funciona bien mi equipo si lo conecto a otro PC con otro Windows.

Desconectado Suky

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 6758
Re: Problema con driver USB HID en Win7
« Respuesta #5 en: 28 de Junio de 2011, 12:58:30 »
Lo raro es que es HID... Va, no he tenido problemas, salvo que siempre use C18 o C32  :tongue: Adjunta el descriptor para mirarlo un poco  :undecided:
No contesto mensajes privados, las consultas en el foro

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18310
    • MicroPIC
Re: Problema con driver USB HID en Win7
« Respuesta #6 en: 28 de Junio de 2011, 13:04:44 »
Ahí va:

Código: C
  1. #IFNDEF __USB_DESCRIPTORS__
  2. #DEFINE __USB_DESCRIPTORS__
  3.  
  4. #include <usb.h>
  5.  
  6.    //////////////////////////////////////////////////////////////////
  7.    ///
  8.    ///  HID Report.  Tells HID driver how to handle and deal with
  9.    ///  received data.  HID Reports can be extremely complex,
  10.    ///  see HID specifcation for help on writing your own.
  11.    ///
  12.    ///  CCS example uses a vendor specified usage, that sends and
  13.    ///  receives 2 absolute bytes ranging from 0 to 0xFF.
  14.    ///
  15.    //////////////////////////////////////////////////////////////////
  16.  
  17.    const char USB_CLASS_SPECIFIC_DESC[] = {
  18.       6, 0, 255,    // Usage Page = Vendor Defined
  19.       9, 1,            // Usage = IO device
  20.       0xa1, 1,       // Collection = Application
  21.       0x19, 1,        // Usage minimum
  22.       0x29, 8,        // Usage maximum
  23.  
  24.       0x15, 0x80,        // Logical minimum (-128)
  25.       0x25, 0x7F,        // Logical maximum (127)
  26.  
  27.       0x75, 8,        // Report size = 8 (bits)
  28.       //0x95, 2,        // Report count = 16 bits (2 bytes)
  29.       0x95, USB_EP1_TX_SIZE, // Report count = xx bytes de salida (Santiago)
  30.       0x81, 2,        // Input (Data, Var, Abs)
  31.       0x19, 1,        // Usage minimum
  32.       0x29, 8,        // Usage maximum
  33.       0x75, 8,        // Report size = 8 (bits)
  34.       //0x95, 2,        // Report count = 16 bits (2 bytes)
  35.       0x95, USB_EP1_RX_SIZE,        // Report count = xx bytes (Santiago)
  36.       0x91, 2,        // Output (Data, Var, Abs)
  37.       0xc0            // End Collection
  38.    };
  39.  
  40.    //if a class has an extra descriptor not part of the config descriptor,
  41.    // this lookup table defines where to look for it in the const
  42.    // USB_CLASS_SPECIFIC_DESC[] array.
  43.    //first element is the config number (if your device has more than one config)
  44.    //second element is which interface number
  45.    //set element to 0xFFFF if this config/interface combo doesn't exist
  46.    const int16 USB_CLASS_SPECIFIC_DESC_LOOKUP[USB_NUM_CONFIGURATIONS][1] =
  47.    {
  48.    //config 1
  49.       //interface 0
  50.          0
  51.    };
  52.  
  53.    //if a class has an extra descriptor not part of the config descriptor,
  54.    // this lookup table defines the size of that descriptor.
  55.    //first element is the config number (if your device has more than one config)
  56.    //second element is which interface number
  57.    //set element to 0xFFFF if this config/interface combo doesn't exist
  58.    const int16 USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[USB_NUM_CONFIGURATIONS][1] =
  59.    {
  60.    //config 1
  61.       //interface 0
  62.          32
  63.    };
  64.  
  65.  
  66. //////////////////////////////////////////////////////////////////
  67. ///
  68. ///   start config descriptor
  69. ///   right now we only support one configuration descriptor.
  70. ///   the config, interface, class, and endpoint goes into this array.
  71. ///
  72. //////////////////////////////////////////////////////////////////
  73.  
  74.    #DEFINE USB_TOTAL_CONFIG_LEN      41  //config+interface+class+endpoint+endpoint (2 endpoints)
  75.  
  76.    const char USB_CONFIG_DESC[] = {
  77.    //IN ORDER TO COMPLY WITH WINDOWS HOSTS, THE ORDER OF THIS ARRAY MUST BE:
  78.       //    config(s)
  79.       //    interface(s)
  80.       //    class(es)
  81.       //    endpoint(s)
  82.  
  83.    //config_descriptor for config index 1
  84.          USB_DESC_CONFIG_LEN, //length of descriptor size          ==1
  85.          USB_DESC_CONFIG_TYPE, //constant CONFIGURATION (CONFIGURATION 0x02)     ==2
  86.          USB_TOTAL_CONFIG_LEN,0, //size of all data returned for this config      ==3,4
  87.          1, //number of interfaces this device supports       ==5
  88.          0x01, //identifier for this configuration.  (IF we had more than one configurations)      ==6
  89.          0x00, //index of string descriptor for this configuration      ==7
  90.          0xc0, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1         ==8
  91.          0x0, //maximum bus power required (maximum milliamperes/2)  (0x32 = 100mA)
  92.  
  93.    //interface descriptor 1
  94.          USB_DESC_INTERFACE_LEN, //length of descriptor      =10
  95.          USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04)       =11
  96.          0x00, //number defining this interface (IF we had more than one interface)    ==12
  97.          0x00, //alternate setting     ==13
  98.          2, //number of endpoins, except 0 (pic167xx has 3, but we dont have to use all).       ==14
  99.          0x03, //class code, 03 = HID     ==15
  100.          0x00, //subclass code //boot     ==16
  101.          0x00, //protocol code      ==17
  102.          0x00, //index of string descriptor for interface      ==18
  103.  
  104.    //class descriptor 1  (HID)
  105.          USB_DESC_CLASS_LEN, //length of descriptor    ==19
  106.          USB_DESC_CLASS_TYPE, //dscriptor type (0x21 == HID)      ==20
  107.          0x00,0x01, //hid class release number (1.0) (try 1.10)      ==21,22
  108.          0x00, //localized country code (0 = none)       ==23
  109.          0x01, //number of hid class descrptors that follow (1)      ==24
  110.          0x22, //report descriptor type (0x22 == HID)                ==25
  111.          USB_CLASS_SPECIFIC_DESC_LOOKUP_SIZE[0][0], 0x00, //length of report descriptor            ==26,27
  112.  
  113.    //endpoint descriptor
  114.          USB_DESC_ENDPOINT_LEN, //length of descriptor                   ==28
  115.          USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05)          ==29
  116.          0x81, //endpoint number and direction (0x81 = EP1 IN)       ==30
  117.          0x03, //transfer type supported (0x03 is interrupt)         ==31
  118.          USB_EP1_TX_SIZE,0x00, //maximum packet size supported                  ==32,33
  119.          5,  //polling interval, in ms.  (cant be smaller than 10)      ==34
  120.  
  121.    //endpoint descriptor
  122.          USB_DESC_ENDPOINT_LEN, //length of descriptor                   ==35
  123.          USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05)          ==36
  124.          0x01, //endpoint number and direction (0x01 = EP1 OUT)      ==37
  125.          0x03, //transfer type supported (0x03 is interrupt)         ==38
  126.          USB_EP1_RX_SIZE,0x00, //maximum packet size supported                  ==39,40
  127.          5 //polling interval, in ms.  (cant be smaller than 10)    ==41
  128.    };
  129.  
  130.    //****** BEGIN CONFIG DESCRIPTOR LOOKUP TABLES ********
  131.    //since we can't make pointers to constants in certain pic16s, this is an offset table to find
  132.    //  a specific descriptor in the above table.
  133.  
  134.    //NOTE: DO TO A LIMITATION OF THE CCS CODE, ALL HID INTERFACES MUST START AT 0 AND BE SEQUENTIAL
  135.    //      FOR EXAMPLE, IF YOU HAVE 2 HID INTERFACES THEY MUST BE INTERFACE 0 AND INTERFACE 1
  136.    #define USB_NUM_HID_INTERFACES   1
  137.  
  138.    //the maximum number of interfaces seen on any config
  139.    //for example, if config 1 has 1 interface and config 2 has 2 interfaces you must define this as 2
  140.    #define USB_MAX_NUM_INTERFACES   1
  141.  
  142.    //define how many interfaces there are per config.  [0] is the first config, etc.
  143.    const char USB_NUM_INTERFACES[USB_NUM_CONFIGURATIONS]={1};
  144.  
  145.    //define where to find class descriptors
  146.    //first dimension is the config number
  147.    //second dimension specifies which interface
  148.    //last dimension specifies which class in this interface to get, but most will only have 1 class per interface
  149.    //if a class descriptor is not valid, set the value to 0xFFFF
  150.    const int16 USB_CLASS_DESCRIPTORS[USB_NUM_CONFIGURATIONS][1][1]=
  151.    {
  152.    //config 1
  153.       //interface 0
  154.          //class 1
  155.          18
  156.    };
  157.  
  158.    #if (sizeof(USB_CONFIG_DESC) != USB_TOTAL_CONFIG_LEN)
  159.       #error USB_TOTAL_CONFIG_LEN not defined correctly
  160.    #endif
  161.  
  162.  
  163. //////////////////////////////////////////////////////////////////
  164. ///
  165. ///   start device descriptors
  166. ///
  167. //////////////////////////////////////////////////////////////////
  168.  
  169.    const char USB_DEVICE_DESC[USB_DESC_DEVICE_LEN] ={
  170.       //starts of with device configuration. only one possible
  171.          USB_DESC_DEVICE_LEN, //the length of this report   ==1
  172.          0x01, //the constant DEVICE (DEVICE 0x01)  ==2
  173.          0x10,0x01, //usb version in bcd (pic167xx is 1.1) ==3,4
  174.          0x00, //class code ==5
  175.          0x00, //subclass code ==6
  176.          0x00, //protocol code ==7
  177.          USB_MAX_EP0_PACKET_LENGTH, //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8) ==8
  178.          0xd8,0x04, //vendor id (0x04D8 is Microchip, or is it 0x0461 ??)
  179.          0xff,0x00, //product id   ==11,12  //don't use ffff says usb-by-example guy.  oops
  180.          0x00,0x01, //device release number  ==13,14
  181.          0x01, //index of string description of manufacturer. therefore we point to string_1 array (see below)  ==15
  182.          0x02, //index of string descriptor of the product  ==16
  183.          0x00, //index of string descriptor of serial number  ==17
  184.          USB_NUM_CONFIGURATIONS  //number of possible configurations  ==18
  185.    };
  186.  
  187.  
  188. //////////////////////////////////////////////////////////////////
  189. ///
  190. ///   start string descriptors
  191. ///   String 0 is a special language string, and must be defined.  People in U.S.A. can leave this alone.
  192. ///
  193. ///   You must define the length else get_next_string_character() will not see the string
  194. ///   Current code only supports 10 strings (0 thru 9)
  195. ///
  196. //////////////////////////////////////////////////////////////////
  197.  
  198. //the offset of the starting location of each string.  offset[0] is the start of string 0, offset[1] is the start of string 1, etc.
  199. char USB_STRING_DESC_OFFSET[]={0,4,12};
  200.  
  201. char const USB_STRING_DESC[]={
  202.    //string 0
  203.          4, //length of string index
  204.          USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
  205.          0x09,0x04,   //Microsoft Defined for US-English
  206.    //string 1
  207.          8, //length of string index
  208.          USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
  209.          'P',0,
  210.          'I',0,
  211.          'C',0,
  212.    //string 2
  213.          38, //length of string index
  214.          USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
  215.          'w',0,
  216.          'w',0,
  217.          'w',0,
  218.          '.',0,
  219.          'M',0,
  220.          'i',0,
  221.          'c',0,
  222.          'r',0,
  223.          'o',0,
  224.          'P',0,
  225.          'i',0,
  226.          'c',0,
  227.          '.',0,
  228.          'e',0,
  229.          's',0,
  230.          ' ',0,
  231.          ' ',0,
  232.          ' ',0,
  233. };
  234.  
  235. #ENDIF

Desconectado LABmouse

  • Moderadores
  • DsPIC30
  • *****
  • Mensajes: 3575
    • Juntos es mejor
Re: Problema con driver USB HID en Win7
« Respuesta #7 en: 28 de Junio de 2011, 13:32:32 »
Lo raro es que funcione en otros windows... por es descarto problemas en programación. Pero casos se han visto.

¿Y si tienes instalado algo con el mismo VID-PID y esta en conflicto.? ¿Por casualidad tienes otro PC cerca para probar?

La otra opción es que Seven gestiona muchísimo mejor la desinstalacion de hardware desde administrador de dispositivos. prueba conectar el microcontrolador y lo desinstalas por completo desde panel de control. luego conectas una vez mas a ver que tal.

Desconectado Suky

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 6758
Re: Problema con driver USB HID en Win7
« Respuesta #8 en: 28 de Junio de 2011, 13:43:00 »
A simple vista se ven varias diferencias con el de Microchip, es 1.1 y el HID report tiene diferencias...  :tongue: Podrías probar cambiando el VID-PID o dejándolo igual que uno de Microchip, que a mi en Win Xp, Win Vista o Win 7 no me ha dado problemas  :roll:
No contesto mensajes privados, las consultas en el foro

Desconectado Nocturno

  • Administrador
  • DsPIC33
  • *******
  • Mensajes: 18310
    • MicroPIC
Re: Problema con driver USB HID en Win7
« Respuesta #9 en: 29 de Junio de 2011, 03:16:02 »
Pues parece que ya lo he resuelto.

Se ve que Win7 es algo más exigente con los tiempos del USB, y mi aplicación estaba en el límite. En mi bucle principal tengo una función "AtiendeHID()" que se ejecutaba entre otras tareas.
Descubrí que si sólo la dejaba a ella la conexión con Win7 resultaba exitosa.
Poco a poco he ido añadiendo el resto de tareas hasta descubrir cuál era el límite de tiempo que puedo estar sin ejecutar AtiendeHID().

Luego he optimizado un poco esas otras funciones para que tarden menos y ya está funcionando bien en Win7.

Gracias por vuestra ayuda.

Desconectado Suky

  • Moderador Local
  • DsPIC33
  • *****
  • Mensajes: 6758
Re: Problema con driver USB HID en Win7
« Respuesta #10 en: 29 de Junio de 2011, 11:05:01 »
Podes utilizar interrupción para USB... Pero no se como se hará en CCS  :mrgreen:


Saludos!
No contesto mensajes privados, las consultas en el foro