|
|
View previous topic :: View next topic |
Author |
Message |
esinger
Joined: 13 Jul 2004 Posts: 1
|
can't get PIC16c745 USB to enumerate |
Posted: Tue Jul 13, 2004 8:49 am |
|
|
Hi,
I am trying to create a standard USB 104-key PC keyboard emulator on a PIC 16c745 using the CCS C compiler version 3.0.0.13 under MPLAB5. I started with the CCS USB example code, then modified it to be a standard keyboard device.
I can get the device to enumerate when I use the example descriptor. However, my modified one won't enumerate properly. I have checked it against numerous references, and it appears to be correct.
I'm copying my descriptor below. I would be grateful if anyone could shed some light on this issue.
Thanks,
Eric
========
#DEFINE USB_NUM_CONFIGURATIONS 1
#DEFINE USB_NUM_INTERFACES 1
#DEFINE USB_NUM_ENDPOINTS 1
#DEFINE USB_NUM_CLASSES 1 // hid
BYTE CONST USB_CONFIG_DESCRIPTORS[USB_NUM_CONFIGURATIONS] = {0};
BYTE CONST USB_INTERFACE_DESCRIPTORS[USB_NUM_INTERFACES] = {9};
BYTE CONST USB_CLASS_DESCRIPTORS[USB_NUM_CLASSES] = {18};
BYTE CONST USB_ENDPOINT_DESCRIPTORS[USB_NUM_ENDPOINTS] = {27};
#DEFINE USB_TOTAL_CONFIG_LEN 34 // config + interface + class + endpoint
#DEFINE USB_HID_DESC_LEN 63
BYTE CONST USB_DEVICE_DESC[] = {
USB_DEVICE_DESC_LEN, // the length of this report ==1
0x01, // the constant DEVICE (DEVICE 0x01) ==2
0x10, 0x01, // usb version in bcd (pic167xx is 1.1) ==3,4
0x00, // class code ==5
0x00, // subclass code ==6
0x00, // protocol code ==7
USB_MAX_EP0_PACKET_LENGTH, // max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8) ==8
0xD8, 0x04, // vendor id (0x04D8 is Microchip, or is it 0x0461 ??)
0x01, 0x00, // product id ==11,12 // don't use ffff says usb-by-example guy. oops
0x00, 0x01, // device release number ==13,14
0x00, // index of string description of manufacturer. therefore we point to string_1 array (see below) ==15
0x00, // index of string descriptor of the product ==16
0x00, // index of string descriptor of serial number ==17
USB_NUM_CONFIGURATIONS // number of possible configurations ==18
};
BYTE CONST USB_CONFIG_DESC[USB_TOTAL_CONFIG_LEN] = {
// config_descriptor for config index 1
USB_CONFIG_DESC_LEN, // length of descriptor size ==1
USB_CONFIG_DESC_KEY, // constant CONFIGURATION (CONFIGURATION 0x02) ==2
USB_TOTAL_CONFIG_LEN, 0, // size of all data returned for this config ==3,4
USB_NUM_INTERFACES, // number of interfaces this device supports ==5
0x01, // identifier for this configuration. (IF we had more than one configurations) ==6
0x00, // index of string descriptor for this configuration ==7
0x80, // bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1 ==8
0x32, // maximum bus power required (maximum milliamperes/2) (0x32 = 100mA)
// interface descriptor 1
USB_INTERFACE_DESC_LEN, // length of descriptor =10
USB_INTERFACE_DESC_KEY, // constant INTERFACE (INTERFACE 0x04) =11
0x00, // number defining this interface (IF we had more than one interface) ==12
0x00, // alternate setting ==13
USB_NUM_ENDPOINTS, // number of endpoins, except 0 (pic167xx has 3, but we dont have to use all). ==14
0x03, // class code, 03 = HID ==15
0x01, // subclass code // boot ==16
0x01, // protocol code // 1=kbd ==17
0x00, // index of string descriptor for interface ==18
// class descriptor 1 (HID)
USB_CLASS_DESC_LEN, // length of descriptor ==19
USB_CLASS_DESC_KEY, // dscriptor type (0x21 == HID) ==20
0x00, 0x01, // hid class release number (1.0) ==21,22
0x00, // localized country code (0 = none) ==23
0x01, // number of hid class descrptors that follow (1) ==24
0x22, // report descriptor type (0x22 == HID) ==25
USB_HID_DESC_LEN, 0x00, // length of report descriptor ==26,27
// endpoint descriptor
USB_ENDPOINT_DESC_LEN, // length of descriptor ==28
USB_ENDPOINT_DESC_KEY, // constant ENDPOINT (ENDPOINT 0x05) ==29
0x81, // endpoint number and direction (0x81 = EP1 IN) ==30
0x03, // transfer type supported (0x03 is interrupt) ==31
0x08, 0x00, // maximum packet size supported ==32,33
0x0A // polling interval, in ms. (cant be smaller than 10) ==34
};
BYTE CONST USB_HID_DESC[] = {
// len = 63
0x05, 0x01 // usage page (generic desktop)
0x09, 0x06 // usage (keyboard)
0xA1, 0x01 // collection (application)
0x05, 0x07 // usage page (key codes)
0x19, 0xE0 // usage minimum (224)
0x29, 0xE7 // usage maximum (231)
0x15, 0x00 // logical minimum (0)
0x25, 0x01 // logical maximum (1)
0x75, 0x01 // report size (1)
0x95, 0x08 // report count (8)
0x81, 0x02 // input (data, variable, absolute)
0x95, 0x01 // report count (1)
0x75, 0x08 // report size (8)
0x81, 0x01 // input (constant)
0x95, 0x05 // report count (5)
0x75, 0x01 // report size (1)
0x05, 0x08 // usage page (page# for LEDs)
0x19, 0x01 // usage minimum (1)
0x29, 0x05 // usage maxmimum (5)
0x91, 0x02 // output (data, variable, absolute)
0x95, 0x01 // report count (1)
0x75, 0x03 // report size (3)
0x91, 0x01 // output (constant)
0x95, 0x06 // report count (6)
0x75, 0x08 // report size (8)
0x15, 0x00 // logical minimum (0)
0x25, 0x65 // logical maximum (101)
0x05, 0x07 // usage page (key codes)
0x19, 0x00 // usage minimum (0)
0x29, 0x65 // usage maximum (101)
0x81, 0x00 // input (data, array)
0xC0 // end collection
};
#DEFINE USB_STRING_0_LEN 4
BYTE CONST USB_STRING_0[USB_STRING_0_LEN] = {
// string index 0 is special
USB_STRING_0_LEN, // length of string index
0x03, // descriptor type 0x03 (STRING)
0x09, 0x04 // Microsoft Defined for US-English
};
etc.... |
|
|
guest Guest
|
can't get PIC16c745 USB to enumerate |
Posted: Tue Aug 10, 2004 6:01 am |
|
|
Hi Eric,
I've got the same problem, I used the mouse-descriptor, and it worked, then I used a keyboard desc wich worked with HI-TECH C V7.87 PL2, but it does not work with CCS.
If you manage it, please tell me: gaul1@compuserve.de
I've to try further.
good luck !
gaul1 |
|
|
gaul1 Guest
|
I got PIC16c745 USB to enumerate |
Posted: Thu Aug 12, 2004 8:17 am |
|
|
Hi Eric,
with my hardware, this works (picdem USB+16c765) javascript:emoticon('')
Laughing
good luck !
gaul1
//usb descriptor reports
#DEFINE USB_NUM_CONFIGURATIONS 1
#DEFINE USB_NUM_INTERFACES 1
#DEFINE USB_NUM_ENDPOINTS 1
#DEFINE USB_NUM_CLASSES 1 //hid
//you cant use pointers when storing constants to program memory.
BYTE CONST USB_CONFIG_DESCRIPTORS[USB_NUM_CONFIGURATIONS]={0};//0
BYTE CONST USB_INTERFACE_DESCRIPTORS[USB_NUM_INTERFACES]={9};//9
BYTE CONST USB_CLASS_DESCRIPTORS[USB_NUM_CLASSES]={18};//18
BYTE CONST USB_ENDPOINT_DESCRIPTORS[USB_NUM_ENDPOINTS]={27};//27
#DEFINE USB_TOTAL_CONFIG_LEN 34 //config+interface+class+endpoint
#DEFINE USB_HID_DESC_LEN 63
BYTE CONST USB_DEVICE_DESC[] = {
//starts of with device configuration. only one possible
0x12, // USB_DEVICE_DESC_LEN, //the length of this report ==1 // len=18=0x12
//dev,0, 1, 0, 0, 0, 8, 0xD8, 4, 0x0C, 0, 0x41, 4, 1, 2, 0, 1 // von usb_ch9.c
0x01, //the constant DEVICE (DEVICE 0x01) ==2
0x00,0x01, //usb version in bcd (pic167xx is 1.1) ==3,4
0x00, //class code ==5
0x00, //subclass code ==6
0x00, //protocol code ==7
8, //USB_MAX_EP0_PACKET_LENGTH, //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8) ==8
0xD8,0x04, //vendor id (0x04D8 is Microchip, or is it 0x0461 ??)
0x0C,0x01, //product id ==11,12 //don't use ffff says usb-by-example guy. oops!
0x41, 5, //device release number ==13,14!
0x01, //index of string description of manufacturer. therefore we point to string_1 array (see below) ==15
0x02, //index of string descriptor of the product ==16
0x00, //index of string descriptor of serial number ==17
1 //USB_NUM_CONFIGURATIONS //number of possible configurations ==18
};
BYTE CONST USB_CONFIG_DESC[USB_TOTAL_CONFIG_LEN] = {
//IN ORDER TO COMPLY WITH WINDOWS HOSTS, THE ORDER OF THIS ARRAY MUST BE:
// config(s)
// interface(s)
// class(es)
// endpoint(s)
//config_descriptor for config index 1
9, //USB_CONFIG_DESC_LEN, //length of descriptor size ==1
2, //USB_CONFIG_DESC_KEY, //constant CONFIGURATION (CONFIGURATION 0x02) ==2
34,0, //USB_TOTAL_CONFIG_LEN,0, //size of all data returned for this config ==3,4
1, //USB_NUM_INTERFACES, //number of interfaces this device supports ==5
0x01, //identifier for this configuration. (IF we had more than one configurations) ==6
0x00, //index of string descriptor for this configuration ==7
0xa0, // von usb_ch9[a0] //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
0x32, //maximum bus power required (maximum milliamperes/2) (0x32 = 100mA)
//interface descriptor 1
9, //USB_INTERFACE_DESC_LEN, //length of descriptor =10
4, //USB_INTERFACE_DESC_KEY, //constant INTERFACE (INTERFACE 0x04) =11
0x00, //number defining this interface (IF we had more than one interface) ==12
0x00, //alternate setting ==13
1, //USB_NUM_ENDPOINTS, //number of endpoins, except 0 (pic167xx has 3, but we dont have to use all). ==14
0x03, //class code, 03 = HID ==15
0x01, //subclass code //boot ==16
1, //0x02, //protocol code ==17
0x00, //index of string descriptor for interface ==18
//class descriptor 1 (HID)
9, //USB_CLASS_DESC_LEN, //length of descriptor ==19
0x21, //USB_CLASS_DESC_KEY, //dscriptor type (0x21 == HID) ==20
0x00,0x01, //hid class release number (1.0) (try 1.10) ==21,22
0x00, //localized country code (0 = none) ==23
0x01, //number of hid class descrptors that follow (1) ==24
0x22, //report descriptor type (0x22 == HID) ==25
USB_HID_DESC_LEN, 0x00, //length of report descriptor (LowByte,HighByte) ==26,27
//endpoint descriptor
7, //USB_ENDPOINT_DESC_LEN, //length of descriptor ==28
5, //USB_ENDPOINT_DESC_KEY, //constant ENDPOINT (ENDPOINT 0x05) ==29
0x81, //endpoint number and direction (0x81 = EP1 IN) ==30
0x03, //transfer type supported (0x03 is interrupt) ==31
0x08,0x00, //maximum packet size supported ==32,33
0x0a, //polling interval, in ms. (cant be smaller than 10 for slow speed devices) ==34
};
//////////////////////////////////////////////////////////////////
///
/// HID Report. Tells HID driver how to handle and deal with
/// received data. HID Reports can be extremely complex,
/// see HID specifcation for help on writing your own.
///
/// This examples configures HID driver to take received data
/// as keyboard
///
//////////////////////////////////////////////////////////////////
//mine
BYTE CONST USB_HID_DESC[] = { //len=63
0x05, 0x01, // usage page (generic desktop)
0x09, 0x06, // usage (keyboard)
0xA1, 0x01, // collection (application)
0x05, 0x07, // usage page (key codes)
0x19, 0xE0, // usage minimum (224)
0x29, 0xE7, // usage maximum (231)
0x15, 0x00, // logical minimum (0)
0x25, 0x01, // logical maximum (1)
0x75, 0x01, // report size (1)
0x95, 0x08, // report count (8)
0x81, 0x02, // input (data, variable, absolute)
0x95, 0x01, // report count (1)
0x75, 0x08, // report size (8)
0x81, 0x01, // input (constant)
0x95, 0x05, // report count (5)
0x75, 0x01, // report size (1)
0x05, 0x08, // usage page (page# for LEDs)
0x19, 0x01, // usage minimum (1)
0x29, 0x05, // usage maxmimum (5)
0x91, 0x02, // output (data, variable, absolute)
0x95, 0x01, // report count (1)
0x75, 0x03, // report size (3)
0x91, 0x01, // output (constant)
0x95, 0x06, // report count (6)
0x75, 0x08, // report size (8)
0x15, 0x00, // logical minimum (0)
0x25, 0x65, // logical maximum (101)
0x05, 0x07, // usage page (key codes)
0x19, 0x00, // usage minimum (0)
0x29, 0x65, // usage maximum (101)
0x81, 0x00, // input (data, array)
0xC0 // end collection
};
//////////////////////////////////////////////////////////////////
///
/// start string descriptors |
|
|
|
|
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
|