Jump to content

Anyone Have Non Demo Usb For 18f2550


Recommended Posts

Hi All,

Anyone have working code for a non trivial example of USB comms using a 18F2550 or similiar 18Fxxxx PIC?

If I can get to the point where I can connect it up, fire Hyperterminal and have two way (eg a menu/parameter select) comms that'd be great.

I've seen the circling mouse pointer demo....but cannot get arbitary two way comms.

Are there special drivers that need to be installed? Which ones?

Thanks,

Phil

Link to post
Share on other sites

Well, I'm going to push this till we get somewhere.

 

I've managed to get a small board to be enumerated by Windows, for both the irritating mouse demo and Robert Langs usb/midi interface. I had a silly problem where my board doesn't use MCLR, yet it was enabled in the config statements.

 

If anyone has experience with USB please correct me if I'm wrong:

- I need a USB descriptor that is of a comms class

- I will need at least two end points defined in that descriptor, one for data being received and one for data being transmitted.

- I can use the Microchip CDC comms class driver.

So a couple of questions...what is the descriptor I should be using. I can't for the life of me decypher the Microchip CDC classes.....at least to the level of getting a simple array of values to substitute into Robert Langs code.

Also is there a specific endpoint class (and what is the format of the descriptor) that is needed when implementing comms for setup and configuration? In this case a minimum of three endpoints would need to be written?????

 

I've written an EP write function I think might work:

unsigned char PutEP1 (unsigned char bytes, unsigned char *buffer)

{ unsigned char * tobuffer;

unsigned char i;

 

ddrb=0; //setup b for output

if ((BDT[EP1IN].EPStat & 0x80) == 0) /* do we own the buffer? UOWN=0*/

{

Flash_Led(); // indicate activity on ep1

BDT[EP1IN].Bytes = bytes;

for (i = 0; i < bytes; i++)

{

bd1ie_buf = buffer;

}

 

BDT[EP1IN].EPStat &= 0x40; /* save only the Data 1/0 bit */

BDT[EP1IN].EPStat ^= 0x40; /* toggle Data 0/1 bit */

BDT[EP1IN].EPStat |= 0x88; /* release buffer */

return BDT[EP1IN].Bytes;

}

return 0;/* Buffer not available, return 0 */

}

 

Does this look reasonable??

 

Any help in getting a simple terminal working with USB would be greatly appreciated. The end application is to hook a PIC device into a PC via USB, then change operating parameters and upload/download data via Hyperterminal (or any comms program) and PIC generated text menus rather than some specific program.

 

Thanks,

Phil

PS: If Robert Lang is reading these forums, I'd greatly appreciate some help.

Link to post
Share on other sites

Hi Phil,

Well, I'm going to push this till we get somewhere.

...

 

Any help in getting a simple terminal working with USB would be greatly appreciated. The end application is to hook a PIC device into a PC via USB, then change operating parameters and upload/download data via Hyperterminal (or any comms program) and PIC generated text menus rather than some specific program.

 

Thanks,

Phil

PS: If Robert Lang is reading these forums, I'd greatly appreciate some help.

I too am getting started on a PIC based USB project. I have read Microchip's USB demo code. Their provided Windows USB API functions (using their DLL) and IOCTL functions (direct driver control) have helped in my understanding. I will try and read through their PIC code again to see if we can be of mutual assistance.

 

Regards,

G

Link to post
Share on other sites

Cool. I've begun a bit more research myself. Looks like I need to do more work with the handling of comms class devices. At the moment I'm trying to convert the Microchip source detailed in their AN956 app note to work with Rob Langs mouse example on the SourceBoost site.

A couple of questions:

The AN956 code defines endpoints EP2 and EP3....is it reasonable to assume that their corresponding driver will also talk to these, and that not defining EP2/EP3 will mean the thing won't work. Simple reason for this actually, in the Lang code buffers are allocated in the 18F2550 dual port ram. Currently I've left the definition for EP0 as is, I've given EP1 a teeny buffer and define proper size buffers for EP2/EP3.

The Lang code as it stands seems to use EP0 for starting the USB connection, sending the usb descriptor and configuration information etc......is there a requirement in the USB spec to use EP0 for this?

To start things off below is the descriptor table ported from the Microchip code for use with a RS232 emulator...note some defines need to be taken from the Microchip code...it won't compile as is. Just copy/paste from that code tree when a symbol doesn't compile.

This descriptor defines two interfaces, three endpoints and four function descriptors.

All I've done really is de-structure the Microchip structures into the single array used in the Lang code.

Next I need to know how to implement the CDC RS232 functions....time to rummage through Microchips code again.

 

Phil

PS: anyone with experience in the comms class for usb...feel free to join in!

 

 

// The following descriptors are based on the example given by

// Thorsten Klose on the internet

char DeviceDescriptor [] = {18, // 18 bytes long

DEVICE, // descriptor type

0x10, 0x01, // USB specification release (1.1)

0x00, // class code

0x00, // subclass code

0x00, // protocol code

64, // maximum packet size 64

0xD8,0x04, // vendor id (04d8) microchip

0x0A,0x00, //product id (000A)

0x00,0x01, // bcd device release number 1.00

0x01, // index to string that describes vendor

0x02, // index to string that describes product

0x00, // index to string that describes serial number (none)

0x01 // number of possible configurations

};

//CONFIG DESCRIPTOR ============================

const char ConfigDescriptor [] = {0x09, // 9 bytes long

CONFIGURATION, // descriptor type

0x43, 0x00, // total length of config, interface, and endpoint descriptors

0x02, // number of interfaces, one for configuration, the other for data transfer in/out

0x01, // configuration number, only one configuration in this USB device

0, // index to string that describes configuration (none)

0x80, // configuration attributes +check+

50, // current consumption in 2mA units (100 mA)

 

/* Interface Descriptor for first interface, configuration of the serial channel*/

INTERFACE, //descriptor type

9, // Size of this descriptor in bytes including this byte

INTERFACE, // INTERFACE descriptor type

0, // Interface Number

0, // Alternate Setting Number

1, // Number of endpoints in this intf

COMM_INTF, // Class code

ABSTRACT_CONTROL_MODEL, // Subclass code

V25TER, // Protocol code

0, // Interface string index

 

/* CDC Class-Specific Descriptors will be used by system to invoke functions on the USB device*/

/* by interface one */

// sizeof(USB_CDC_HEADER_FN_DSC),CS_INTERFACE,DSC_FN_HEADER,0x0110,

5, //size of cdc header function descriptor

CS_INTERFACE,

DSC_FN_HEADER,

0x02,

0x00,

 

// sizeof(USB_CDC_ACM_FN_DSC),CS_INTERFACE,DSC_FN_ACM,0x02,

4,

CS_INTERFACE,

DSC_FN_ACM, //Abstract control management function

0x02,

 

 

//sizeof(USB_CDC_UNION_FN_DSC),CS_INTERFACE,DSC_FN_UNION,CDC_COMM_INTF_ID,CDC_DATA

_INTF_ID,

5,

CS_INTERFACE,

DSC_FN_UNION,

CDC_COMM_INTF_ID,

CDC_DATA_INTF_ID,

 

// sizeof(USB_CDC_CALL_MGT_FN_DSC),CS_INTERFACE,DSC_FN_CALL_MGT,0x00,CDC_DATA_INTF_

ID,

5,

CS_INTERFACE,

DSC_FN_CALL_MGT,

0x00,

CDC_DATA_INTF_ID,

 

 

 

/* Endpoint Descriptor for interface one*/

//sizeof(USB_EP_DSC),DSC_EP,_EP02_IN,_INT,CDC_INT_EP_SIZE,0x02,

7, //length

ENDPOINT, //dsc type in this case an endpoint descriptor

EP2IN, //a magic number for OS to identify the EP with

_INT, //Interrupt transfer...an attribute of this EP

CDC_INT_EP_SIZEL, //note the size was defined in Microchips code as a word (16bit)

CDC_INT_EP_SIZEH, //its been split for this code

0x02, //interval

 

 

/* Interface Descriptor for data transfer, it has two endpoints, one in one out*/

9, // Size of this descriptor in bytes

INTERFACE, // INTERFACE descriptor type

1, // Interface Number

0, // Alternate Setting Number

2, // Number of endpoints in this intf

DATA_INTF, // Class code

0, // Subclass code

NO_PROTOCOL, // Protocol code

0, // Interface string index

 

/* Endpoint Descriptors for interface 2*/

//sizeof(USB_EP_DSC),DSC_EP,_EP03_OUT,_BULK,CDC_BULK_OUT_EP_SIZE,0x00,

//outgoing EP

7,

ENDPOINT,

EP3OUT,

_BULK,

CDC_BULK_OUT_EP_SIZEL,

CDC_BULK_OUT_EP_SIZEH,

0,

 

//sizeof(USB_EP_DSC),DSC_EP,_EP03_IN,_BULK,CDC_BULK_IN_EP_SIZE,0x00

//incoming EP

7,

ENDPOINT,

EP3IN,

_BULK,

CDC_BULK_IN_EP_SIZEL,

CDC_BULK_IN_EP_SIZEH,

0

 

 

};

// end of class specific descriptors

Link to post
Share on other sites

Hi Phil,

 

I have been editing and now have a modified Microchip source which compiles with BoostC in the SourceBoost IDE. If you wish me to e-mail / pass you a copy of the modified sources, please let me know. I think I may be able to do so via the forum's personal message system? It may save you a monster of an edit!

 

------------------------------------------------

 

First set of results are for the USB firmware and some of the demo user stuff, but none of the temperature stuff, just to get an idea of the memory requirements

 

With aggressive optimistation in both compiler and linker

 

Memory Usage Report

===================

RAM available:2048 bytes, used:475 bytes (23.2%), free:1573 bytes (76.8%),

Heap size:1573 bytes, Heap max single alloc:127 bytes

ROM available:32768 bytes, used:3427 bytes (10.5%), free:29341 bytes (89.5%)

 

------------------------------------------------

 

Second set of results are for the same as above except the calls to the stuff in user.* and temperature.* have been commented out, although compileed and included in the link, but optimised out by the linker, which gives:

 

With aggressive optimistation in both compiler and linker

 

RAM available:2048 bytes, used:474 bytes (23.2%), free:1574 bytes (76.8%),

Heap size:1574 bytes, Heap max single alloc:127 bytes

ROM available:32768 bytes, used:3031 bytes (9.3%), free:29737 bytes (90.7%)

 

------------------------------------------------

 

I have not had sufficient time to proceed further. I think the following are the main files to modify for a new project

 

 

usbdsc.c

Declares the descriptors and initialises them as required. modified for each project.

Huge comment section to be read!!!

 

 

usbmap.c

Defines all necessary endpoints from ep0 up until the maximum number of endpoints specified in usbcfg.h as macro MAX_EP_NUMBER, have been declared.

Huge comment section to be read!!!

 

 

usbcfg.h

Definitions for operational configuration (I think). I need to expand my short notes below.

 

0x00 , ep2 is CDC COMM

ep2Bi of length 8 bytes is CDC INT

 

0x01 , ep3 is CDC DATA

ep3B0 of length 64 bytes is CDC BULK OUT

ep3Bi of length 64 bytes is CDC BULK IN

 

 

Regards,

G

Link to post
Share on other sites

>>Memory Usage Report

>>===================

>>RAM available:2048 bytes, used:475 bytes (23.2%), free:1573 bytes (76.8%),

>>Heap size:1573 bytes, Heap max single alloc:127 bytes

>>ROM available:32768 bytes, used:3427 bytes (10.5%), free:29341 bytes (89.5%)

 

Well you've gotten futher than me to the point where it links! I've PM'd you with email details. Just point me to any areas you want me to work on and I'll get to it.

 

Phil

Link to post
Share on other sites
  • 1 year later...
Please could you share the code with me as well. I know it is 2 years down the line - but everyone seems to get stuck at this point.

 

Your help will appreciated.

 

Likewise, I'd be interested in this - it's for me to start with USB as well. Funny how these things go in waves...

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...