-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for one-way FPGA advertisement pin
Apollo firmware will keep the USB switch handed over to the FPGA as long as the gateware keeps advertising its usage through the FPGA_ADV pin (FPGA_INT). When these messages stop arriving, Apollo will take over the port. If the advertisement resumes, the port will not be handed off to the FPGA again until a "reconfiguration" (0xc0) or a "honor FPGA_ADV" (0xc2) vendor request arrives. Additionally, the host tools can request a gateware to hand off the USB port to Apollo if the necessary request is available. - firmware: Adds HONOR_FPGA_ADV vendor request (0xc2) - apollo_fpga: Use REQUEST_APOLLO_ADV_STOP (0xf0) to enumerate Apollo
- Loading branch information
Showing
10 changed files
with
338 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
# Copyright (c) 2020 Great Scott Gadgets <[email protected]> | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
import os | ||
import time | ||
import usb.core | ||
|
||
from .jtag import JTAGChain | ||
|
@@ -32,13 +34,18 @@ def create_ila_frontend(ila, *, use_cs_multiplexing=False): | |
class ApolloDebugger: | ||
""" Class representing a link to an Apollo Debug Module. """ | ||
|
||
# This VID/PID pair is unique to development LUNA boards. | ||
# TODO: potentially change this to an OpenMoko VID, like other LUNA boards. | ||
USB_IDS = [(0x1d50, 0x615c), (0x16d0, 0x05a5)] | ||
# VID/PID pairs for Apollo and gateware. | ||
APOLLO_USB_IDS = [(0x1d50, 0x615c)] | ||
LUNA_USB_IDS = [(0x1d50, 0x615b)] | ||
|
||
# If we have a LUNA_USB_IDS variable, we can use it to find the LUNA device. | ||
if os.getenv("LUNA_USB_IDS"): | ||
LUNA_USB_IDS += tuple([int(x, 16) for x in os.getenv("LUNA_USB_IDS").split(":")]) | ||
|
||
REQUEST_SET_LED_PATTERN = 0xa1 | ||
REQUEST_RECONFIGURE = 0xc0 | ||
REQUEST_FORCE_FPGA_OFFLINE = 0xc1 | ||
REQUEST_HONOR_FPGA_ADV = 0xc2 | ||
|
||
LED_PATTERN_IDLE = 500 | ||
LED_PATTERN_UPLOAD = 50 | ||
|
@@ -69,11 +76,30 @@ def __init__(self): | |
""" Sets up a connection to the debugger. """ | ||
|
||
# Try to create a connection to our Apollo debug firmware. | ||
for vid, pid in self.USB_IDS: | ||
for vid, pid in self.APOLLO_USB_IDS: | ||
device = usb.core.find(idVendor=vid, idProduct=pid) | ||
if device is not None: | ||
break | ||
|
||
# If no Apollo VID/PID is found but a gateware VID/PID is, we request the gateware | ||
# to liberate the USB port. In devices with a shared port, this effectively hands off | ||
# the USB port to Apollo. | ||
find_again = False | ||
if device is None: | ||
for vid, pid in self.LUNA_USB_IDS: | ||
fpga_device = usb.core.find(idVendor=vid, idProduct=pid) | ||
if fpga_device is not None: | ||
find_again = self._request_handoff_to_apollo(fpga_device) | ||
break | ||
|
||
# If we requested a handoff, retry the connection to Apollo debug firmware | ||
if find_again: | ||
time.sleep(2) # wait for Apollo enumeration | ||
for vid, pid in self.APOLLO_USB_IDS: | ||
device = usb.core.find(idVendor=vid, idProduct=pid) | ||
if device is not None: | ||
break | ||
|
||
# If we couldn't find an Apollo device, bail out. | ||
if device is None: | ||
raise DebuggerNotFound() | ||
|
@@ -93,6 +119,17 @@ def __init__(self): | |
self.registers = self.spi | ||
|
||
|
||
@staticmethod | ||
def _request_handoff_to_apollo(self, device): | ||
""" Requests the gateware to liberate the USB port. """ | ||
REQUEST_APOLLO_ADV_STOP = 0xF0 | ||
request_type = usb.ENDPOINT_OUT | usb.RECIP_DEVICE | usb.TYPE_VENDOR | ||
try: | ||
device.ctrl_transfer(request_type, REQUEST_APOLLO_ADV_STOP, timeout=5000) | ||
except usb.USBError: | ||
return False | ||
return True | ||
|
||
|
||
def detect_connected_version(self): | ||
""" Attempts to determine the revision of the connected hardware. | ||
|
@@ -241,6 +278,13 @@ def force_fpga_offline(self): | |
except usb.core.USBError: | ||
pass | ||
|
||
def honor_fpga_adv(self): | ||
""" Tell Apollo to honor requests from FPGA_ADV again. Useful after reconfiguration. """ | ||
try: | ||
self.out_request(self.REQUEST_HONOR_FPGA_ADV) | ||
except usb.core.USBError: | ||
pass | ||
|
||
def close(self): | ||
""" Closes the USB device so it can be reused, possibly by another ApolloDebugger """ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.