Dynamically Changing Descriptor

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Discussing the issue of multiple devices with my customer.  They suggested that we could put jumpers or DIP switches on the board and change something in the descriptor to reflect the switch settings. 

   

I experimented trying to change the device descriptor in code at start up, but it didn't appear to show up in the descriptor received by the PC.  In main() after TD_Init(), I did the following:

   

*((BYTE *)DeviceDscr+16) = 0x55;

   

This should have changed the Serial Number.  I tried changing other offsets with no results on the PC side.  I also tried changing it in a couple of other places in the code.

   

I'm probably missing something obvious.

   

Bill

0 Likes
1 Reply
Anonymous
Not applicable

Hi Bill,

I have made an example project for you which demonstrates how you can change the device descriptor dynamically.I have tested at my end using Keil compiler and its working fine.

I took the basic bulkloop example and did the following changes:
1. Added another device descriptor with name DeviceDscr1, and changed the vid and serial number in file dscr.a51.

2. In dscr.a51 also added DeviceDscr1 in the public definition(Line 32).
3. Declared DeviceDscr1 as extern in fx2.h(Line 297).
4. In fw.c I added this code
if( flag )
pDeviceDscr = (WORD)&DeviceDscr;
else
pDeviceDscr = (WORD)&DeviceDscr1;
so this will choose the descriptor according to the flag value.Instead you can add your logic to choose the descriptor and you can add more device descriptors similarly.

I have attached the project, Please let me know if you can see it working at your end.

Regards,
Shubham

0 Likes