diff --git a/lambdalib/cores/usb/generic_device.py b/lambdalib/cores/usb/generic_device.py index a673274..3b2720e 100644 --- a/lambdalib/cores/usb/generic_device.py +++ b/lambdalib/cores/usb/generic_device.py @@ -34,6 +34,7 @@ def __init__(self, pins, max_packet_size=None, with_cdc=True, with_microsoft_os_1_0=False, + force_contiguous_blockram=False, **kwargs): self.pins = pins @@ -61,6 +62,7 @@ def __init__(self, pins, self.control_ep_handlers = [] self.with_cdc = with_cdc self.with_microsoft_os_1_0 = with_microsoft_os_1_0 + self.force_contiguous_blockram = force_contiguous_blockram self.kwargs = kwargs @@ -116,6 +118,16 @@ def create_descriptors(self): def add_microsoft_os_1_0(self, descriptors): """ Add Microsoft OS 1.0 descriptors for Windows compatibility. """ + if self.force_contiguous_blockram: + # This is a workaround for LUNA GetDescriptorHandlerBlock + # that only supports contiguous indexes for its ROM layout. + # We create fake descriptors as padding, to force BSRAM allocation + # for designs where building a non contiguous descriptor in + # LUTRAM is not an option (too many resources wasted) + # but we can spare some more BSRAM blocks. + while descriptors._next_string_index != 0xee: + descriptors.get_index_for_string(str(descriptors._next_string_index)) + descriptors.add_descriptor(get_string_descriptor("MSFT100\xee"), index=0xee) msft_descriptors = MicrosoftOS10DescriptorCollection() @@ -161,7 +173,7 @@ def elaborate(self, platform): descriptors, # Windows compatible descriptors cannot be build in block ram # because MSFT string at index 0xee is not contiguous. - avoid_blockram=self.with_microsoft_os_1_0, + avoid_blockram=self.with_microsoft_os_1_0 and not self.force_contiguous_blockram, ) # Add optional custom requests handlers (vendor)