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

docs: Cynthion documentation branch #33

Merged
merged 36 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3f9b5a9
docs: Set language for sphinx documentation configuration
antoinevg Jan 9, 2024
cf2cf04
docs: Bump sphinx_rtd_them to 2.0.0
antoinevg Jan 18, 2024
134515f
docs: Draft outline
antoinevg Jan 4, 2024
a2167ae
docs: Add safety information
antoinevg Jan 11, 2024
e04b520
docs: bring documentation file names in line with hackrf doc conventions
antoinevg Jan 19, 2024
3c9b2a1
docs: add information about facedancer examples
antoinevg Jan 19, 2024
297d4a8
docs: simplify facedancer example
antoinevg Feb 22, 2024
cf1f7e6
docs: add self-made hardware bringup guide
antoinevg Apr 24, 2024
6783837
docs: moved facedancer examples to facedancer docs
antoinevg May 8, 2024
72a88b0
docs: add introduction page and product diagrams
antoinevg May 8, 2024
f6849eb
docs: add connection diagrams
antoinevg May 8, 2024
5bb5cfd
docs: update safety information
antoinevg May 9, 2024
8ecf2a4
docs: clean up documentation organization
antoinevg May 9, 2024
4ab1a33
docs: split apollo information into its own page
antoinevg May 9, 2024
4cf221a
docs: add a hardware connection diagram to 'getting started with usbp…
antoinevg May 9, 2024
bce1a5a
docs: flesh out developer documentation
antoinevg May 10, 2024
d9c75a6
docs: set width of cynthion photo on index page
antoinevg May 13, 2024
8d6d568
docs: update Cynthion LED and button descriptions
antoinevg May 13, 2024
da76a17
docs: break developer gateware/firmware docs into separate pages
antoinevg May 13, 2024
3e99552
docs: add autosectionlabel plugin to sphinx configuration
antoinevg May 14, 2024
f3f0db0
docs: resolve all TODOs in the getting started section
antoinevg May 14, 2024
070631d
docs: update cli documentation to refer to cynthion rather than apollo
antoinevg May 23, 2024
434e2da
docs: drop reference to deprecated optional dependency 'gateware-soc'
antoinevg May 23, 2024
1554a77
docs: add upgrade instructions to getting started document
antoinevg Jun 5, 2024
f234271
docs: updated placeholder images with shoot samples
antoinevg Jun 6, 2024
88c6b9a
docs: update getting started and bringup guide
antoinevg Jun 26, 2024
ebb76e3
docs: add some examples for the docs to the cynthion python package
antoinevg Jun 26, 2024
d72f1e8
docs: update facedancer and usbproxy guides
antoinevg Jun 26, 2024
de28c3b
docs: add dfu-util instructions to bringup guide
antoinevg Jun 28, 2024
9128f04
docs: update 'cynthion -h' output
antoinevg Jun 28, 2024
f751c3a
docs: fix labels for connection diagrams
antoinevg Jun 28, 2024
c4c0f31
docs: resize cynthion images and convert to jpg
antoinevg Jun 28, 2024
5543e43
docs: update docs with review feedback
antoinevg Jun 28, 2024
d6c7f87
docs: update bringup guide bootloader lock instructions
antoinevg Jun 28, 2024
9855b41
docs: remove extraneous imports from documentation examples (tx @claui!)
antoinevg Jul 1, 2024
6bd03fd
docs: update docs with @claui's review feedback
antoinevg Jul 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cynthion/python/examples/facedancer-rubber-ducky.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import asyncio

from facedancer import main
from facedancer.devices.keyboard import USBKeyboardDevice

device = USBKeyboardDevice()

async def type_letters():
# Wait for device to connect
await asyncio.sleep(2)

# Type a string with the device
await device.type_string("echo hello, facedancer\n")

main(device, type_letters())
28 changes: 28 additions & 0 deletions cynthion/python/examples/facedancer-usbproxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
#
# This file is part of Facedancer.
#
""" USB Proxy example; forwards all USB transactions and logs them to the console. """

from facedancer import main

from facedancer.proxy import USBProxyDevice
from facedancer.filters import USBProxySetupFilters, USBProxyPrettyPrintFilter

# replace with the proxied device's information
ID_VENDOR = 0x1050
ID_PRODUCT = 0x0407


if __name__ == "__main__":
# create a USB Proxy Device
proxy = USBProxyDevice(idVendor=ID_VENDOR, idProduct=ID_PRODUCT)

# add a filter to forward control transfers between the target host and
# proxied device
proxy.add_filter(USBProxySetupFilters(proxy, verbose=0))

# add a filter to log USB transactions to the console
proxy.add_filter(USBProxyPrettyPrintFilter(verbose=5))

main(proxy)
1 change: 1 addition & 0 deletions docs/images/cynthion-bottom.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/images/cynthion-connections-facedancer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/images/cynthion-connections-host.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/images/cynthion-connections-packetry.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/images/cynthion-connections-usbproxy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/images/cynthion-front.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/images/cynthion-left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/images/cynthion-right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/images/cynthion-top.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/cynthion.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/cynthion.png
Binary file not shown.
Binary file added docs/images/cynthion_hardware.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sphinx==7.2.6
sphinx_rtd_theme==1.3.0
sphinx_rtd_theme==2.0.0
readthedocs-sphinx-search==0.3.2
jinja2==3.1.4
6 changes: 4 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
# -- General configuration ---------------------------------------------------

extensions = [
'sphinx.ext.autodoc'
'sphinx.ext.autosectionlabel',
'sphinx.ext.autodoc',
]
autosectionlabel_prefix_document = True

templates_path = ['_templates']
exclude_patterns = ['_build']
source_suffix = '.rst'
master_doc = 'index'
language = None
language = "en"
exclude_patterns = []
pygments_style = None

Expand Down
70 changes: 70 additions & 0 deletions docs/source/developer/bitstream_generation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
====================
Bitstream Generation
====================

Before proceeding, please ensure you have followed the prerequisites in the :doc:`Setting up a Development Environment <introduction>` section.


Cynthion Gateware
-----------------

The Cynthion repository contains gateware for two designs:

- ``analyzer`` -- USB analyzer for using Cynthion with Packetry.
- ``soc`` -- System-on-Chip for using Cynthion with Facedancer.

Bitstreams can be generated from the ``cynthion`` Python package sub-directory as follows:

Analyzer Gateware
^^^^^^^^^^^^^^^^^

.. code-block:: sh

# change to the 'cynthion' Python package directory
cd cynthion/python/

# generate bitstream
python3 -m cynthion.gateware.analyzer.top

SoC Gateware
^^^^^^^^^^^^

.. code-block:: sh

# change to the 'cynthion' Python package directory
cd cynthion/python/

# generate bitstream
python3 -m cynthion.gateware.soc.top

Additional Options
^^^^^^^^^^^^^^^^^^

Additional options for bitstream generation can be listed by appending ``--help`` to the command:

.. code-block:: text

$ python3 -m cynthion.gateware.analyzer.top --help

usage: top.py [-h] [--output filename] [--erase] [--upload] [--flash]
[--dry-run] [--keep-files] [--fpga part_number] [--console port]

Gateware generation/upload script for 'USBAnalyzerApplet' gateware.

optional arguments:
-h, --help show this help message and exit
--output filename, -o filename
Build and output a bitstream to the given file.
--erase, -E Clears the relevant FPGA's flash before performing
other options.
--upload, -U Uploads the relevant design to the target hardware.
Default if no options are provided.
--flash, -F Flashes the relevant design to the target hardware's
configuration flash.
--dry-run, -D When provided as the only option; builds the relevant
bitstream without uploading or flashing it.
--keep-files Keeps the local files in the default `build` folder.
--fpga part_number Overrides build configuration to build for a given
FPGA. Useful if no FPGA is connected during build.
--console port Attempts to open a convenience 115200 8N1 UART console
on the specified port immediately after uploading.
40 changes: 40 additions & 0 deletions docs/source/developer/cli.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
========================
The ``cynthion`` Utility
========================

The ``cynthion`` distribution provides the ``cynthion`` command-line utility,
that can be used to perform various simple functions useful in development;
including simple JTAG operations, SVF playback, manipulating the board’s flash,
and debug communications.

.. code:: text
antoinevg marked this conversation as resolved.
Show resolved Hide resolved

$ cynthion
usage: cynthion [-h] command ...

Cynthion FPGA Configuration / Debug tool

positional arguments:
command
info Print device info.
jtag-scan Prints information about devices on the onboard JTAG chain.
flash-info Prints information about the FPGA's attached configuration flash.
flash-erase Erases the contents of the FPGA's flash memory.
flash-program Programs the target bitstream onto the FPGA's configuration flash.
flash-fast Programs a bitstream onto the FPGA's configuration flash using a SPI bridge.
flash-read Reads the contents of the attached FPGA's configuration flash.
svf Plays a given SVF file over JTAG.
configure Uploads a bitstream to the device's FPGA over JTAG.
reconfigure Requests the attached ECP5 reconfigure itself from its SPI flash.
force-offline Forces the board's FPGA offline.
spi Sends the given list of bytes over debug-SPI, and returns the response.
spi-inv Sends the given list of bytes over SPI with inverted CS.
spi-reg Reads or writes to a provided register over the debug-SPI.
jtag-spi Sends the given list of bytes over SPI-over-JTAG, and returns the response.
jtag-reg Reads or writes to a provided register of JTAG-tunneled debug SPI.
leds Sets the specified pattern for the Debug LEDs.
selftest Run a hardware self-test on a connected Cynthion.
mcu-firmware Update Apollo firmware version.

optional arguments:
-h, --help show this help message and exit
44 changes: 44 additions & 0 deletions docs/source/developer/introduction.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
============
Introduction
============


Setting up a Development Environment
------------------------------------

This guide highlights the installation and setup process for setting up a local copy of the Cynthion source code for development.


Prerequisites
-------------

- `Python <https://wiki.python.org/moin/BeginnersGuide/Download>`__ v3.8, or later.
- A working FPGA toolchain. We only officially support a toolchain
composed of the `Project Trellis <https://github.com/YosysHQ/prjtrellis>`__
ECP5 tools, the `yosys <https://github.com/YosysHQ/yosys>`__
synthesis suite, and the `NextPNR <https://github.com/YosysHQ/nextpnr>`__
place-and-route tool. You can obtain the latest binary distribution of this
software from the `oss-cad-suite-build <https://github.com/YosysHQ/oss-cad-suite-build>`__
project.
- A working `Rust development environment <https://www.rust-lang.org/learn/get-started>`__ if you want to develop firmware for Cynthion's SoC bitstream.
- A `RISC-V GNU Compiler Toolchain <https://github.com/riscv-collab/riscv-gnu-toolchain>`__ if you want to use ``gdb`` for SoC firmware debugging over JTAG.


Installation
------------

For development you'll need a local copy of the Cynthion repository:

.. code-block:: sh

git clone https://github.com/greatscottgadgets/cynthion.git

To install the ``cynthion`` Python package to allow for in-place editing of the sources you can use the ``pip --editable`` command:

.. code-block:: sh

# change to the 'cynthion' Python package directory
cd cynthion/python/

# install the 'cynthion' Python package, including dependencies required for gateware development
pip install --editable ".[gateware]"
80 changes: 80 additions & 0 deletions docs/source/developer/soc_firmware_compilation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
========================
SoC Firmware Compilation
========================

Before proceeding, please ensure you have followed the prerequisites in the :doc:`Setting up a Development Environment <introduction>` section.

Building and Running
--------------------

Firmware for the Cynthion SoC can be found in the ``firmware/moondancer/`` sub-directory.

You can rebuild the firmware using ``cargo`` as follows:

.. code-block:: text

# change to the Cynthion firmware directory
cd firmware/moondancer/

# rebuild the firmware
cargo build --release

To upload the firmware binary to Cynthion and flash the SoC bitstream you can run:

.. code-block:: text

# change to the Cynthion firmware directory
cd firmware/moondancer/

# upload firmware and run it
cargo run --release

.. note::

By default the firmware's flash script will look for the SoC UART
on ``/dev/ttyACM0``, if this is not the case on your machine you
will need to specify the correct path using the ``UART`` environment
variable, for example:

.. code-block:: sh

UART=/dev/cu.usbmodem22401 cargo run --release

By default the SoC bitstream is obtained from the latest build in
``cynthion/python/build/top.bit`` but you can override
it with:

.. code-block:: sh

BITSTREAM=path/to/bitstream.bit cargo run --release


Running Firmware Unit Tests
---------------------------

Once the firmware is running on the SoC you can execute some unit tests to exercise the firmware.

In order to do this you will need to connect both the **CONTROL** and
**AUX** ports of the Cynthion to the host and then run:

.. code-block:: sh

# change to the Cynthion firmware directory
cd firmware/moondancer/

# run firmware unit tests
python -m unittest


Firmware Examples
-----------------

There are a number of firmware examples in the ``firmware/moondancer/examples/`` sub-directory.

.. code-block:: sh

# change to the Cynthion firmware directory
cd firmware/moondancer/

# run example
cargo run --release --example <example name>
Loading
Loading