Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gateware.platform: add ApolloAdvertiser hook in boards with USB switch #23

Merged
merged 2 commits into from
Mar 7, 2024

Conversation

mndza
Copy link
Contributor

@mndza mndza commented Dec 4, 2023

control_phy_hook is called during USBDevice elaboration and:

  • Adds ApolloAdvertiser submodule.
  • Modifies the device descriptor to add an additional interface with bInterfaceClass=0xFF and bInterfaceSubclass=0 (Apollo interface).
  • Adds request handler with that interface as recipient for stopping advertisement.

Merge in block with:

@martinling
Copy link
Member

martinling commented Feb 15, 2024

This needs a quick update to add the hook to the r1.4 platform.

However, even after making that change myself, this isn't currently working for me in cynthion-test.

The visible symptom is that when running a bitstream that uses the CONTROL port, I tell Apollo to honor_fpga_adv, and that request succeeds, but Apollo remains enumerated on the CONTROL port. However, when the bitstream is loaded from flash at reset, it does enumerate on the CONTROL port, which suggests the advertising mechanism is initially working.

I'm using current main/master branches of Apollo, LUNA and Cynthion with greatscottgadgets/apollo#22, greatscottgadgets/luna#225, greatscottgadgets/luna#226 and this PR merged, with the r1.4 platform patched to include the hook as per r1.3.

You should be able to reproduce this as follows (no Tycho required):

  1. Check out the update-dependencies branch of https://github.com/martinling/cynthion-test/ and update submodules.
  2. Edit the Makefile and set MAJOR and MINOR to match your Cynthion board.
  3. Delete firmware.bin and all the .bit files (these are prebuilt for r1.4).
  4. Run make firmware bitstreams to set up the environment and rebuild the binaries.
  5. Put Cynthion into Saturn-V mode and run environment/bin/fwup-util firmware.bin to flash Apollo.
  6. Run environment/bin/apollo flash with either analyzer.bit, or speedtest.bit, both of which use the CONTROL port.
  7. Press the RESET button.
  8. The FPGA enumerates on the CONTROL port.
  9. Press the PROGRAM button.
  10. Apollo enumerates on the CONTROL port.
  11. Run the following with environment/bin/python:
from apollo_fpga import ApolloDebugger
apollo = ApolloDebugger()
apollo.honor_fpga_adv()
  1. Apollo remains on the bus.

@mndza
Copy link
Contributor Author

mndza commented Feb 15, 2024

I think I have found the root cause of the problem.

We changed the behavior of the PROGRAM button in greatscottgadgets/apollo#28: when Apollo takes over the control port, it also unconfigures the FPGA. Consequently, honor_fpga_adv will simply do nothing because no message has been received in the current time window.

Could you try the following?

from apollo_fpga import ApolloDebugger
apollo = ApolloDebugger()
apollo.soft_reset()
apollo.honor_fpga_adv()

I did not test this properly after that merge because of my PCB issues with FPGA_ADV (a bad contact that I was unable to rectify).

`control_phy_hook` is called during `USBDevice` elaboration and:
- Adds `ApolloAdvertiser` submodule.
- Modifies the device descriptor to add an additional interface with
  `bInterfaceClass=0xFF` and `bInterfaceSubclass=0` (Apollo interface).
- Adds request handler with that interface as recipient for stopping
  advertisement.
@martinling
Copy link
Member

Could you try the following?

from apollo_fpga import ApolloDebugger
apollo = ApolloDebugger()
apollo.soft_reset()
apollo.honor_fpga_adv()

This isn't working either - Apollo stays enumerated. But if I push RESET, the bitstream loads from flash and enumerates.

Configuring a bitstream into RAM also doesn't work - the honor_fpga_adv call is there at the end of the configure_fpga command, but after starting the bitstream, Apollo stays enumerated. Yet the bitstream is definitely running, because in the case of speedtest.bit it enumerates on the other ports successfully. And if I write that bitstream to flash, Apollo hands CONTROL over to it on startup.

Copy link
Member

@martinling martinling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've resolved the above issues, and this is now being used successfully on the update-dependencies branch of the Cynthion factory test.

@mossmann mossmann merged commit f3b0453 into greatscottgadgets:main Mar 7, 2024
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants