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 support@ccsinfo.com

Using CCS USB CDC library under Linux

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



Joined: 06 Sep 2009
Posts: 4

View user's profile Send private message

Using CCS USB CDC library under Linux
PostPosted: Sun Sep 06, 2009 8:42 pm     Reply with quote

Hello everybody,

I'm new to CCS Compiler and I'd like some help from you. I've done a simple program using the USB CDC library. It works nice under windows, but under Linux I'm getting some errors. Linux is supposed to automatic assign one CDC device to a serial port (i.e. /dev/ttyACMn), but that doesn't happen.

With lsusb, I get this message:

Code:
lsusb -d 0461:0033 -vvv

Bus 002 Device 006: ID 0461:0033 Primax Electronics, Ltd
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            2 Communications
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x0461 Primax Electronics, Ltd
  idProduct          0x0033
  bcdDevice            1.00
  iManufacturer           1
  iProduct                2
  iSerial                 0
  bNumConfigurations      0
cannot read device status, Operation not permitted (1)


And dmesg output is like this:

Code:
(...)
[  600.528022] usb 2-5: new full speed USB device using ohci_hcd and address 6
[  600.734708] usb 2-5: unable to read config index 0 descriptor/start: -62
[  600.734712] usb 2-5: chopping to 0 config(s)
[  600.741008] usb 2-5: string descriptor 0 read error: -62
[  600.746704] usb 2-5: string descriptor 0 read error: -62
[  600.762609] usb 2-5: no configuration chosen from 0 choices


My code is very simple, it's just for test and it's based on the example provided with the installation of the compiler. All the header files were copied from the device and driver directories.

Code:
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)

#include <usb_cdc.h>

void main(void)
{
   char c;
   usb_init_cs();

   while (TRUE)
   {
      usb_task();
      if (usb_cdc_kbhit())
      {
      c=usb_cdc_getc();
      usb_cdc_putc(c+1);
      }
   }
}


Am I doing anything wrong? Is there any code missing? Should I put any resistor on the D+ D- pin? Or should I check it in other Linux Distro? (I'm using Ubuntu 9.04 - Jaunty Jackalope)

Thank you in advance!

Don
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Mon Sep 07, 2009 1:07 pm     Reply with quote

I didn't try it in the ubuntu yet but the sample code that is provided with ccs ( ex_usb_serial.c ) works with windows. Try that first, and then turn to your own code. Wink
Donlanthirion



Joined: 06 Sep 2009
Posts: 4

View user's profile Send private message

PostPosted: Mon Sep 07, 2009 2:32 pm     Reply with quote

Hello, Bungee,

Thank you for your reply.

I tried my code under Windows and it worked fine. I can open a communication link with HyperTerminal and exchange data, but Ubuntu can't understand what kind of device it is. I tried with Fedora 10 (it's kind old) yesterday and got the same error.

I'll check which Kernel I'm using, but I'm quite positive I have the latest Kernel.
Ttelmah
Guest







PostPosted: Mon Sep 07, 2009 2:44 pm     Reply with quote

Er.
Obvious comment, the Primax driver, has nothing to do with the CCS example....

The vendor ID, is the correct one for Microchip, and if you check the USB database, is registered to them, _not_ to Primax.

I'd suspect a number of possibilities:
1) Somebody has been playing with your Linux, and built a driver for a Primax device, and incorrectly put in the Microchip ID.
2) Primax has built a device based on the PIC, and has distributed a UNIX driver using the Microchip ID, rather than their own.....
Various similar variations.....

Somehow your Linux thinks that Vendor ID 461, is linked to a Primax product, not Microchip....

Best Wishes
Donlanthirion



Joined: 06 Sep 2009
Posts: 4

View user's profile Send private message

PostPosted: Mon Sep 07, 2009 5:18 pm     Reply with quote

Hello Ttelmah,

You were right, the VID wasn't Microchip. Microchip VID is actually 0x04d8 ( http://ww1.microchip.com/downloads/en/AppNotes/Application%20for%20USB%20Vendor%20ID%20Sublicense.pdf ), and the example provided by CCS Compiler uses the PID 0x0033, not 0x000a used by the Microchip example.

I tried changing them to see if it works, but I've got the same error. "sudo modprobe usbserial vendor=0x04d8 product=0x000a" didn't work either.

Thank you anyway!

Don
Donlanthirion



Joined: 06 Sep 2009
Posts: 4

View user's profile Send private message

PostPosted: Mon Sep 07, 2009 6:43 pm     Reply with quote

Hello, everyone,

I've compiled the CDC Demo from Microchip (using C18 Compiler) and it worked nicely. Maybe it's a bug from CCS Compiler for the CDC USB Driver?
Darrenz
Guest







PostPosted: Thu Oct 08, 2009 11:32 am     Reply with quote

I'm trying to use the CDC protocol on linux with the following library, but does not work. Please, someone can help me?.

#IFNDEF __USB_DESCRIPTORS__
#DEFINE __USB_DESCRIPTORS__

#include <usb.h>


//////////////////////////////////////////////////////////////////
///
/// start config descriptor
/// right now we only support one configuration descriptor.
/// the config, interface, class, and endpoint goes into this array.
///
//////////////////////////////////////////////////////////////////

#DEFINE USB_TOTAL_CONFIG_LEN 67 //config+interface+class+endpoint+endpoint (2 endpoints)

const char USB_CONFIG_DESC[] = {
//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
USB_DESC_CONFIG_LEN, //length of descriptor size ==0
USB_DESC_CONFIG_TYPE, //constant CONFIGURATION (CONFIGURATION 0x02) ==1
USB_TOTAL_CONFIG_LEN,0, //size of all data returned for this config ==2,3
2, //number of interfaces this device supports ==4
0x01, //identifier for this configuration. (IF we had more than one configurations) ==5
0x00, //index of string descriptor for this configuration ==6
0xC0, //bit 6=1 if self powered, bit 5=1 if supports remote wakeup (we don't), bits 0-4 unused and bit7=1 ==7
0x32, //maximum bus power required (maximum milliamperes/2) (0x32 = 100mA) ==8

//interface descriptor 0 (comm class interface)
USB_DESC_INTERFACE_LEN, //length of descriptor =9
USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =10
0x00, //number defining this interface (IF we had more than one interface) ==11
0x00, //alternate setting ==12
1, //number of endpoints ==13
0x02, //class code, 02 = Comm Interface Class ==14
0x02, //subclass code, 2 = Abstract ==15
0x01, //protocol code, 1 = v.25ter ==16
0x00, //index of string descriptor for interface ==17

//class descriptor [functional header]
5, //length of descriptor ==18
0x24, //dscriptor type (0x24 == ) ==19
0, //sub type (0=functional header) ==20
0x10,0x01, // ==21,22 //cdc version

//class descriptor [acm header]
4, //length of descriptor ==23
0x24, //dscriptor type (0x24 == ) ==24
2, //sub type (2=ACM) ==25
2, //capabilities ==26 //we support Set_Line_Coding, Set_Control_Line_State, Get_Line_Coding, and the notification Serial_State.

//class descriptor [union header]
5, //length of descriptor ==27
0x24, //dscriptor type (0x24 == ) ==28
6, //sub type (6=union) ==29
0, //master intf ==30 //The interface number of the Communication or Dat a Cl [spam] interface, designated as the masteror controlling interface for the union.
1, //save intf0 ==31 //Interface number of first slave or associated interface in the union. *

//class descriptor [call mgmt header]
5, //length of descriptor ==32
0x24, //dscriptor type (0x24 == ) ==33
1, //sub type (1=call mgmt) ==34
0, //capabilities ==35 //device does not handle call management itself
1, //data interface ==36 //interface number of data class interface

//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor ==37
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==38
USB_CDC_COMM_IN_ENDPOINT | 0x80, //endpoint number and direction
0x03, //transfer type supported (0x03 is interrupt) ==40
USB_CDC_COMM_IN_SIZE,0x00, //maximum packet size supported ==41,42
250, //polling interval, in ms. (cant be smaller than 10) ==43

//interface descriptor 1 (data class interface)
USB_DESC_INTERFACE_LEN, //length of descriptor =44
USB_DESC_INTERFACE_TYPE, //constant INTERFACE (INTERFACE 0x04) =45
0x01, //number defining this interface (IF we had more than one interface) ==46
0x00, //alternate setting ==47
2, //number of endpoints ==48
0x0A, //class code, 0A = Data Interface Class ==49
0x00, //subclass code ==50
0x00, //protocol code ==51
0x00, //index of string descriptor for interface ==52

//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor ==60
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==61
USB_CDC_DATA_OUT_ENDPOINT, //endpoint number and direction (0x02 = EP2 OUT) ==62
0x02, //transfer type supported (0x02 is bulk) ==63
// make8(USB_CDC_DATA_OUT_SIZE,0),make8(USB_CDC_DATA_OUT_SIZE,1), //maximum packet size supported ==64, 65
USB_CDC_DATA_OUT_SIZE & 0xFF, (USB_CDC_DATA_OUT_SIZE >> 8) & 0xFF, //maximum packet size supported ==64, 65
250, //polling interval, in ms. (cant be smaller than 10) ==66

//endpoint descriptor
USB_DESC_ENDPOINT_LEN, //length of descriptor ==53
USB_DESC_ENDPOINT_TYPE, //constant ENDPOINT (ENDPOINT 0x05) ==54
USB_CDC_DATA_IN_ENDPOINT | 0x80, //endpoint number and direction (0x82 = EP2 IN) ==55
0x02, //transfer type supported (0x02 is bulk) ==56
// make8(USB_CDC_DATA_IN_SIZE,0),make8(USB_CDC_DATA_IN_SIZE,1), //maximum packet size supported ==57, 58
USB_CDC_DATA_IN_SIZE & 0xFF, (USB_CDC_DATA_IN_SIZE >> 8) & 0xFF, //maximum packet size supported ==64, 65
250, //polling interval, in ms. (cant be smaller than 10) ==59
};

//****** BEGIN CONFIG DESCRIPTOR LOOKUP TABLES ********
//since we can't make pointers to constants in certain pic16s, this is an offset table to find
// a specific descriptor in the above table.

//the maximum number of interfaces seen on any config
//for example, if config 1 has 1 interface and config 2 has 2 interfaces you must define this as 2
#define USB_MAX_NUM_INTERFACES 2

//define how many interfaces there are per config. [0] is the first config, etc.
const char USB_NUM_INTERFACES[USB_NUM_CONFIGURATIONS]={2};

//define where to find class descriptors
//first dimension is the config number
//second dimension specifies which interface
//last dimension specifies which class in this interface to get, but most will only have 1 class per interface
//if a class descriptor is not valid, set the value to 0xFFFF
const int16 USB_CLASS_DESCRIPTORS[USB_NUM_CONFIGURATIONS][USB_MAX_NUM_INTERFACES][4]=
{
//config 1
//interface 0
//class 1-4
18,23,27,32,
//interface 1
//no classes for this interface
0xFFFF,0xFFFF,0xFFFF,0xFFFF
};

#if (sizeof(USB_CONFIG_DESC) != USB_TOTAL_CONFIG_LEN)
#error USB_TOTAL_CONFIG_LEN not defined correctly
#endif


//////////////////////////////////////////////////////////////////
///
/// start device descriptors
///
//////////////////////////////////////////////////////////////////

const char USB_DEVICE_DESC[USB_DESC_DEVICE_LEN] ={
//starts of with device configuration. only one possible
USB_DESC_DEVICE_LEN, //the length of this report ==0
0x01, //the constant DEVICE (DEVICE 0x01) ==1
0x10,0x01, //usb version in bcd ==2,3
0x0A, //class code. 0x02=Communication Device Class ==4
0x00, //subclass code ==5
0x00, //protocol code ==6
USB_MAX_EP0_PACKET_LENGTH, //max packet size for endpoint 0. (SLOW SPEED SPECIFIES 8) ==7
0xD8,0x04, //vendor id (0x04D8 is Microchip, or is it 0x0461 ??) ==8,9
0x1B,0x00, //product id ==10,11
0x00,0x01, //device release number ==12,13
0x01, //index of string description of manufacturer. therefore we point to string_1 array (see below) ==14
0x02, //index of string descriptor of the product ==15
0x00, //index of string descriptor of serial number ==16
USB_NUM_CONFIGURATIONS //number of possible configurations ==17
};


//////////////////////////////////////////////////////////////////
///
/// start string descriptors
/// String 0 is a special language string, and must be defined. People in U.S.A. can leave this alone.
///
/// You must define the length else get_next_string_character() will not see the string
/// Current code only supports 10 strings (0 thru 9)
///
//////////////////////////////////////////////////////////////////

//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.
char USB_STRING_DESC_OFFSET[]={0,4,12};

char const USB_STRING_DESC[]={
//string 0
4, //length of string index
USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
0x09,0x04, //Microsoft Defined for US-English
//string 1
8, //length of string index
USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
'U',0,
'S',0,
'B',0,
//string 2
24, //length of string index
USB_DESC_STRING_TYPE, //descriptor type 0x03 (STRING)
'P',0,
'O',0,
'W',0,
'E',0,
'R',0,
'J',0,
'A',0,
'G',0,
'U',0,
'A',0,
'R',0,

};

#ENDIF
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