Skip to content

Commit

Permalink
cores/usb/generic_device: option to force block ram allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
povauboin committed Sep 27, 2024
1 parent ad9a193 commit ce66607
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lambdalib/cores/usb/generic_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ce66607

Please sign in to comment.