dynamic product ids?

30 views
Skip to first unread message

ulao

unread,
Aug 20, 2021, 8:23:48 PM8/20/21
to LUFA Library Support List

How can I use product ID dynamically?

.VendorID is read only..

I'm well aware that USB is static, but I set a product ID based on eeprom at initialization. I need to be able to set this dynamically.


ulao

unread,
Aug 21, 2021, 1:14:10 PM8/21/21
to LUFA Library Support List

so figured most of it out (I think) but the device does not enumerate so I'm missing something.

 

I swapped theses guys out

     #define USE_RAM_DESCRIPTORS
//          #define USE_FLASH_DESCRIPTORS

 

then change

 const USB_Descriptor_Device_t PROGMEM  DeviceDescriptor

ro

  USB_Descriptor_Device_t  DeviceDescriptor  and defined it in the h file.

 

and that allows this

DeviceDescriptor.ProductID = 0x16D0 ;

 

but it does not enumerate.

Dean Camera

unread,
Aug 23, 2021, 4:36:10 AM8/23/21
to lufa-s...@googlegroups.com, ulao

That's correct; you need to enable USE_RAM_DESCRIPTORS, as well as remove the `const` and `PROGMEM` qualifiers on all the descriptors (if you want to retain some of them in Flash, you can undefine all the `USE_*_DESCRIPTORS` options and instead indicate the memory space in the `CALLBACK_USB_GetDescriptor` descriptor callback via the additional output parameter that will be enabled.

The last step for using all-RAM descriptors, which I think you may have missed, is to remove the `pgm_read_byte()` calls inside `CALLBACK_USB_GetDescriptor`. Currently it will still be trying to read the descriptor length from flash, rather than RAM. Just replace the `pgm_read_byte(&SomeDescriptor.Header.Size);` instances with plain `SomeDescriptor.Header.Size;`.

Cheers,

- Dean

--
You received this message because you are subscribed to the Google Groups "LUFA Library Support List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lufa-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lufa-support/249b0c78-bce7-4836-b0c1-fc55575762a1n%40googlegroups.com.

ulao

unread,
Aug 23, 2021, 1:30:16 PM8/23/21
to LUFA Library Support List
few paths still unclear for me I'm afraid but I made these changes.

switch (DescriptorType)
    {
        case DTYPE_Device:
            Address = &DeviceDescriptor;
            Size    = sizeof(USB_Descriptor_Configuration_t);
            break;
        case DTYPE_Configuration:
            Address = &ConfigurationDescriptor;
            Size    = sizeof(ConfigurationDescriptor);
            break;
        case DTYPE_String:
            switch (DescriptorNumber)
            {
                case 0x00:
                    Address = &LanguageString;
                    Size    = LanguageString.Header.Size;//pgm_read_byte(&LanguageString.Header.Size);
                    break;
                case 0x01:
                    Address = &ManufacturerString;
                    Size    = ManufacturerString.Header.Size;//pgm_read_byte(&ManufacturerString.Header.Size);
                    break;
                case 0x02://todo no need, it does not show up anyways.
                    Address = &ProductString;
                    Size    = ProductString.Header.Size;
                    break;
                case 0x03:
                    Address = &VersionString;
                    Size    = VersionString.Header.Size;//pgm_read_byte(&VersionString.Header.Size);
                    break;
            }

            break;
        case DTYPE_HID:
            Address = &ConfigurationDescriptor.HID_JoystickHID;
            Size    = sizeof(USB_HID_Descriptor_HID_t);
            break;
        case DTYPE_Report:
            Address = &JoystickReport;
            Size    = sizeof(JoystickReport);
            break;
    }

    *DescriptorAddress = Address;


unclear changes.
do I need this in the make file? -DUSE_RAM_DESCRIPTORS



" qualifiers on all the descriptors" As in all that follow DeviceDescriptor, or does the ConfigurationDescriptor and HIDReport need to follow.



can I still define DeviceDescriptor like I was using

 USB_Descriptor_Device_t  DeviceDescriptor =
{
    .Header                 = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
.................
    .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
};

and then just redefine the parts I need?


Thx for the help. Hope to get this working soon.

ulao

unread,
Aug 23, 2021, 1:39:40 PM8/23/21
to LUFA Library Support List
"if you want to retain some of them in Flash, you can undefine all the `USE_*_DESCRIPTORS` options and instead indicate the memory space in the `CALLBACK_USB_GetDescriptor` descriptor callback via the additional output parameter that will be enabled. "

If you are saying that I need to use all descriptors the same way, like the strings also... then yeah, that going to make a mess. So if I undefined all the USE_*_DESCRIPTORS
//        #define USE_RAM_DESCRIPTORS
//        #define USE_FLASH_DESCRIPTORS
//        #define USE_EEPROM_DESCRIPTORS
then how would one example look in the CALLBACK_USB_GetDescriptor ?

Address =  (*void) &DeviceDescriptor;
?

ulao

unread,
Aug 23, 2021, 3:02:31 PM8/23/21
to LUFA Library Support List
Ok, I see the call sign is changed now that I look at the code So I need to add the memory space

uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
                                    const uint8_t wIndex,
                                    const void** const DescriptorAddress, uint8_t* const DescriptorMemorySpace)

and how to I access the DeviceDescriptor?
DescriptorMemorySpace.someArrayName[10]= 0x0d09;

?

ulao

unread,
Aug 23, 2021, 3:39:43 PM8/23/21
to LUFA Library Support List

I see what you are talking about namespace-wise now.

1) remove all defines for USE_*_DESCRIPTORS
2) change memory allocation to USB_Descriptor_Device_t  DeviceDescriptor
3) write a new call sign in h and c const void** const DescriptorAddress, uint8_t* const DescriptorMemorySpace)
4) default to     *DescriptorMemorySpace = MEMSPACE_FLASH;
but where needed use *DescriptorMemorySpace = MEMSPACE_RAM;
5) update what I need i.e DeviceDescriptor.ProductID = 0x0d09;

works :)
Reply all
Reply to author
Forward
0 new messages