From 82f4e1281d1918778508594c344eb6bce8e8af82 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Tue, 14 May 2024 20:52:21 +0100 Subject: [PATCH 1/6] Change manufacturer string from "LUNA" to "Cynthion Project". --- cynthion/python/src/gateware/analyzer/top.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cynthion/python/src/gateware/analyzer/top.py b/cynthion/python/src/gateware/analyzer/top.py index 9ca4be36..92054d83 100644 --- a/cynthion/python/src/gateware/analyzer/top.py +++ b/cynthion/python/src/gateware/analyzer/top.py @@ -160,7 +160,7 @@ def create_descriptors(self): d.idVendor = USB_VENDOR_ID d.idProduct = USB_PRODUCT_ID - d.iManufacturer = "LUNA" + d.iManufacturer = "Cynthion Project" d.iProduct = "USB Analyzer" d.iSerialNumber = "[autodetect serial here]" d.bcdDevice = 0.02 From 16ecadb4dd9f3faf125d83852fea3b9e24626672 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Tue, 14 May 2024 20:52:46 +0100 Subject: [PATCH 2/6] Use serial number from ECP5 configuration flash. --- cynthion/python/src/gateware/analyzer/top.py | 29 ++++++++++---------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/cynthion/python/src/gateware/analyzer/top.py b/cynthion/python/src/gateware/analyzer/top.py index 92054d83..2d82a421 100644 --- a/cynthion/python/src/gateware/analyzer/top.py +++ b/cynthion/python/src/gateware/analyzer/top.py @@ -16,22 +16,23 @@ from datetime import datetime from enum import IntEnum, IntFlag -from amaranth import Signal, Elaboratable, Module -from amaranth.build.res import ResourceError -from usb_protocol.emitters import DeviceDescriptorCollection -from usb_protocol.types import USBRequestType +from amaranth import Signal, Elaboratable, Module +from amaranth.build.res import ResourceError +from usb_protocol.emitters import DeviceDescriptorCollection +from usb_protocol.types import USBRequestType -from luna.usb2 import USBDevice, USBStreamInEndpoint -from luna import top_level_cli +from luna.usb2 import USBDevice, USBStreamInEndpoint +from luna import top_level_cli -from luna.gateware.usb.request.control import ControlRequestHandler -from luna.gateware.usb.stream import USBInStreamInterface -from luna.gateware.stream.generator import StreamSerializer -from luna.gateware.utils.cdc import synchronize -from luna.gateware.architecture.car import LunaECP5DomainGenerator -from luna.gateware.interface.ulpi import UTMITranslator +from luna.gateware.usb.request.control import ControlRequestHandler +from luna.gateware.usb.stream import USBInStreamInterface +from luna.gateware.stream.generator import StreamSerializer +from luna.gateware.utils.cdc import synchronize +from luna.gateware.architecture.car import LunaECP5DomainGenerator +from luna.gateware.architecture.flash_sn import ECP5FlashUIDStringDescriptor +from luna.gateware.interface.ulpi import UTMITranslator -from .analyzer import USBAnalyzer +from .analyzer import USBAnalyzer import cynthion @@ -162,7 +163,7 @@ def create_descriptors(self): d.iManufacturer = "Cynthion Project" d.iProduct = "USB Analyzer" - d.iSerialNumber = "[autodetect serial here]" + d.iSerialNumber = ECP5FlashUIDStringDescriptor d.bcdDevice = 0.02 d.bNumConfigurations = 1 From 153532aa07edc0cce2d2595fa31de39a30dcddcb Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Tue, 14 May 2024 20:56:02 +0100 Subject: [PATCH 3/6] Add version numbers to all Cynthion platforms. --- cynthion/python/src/gateware/platform/cynthion_r0_1.py | 2 +- cynthion/python/src/gateware/platform/cynthion_r0_2.py | 2 +- cynthion/python/src/gateware/platform/cynthion_r0_3.py | 2 +- cynthion/python/src/gateware/platform/cynthion_r0_4.py | 2 +- cynthion/python/src/gateware/platform/cynthion_r0_5.py | 2 +- cynthion/python/src/gateware/platform/cynthion_r0_6.py | 4 ++-- cynthion/python/src/gateware/platform/cynthion_r0_7.py | 4 ++-- cynthion/python/src/gateware/platform/cynthion_r1_0.py | 4 ++-- cynthion/python/src/gateware/platform/cynthion_r1_1.py | 4 ++-- cynthion/python/src/gateware/platform/cynthion_r1_2.py | 4 ++-- cynthion/python/src/gateware/platform/cynthion_r1_3.py | 4 ++-- cynthion/python/src/gateware/platform/cynthion_r1_4.py | 4 ++-- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/cynthion/python/src/gateware/platform/cynthion_r0_1.py b/cynthion/python/src/gateware/platform/cynthion_r0_1.py index 03b3766c..18c053a0 100644 --- a/cynthion/python/src/gateware/platform/cynthion_r0_1.py +++ b/cynthion/python/src/gateware/platform/cynthion_r0_1.py @@ -37,7 +37,7 @@ class CynthionPlatformRev0D1(CynthionPlatform): """ Board description for the pre-release r0.1 revision of Cynthion. """ name = "Cynthion r0.1" - + version = (0, 1) device = "LFE5U-12F" package = "BG256" diff --git a/cynthion/python/src/gateware/platform/cynthion_r0_2.py b/cynthion/python/src/gateware/platform/cynthion_r0_2.py index ffaf64e6..e1c3172b 100644 --- a/cynthion/python/src/gateware/platform/cynthion_r0_2.py +++ b/cynthion/python/src/gateware/platform/cynthion_r0_2.py @@ -23,7 +23,7 @@ class CynthionPlatformRev0D2(CynthionPlatform): """ Board description for the pre-release r0.2 revision of Cynthion. """ name = "Cynthion r0.2" - + version = (0, 2) device = "LFE5U-12F" package = "BG256" speed = os.getenv("ECP5_SPEED_GRADE", "8") diff --git a/cynthion/python/src/gateware/platform/cynthion_r0_3.py b/cynthion/python/src/gateware/platform/cynthion_r0_3.py index 5a6f86f2..76400d53 100644 --- a/cynthion/python/src/gateware/platform/cynthion_r0_3.py +++ b/cynthion/python/src/gateware/platform/cynthion_r0_3.py @@ -23,7 +23,7 @@ class CynthionPlatformRev0D3(CynthionPlatform): """ Board description for the pre-release r0.3 revision of Cynthion. """ name = "Cynthion r0.3" - + version = (0, 3) device = "LFE5U-12F" package = "BG256" speed = os.getenv("ECP5_SPEED_GRADE", "8") diff --git a/cynthion/python/src/gateware/platform/cynthion_r0_4.py b/cynthion/python/src/gateware/platform/cynthion_r0_4.py index 170e9120..b4a33bdf 100644 --- a/cynthion/python/src/gateware/platform/cynthion_r0_4.py +++ b/cynthion/python/src/gateware/platform/cynthion_r0_4.py @@ -23,7 +23,7 @@ class CynthionPlatformRev0D4(CynthionPlatform): """ Board description for the pre-release r0.4 revision of Cynthion. """ name = "Cynthion r0.4" - + version = (0, 4) device = "LFE5U-12F" package = "BG256" speed = os.getenv("ECP5_SPEED_GRADE", "8") diff --git a/cynthion/python/src/gateware/platform/cynthion_r0_5.py b/cynthion/python/src/gateware/platform/cynthion_r0_5.py index 16438395..c1bf2941 100644 --- a/cynthion/python/src/gateware/platform/cynthion_r0_5.py +++ b/cynthion/python/src/gateware/platform/cynthion_r0_5.py @@ -23,7 +23,7 @@ class CynthionPlatformRev0D5(CynthionPlatform): """ Board description for the pre-release r0.5 revision of Cynthion. """ name = "Cynthion r0.5" - + version = (0, 5) device = "LFE5U-12F" package = "BG256" speed = os.getenv("ECP5_SPEED_GRADE", "8") diff --git a/cynthion/python/src/gateware/platform/cynthion_r0_6.py b/cynthion/python/src/gateware/platform/cynthion_r0_6.py index d200b780..1ced953f 100644 --- a/cynthion/python/src/gateware/platform/cynthion_r0_6.py +++ b/cynthion/python/src/gateware/platform/cynthion_r0_6.py @@ -18,7 +18,7 @@ class CynthionPlatformRev0D6(CynthionPlatform): """ Board description for Cynthion r0.6 """ name = "Cynthion r0.6" - + version = (0, 6) device = "LFE5U-12F" package = "BG256" speed = os.getenv("ECP5_SPEED_GRADE", "8") @@ -185,4 +185,4 @@ class CynthionPlatformRev0D6(CynthionPlatform): usb_device_hooks = { "control_phy_0": control_phy_hook - } \ No newline at end of file + } diff --git a/cynthion/python/src/gateware/platform/cynthion_r0_7.py b/cynthion/python/src/gateware/platform/cynthion_r0_7.py index a4d0420e..3b439b29 100644 --- a/cynthion/python/src/gateware/platform/cynthion_r0_7.py +++ b/cynthion/python/src/gateware/platform/cynthion_r0_7.py @@ -18,7 +18,7 @@ class CynthionPlatformRev0D7(CynthionPlatform): """ Board description for Cynthion r0.7 """ name = "Cynthion r0.7" - + version = (0, 7) device = "LFE5U-25F" package = "BG256" speed = os.getenv("ECP5_SPEED_GRADE", "8") @@ -185,4 +185,4 @@ class CynthionPlatformRev0D7(CynthionPlatform): usb_device_hooks = { "control_phy_0": control_phy_hook - } \ No newline at end of file + } diff --git a/cynthion/python/src/gateware/platform/cynthion_r1_0.py b/cynthion/python/src/gateware/platform/cynthion_r1_0.py index 7fb8e974..34abe40f 100644 --- a/cynthion/python/src/gateware/platform/cynthion_r1_0.py +++ b/cynthion/python/src/gateware/platform/cynthion_r1_0.py @@ -18,7 +18,7 @@ class CynthionPlatformRev1D0(CynthionPlatform): """ Board description for Cynthion r1.0 """ name = "Cynthion r1.0" - + version = (1, 0) device = "LFE5U-12F" package = "BG256" speed = os.getenv("ECP5_SPEED_GRADE", "8") @@ -185,4 +185,4 @@ class CynthionPlatformRev1D0(CynthionPlatform): usb_device_hooks = { "control_phy_0": control_phy_hook - } \ No newline at end of file + } diff --git a/cynthion/python/src/gateware/platform/cynthion_r1_1.py b/cynthion/python/src/gateware/platform/cynthion_r1_1.py index 646a9c44..68bd6bad 100644 --- a/cynthion/python/src/gateware/platform/cynthion_r1_1.py +++ b/cynthion/python/src/gateware/platform/cynthion_r1_1.py @@ -18,7 +18,7 @@ class CynthionPlatformRev1D1(CynthionPlatform): """ Board description for Cynthion r1.1 """ name = "Cynthion r1.1" - + version = (1, 1) device = "LFE5U-12F" package = "BG256" speed = os.getenv("ECP5_SPEED_GRADE", "8") @@ -185,4 +185,4 @@ class CynthionPlatformRev1D1(CynthionPlatform): usb_device_hooks = { "control_phy_0": control_phy_hook - } \ No newline at end of file + } diff --git a/cynthion/python/src/gateware/platform/cynthion_r1_2.py b/cynthion/python/src/gateware/platform/cynthion_r1_2.py index f972d054..c2f2da23 100644 --- a/cynthion/python/src/gateware/platform/cynthion_r1_2.py +++ b/cynthion/python/src/gateware/platform/cynthion_r1_2.py @@ -18,7 +18,7 @@ class CynthionPlatformRev1D2(CynthionPlatform): """ Board description for Cynthion r1.2 """ name = "Cynthion r1.2" - + version = (1, 2) device = "LFE5U-12F" package = "BG256" speed = os.getenv("ECP5_SPEED_GRADE", "8") @@ -197,4 +197,4 @@ class CynthionPlatformRev1D2(CynthionPlatform): usb_device_hooks = { "control_phy_0": control_phy_hook - } \ No newline at end of file + } diff --git a/cynthion/python/src/gateware/platform/cynthion_r1_3.py b/cynthion/python/src/gateware/platform/cynthion_r1_3.py index 08c91358..d4356ac8 100644 --- a/cynthion/python/src/gateware/platform/cynthion_r1_3.py +++ b/cynthion/python/src/gateware/platform/cynthion_r1_3.py @@ -18,7 +18,7 @@ class CynthionPlatformRev1D3(CynthionPlatform): """ Board description for Cynthion r1.3 """ name = "Cynthion r1.3" - + version = (1, 3) device = "LFE5U-12F" package = "BG256" speed = os.getenv("ECP5_SPEED_GRADE", "8") @@ -197,4 +197,4 @@ class CynthionPlatformRev1D3(CynthionPlatform): usb_device_hooks = { "control_phy_0": control_phy_hook - } \ No newline at end of file + } diff --git a/cynthion/python/src/gateware/platform/cynthion_r1_4.py b/cynthion/python/src/gateware/platform/cynthion_r1_4.py index 36606ac1..7d314a4b 100644 --- a/cynthion/python/src/gateware/platform/cynthion_r1_4.py +++ b/cynthion/python/src/gateware/platform/cynthion_r1_4.py @@ -18,7 +18,7 @@ class CynthionPlatformRev1D4(CynthionPlatform): """ Board description for Cynthion r1.4 """ name = "Cynthion r1.4" - + version = (1, 4) device = "LFE5U-12F" package = "BG256" speed = os.getenv("ECP5_SPEED_GRADE", "8") @@ -194,4 +194,4 @@ class CynthionPlatformRev1D4(CynthionPlatform): usb_device_hooks = { "control_phy_0": control_phy_hook - } \ No newline at end of file + } From f07cec444394db6fd613e23311ff37dbde747893 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Tue, 14 May 2024 20:57:33 +0100 Subject: [PATCH 4/6] Set bcdDevice to platform version. --- cynthion/python/src/gateware/analyzer/top.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cynthion/python/src/gateware/analyzer/top.py b/cynthion/python/src/gateware/analyzer/top.py index 2d82a421..157da902 100644 --- a/cynthion/python/src/gateware/analyzer/top.py +++ b/cynthion/python/src/gateware/analyzer/top.py @@ -146,9 +146,10 @@ class USBAnalyzerApplet(Elaboratable): - DRAM backing for analysis """ - def create_descriptors(self): + def create_descriptors(self, platform): """ Create the descriptors we want to use for our device. """ + major, minor = platform.version descriptors = DeviceDescriptorCollection() # @@ -164,7 +165,7 @@ def create_descriptors(self): d.iManufacturer = "Cynthion Project" d.iProduct = "USB Analyzer" d.iSerialNumber = ECP5FlashUIDStringDescriptor - d.bcdDevice = 0.02 + d.bcdDevice = major + (minor * 0.01) d.bNumConfigurations = 1 @@ -239,7 +240,7 @@ def elaborate(self, platform): m.submodules.usb = usb = USBDevice(bus=uplink_ulpi) # Add our standard control endpoint to the device. - descriptors = self.create_descriptors() + descriptors = self.create_descriptors(platform) control_endpoint = usb.add_standard_control_endpoint(descriptors) # Add our vendor request handler to the control endpoint. From b757bc1716c11e97ed814b7958ec192d1f3b10c7 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Tue, 14 May 2024 21:11:48 +0100 Subject: [PATCH 5/6] Set additional fields of interface descriptor. --- cynthion/python/src/gateware/analyzer/top.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cynthion/python/src/gateware/analyzer/top.py b/cynthion/python/src/gateware/analyzer/top.py index 157da902..42b7befb 100644 --- a/cynthion/python/src/gateware/analyzer/top.py +++ b/cynthion/python/src/gateware/analyzer/top.py @@ -175,6 +175,10 @@ def create_descriptors(self, platform): with c.InterfaceDescriptor() as i: i.bInterfaceNumber = 0 + i.bInterfaceClass = 0xFF + i.bInterfaceSubclass = cynthion.shared.usb.bInterfaceSubClass.analyzer + i.bInterfaceProtocol = cynthion.shared.usb.bInterfaceProtocol.analyzer + i.iInterface = "USB Analyzer" with i.EndpointDescriptor() as e: e.bEndpointAddress = BULK_ENDPOINT_ADDRESS From edf9a518e50d0e9e89d83b18475203017a69961f Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Tue, 14 May 2024 23:16:43 +0100 Subject: [PATCH 6/6] Handle analyzer vendor requests addressed to interface, not device. --- cynthion/python/src/gateware/analyzer/top.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cynthion/python/src/gateware/analyzer/top.py b/cynthion/python/src/gateware/analyzer/top.py index 42b7befb..3eaf51f9 100644 --- a/cynthion/python/src/gateware/analyzer/top.py +++ b/cynthion/python/src/gateware/analyzer/top.py @@ -19,7 +19,7 @@ from amaranth import Signal, Elaboratable, Module from amaranth.build.res import ResourceError from usb_protocol.emitters import DeviceDescriptorCollection -from usb_protocol.types import USBRequestType +from usb_protocol.types import USBRequestType, USBRequestRecipient from luna.usb2 import USBDevice, USBStreamInEndpoint from luna import top_level_cli @@ -94,8 +94,11 @@ def elaborate(self, platform): m.submodules.transmitter = transmitter = \ StreamSerializer(data_length=1, domain="usb", stream_type=USBInStreamInterface, max_length_width=1) - # Handle vendor requests - with m.If(setup.type == USBRequestType.VENDOR): + # Handle vendor requests to our interface. + with m.If( + (setup.type == USBRequestType.VENDOR) & + (setup.recipient == USBRequestRecipient.INTERFACE) & + (setup.index == 0)): m.d.comb += interface.claim.eq( (setup.request == USBAnalyzerVendorRequests.GET_STATE) |