1 |
210 |
ja_rd |
\chapter{Hardware Demo}
|
2 |
|
|
\label{hw_demo}
|
3 |
|
|
|
4 |
|
|
\section{Pre-generated demo}
|
5 |
|
|
\label{pregenerated_demo}
|
6 |
|
|
|
7 |
|
|
The project includes a few synthesizable code samples, including a
|
8 |
|
|
'Hello world' demo and a memory tester. Only the 'hello' demo is included
|
9 |
|
|
in pre-generated form, the others have to be built using the included
|
10 |
|
|
makefiles -- assuming you have a mips toolchain.\\
|
11 |
|
|
|
12 |
|
|
'Pre-generated' in this context means that all the vhdl files necessary for
|
13 |
221 |
ja_rd |
building the demo are already included with the project, including the
|
14 |
|
|
configuration package that contains the program's object code, and the only
|
15 |
210 |
ja_rd |
tool needed is the synthesis tool.
|
16 |
|
|
|
17 |
|
|
The pregenerated demo is included just for convenience, so that you can
|
18 |
|
|
launch some small application on hardware without installing a C toolchain.\\
|
19 |
|
|
|
20 |
|
|
A constraints file is provided ('/vhdl/demo/c2sb\_demo.csv') which includes
|
21 |
|
|
all the pin constraints for the default target board, in CSV format. This
|
22 |
|
|
constraints file is shared by all demos targeted to the DE-1 board.\\
|
23 |
|
|
|
24 |
|
|
The default target board is TerasIC's DE-1, with a Cyclone-II FPGA
|
25 |
|
|
(EP2C20F484C7). This is the only hardware platform the core has been
|
26 |
|
|
tested in, so far.\\
|
27 |
|
|
|
28 |
|
|
I have used the free Altera IDE (Altera Quartus II 9.0). This version of
|
29 |
|
|
Quartus does not even require a free license file and can be downloaded for
|
30 |
|
|
free from the altera web site. But if you have a DE-1 board on hand I guess
|
31 |
|
|
you already know that.\\
|
32 |
|
|
|
33 |
|
|
I assume you are familiar with Altera tools but anyway this is how to set up
|
34 |
|
|
a project using Quartus II:
|
35 |
|
|
|
36 |
|
|
\begin{enumerate}
|
37 |
|
|
\item Create new project with the new project wizard.
|
38 |
|
|
Top entity should be c2sb\_demo.
|
39 |
|
|
Suggested path is /syn/altera/(project name).
|
40 |
|
|
\item Set target device as EP2C20F484C7.
|
41 |
|
|
This choice tells the synth tool what speed grade and chip package
|
42 |
|
|
we'll be targetting.
|
43 |
|
|
\item 'Next' your way out of the new project wizard.
|
44 |
|
|
\item Add to the project all the vhdl files in /vhdl and /vhdl/demo,
|
45 |
|
|
except mips\_cache\_stub.vhdl and sdram\_controller.vhdl.
|
46 |
221 |
ja_rd |
\item Add to the project all the vhdl files in /vhdl/SoC.
|
47 |
210 |
ja_rd |
\item Select file c2sb\_demo.vhdl as top.
|
48 |
|
|
\item Import pin constraints file (assignments-\textgreater import assignments).
|
49 |
|
|
\item Create a clock constraint for signal clk (51 MHz or some other
|
50 |
|
|
suitable speed which gives us some minimal slack).
|
51 |
|
|
\item In the device settings window, click "Device and pin options...".
|
52 |
|
|
\item Select tab "Dual-Purpose pins".
|
53 |
|
|
\item Double-click on nCEO value column and select "use as regular I/O".
|
54 |
|
|
IMPORTANT: otherwise the synthesis will fail; we need to use a FPGA
|
55 |
|
|
pin that happens to be dual-purpose (programming and regular).
|
56 |
221 |
ja_rd |
\item Select 'speed' optimization.
|
57 |
210 |
ja_rd |
\item Save the project and synthesize.
|
58 |
|
|
\item Make sure the clock constraint is met (timing analyzer report).
|
59 |
|
|
There is a random element to the synthesis process, as you know,
|
60 |
|
|
but the core as shipped should pass the constraint.
|
61 |
|
|
\item Program the FPGA from Quartus-2
|
62 |
|
|
\item If you have a terminal hooked to the serial port (19200/8/N/1) you
|
63 |
|
|
should see a welcome message after depressing the reset button.
|
64 |
221 |
ja_rd |
(by default this is pushbutton 2).
|
65 |
210 |
ja_rd |
\end{enumerate}
|
66 |
|
|
|
67 |
|
|
In the present version, the synthesis will produce a lot of warnings. The
|
68 |
|
|
ugliest are about unused pins and an undeclared clock line. None of them
|
69 |
|
|
should be really scary.\\
|
70 |
|
|
|
71 |
|
|
Note that none of the on-board goodies are used in the demo except as noted
|
72 |
|
|
in section ~\ref{porting_hw_demo} below.\\
|
73 |
|
|
|
74 |
|
|
In order to generate the demos (not using the pre-generated file) you
|
75 |
|
|
have to use the makefiles provided with the code samples. Please see
|
76 |
|
|
the sample readme files and the makefiles for details. In short, provided
|
77 |
|
|
you have a MIPS toolchain installed and Python 2.5+, all you have to do
|
78 |
|
|
is run make (which will automatically build all the vhdl files where they
|
79 |
|
|
need to be, etc.) and run the synthesis.\\
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
\section{Porting to other dev boards}
|
83 |
|
|
\label{porting_hw_demo}
|
84 |
|
|
|
85 |
|
|
I will only deal here with the 'hello' demo, the process is the same
|
86 |
|
|
for all other samples that don't involve external FLASH.\\
|
87 |
|
|
|
88 |
|
|
The 'hello' demo should be easily portable to any board which has all of
|
89 |
|
|
this:
|
90 |
|
|
|
91 |
|
|
\begin{itemize}
|
92 |
221 |
ja_rd |
\item An FPGA capable enough (the demo uses internal memory for code).
|
93 |
|
|
\item At least 4KB of 16-bit wide external, asynchronous, old-fashioned SRAM.
|
94 |
|
|
\item A reset pin (possibly a pushbutton).
|
95 |
|
|
\item A clock input (uart modules assume 50MHz, see below).
|
96 |
|
|
\item RXD and TXD UART pins, plus a connector, header or whatever.
|
97 |
210 |
ja_rd |
\end{itemize}
|
98 |
|
|
|
99 |
221 |
ja_rd |
The only module that care at all about clock rate is the UART embedded into
|
100 |
|
|
the SoC module. It's hardwired to 19200 bauds when clocked at 50MHz, so if you
|
101 |
210 |
ja_rd |
use a different frequency you must edit the generics in the demo entity
|
102 |
221 |
ja_rd |
accordingly -- the demo generics are passed all the way down to whatever
|
103 |
|
|
module needs them.\\
|
104 |
|
|
The UART has hardly been tested at clock rates other than 50MHz and has not
|
105 |
|
|
passed any independent test bench; try the core first at 50 MHz.\\
|
106 |
210 |
ja_rd |
|
107 |
|
|
Though there is no reset control logic, the reset input is synchronized
|
108 |
|
|
internally, so you can use a raw pushbutton -- you may trigger multiple
|
109 |
|
|
resets if your pushbutton isn't tight but you'll never cause metastability
|
110 |
|
|
trouble.\\
|
111 |
|
|
|
112 |
|
|
Assuming you take care of all of the above, the easiest way I see to port
|
113 |
|
|
the demo is just editing the top module ports ('/vhdl/demo/c2sb\_demo.vhdl')
|
114 |
221 |
ja_rd |
to match your board setup. The only tricky part is the interface to FLASH
|
115 |
|
|
and SDRAM.\\
|
116 |
210 |
ja_rd |
|
117 |
|
|
All the code in this project is vendor agnostic (or should be, I have only
|
118 |
|
|
tried it on Quartus and ISE). Specifically, it does not instantiate memory
|
119 |
|
|
blocks (relying instead on memory inference) or clock managers or buffers.
|
120 |
|
|
This has its drawbacks but is an stated goal of the project -- in the long
|
121 |
|
|
run it pays, I think, and it certainly makes the porting easier.\\
|
122 |
|
|
|
123 |
|
|
\section{'Adventure' demo}
|
124 |
|
|
\label{adventure}
|
125 |
|
|
|
126 |
|
|
There is another demo targeting the same hardware as the 'hello' demo above:
|
127 |
|
|
a port of 'Adventure'. The C source (included) has been slightly modified
|
128 |
|
|
to not use any library functions nor any filesystem (instead uses a built-in
|
129 |
|
|
constant string table).\\
|
130 |
|
|
|
131 |
|
|
Build steps are the same as for the hello demo (the make target is 'demo').\\
|
132 |
|
|
|
133 |
|
|
Since the binary executable is too large to fit internal BRAM, it has to be
|
134 |
|
|
executed from the DE-1 onboard flash. You need to write file 'adventure.bin'
|
135 |
|
|
to the start of the FLASH using the 'Control Panel' tool that came with your
|
136 |
|
|
DE-1 board. That's the only salient difference. That and the amount of SRAM;
|
137 |
|
|
The 512KB present on the DE-1 are enough but I don't remember right now
|
138 |
|
|
what is the minimum, please look at the map file. This should only matter
|
139 |
|
|
if you want to port to another board.\\
|
140 |
|
|
|
141 |
|
|
The game will offer you an auto-walkthrough option. Answer 'y' and it will
|
142 |
|
|
play itself for about 250 moves, leaving you at an intermediate stage of
|
143 |
|
|
the game from which you can play on.\\
|
144 |
|
|
|
145 |
|
|
Now, admittedly 'Adventure' is no standard benchmark and even running it to
|
146 |
|
|
completion does not guarantee that there are no bugs hidden in the cache or
|
147 |
|
|
any of the opcodes.
|
148 |
|
|
On the other hand, when you get to the \emph{maze of twisty little passages}
|
149 |
|
|
you know you have a computer, finished or not. The 'Adventure' demo is
|
150 |
|
|
great as a confidence builder.\\
|
151 |
|
|
|
152 |
|
|
Besides, running Adventure on a computer built by myself is something
|
153 |
221 |
ja_rd |
I've always wanted to do :)\\
|