Crossworks implementation of USB bootloader

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Crossworks implementation of USB bootloader

357 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by williamjsell on Fri Jan 25 12:11:05 MST 2013
firstly, I searched to see if there was a port of the AN10866 USB bootloader over to Rowley Crossworks in the public domain, but no luck here, so if anyone has done this... :) ...so figured this should not be too hard, but I ran into a couple of snags.  The keyword __packed is not supported by Crossworks, so I used the #pragma pack(1), which should work the same way.  I then ran into a code issue. 

the declaration:

USB_COMMON_DESCRIPTOR *pD;

the initialization:

pD = (USB_COMMON_DESCRIPTOR *)USB_ConfigDescriptor;

The Keil compiler builds fine, but Crossworks bitches on this statement:

(uint8_t *)pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;

with the message

"lvalue required as left operand of assignment"

Makes sort of sense, it wants pD to reference a member of the structure it points to, even though it is being cast to uint8_t.  Looks like the author is attempting to increment the pointer by wTotalLength.  I am a little lost here.  Firstly, looks like it should work, but I tried several different iterations and I get the same message...any ideas?

thanks
Labels (1)
0 Kudos
2 Replies

315 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by williamjsell on Mon Jan 28 10:30:15 MST 2013
no, that did not work.  Removing the cast of (uint8_t *) works, but is this the intent of the author?  The line

pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength;

compiles, but this is not how I would have done this.  Surely it would have been safer to have written

pD += sizeof(USB_CONFIGURATION_DESCRIPTOR);

it is unclear is wTotalLength is referring to the size of the structure, or to some offset which the programmer has not made clear to the reader.  I will keep digging and post my findings...

Thanks

-Bill
0 Kudos

315 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wmues on Sun Jan 27 04:50:56 MST 2013
Bill,

you wrote:
"Makes sort of sense, it wants pD to reference a member of the structure it points to, even though it is being cast to uint8_t."

No, it is cast to "uint8_t *".

Have you tried "((uint8_t *)pD) += "?

0 Kudos