Tang Nano 9K - hoglet67/AtomFpga GitHub Wiki
Introduction
AtomFpga includes a feature-rich port for the SiPEED Tang Nano 9K.
Features
- HDMI output (640x480 @ 60Hz)
- optional VGA output (640x480 @ 60Hz)
- 64K ROM (uses external SPI FLASH)
- 128K Program RAM (uses PSRAM)
- 8K Video RAM (used Dual Ported Block RAM)
- Atom 2K15 compatible RAM/ROM expansion
- AtoMMC file system (this uses an AVR soft core with 2KB RAM and 18KB ROM)
- Supports FAT-32 formatted SD/SDHC cards
- 80x40 video extensions inc. hardware scrolling
- PS/2 Keyboard
- PS/2 Mouse
- optional UART
- SID audio
- 1MHz and 2MHz operation
- 11 bit wide GPIO bus, can be used for tracing 6502 activity
Connections
Minimally you need:
- power (via the USB C cable)
- a DVI monitor (via the HDMI connector)
- a Micro SD/SDHC Card formatted in FAT-32 with the Atom Software Archive unzipped onto it
- a PS/2 keyboard
- mono audio (via two 3K3 resistors and a 4.7nF capacitor)
The PS/2 keyboard is the tricky part. If you can find one that works when powered from 3.3V then it can be directly connect. Otherwise you will need to use some bidirectional level shifters (like this)
See the .CST file for the pin connections: https://github.com/hoglet67/AtomFpga/blob/master/gowin/AtomFpga_TangNano9K/src/AtomFpga_TangNano9K.cst
Installing the FPGA Software
-
Install the latest stable version of the Gowen EDA tools
- https://www.gowinsemi.com/en/support/download_eda/
- You need to register
- the Education version works, and doesn't require a license
- v1.9.8.11 (Linux) is known to work
-
Install the latest stable version of openFPGAloader
You can use the Gowin Programmer to load the FPGA image, but you need to use openFPGAloader to program the external SPI FLASH with ROM data.
git clone https://github.com/trabucayre/openFPGALoader.git
cd openFPGAloader
mkdir build
cd build
cmake ..
make
sudo make install
On Windows 10 you'll need to do this using WSL2, which is a bit more involved, see the Windows section on this page: https://learn.lushaylabs.com/os-toolchain-manual-installation/
Building the FPGA bitstream file
- Clone the AtomFpga project:
git clone https://github.com/hoglet67/AtomFpga.git
- Clone the AtomGodilVideo project:
git clone https://github.com/hoglet67/AtomGodilVideo.git
- Copy the AtomGodilVideo sources into AtomFpga
cp -a AtomGodilVideo/src AtomFpga/src/common/AtomGodilVideo
Sorry about having to do this, at some point I'll change this to a be a git sub-module
-
Building AtomFpga
- Start the Gowin EDA IDE
- File/Open and the navigate to the AtomFpga project file: gowin/AtomFpga_TangNano9K.gprj
- Click on the Run All button (far right with two circular green arrows)
- After about 10 minutes you should have a .fs file: gowin/AtomFpga_TangNano9K/impl/pnr/AtomFpga_TangNano9K.fs
Programming external FLASH with the ROM image
As Block RAM is scarse on the FPGA, on power up 16K of ROM content is loaded from the external SPI FLASH into PSRAM. This 16K comprises Atom Basic, Floating Point, AtoMMC and Kernel, which are 4K each.
The easiest way to program the external SPI FLASH is using openFPGAloader
openFPGALoader -b tangnano9k --external-flash --offset 65536 roms/16K_avr.rom
This takes about 10 minutes, as the SPI Flash is written by bit banging the interface using JTAG boundary scan
Programming internal FLASH with FPGA image
openFPGALoader -b tangnano9k -f gowin/AtomFpga_TangNano9K/impl/pnr/AtomFpga_TangNano9K.fs
Creating the SD Card
- The SD Card should be formatted with FAT-32
- Download the latest version of the Atom Software Archive from here
- Unzip this onto the (blank) SD card