Jump to content

Structure Initialisation Problem


Recommended Posts

Bug description:

I have started to port the Microchip Technology USB firmware for CDC RS-232 design reference from Microchip C18 compiler to BoostC compiler. The example code which I have cut and pasted produces the following compiler error message:

error: incompatible types 'unsigned char' and 'struct USB_DEV_DSC'

I am not too sure what is happening, but it looks like the compiler is treating at least the first member of the struct variable 'device_dsc' as the same type as the structure itself.

 

Additionally the output shows both success and failure! Is 'main.c success' the output from the preprocessor and the 'failure' from the compiler?

 

Steps to reproduce:

Compile the example code.

 

Expected behaviour:

The compiler should initialise the structure correctly.

 

Is the problem 100% reproduceable:

With this example code yes.

 

IDE version : Any

Compiler : BoostC Compiler

Compiler version : 6.35

Target device : PIC18F4550

OS: : XP Pro SP2

 

Code example:

#include <system.h>

#define DSC_DEV        0x01
#define CDC_DEVICE     0x02
#define EP0_BUFF_SIZE  8   /* 8, 16, 32, or 64 */

typedef unsigned char byte;
typedef unsigned int  word;

typedef struct _USB_DEV_DSC
{
   byte bLength;       byte bDscType;      word bcdUSB;
   byte bDevCls;       byte bDevSubCls;    byte bDevProtocol;
   byte bMaxPktSize0;  word idVendor;      word idProduct;
   word bcdDevice;     byte iMFR;          byte iProduct;
   byte iSerialNum;    byte bNumCfg;
} USB_DEV_DSC;

USB_DEV_DSC device_dsc=
{
   sizeof(USB_DEV_DSC),    // Size of this descriptor in bytes
   DSC_DEV,                // DEVICE descriptor type
   0x0200,                 // USB Spec Release Number in BCD format
   CDC_DEVICE,             // Class Code
   0x00,                   // Subclass code
   0x00,                   // Protocol code
   EP0_BUFF_SIZE,          // Max packet size for EP0, see usbcfg.h
   0x04D8,                 // Vendor ID
   0x000A,                 // Product ID: CDC RS-232 Emulation Demo
   0x0000,                 // Device release number in BCD format
   0x01,                   // Manufacturer string index
   0x02,                   // Product string index
   0x00,                   // Device serial number string index
   0x01                    // Number of possible configurations
};

Compiler output:

Executing: "I:\Program Files\SourceBoost\boostc.pic18.exe" main.c -O0  -W1  -v  -t 18F4550
BoostC Optimizing C Compiler Version 6.35 (for PIC18 architecture)
http://www.sourceboost.com
Copyright(C) 2004-2006 Pavel Baranov
Copyright(C) 2004-2006 David Hobday
Licensed to me under Single user Full License for 1 node(s)
Limitations: PIC18 max code size:Unlimited, max RAM banks:Unlimited, Non commercial use only
main.c

Starting preprocessor: "I:\Program Files\SourceBoost\pp.exe" "I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c" -i "I:\Program Files\SourceBoost\include" -d _PIC18F4550 -la -c2 -o main.pp -v -d _BOOSTC -d _PIC18 
I:\Documents and Settings\Darkroom\My Documents\Projects\Microchip\Structs\main.c(25:2): error: incompatible types 'unsigned char' and 'struct USB_DEV_DSC'
main.c success

failure
BUILD FAILED: Tue Apr 18 21:10:35 2006

Link to post
Share on other sites

Beany,

 

Afraid data structure initialisation this way is not going to work :(

Use the following instead:

 

#include <system.h>

#define DSC_DEV        0x01
#define CDC_DEVICE     0x02
#define EP0_BUFF_SIZE  8   /* 8, 16, 32, or 64 */

typedef unsigned char byte;
typedef unsigned int  word;

typedef struct _USB_DEV_DSC
{
  byte bLength;       byte bDscType;      word bcdUSB;
  byte bDevCls;       byte bDevSubCls;    byte bDevProtocol;
  byte bMaxPktSize0;  word idVendor;      word idProduct;
  word bcdDevice;     byte iMFR;          byte iProduct;
  byte iSerialNum;    byte bNumCfg;
} USB_DEV_DSC;

USB_DEV_DSC device_dsc;

void main()
{
device_dsc.bLength = sizeof(USB_DEV_DSC); 	// Size of this descriptor in bytes
device_dsc.bDscType = DSC_DEV; 				// DEVICE descriptor type
...
}

 

Regards

Dave

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...