| 1 |
Metadata-Version: 2.4 |
| 2 |
Name: Apycula |
| 3 |
Version: 0.33 |
| 4 |
Summary: Open Source tools for Gowin FPGAs |
| 5 |
Home-page: https://github.com/YosysHQ/apicula |
| 6 |
Author: Pepijn de Vos |
| 7 |
Author-email: [email protected] |
| 8 |
Classifier: Programming Language :: Python :: 3 |
| 9 |
Classifier: License :: OSI Approved :: MIT License |
| 10 |
Classifier: Operating System :: OS Independent |
| 11 |
Requires-Python: >=3.9 |
| 12 |
Description-Content-Type: text/markdown |
| 13 |
License-File: LICENSE |
| 14 |
Requires-Dist: msgspec |
| 15 |
Requires-Dist: numpy |
| 16 |
Requires-Dist: fastcrc |
| 17 |
Provides-Extra: pure |
| 18 |
Requires-Dist: msgpack; extra == "pure" |
| 19 |
Requires-Dist: cattrs; extra == "pure" |
| 20 |
Dynamic: author |
| 21 |
Dynamic: author-email |
| 22 |
Dynamic: classifier |
| 23 |
Dynamic: description |
| 24 |
Dynamic: description-content-type |
| 25 |
Dynamic: home-page |
| 26 |
Dynamic: license-file |
| 27 |
Dynamic: provides-extra |
| 28 |
Dynamic: requires-dist |
| 29 |
Dynamic: requires-python |
| 30 |
Dynamic: summary |
| 31 |
|
| 32 |
# Project Apicula |
| 33 |
|
| 34 |
<img src="apicula.svg" width="250" /> |
| 35 |
|
| 36 |
Open source tools and [Documentation](https://github.com/YosysHQ/apicula/wiki) for the Gowin FPGA bitstream format. |
| 37 |
|
| 38 |
Project Apicula uses a combination of fuzzing and parsing of the vendor data files to provide Python tools for generating bitstreams. |
| 39 |
|
| 40 |
## Getting Started |
| 41 |
|
| 42 |
Install the latest git [yosys](https://github.com/yosyshq/yosys#setup), [nextpnr-himbaechel](https://github.com/YosysHQ/nextpnr#gowin), [openFPGALoader](https://github.com/trabucayre/openFPGALoader), and Python 3.9 or higher. [Yowasp](http://yowasp.org/) versions of Yosys and Nextpnr are also supported. |
| 43 |
|
| 44 |
Currently supported boards are |
| 45 |
* Trenz TEC0117: GW1NR-UV9QN881C6/I5 |
| 46 |
* Sipeed Tang Nano: GW1N-LV1QN48C6/I5 |
| 47 |
* Sipeed Tang Nano 1K: GW1NZ-LV1QN48C6/I5 |
| 48 |
* Sipeed Tang Nano 4K: GW1NSR-LV4CQN48PC7/I6 |
| 49 |
* Sipeed Tang Nano 9K: GW1NR-LV9QN88PC6/I5 [^1] |
| 50 |
* Sipeed Tang Nano 20K: GW2AR-LV18QN88C8/I7 [^1] |
| 51 |
* Sipeed Tang Primer 20K: GW2A-LV18PG256C8/I7 [^1] |
| 52 |
* Seeed RUNBER: GW1N-UV4LQ144C6/I5 |
| 53 |
* szfpga: GW1NR-LV9LQ144PC6/I5 |
| 54 |
|
| 55 |
[^1]: `C` devices require passing the `--vopt family` flag as well as `--device` to Nextpnr, and stating the family in place of device when passing `-d` to `gowin_pack` because the C isn't part of the device ID but only present in the date code. Check `examples/Makefile` for the correct command. |
| 56 |
|
| 57 |
Install the tools with pip. |
| 58 |
|
| 59 |
```bash |
| 60 |
pip install apycula |
| 61 |
``` |
| 62 |
|
| 63 |
On platforms where the default C extension dependencies are not available, you can use pure Python alternatives instead: |
| 64 |
|
| 65 |
```bash |
| 66 |
pip install --no-deps apycula msgpack cattrs |
| 67 |
``` |
| 68 |
|
| 69 |
Note that on some systems the installed binaries might not be on the path. Either add the binaries to the path, or use the path of the _installed binary_ directly. (running the source files will lead to import errors) |
| 70 |
|
| 71 |
```bash |
| 72 |
which gowin_pack # check if binaries are on the path |
| 73 |
python -m site --user-base # find the site packages base directory |
| 74 |
ls $HOME/.local/bin # confirm the binaries are installed in this folder |
| 75 |
export PATH="$HOME/.local/bin:$PATH" # add binaries to the path |
| 76 |
``` |
| 77 |
|
| 78 |
From there, compile a blinky. |
| 79 |
|
| 80 |
The example below is for the Trenz TEC0117. For other devices, use the model numbers listed above for `--device`, and replace `tec0117` with `runber`, `tangnano`, `tangnano4k` or `tangnano9k` accordingly. Also note the number of LEDs on your board: 8 for tec0117 and runber, 3 for honeycomb and tangnano. |
| 81 |
You can also use the Makefile in the examples folder to build the examples. |
| 82 |
|
| 83 |
```bash |
| 84 |
cd examples |
| 85 |
yosys -D LEDS_NR=8 -p "read_verilog blinky.v; synth_gowin -json blinky.json" |
| 86 |
DEVICE='GW1NR-UV9QN881C6/I5' # change to your device |
| 87 |
BOARD='tec0117' # change to your board |
| 88 |
nextpnr-himbaechel --json blinky.json \ |
| 89 |
--write pnrblinky.json \ |
| 90 |
--device $DEVICE \ |
| 91 |
--vopt cst=$BOARD.cst |
| 92 |
gowin_pack -d $DEVICE -o pack.fs pnrblinky.json # chango to your device |
| 93 |
# gowin_unpack -d $DEVICE -o unpack.v pack.fs |
| 94 |
# yosys -p "read_verilog -lib +/gowin/cells_sim.v; clean -purge; show" unpack.v |
| 95 |
openFPGALoader -b $BOARD pack.fs |
| 96 |
``` |
| 97 |
|
| 98 |
For the Tangnano9k board, you need to call nextpnr and gowin_pack with the chip family as follows: |
| 99 |
``` |
| 100 |
nextpnr-himbaechel --json blinky.json \ |
| 101 |
--write pnrblinky.json \ |
| 102 |
--device $DEVICE \ |
| 103 |
--vopt family=GW1N-9C \ |
| 104 |
--vopt cst=$BOARD.cst |
| 105 |
gowin_pack -d GW1N-9C -o pack.fs pnrblinky.json |
| 106 |
``` |
| 107 |
|
| 108 |
For the Tangnano20k (TangPrimer20k) board, you need to call yosys with the chip family as follows: |
| 109 |
``` |
| 110 |
yosys -D LEDS_NR=8 -p "read_verilog blinky.v; synth_gowin -json blinky.json -family gw2a" |
| 111 |
``` |
| 112 |
|
| 113 |
## Getting started for contributors |
| 114 |
|
| 115 |
In addition to the above, to run the fuzzers and build the ChipDB, the following additional dependencies are needed. |
| 116 |
|
| 117 |
Version 1.9.10.03 of the Gowin vendor tools. Newer versions may work, but have not been tested. |
| 118 |
|
| 119 |
Alternatively, you can use the `Dockerfile` to run the fuzzers in a container. |
| 120 |
|
| 121 |
To run the fuzzers, do the following in a checkout of this repo |
| 122 |
|
| 123 |
```bash |
| 124 |
pip install -e . |
| 125 |
export GOWINHOME=/gowin/installation |
| 126 |
make |
| 127 |
``` |
| 128 |
|
| 129 |
## Resources |
| 130 |
|
| 131 |
Check out the `doc` folder for documentation about the FPGA architecture, vendor file structure, and bitstream structure. |
| 132 |
|
| 133 |
My internship report about this project [can be downloaded here](https://github.com/pepijndevos/internshipreport). |
| 134 |
|
| 135 |
My presentations at [FPT2020](https://www.youtube.com/watch?v=kyQLtBh6h0U) and [RC3](https://media.ccc.de/v/rc3-739325-how_to_fuzz_an_fpga_my_experience_documenting_gowin_fpgas). |
| 136 |
|
| 137 |
I did a few [livestreams on twitch](https://www.twitch.tv/pepijnthefox) working on this project, which are collected [on this playlist](https://www.youtube.com/playlist?list=PLIYslVBAlKZad3tjr5Y4gqBV3QKQ5_tPw) I've also started to write Jupyter notebooks of my explorations that are more condensed than a video. |
| 138 |
|
| 139 |
You can also come chat on [Matrix](https://matrix.to/#/#apicula:matrix.org) or [IRC](https://web.libera.chat/#yosys-apicula) |
| 140 |
|
| 141 |
### Funding |
| 142 |
|
| 143 |
This project was funded through the <a href="https://nlnet.nl/PET">NGI0 PET</a> and [NGI Zero Entrust](https://nlnet.nl/entrust) Fund, a fund established by <a href="https://nlnet.nl">NLnet</a> with financial support from the European Commission's <a href="https://ngi.eu">Next Generation Internet</a> programme, under the aegis of DG Communications Networks, Content and Technology under grant agreement N<sup>o</sup> 825310 and 101069594. |