Skip to content

Commit

Permalink
Merge pull request #183 from xobs/usb-to-0x43
Browse files Browse the repository at this point in the history
Use 0x43/0xc3 for USB bridge magic packet
  • Loading branch information
enjoy-digital committed May 21, 2019
2 parents 10670e2 + 014c950 commit 3a72688
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions litex/tools/remote/comm_usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
# The SETUP packet looks like this:
#
# +----+----+----------+----+----+
# | C0 | 00 | ADDRESS | 04 | 00 | read packet
# | C3 | 00 | ADDRESS | 04 | 00 | read packet
# +----+----+----------+----+----+
# 1 1 4 1 1
#
# +----+----+----------+----+----+
# | 40 | 00 | ADDRESS | 04 | 00 | write packet
# | 43 | 00 | ADDRESS | 04 | 00 | write packet
# +----+----+----------+----+----+
# 1 1 4 1 1
#
Expand All @@ -37,8 +37,8 @@
# byte indicates what type of packet it is, and that it is a Wishbone Bridge
# packet. This is the value "0x40" (VENDOR type packet destined for DEVICE)
# with the "Data Phase Transfer" bit either set or cleared:
# - Read: 0xc0
# - Write: 0x40
# - Read: 0xc3
# - Write: 0x43
#
# The next byte is bRequest, which in the current implementation is unused.
# Set this value to 0.
Expand Down Expand Up @@ -103,15 +103,22 @@ def read(self, addr, length=None):

def usb_read(self, addr, depth=0):
try:
value = self.dev.ctrl_transfer(bmRequestType=0xc0,
value = self.dev.ctrl_transfer(bmRequestType=0xc3,
bRequest=0x00,
wValue=addr & 0xffff,
wIndex=(addr >> 16) & 0xffff,
data_or_wLength=4)
if value is None:
raise TypeError
return int.from_bytes(value, byteorder="little")
except (usb.core.USBError, TypeError):
except usb.core.USBError as e:
if e.errno == 13:
print("Access Denied. Maybe try using sudo?")
self.close()
self.open()
if depth < self.MAX_RECURSION_COUNT:
return self.usb_read(addr, depth+1)
except TypeError:
self.close()
self.open()
if depth < self.MAX_RECURSION_COUNT:
Expand All @@ -127,15 +134,17 @@ def write(self, addr, data):

def usb_write(self, addr, value, depth=0):
try:
self.dev.ctrl_transfer(bmRequestType=0x40, bRequest=0x00,
value = self.dev.ctrl_transfer(bmRequestType=0x43, bRequest=0x00,
wValue=addr & 0xffff,
wIndex=(addr >> 16) & 0xffff,
data_or_wLength=bytes([(value >> 0) & 0xff,
(value >> 8) & 0xff,
(value >> 16) & 0xff,
(value >> 24) & 0xff]
), timeout=None)
except usb.core.USBError:
except usb.core.USBError as e:
if e.errno == 13:
print("Access Denied. Maybe try using sudo?")
self.close()
self.open()
if depth < self.MAX_RECURSION_COUNT:
Expand Down

0 comments on commit 3a72688

Please sign in to comment.