1 |
60 |
zero_gravi |
Let's Get It Started!
|
2 |
|
|
|
3 |
|
|
To make your NEORV32 project run, follow the guides from the upcoming sections. Follow these guides
|
4 |
|
|
step by step and in the presented order.
|
5 |
|
|
|
6 |
|
|
:sectnums:
|
7 |
61 |
zero_gravi |
== Software Toolchain Setup
|
8 |
60 |
zero_gravi |
|
9 |
61 |
zero_gravi |
To compile (and debug) executables for the NEORV32 a RISC-V toolchain is required.
|
10 |
|
|
There are two possibilities to get this:
|
11 |
60 |
zero_gravi |
|
12 |
|
|
1. Download and _build_ the official RISC-V GNU toolchain yourself
|
13 |
61 |
zero_gravi |
2. Download and install a prebuilt version of the toolchain; this might also done via the package manager / app store of your OS
|
14 |
60 |
zero_gravi |
|
15 |
61 |
zero_gravi |
[TIP]
|
16 |
60 |
zero_gravi |
The default toolchain prefix for this project is **`riscv32-unknown-elf`**. Of course you can use any other RISC-V
|
17 |
|
|
toolchain (like `riscv64-unknown-elf`) that is capable to emit code for a `rv32` architecture. Just change the _RISCV_TOOLCHAIN_ variable in the application
|
18 |
|
|
makefile(s) according to your needs or define this variable when invoking the makefile.
|
19 |
|
|
|
20 |
|
|
[IMPORTANT]
|
21 |
|
|
Keep in mind that – for instance – a rv32imc toolchain only provides library code compiled with
|
22 |
|
|
compressed (_C_) and `mul`/`div` instructions (_M_)! Hence, this code cannot be executed (without
|
23 |
|
|
emulation) on an architecture without these extensions!
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
:sectnums:
|
27 |
|
|
=== Building the Toolchain from Scratch
|
28 |
|
|
|
29 |
61 |
zero_gravi |
To build the toolchain by yourself you can follow the guide from the official https://github.com/riscv/riscv-gnu-toolchain GitHub page.
|
30 |
|
|
You need to make sure the generated toolchain fits the architecture of the NEORV32 core. To get a toolchain that even supports minimal
|
31 |
|
|
ISA extension configurations, it is recommend to compile for `rv32i` only. Please note that this minimal ISA also provides further ISA
|
32 |
|
|
extensions like `m` or `c`. Of course you can use a `multilib` approach to generate
|
33 |
|
|
toolchains for several target ISAs.
|
34 |
60 |
zero_gravi |
|
35 |
61 |
zero_gravi |
.Configuring GCC build for `rv32i` (minimal ISA)
|
36 |
60 |
zero_gravi |
[source,bash]
|
37 |
|
|
----
|
38 |
|
|
riscv-gnu-toolchain$ ./configure --prefix=/opt/riscv --with-arch=rv32i –-with-abi=ilp32
|
39 |
|
|
riscv-gnu-toolchain$ make
|
40 |
|
|
----
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
:sectnums:
|
44 |
|
|
=== Downloading and Installing a Prebuilt Toolchain
|
45 |
|
|
|
46 |
|
|
Alternatively, you can download a prebuilt toolchain.
|
47 |
|
|
|
48 |
61 |
zero_gravi |
:sectnums:
|
49 |
|
|
==== Use The Toolchain I have Build
|
50 |
60 |
zero_gravi |
|
51 |
61 |
zero_gravi |
I have compiled a GCC toolchain on a 64-bit x86 Ubuntu (Ubuntu on Windows, actually) and uploaded it to
|
52 |
60 |
zero_gravi |
GitHub. You can directly download the according toolchain archive as single _zip-file_ within a packed
|
53 |
61 |
zero_gravi |
release from https://github.com/stnolting/riscv-gcc-prebuilt.
|
54 |
60 |
zero_gravi |
|
55 |
|
|
Unpack the downloaded toolchain archive and copy the content to a location in your file system (e.g.
|
56 |
|
|
`/opt/riscv`). More information about downloading and installing my prebuilt toolchains can be found in
|
57 |
|
|
the repository's README.
|
58 |
|
|
|
59 |
|
|
|
60 |
61 |
zero_gravi |
:sectnums:
|
61 |
|
|
==== Use a Third Party Toolchain
|
62 |
|
|
|
63 |
60 |
zero_gravi |
Of course you can also use any other prebuilt version of the toolchain. There are a lot RISC-V GCC packages out there -
|
64 |
61 |
zero_gravi |
even for Windows. On Linux system you might even be able to fetch a toolchain via your distribution's package manager.
|
65 |
60 |
zero_gravi |
|
66 |
|
|
[IMPORTANT]
|
67 |
|
|
Make sure the toolchain can (also) emit code for a `rv32i` architecture, uses the `ilp32` or `ilp32e` ABI and **was not build** using
|
68 |
|
|
CPU extensions that are not supported by the NEORV32 (like `D`).
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
:sectnums:
|
72 |
|
|
=== Installation
|
73 |
|
|
|
74 |
61 |
zero_gravi |
Now you have the toolchain binaries. The last step is to add them to your `PATH` environment variable (if you have not
|
75 |
|
|
already done so): make sure to add the _binaries_ folder (`bin`) of your toolchain.
|
76 |
60 |
zero_gravi |
|
77 |
|
|
[source,bash]
|
78 |
|
|
----
|
79 |
|
|
$ export PATH:$PATH:/opt/riscv/bin
|
80 |
|
|
----
|
81 |
|
|
|
82 |
|
|
You should add this command to your `.bashrc` (if you are using bash) to automatically add the RISC-V
|
83 |
|
|
toolchain at every console start.
|
84 |
|
|
|
85 |
|
|
:sectnums:
|
86 |
|
|
=== Testing the Installation
|
87 |
|
|
|
88 |
|
|
To make sure everything works fine, navigate to an example project in the NEORV32 example folder and
|
89 |
|
|
execute the following command:
|
90 |
|
|
|
91 |
|
|
[source,bash]
|
92 |
|
|
----
|
93 |
|
|
neorv32/sw/example/blink_led$ make check
|
94 |
|
|
----
|
95 |
|
|
|
96 |
61 |
zero_gravi |
This will test all the tools required for the generating NEORV32 executables.
|
97 |
|
|
Everything is working fine if `Toolchain check OK` appears at the end.
|
98 |
60 |
zero_gravi |
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
<<<
|
102 |
|
|
// ####################################################################################################################
|
103 |
|
|
:sectnums:
|
104 |
|
|
== General Hardware Setup
|
105 |
|
|
|
106 |
61 |
zero_gravi |
This guide will setup a NEORV32 project for FPGA implementation (or simulation only) _from scratch_
|
107 |
60 |
zero_gravi |
|
108 |
|
|
[TIP]
|
109 |
61 |
zero_gravi |
If you want to use a complete pre-defined setup to start with, check out the
|
110 |
|
|
project's `setups` folder (https://github.com/stnolting/neorv32/tree/master/setups),
|
111 |
|
|
which provides (script-based) demo setups for various FPGA boards and toolchains.
|
112 |
60 |
zero_gravi |
|
113 |
61 |
zero_gravi |
This tutorial uses a _simplified_ test setup of the processor
|
114 |
|
|
to keeps things simple at the beginning as this setup is intended as
|
115 |
|
|
evaluation or "hello world" project to check out the NEORV32.
|
116 |
60 |
zero_gravi |
|
117 |
61 |
zero_gravi |
[start=1]
|
118 |
60 |
zero_gravi |
. Create a new project with your FPGA EDA tool of choice.
|
119 |
|
|
. Add all VHDL files from the project's `rtl/core` folder to your project. Make sure to _reference_ the
|
120 |
|
|
files only – do not copy them.
|
121 |
61 |
zero_gravi |
. Make sure to add all the rtl files to a new library called `neorv32`. If your FPGA tools does not
|
122 |
|
|
provide a field to enter the library name, check out the "properties" menu of the added rtl files.
|
123 |
60 |
zero_gravi |
. The `rtl/core/neorv32_top.vhd` VHDL file is the top entity of the NEORV32 processor. If you
|
124 |
|
|
already have a design, instantiate this unit into your design and proceed.
|
125 |
61 |
zero_gravi |
|
126 |
|
|
[IMPORTANT]
|
127 |
|
|
Make sure to include the `neorv32` package into your design when instantiating the processor: add
|
128 |
|
|
`library neorv32;` and `use neorv32.neorv32_package.all;` to your design unit.
|
129 |
|
|
|
130 |
|
|
[start=5]
|
131 |
|
|
. If you do not have a design yet and just want to check out the NEORV32 – no problem! This guide
|
132 |
|
|
uses a simplified top entity, that encapsulates the actual processor top entity: add the
|
133 |
|
|
`rtl/templates/processor/neorv32_ProcessorTop_Test.vhd` VHDL file to your project, too, and
|
134 |
|
|
select it as _top entity_.
|
135 |
60 |
zero_gravi |
. This test setup provides a minimal test hardware setup:
|
136 |
|
|
|
137 |
|
|
.NEORV32 "hello world" test setup
|
138 |
|
|
image::neorv32_test_setup.png[align=center]
|
139 |
|
|
|
140 |
|
|
[start=7]
|
141 |
61 |
zero_gravi |
. It only implements some very basic processor and CPU features. Also, only the
|
142 |
|
|
minimum number of signals is propagated to the outer world.
|
143 |
|
|
. However, a minimal setup-specific configuration of the NEORV32 processor is required to make it run
|
144 |
|
|
on your FPGA board of choice. Only the absolutely required modifications will be made while
|
145 |
|
|
keeping the default configuration for the remaining configuration options:
|
146 |
60 |
zero_gravi |
|
147 |
61 |
zero_gravi |
.Cut-out of `neorv32_ProcessorTop_Test.vhd` showing the processor instance and its configuration
|
148 |
60 |
zero_gravi |
[source,vhdl]
|
149 |
|
|
----
|
150 |
|
|
neorv32_top_inst: neorv32_top
|
151 |
|
|
generic map (
|
152 |
|
|
-- General --
|
153 |
|
|
CLOCK_FREQUENCY => 100000000, -- in Hz # <1>
|
154 |
61 |
zero_gravi |
INT_BOOTLOADER_EN => true,
|
155 |
60 |
zero_gravi |
...
|
156 |
|
|
-- Internal instruction memory --
|
157 |
|
|
MEM_INT_IMEM_EN => true,
|
158 |
|
|
MEM_INT_IMEM_SIZE => 16*1024, # <2>
|
159 |
|
|
-- Internal data memory --
|
160 |
|
|
MEM_INT_DMEM_EN => true,
|
161 |
|
|
MEM_INT_DMEM_SIZE => 8*1024, # <3>
|
162 |
|
|
...
|
163 |
|
|
----
|
164 |
61 |
zero_gravi |
<1> Clock frequency of `clk_i` signal in Hertz
|
165 |
|
|
<2> Default size of internal instruction memory: 16kB
|
166 |
|
|
<3> Default size of internal data memory: 8kB
|
167 |
60 |
zero_gravi |
|
168 |
|
|
[start=9]
|
169 |
61 |
zero_gravi |
. There is one generic that has to be set according to your FPGA board setup: the actual clock frequency
|
170 |
|
|
of the top's clock input signal (`clk_i`). Use the _CLOCK_FREQUENC_Y generic to specify your clock source's
|
171 |
60 |
zero_gravi |
frequency in Hertz (Hz) (note "1").
|
172 |
61 |
zero_gravi |
. If you feel like it – or if your FPGA does not provide many resources – you can modify the
|
173 |
60 |
zero_gravi |
**memory sizes** (_MEM_INT_IMEM_SIZE_ and _MEM_INT_DMEM_SIZE_ – marked with notes "2" and "3") or even
|
174 |
61 |
zero_gravi |
exclude certain ISA extensions and peripheral modules from implementation - but as mentioned above, let's keep things
|
175 |
60 |
zero_gravi |
simple at first and use the standard configuration for now.
|
176 |
|
|
|
177 |
|
|
[NOTE]
|
178 |
61 |
zero_gravi |
If you have changed the default memory configuration (_MEM_INT_IMEM_SIZE_ and _MEM_INT_DMEM_SIZE_ generics)
|
179 |
|
|
keep those new sizes in mind – these values are required for setting
|
180 |
60 |
zero_gravi |
up the software framework in the next section <<_general_software_framework_setup>>.
|
181 |
|
|
|
182 |
|
|
[start=11]
|
183 |
|
|
. Depending on your FPGA tool of choice, it is time to assign the signals of the test setup top entity to
|
184 |
|
|
the according pins of your FPGA board. All the signals can be found in the entity declaration:
|
185 |
|
|
|
186 |
|
|
.Entity signals of `neorv32_test_setup.vhd`
|
187 |
|
|
[source,vhdl]
|
188 |
|
|
----
|
189 |
|
|
entity neorv32_test_setup is
|
190 |
|
|
port (
|
191 |
|
|
-- Global control --
|
192 |
|
|
clk_i : in std_ulogic := '0'; -- global clock, rising edge
|
193 |
|
|
rstn_i : in std_ulogic := '0'; -- global reset, low-active, async
|
194 |
|
|
-- GPIO --
|
195 |
|
|
gpio_o : out std_ulogic_vector(7 downto 0); -- parallel output
|
196 |
|
|
-- UART0 --
|
197 |
|
|
uart0_txd_o : out std_ulogic; -- UART0 send data
|
198 |
|
|
uart0_rxd_i : in std_ulogic := '0' -- UART0 receive data
|
199 |
|
|
);
|
200 |
|
|
end neorv32_test_setup;
|
201 |
|
|
----
|
202 |
|
|
|
203 |
|
|
[start=12]
|
204 |
|
|
. Attach the clock input `clk_i` to your clock source and connect the reset line `rstn_i` to a button of
|
205 |
|
|
your FPGA board. Check whether it is low-active or high-active – the reset signal of the processor is
|
206 |
|
|
**low-active**, so maybe you need to invert the input signal.
|
207 |
|
|
. If possible, connected at least bit `0` of the GPIO output port `gpio_o` to a high-active LED (invert
|
208 |
61 |
zero_gravi |
the signal when your LEDs are low-active). This LED will be used as status LED for the setup.
|
209 |
|
|
. Finally, if your FPGA board provides a serial host interface (USB-to-serial converter) interface,
|
210 |
|
|
connect the UART communication signals `uart0_txd_o` and `uart0_rxd_i`.
|
211 |
60 |
zero_gravi |
. Perform the project HDL compilation (synthesis, mapping, bitstream generation).
|
212 |
61 |
zero_gravi |
. Program the generated bitstream into your FPGA and press the button connected to the reset signal.
|
213 |
|
|
. Done! The assigned status LED should be flashing now for some sections before permanently lighting up.
|
214 |
60 |
zero_gravi |
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
<<<
|
218 |
|
|
// ####################################################################################################################
|
219 |
|
|
:sectnums:
|
220 |
|
|
== General Software Framework Setup
|
221 |
|
|
|
222 |
61 |
zero_gravi |
To allow executables to be _actually executed_ on the NEORV32 Processor the configuration of the software framework
|
223 |
|
|
has to be aware to the hardware configuration. This guide focuses on the memory configuration. To enabled
|
224 |
|
|
certain CPU ISA festures refer to the <<_enabling_risc_v_cpu_extensions>> section.
|
225 |
60 |
zero_gravi |
|
226 |
61 |
zero_gravi |
[TIP]
|
227 |
|
|
If you have **not** changed the _default_ memory configuration in section <<_general_hardware_setup>>
|
228 |
|
|
you are already done and you can skip the rest of this guide.
|
229 |
|
|
|
230 |
60 |
zero_gravi |
[start=1]
|
231 |
|
|
. Open the NEORV32 linker script `sw/common/neorv32.ld` with a text editor. Right at the
|
232 |
61 |
zero_gravi |
beginning of this script you will find the `MEMORY` configuration listing the different memory section:
|
233 |
60 |
zero_gravi |
|
234 |
61 |
zero_gravi |
.Cut-out of the linker script `neorv32.ld`: `ram` memory section configuration
|
235 |
60 |
zero_gravi |
[source,c]
|
236 |
|
|
----
|
237 |
|
|
MEMORY
|
238 |
|
|
{
|
239 |
61 |
zero_gravi |
ram (rwx) : ORIGIN = 0x80000000, LENGTH = DEFINED(make_bootloader) ? 512 : 8*1024 # <1>
|
240 |
|
|
...
|
241 |
60 |
zero_gravi |
----
|
242 |
61 |
zero_gravi |
<1> Size of the data memory address space (right-most value) (internal/external DMEM); here 8kB
|
243 |
60 |
zero_gravi |
|
244 |
61 |
zero_gravi |
[start=2]
|
245 |
|
|
. We only need to change the `ram` section, which presents the available data address space.
|
246 |
|
|
If you have changed the DMEM (_MEM_INT_DMEM_SIZE_ generic) size adapt the `LENGTH` parameter of the `ram`
|
247 |
|
|
section (here: `8*1024`) so it is equal to your DMEM hardware configuration.
|
248 |
60 |
zero_gravi |
|
249 |
61 |
zero_gravi |
[IMPORTANT]
|
250 |
|
|
Make sure you only modify the _right-most_ value (here: 8*1024)! +
|
251 |
|
|
The "`512`" are not relevant for the application.
|
252 |
|
|
|
253 |
60 |
zero_gravi |
[start=3]
|
254 |
61 |
zero_gravi |
. Done! Save your changes and close the linker script.
|
255 |
60 |
zero_gravi |
|
256 |
61 |
zero_gravi |
.Advanced: Section base address and size
|
257 |
60 |
zero_gravi |
[IMPORTANT]
|
258 |
61 |
zero_gravi |
More information can be found in the datasheet section https://stnolting.github.io/neorv32/#_address_space[Address Space].
|
259 |
60 |
zero_gravi |
|
260 |
|
|
|
261 |
|
|
|
262 |
|
|
<<<
|
263 |
|
|
// ####################################################################################################################
|
264 |
|
|
:sectnums:
|
265 |
|
|
== Application Program Compilation
|
266 |
|
|
|
267 |
61 |
zero_gravi |
This guide shows how to compile an example C-code application into a NEORV32 executable that
|
268 |
|
|
can be uploaded via the bootloader or the on-chip debugger.
|
269 |
|
|
|
270 |
|
|
[IMPORTANT]
|
271 |
|
|
If your FPGA board does not provide such an interface - don't worry!
|
272 |
|
|
Section <<_installing_an_executable_directly_into_memory>> shows how to
|
273 |
|
|
run custom programs on your FPGA setup without having a UART.
|
274 |
|
|
|
275 |
60 |
zero_gravi |
[start=1]
|
276 |
61 |
zero_gravi |
. Open a terminal console and navigate to one of the project's example programs. For instance, navigate to the
|
277 |
|
|
simple `sw/example_blink_led` example program. This program uses the NEORV32 GPIO module to display
|
278 |
60 |
zero_gravi |
an 8-bit counter on the lowest eight bit of the `gpio_o` output port.
|
279 |
|
|
. To compile the project and generate an executable simply execute:
|
280 |
|
|
|
281 |
|
|
[source,bash]
|
282 |
|
|
----
|
283 |
61 |
zero_gravi |
neorv32/sw/example/blink_led$ make clean_all exe
|
284 |
60 |
zero_gravi |
----
|
285 |
|
|
|
286 |
|
|
[start=3]
|
287 |
61 |
zero_gravi |
. We are using the `clean_all` taret to make sure everything is re-build.
|
288 |
60 |
zero_gravi |
. This will compile and link the application sources together with all the included libraries. At the end,
|
289 |
61 |
zero_gravi |
your application is transformed into an ELF file (`main.elf`). The _NEORV32 image generator_ (in `sw/image_gen`)
|
290 |
|
|
takes this file and creates a final executable. The makefile will show the resulting memory utilization and
|
291 |
|
|
the executable size:
|
292 |
60 |
zero_gravi |
|
293 |
|
|
[source,bash]
|
294 |
|
|
----
|
295 |
61 |
zero_gravi |
neorv32/sw/example/blink_led$ make clean_all exe
|
296 |
60 |
zero_gravi |
Memory utilization:
|
297 |
61 |
zero_gravi |
text data bss dec hex filename
|
298 |
|
|
3176 0 120 3296 ce0 main.elf
|
299 |
|
|
Compiling ../../../sw/image_gen/image_gen
|
300 |
60 |
zero_gravi |
Executable (neorv32_exe.bin) size in bytes:
|
301 |
61 |
zero_gravi |
3188
|
302 |
60 |
zero_gravi |
----
|
303 |
|
|
|
304 |
61 |
zero_gravi |
[start=5]
|
305 |
|
|
. That's it. The `exe` target has created the actual executable `neorv32_exe.bin` in the current folder
|
306 |
|
|
that is ready to be uploaded to the processor.
|
307 |
60 |
zero_gravi |
|
308 |
|
|
[TIP]
|
309 |
61 |
zero_gravi |
The compilation process will also create a `main.asm` assembly listing file in the current folder, which
|
310 |
|
|
shows the actual assembly code of the application.
|
311 |
60 |
zero_gravi |
|
312 |
|
|
|
313 |
|
|
|
314 |
|
|
<<<
|
315 |
|
|
// ####################################################################################################################
|
316 |
|
|
:sectnums:
|
317 |
|
|
== Uploading and Starting of a Binary Executable Image via UART
|
318 |
|
|
|
319 |
61 |
zero_gravi |
Follow this guide to use the bootloader to upload an executable via UART.
|
320 |
60 |
zero_gravi |
|
321 |
61 |
zero_gravi |
[NOTE]
|
322 |
|
|
This concept uses the default "Indirect Boot" scenario that uses the bootloader to upload new executables.
|
323 |
|
|
See datasheet section https://stnolting.github.io/neorv32/#_indirect_boot[Indirect Boot] for more information.
|
324 |
60 |
zero_gravi |
|
325 |
61 |
zero_gravi |
[IMPORTANT]
|
326 |
|
|
If your FPGA board does not provide such an interface - don't worry!
|
327 |
|
|
Section <<_installing_an_executable_directly_into_memory>> shows how to
|
328 |
|
|
run custom programs on your FPGA setup without having a UART.
|
329 |
60 |
zero_gravi |
|
330 |
|
|
[start=1]
|
331 |
61 |
zero_gravi |
. Connect the primary UART (UART0) interface of your FPGA board to a serial port of your host computer.
|
332 |
|
|
. Start a terminal program. In this tutorial, I am using TeraTerm for Windows. You can download it fore free
|
333 |
|
|
from https://ttssh2.osdn.jp/index.html.en
|
334 |
60 |
zero_gravi |
|
335 |
61 |
zero_gravi |
[NOTE]
|
336 |
|
|
_Any_ terminal program that can connect to a serial port should work. However, make sure the program
|
337 |
|
|
can transfer data in _raw_ byte mode without any protocol overhead around it.
|
338 |
60 |
zero_gravi |
|
339 |
|
|
[start=3]
|
340 |
61 |
zero_gravi |
. Open a connection to the the serial port your UART is connected to. Configure the terminal setting according to the
|
341 |
60 |
zero_gravi |
following parameters:
|
342 |
|
|
|
343 |
|
|
* 19200 Baud
|
344 |
|
|
* 8 data bits
|
345 |
|
|
* 1 stop bit
|
346 |
|
|
* no parity bits
|
347 |
61 |
zero_gravi |
* _no_ transmission/flow control protocol
|
348 |
|
|
* receiver (host computer) newline on `\r\n` (carriage return & newline)
|
349 |
60 |
zero_gravi |
|
350 |
|
|
[start=4]
|
351 |
61 |
zero_gravi |
. Also make sure that single chars are send from your computer _without_ any consecutive "new line" or "carriage
|
352 |
60 |
zero_gravi |
return" commands (this is highly dependent on your terminal application of choice, TeraTerm only
|
353 |
|
|
sends the raw chars by default).
|
354 |
|
|
. Press the NEORV32 reset button to restart the bootloader. The status LED starts blinking and the
|
355 |
|
|
bootloader intro screen appears in your console. Hurry up and press any key (hit space!) to abort the
|
356 |
|
|
automatic boot sequence and to start the actual bootloader user interface console.
|
357 |
|
|
|
358 |
|
|
.Bootloader console; aborted auto-boot sequence
|
359 |
|
|
[source,bash]
|
360 |
|
|
----
|
361 |
|
|
<< NEORV32 Bootloader >>
|
362 |
|
|
|
363 |
|
|
BLDV: Mar 23 2021
|
364 |
|
|
HWV: 0x01050208
|
365 |
|
|
CLK: 0x05F5E100
|
366 |
|
|
MISA: 0x40901105
|
367 |
|
|
ZEXT: 0x00000023
|
368 |
|
|
PROC: 0x0EFF0037
|
369 |
|
|
IMEM: 0x00004000 bytes @ 0x00000000
|
370 |
|
|
DMEM: 0x00002000 bytes @ 0x80000000
|
371 |
|
|
|
372 |
|
|
Autoboot in 8s. Press key to abort.
|
373 |
|
|
Aborted.
|
374 |
|
|
|
375 |
|
|
Available commands:
|
376 |
|
|
h: Help
|
377 |
|
|
r: Restart
|
378 |
|
|
u: Upload
|
379 |
|
|
s: Store to flash
|
380 |
|
|
l: Load from flash
|
381 |
|
|
e: Execute
|
382 |
|
|
CMD:>
|
383 |
|
|
----
|
384 |
|
|
|
385 |
|
|
[start=6]
|
386 |
61 |
zero_gravi |
. Execute the "Upload" command by typing `u`. Now the bootloader is waiting for a binary executable to be send.
|
387 |
60 |
zero_gravi |
|
388 |
|
|
[source,bash]
|
389 |
|
|
----
|
390 |
|
|
CMD:> u
|
391 |
|
|
Awaiting neorv32_exe.bin...
|
392 |
|
|
----
|
393 |
|
|
|
394 |
|
|
[start=7]
|
395 |
61 |
zero_gravi |
. Use the "send file" option of your terminal program to send a NEORV32 executable (`neorv32_exe.bin`).
|
396 |
|
|
. Again, make sure to transmit the executable in raw binary mode (no transfer protocol).
|
397 |
|
|
When using TeraTerm, select the "binary" option in the send file dialog.
|
398 |
60 |
zero_gravi |
. If everything went fine, OK will appear in your terminal:
|
399 |
|
|
|
400 |
|
|
[source,bash]
|
401 |
|
|
----
|
402 |
|
|
CMD:> u
|
403 |
|
|
Awaiting neorv32_exe.bin... OK
|
404 |
|
|
----
|
405 |
|
|
|
406 |
|
|
[start=10]
|
407 |
61 |
zero_gravi |
. The executable is now in the instruction memory of the processor. To execute the program right
|
408 |
60 |
zero_gravi |
now run the "Execute" command by typing `e`:
|
409 |
|
|
|
410 |
|
|
[source,bash]
|
411 |
|
|
----
|
412 |
|
|
CMD:> u
|
413 |
|
|
Awaiting neorv32_exe.bin... OK
|
414 |
|
|
CMD:> e
|
415 |
|
|
Booting...
|
416 |
|
|
Blinking LED demo program
|
417 |
|
|
----
|
418 |
|
|
|
419 |
|
|
[start=11]
|
420 |
61 |
zero_gravi |
. If everything went fine, you should see the LEDs blinking.
|
421 |
60 |
zero_gravi |
|
422 |
61 |
zero_gravi |
[NOTE]
|
423 |
|
|
The bootloader will print error codes if something went wrong.
|
424 |
|
|
See section https://stnolting.github.io/neorv32/#_bootloader[Bootloader] of the NEORV32 datasheet for more information.
|
425 |
60 |
zero_gravi |
|
426 |
61 |
zero_gravi |
[TIP]
|
427 |
|
|
See section <<_programming_an_external_spi_flash_via_the_bootloader>> to learn how to use an external SPI
|
428 |
|
|
flash for nonvolatile program storage.
|
429 |
60 |
zero_gravi |
|
430 |
61 |
zero_gravi |
[TIP]
|
431 |
|
|
Executables can also be uploaded via the **on-chip debugger**.
|
432 |
|
|
See section <<_debugging_with_gdb>> for more information.
|
433 |
|
|
|
434 |
|
|
|
435 |
|
|
|
436 |
60 |
zero_gravi |
<<<
|
437 |
|
|
// ####################################################################################################################
|
438 |
|
|
:sectnums:
|
439 |
61 |
zero_gravi |
== Installing an Executable Directly Into Memory
|
440 |
60 |
zero_gravi |
|
441 |
61 |
zero_gravi |
If you do not want to use the bootloader (or the on-chip debugger) for executable upload or if your setup does not provide
|
442 |
|
|
a serial interface for that, you can also directly install an application into embedded memory.
|
443 |
60 |
zero_gravi |
|
444 |
61 |
zero_gravi |
This concept uses the "Direct Boot" scenario that implements the processor-internal IMEM as ROM, which is
|
445 |
|
|
pre-initialized with the application's executable during synthesis. Hence, it provides _non-volatile_ storage of the
|
446 |
|
|
executable inside the processor. This storage cannot be altered during runtime and any source code modification of
|
447 |
|
|
the application requires to re-program the FPGA via the bitstream.
|
448 |
|
|
|
449 |
|
|
[TIP]
|
450 |
|
|
See datasheet section https://stnolting.github.io/neorv32/#_direct_boot[Direct Boot] for more information.
|
451 |
|
|
|
452 |
|
|
|
453 |
|
|
|
454 |
|
|
Using the IMEM as ROM:
|
455 |
|
|
|
456 |
|
|
* for this boot concept the bootloader is no longer required
|
457 |
|
|
* this concept only works for the internal IMEM (but can be extended to work with external memories coupled via the processor's bus interface)
|
458 |
|
|
* make sure that the memory components (like block RAM) the IMEM is mapped to support an initialization via the bitstream
|
459 |
|
|
|
460 |
60 |
zero_gravi |
[start=1]
|
461 |
61 |
zero_gravi |
. At first, make sure your processor setup actually implements the internal IMEM: the `MEM_INT_IMEM_EN` generics has to be set to `true`:
|
462 |
|
|
|
463 |
|
|
.Processor top entity configuration - enable internal IMEM
|
464 |
|
|
[source,vhdl]
|
465 |
|
|
----
|
466 |
|
|
-- Internal Instruction memory --
|
467 |
|
|
MEM_INT_IMEM_EN => true, -- implement processor-internal instruction memory
|
468 |
|
|
----
|
469 |
|
|
|
470 |
|
|
[start=2]
|
471 |
|
|
. For this setup we do not want the bootloader to be implemented at all. Disable implementation of the bootloader by setting the
|
472 |
|
|
`INT_BOOTLOADER_EN` generic to `false`. This will also modify the processor-internal IMEM so it is initialized with the executable during synthesis.
|
473 |
|
|
|
474 |
|
|
.Processor top entity configuration - disable internal bootloader
|
475 |
|
|
[source,vhdl]
|
476 |
|
|
----
|
477 |
|
|
-- General --
|
478 |
|
|
INT_BOOTLOADER_EN => false, -- boot configuration: false = boot from int/ext (I)MEM
|
479 |
|
|
----
|
480 |
|
|
|
481 |
|
|
[start=3]
|
482 |
|
|
. To generate an "initialization image" for the IMEM that contains the actual application, run the `install` target when compiling your application:
|
483 |
|
|
|
484 |
|
|
[source,bash]
|
485 |
|
|
----
|
486 |
|
|
neorv32/sw/example/blink_led$ make clean_all install
|
487 |
|
|
Memory utilization:
|
488 |
|
|
text data bss dec hex filename
|
489 |
|
|
3176 0 120 3296 ce0 main.elf
|
490 |
|
|
Compiling ../../../sw/image_gen/image_gen
|
491 |
|
|
Installing application image to ../../../rtl/core/neorv32_application_image.vhd
|
492 |
|
|
----
|
493 |
|
|
|
494 |
|
|
[start=4]
|
495 |
|
|
. The `install` target has compiled all the application sources but instead of creating an executable (`neorv32_exe.bit`) that can be uploaded via the
|
496 |
|
|
bootloader, it has created a VHDL memory initialization image `core/neorv32_application_image.vhd`.
|
497 |
|
|
. This VHDL file is automatically copied to the core's rtl folder (`rtl/core`) so it will be included for the next synthesis.
|
498 |
|
|
. Perform a new synthesis. The IMEM will be build as pre-initialized ROM (inferring embedded memories if possible).
|
499 |
|
|
. Upload your bitstream. Your application code now resides unchangeable in the processor's IMEM and is directly executed after reset.
|
500 |
|
|
|
501 |
|
|
|
502 |
|
|
The synthesis tool / simulator will print asserts to inform about the (IMEM) memory / boot configuration:
|
503 |
|
|
|
504 |
|
|
[source]
|
505 |
|
|
----
|
506 |
|
|
NEORV32 PROCESSOR CONFIG NOTE: Boot configuration: Direct boot from memory (processor-internal IMEM).
|
507 |
|
|
NEORV32 PROCESSOR CONFIG NOTE: Implementing processor-internal IMEM as ROM (3176 bytes), pre-initialized with application.
|
508 |
|
|
----
|
509 |
|
|
|
510 |
|
|
|
511 |
|
|
|
512 |
|
|
<<<
|
513 |
|
|
// ####################################################################################################################
|
514 |
|
|
:sectnums:
|
515 |
|
|
== Setup of a New Application Program Project
|
516 |
|
|
|
517 |
|
|
[start=1]
|
518 |
|
|
. The easiest way of creating a _new_ software application project is to copy an _existing_ one. This will keep all
|
519 |
|
|
file dependencies. For example you can copy `sw/example/blink_led` to `sw/example/flux_capacitor`.
|
520 |
|
|
. If you want to place you application somewhere outside `sw/example` you need to adapt the application's makefile.
|
521 |
|
|
In the makefile you will find a variable that keeps the relative or absolute path to the NEORV32 repo home
|
522 |
60 |
zero_gravi |
folder. Just modify this variable according to your new project's home location:
|
523 |
|
|
|
524 |
|
|
[source,makefile]
|
525 |
|
|
----
|
526 |
|
|
# Relative or absolute path to the NEORV32 home folder (use default if not set by user)
|
527 |
|
|
NEORV32_HOME ?= ../../..
|
528 |
|
|
----
|
529 |
|
|
|
530 |
|
|
[start=3]
|
531 |
61 |
zero_gravi |
. If your project contains additional source files outside of the project folder, you can add them to
|
532 |
|
|
the `APP_SRC` variable:
|
533 |
60 |
zero_gravi |
|
534 |
|
|
[source,makefile]
|
535 |
|
|
----
|
536 |
|
|
# User's application sources (add additional files here)
|
537 |
|
|
APP_SRC = $(wildcard *.c) ../somewhere/some_file.c
|
538 |
|
|
----
|
539 |
|
|
|
540 |
|
|
[start=4]
|
541 |
61 |
zero_gravi |
. You also can add a folder containing your application's include files to the
|
542 |
|
|
`APP_INC` variable (do not forget the `-I` prefix):
|
543 |
60 |
zero_gravi |
|
544 |
|
|
[source,makefile]
|
545 |
|
|
----
|
546 |
|
|
# User's application include folders (don't forget the '-I' before each entry)
|
547 |
|
|
APP_INC = -I . -I ../somewhere/include_stuff_folder
|
548 |
|
|
----
|
549 |
|
|
|
550 |
|
|
|
551 |
|
|
|
552 |
|
|
<<<
|
553 |
|
|
// ####################################################################################################################
|
554 |
|
|
:sectnums:
|
555 |
|
|
== Enabling RISC-V CPU Extensions
|
556 |
|
|
|
557 |
61 |
zero_gravi |
Whenever you enable/disable a RISC-V CPU extensions via the according `CPU_EXTENSION_RISCV_x` generic, you need to
|
558 |
60 |
zero_gravi |
adapt the toolchain configuration so the compiler can actually generate according code for it.
|
559 |
|
|
|
560 |
|
|
To do so, open the makefile of your project (for example `sw/example/blink_led/makefile`) and scroll to the
|
561 |
61 |
zero_gravi |
"USER CONFIGURATION" section right at the beginning of the file. You need to modify the `MARCH` variable and eventually
|
562 |
|
|
the `MABI` variable according to your CPU hardware configuration.
|
563 |
60 |
zero_gravi |
|
564 |
|
|
[source,makefile]
|
565 |
|
|
----
|
566 |
|
|
# CPU architecture and ABI
|
567 |
|
|
MARCH = -march=rv32i # <1>
|
568 |
|
|
MABI = -mabi=ilp32 # <2>
|
569 |
|
|
----
|
570 |
|
|
<1> MARCH = Machine architecture ("ISA string")
|
571 |
|
|
<2> MABI = Machine binary interface
|
572 |
|
|
|
573 |
61 |
zero_gravi |
For example, if you enable the RISC-V `C` extension (16-bit compressed instructions) via the `CPU_EXTENSION_RISCV_C`
|
574 |
|
|
generic (set `true`) you need to add the 'c' extension also to the `MARCH` ISA string in order to make the compiler
|
575 |
|
|
emit compressed instructions.
|
576 |
60 |
zero_gravi |
|
577 |
61 |
zero_gravi |
[WARNING]
|
578 |
|
|
ISA extension enabled in hardware can be a superset of the extensions enabled in software, but not the other way
|
579 |
|
|
around. For example generating compressed instructions for a CPU configuration that has the `c` extension disabled
|
580 |
|
|
will cause _illegal instruction exceptions_ at runtime.
|
581 |
60 |
zero_gravi |
|
582 |
61 |
zero_gravi |
You can also override the default `MARCH` and `MABI` configurations from the makefile when invoking the makefile:
|
583 |
|
|
|
584 |
60 |
zero_gravi |
[source,bash]
|
585 |
|
|
----
|
586 |
|
|
$ make MARCH=-march=rv32ic clean_all all
|
587 |
|
|
----
|
588 |
|
|
|
589 |
|
|
[NOTE]
|
590 |
61 |
zero_gravi |
The RISC-V ISA string (for _MARCH_) follows a certain _canonical_ structure:
|
591 |
60 |
zero_gravi |
`rev32[i/e][m][a][f][d][g][q][c][b][v][n]...` For example `rv32imac` is valid while `rv32icma` is not valid.
|
592 |
|
|
|
593 |
|
|
|
594 |
|
|
|
595 |
|
|
<<<
|
596 |
|
|
// ####################################################################################################################
|
597 |
|
|
:sectnums:
|
598 |
61 |
zero_gravi |
== Customizing the Internal Bootloader
|
599 |
60 |
zero_gravi |
|
600 |
61 |
zero_gravi |
The NEORV32 bootloader provides several options to configure and customize it for a certain application setup.
|
601 |
|
|
This configuration is done by passing _defines_ when compiling the bootloader. Of course you can also
|
602 |
|
|
modify to bootloader source code to provide a setup that perfectly fits your needs.
|
603 |
60 |
zero_gravi |
|
604 |
61 |
zero_gravi |
[IMPORTANT]
|
605 |
|
|
Each time the bootloader sources are modified, the bootloader has to be re-compiled (and re-installed to the
|
606 |
|
|
bootloader ROM) and the processor has to be re-synthesized.
|
607 |
60 |
zero_gravi |
|
608 |
61 |
zero_gravi |
[NOTE]
|
609 |
|
|
Keep in mind that the maximum size for the bootloader is limited to 32kB and should be compiled using the
|
610 |
|
|
base ISA `rv32i` only to ensure it can work independently of the actual CPU configuration.
|
611 |
60 |
zero_gravi |
|
612 |
61 |
zero_gravi |
.Bootloader configuration parameters
|
613 |
|
|
[cols="<2,^1,^2,<6"]
|
614 |
|
|
[options="header", grid="rows"]
|
615 |
|
|
|=======================
|
616 |
|
|
| Parameter | Default | Legal values | Description
|
617 |
|
|
4+^| Serial console interface
|
618 |
|
|
| `UART_EN` | `1` | `0`, `1` | Set to `0` to disable UART0 (no serial console at all)
|
619 |
|
|
| `UART_BAUD` | `19200` | _any_ | Baud rate of UART0
|
620 |
|
|
4+^| Status LED
|
621 |
|
|
| `STATUS_LED_EN` | `1` | `0`, `1` | Enable bootloader status led ("heart beat") at `GPIO` output port pin #`STATUS_LED_PIN` when `1`
|
622 |
|
|
| `STATUS_LED_PIN` | `0` | `0` ... `31` | `GPIO` output pin used for the high-active status LED
|
623 |
|
|
4+^| Boot configuration
|
624 |
|
|
| `AUTO_BOOT_SPI_EN` | `0` | `0`, `1` | Set `1` to enable immediate boot from external SPI flash
|
625 |
|
|
| `AUTO_BOOT_OCD_EN` | `0` | `0`, `1` | Set `1` to enable boot via on-chip debugger (OCD)
|
626 |
|
|
| `AUTO_BOOT_TIMEOUT` | `8` | _any_ | Time in seconds after the auto-boot sequence starts (if there is no UART input by user); set to 0 to disabled auto-boot sequence
|
627 |
|
|
4+^| SPI configuration
|
628 |
|
|
| `SPI_FLASH_CS` | `0` | `0` ... `7` | SPI chip select output (`spi_csn_o`) for selecting flash
|
629 |
|
|
| `SPI_FLASH_SECTOR_SIZE` | `65536` | _any_ | SPI flash sector size in bytes
|
630 |
|
|
| `SPI_FLASH_CLK_PRSC` | `CLK_PRSC_8` | `CLK_PRSC_2` `CLK_PRSC_4` `CLK_PRSC_8` `CLK_PRSC_64` `CLK_PRSC_128` `CLK_PRSC_1024` `CLK_PRSC_2024` `CLK_PRSC_4096` | SPI clock pre-scaler (dividing main processor clock)
|
631 |
|
|
| `SPI_BOOT_BASE_ADDR` | `0x08000000` | _any_ 32-bit value | Defines the _base_ address of the executable in external flash
|
632 |
|
|
|=======================
|
633 |
60 |
zero_gravi |
|
634 |
61 |
zero_gravi |
Each configuration parameter is implemented as C-language `define` that can be manually overridden (_redefined_) when
|
635 |
|
|
invoking the bootloader's makefile. The according parameter and its new value has to be _appended_
|
636 |
|
|
(using `+=`) to the makefile's `USER_FLAGS` variable. Make sure to use the `-D` prefix here.
|
637 |
60 |
zero_gravi |
|
638 |
61 |
zero_gravi |
For example, to configure a UART Baud rate of 57600 and redirecting the status LED to output pin 20
|
639 |
|
|
use the following command (_in_ the bootloader's source folder `sw/bootloader`):
|
640 |
60 |
zero_gravi |
|
641 |
61 |
zero_gravi |
.Example: customizing, re-compiling and re-installing the bootloader
|
642 |
|
|
[source,console]
|
643 |
60 |
zero_gravi |
----
|
644 |
61 |
zero_gravi |
$ make USER_FLAGS+=-DUART_BAUD=57600 USER_FLAGS+=-DSTATUS_LED_PIN=20 clean_all bootloader
|
645 |
60 |
zero_gravi |
----
|
646 |
|
|
|
647 |
61 |
zero_gravi |
[NOTE]
|
648 |
|
|
The `clean_all` target ensure that all libraries are re-compiled. The `bootloader` target will automatically
|
649 |
|
|
compile and install the bootloader to the HDL boot ROM (updating `rtl/core/neorv32_bootloader_image.vhd`).
|
650 |
60 |
zero_gravi |
|
651 |
61 |
zero_gravi |
:sectnums:
|
652 |
|
|
=== Bootloader Boot Configuration
|
653 |
60 |
zero_gravi |
|
654 |
61 |
zero_gravi |
The bootloader provides several _boot configurations_ that define where the actual application's executable
|
655 |
|
|
shall be fetched from. Note that the non-default boot configurations provide a smaller memory footprint
|
656 |
|
|
reducing boot ROM implementation costs.
|
657 |
60 |
zero_gravi |
|
658 |
61 |
zero_gravi |
:sectnums!:
|
659 |
|
|
==== Default Boot Configuration
|
660 |
60 |
zero_gravi |
|
661 |
61 |
zero_gravi |
The _default_ bootloader configuration provides a UART-based user interface that allows to upload new executables
|
662 |
|
|
at any time. Optionally, the executable can also be programmed to an external SPI flash by the bootloader (see
|
663 |
|
|
section <<_programming_an_external_spi_flash_via_the_bootloader>>).
|
664 |
60 |
zero_gravi |
|
665 |
61 |
zero_gravi |
This configuration also provides an _automatic boot sequence_ (auto-boot) which will start fetching an executable
|
666 |
|
|
from external SPI flash using the default SPI configuration. By this, the default bootloader configuration
|
667 |
|
|
provides a "non volatile program storage" mechanism that automatically boot from external SPI flash
|
668 |
|
|
(after `AUTO_BOOT_TIMEOUT`) while still providing the option to re-program SPI flash at any time
|
669 |
|
|
via the UART interface.
|
670 |
60 |
zero_gravi |
|
671 |
61 |
zero_gravi |
:sectnums!:
|
672 |
|
|
==== `AUTO_BOOT_SPI_EN`
|
673 |
60 |
zero_gravi |
|
674 |
61 |
zero_gravi |
The automatic boot from SPI flash (enabled when `AUTO_BOOT_SPI_EN` is `1`) will fetch an executable from an external
|
675 |
|
|
SPI flash (using the according _SPI configuration_) right after reset. The bootloader will start fetching
|
676 |
|
|
the image at SPI flash base address `SPI_BOOT_BASE_ADDR`.
|
677 |
60 |
zero_gravi |
|
678 |
61 |
zero_gravi |
Note that there is _no_ UART console to interact with the bootloader. However, this boot configuration will
|
679 |
|
|
output minimal status messages via UART (if `UART_EN` is `1`).
|
680 |
60 |
zero_gravi |
|
681 |
61 |
zero_gravi |
:sectnums!:
|
682 |
|
|
==== `AUTO_BOOT_OCD_EN`
|
683 |
60 |
zero_gravi |
|
684 |
61 |
zero_gravi |
If `AUTO_BOOT_OCD_EN` is `1` the bootloader is implemented as minimal "halt loop" to be used with the on-chip debugger.
|
685 |
|
|
After initializing the hardware, the CPU waits in this endless loop until the on-chip debugger takes control over
|
686 |
|
|
the core (to upload and run the actual executable). See section <<_debugging_using_the_on_chip_debugger>>
|
687 |
|
|
for more information on how to use the on-chip debugger to upload and run executables.
|
688 |
60 |
zero_gravi |
|
689 |
61 |
zero_gravi |
[NOTE]
|
690 |
|
|
All bootloader boot configuration support uploading new executables via the on-chip debugger.
|
691 |
60 |
zero_gravi |
|
692 |
61 |
zero_gravi |
[WARNING]
|
693 |
|
|
Note that this boot configuration does not load any executable at all! Hence,
|
694 |
|
|
this boot configuration is intended to be used with the on-chip debugger only.
|
695 |
60 |
zero_gravi |
|
696 |
|
|
|
697 |
|
|
|
698 |
61 |
zero_gravi |
<<<
|
699 |
|
|
// ####################################################################################################################
|
700 |
|
|
:sectnums:
|
701 |
|
|
== Programming an External SPI Flash via the Bootloader
|
702 |
60 |
zero_gravi |
|
703 |
61 |
zero_gravi |
The default processor-internal NEORV32 bootloader supports automatic booting from an external SPI flash.
|
704 |
|
|
This guide shows how to write an executable to the SPI flash via the bootloader so it can be automatically
|
705 |
|
|
fetched and executed after processor reset. For example, you can use a section of the FPGA bitstream configuration
|
706 |
|
|
memory to store an application executable.
|
707 |
60 |
zero_gravi |
|
708 |
61 |
zero_gravi |
[NOTE]
|
709 |
|
|
This section assumes the _default_ configuration of the NEORV32 bootloader.
|
710 |
|
|
See section <<_customizing_the_internal_bootloader>> on how to customize the bootloader and its setting
|
711 |
|
|
(for example the SPI chip-select port, the SPI clock speed or the flash base address for storing the executable).
|
712 |
60 |
zero_gravi |
|
713 |
|
|
|
714 |
61 |
zero_gravi |
:sectnums:
|
715 |
|
|
=== SPI Flash
|
716 |
60 |
zero_gravi |
|
717 |
61 |
zero_gravi |
The bootloader can access an SPI compatible flash via the processor top entity's SPI port. By default, the flash
|
718 |
|
|
chip-select line is to `spi_csn_o(0)` and uses 1/8 of the processor's main clock as clock frequency.
|
719 |
|
|
The SPI flash has to support single-byte read and write, 24-bit addresses and at least the following standard commands:
|
720 |
60 |
zero_gravi |
|
721 |
61 |
zero_gravi |
* READ `0x03`
|
722 |
|
|
* READ STATUS `0x05`
|
723 |
|
|
* WRITE ENABLE `0x06`
|
724 |
|
|
* PAGE PROGRAM `0x02`
|
725 |
|
|
* SECTOR ERASE `0xD8`
|
726 |
|
|
* READ ID `0x9E`
|
727 |
60 |
zero_gravi |
|
728 |
61 |
zero_gravi |
Compatible (FGPA configuration) SPI flash memories are for example the "Winbond W25Q64FV2 or the "Micron N25Q032A".
|
729 |
60 |
zero_gravi |
|
730 |
|
|
|
731 |
|
|
:sectnums:
|
732 |
61 |
zero_gravi |
=== Programming an Executable
|
733 |
60 |
zero_gravi |
|
734 |
|
|
[start=1]
|
735 |
|
|
. At first, reset the NEORV32 processor and wait until the bootloader start screen appears in your terminal program.
|
736 |
|
|
. Abort the auto boot sequence and start the user console by pressing any key.
|
737 |
61 |
zero_gravi |
. Press u to upload the executable that you want to store to the external flash:
|
738 |
60 |
zero_gravi |
|
739 |
|
|
[source]
|
740 |
|
|
----
|
741 |
|
|
CMD:> u
|
742 |
|
|
Awaiting neorv32_exe.bin...
|
743 |
|
|
----
|
744 |
|
|
|
745 |
|
|
[start=4]
|
746 |
61 |
zero_gravi |
. Send the binary in raw binary via your terminal program. When the upload is completed and "OK"
|
747 |
60 |
zero_gravi |
appears, press `p` to trigger the programming of the flash (do not execute the image via the `e`
|
748 |
|
|
command as this might corrupt the image):
|
749 |
|
|
|
750 |
|
|
[source]
|
751 |
|
|
----
|
752 |
|
|
CMD:> u
|
753 |
|
|
Awaiting neorv32_exe.bin... OK
|
754 |
|
|
CMD:> p
|
755 |
|
|
Write 0x000013FC bytes to SPI flash @ 0x00800000? (y/n)
|
756 |
|
|
----
|
757 |
|
|
|
758 |
|
|
[start=5]
|
759 |
|
|
. The bootloader shows the size of the executable and the base address inside the SPI flash where the
|
760 |
|
|
executable is going to be stored. A prompt appears: Type `y` to start the programming or type `n` to
|
761 |
61 |
zero_gravi |
abort.
|
762 |
60 |
zero_gravi |
|
763 |
61 |
zero_gravi |
[TIP]
|
764 |
|
|
Section <<_customizing_the_internal_bootloader>> show the according C-language `define` that can be modified
|
765 |
|
|
to specify the base address of the executable inside the SPI flash.
|
766 |
|
|
|
767 |
60 |
zero_gravi |
[source]
|
768 |
|
|
----
|
769 |
|
|
CMD:> u
|
770 |
|
|
Awaiting neorv32_exe.bin... OK
|
771 |
|
|
CMD:> p
|
772 |
61 |
zero_gravi |
Write 0x000013FC bytes to SPI flash @ 0x08000000? (y/n) y
|
773 |
60 |
zero_gravi |
Flashing... OK
|
774 |
|
|
CMD:>
|
775 |
|
|
----
|
776 |
|
|
|
777 |
|
|
[start=6]
|
778 |
|
|
. If "OK" appears in the terminal line, the programming process was successful. Now you can use the
|
779 |
|
|
auto boot sequence to automatically boot your application from the flash at system start-up without
|
780 |
|
|
any user interaction.
|
781 |
|
|
|
782 |
|
|
|
783 |
|
|
|
784 |
|
|
<<<
|
785 |
|
|
// ####################################################################################################################
|
786 |
|
|
:sectnums:
|
787 |
61 |
zero_gravi |
== Packaging the Processor as IP block for Xilinx Vivado Block Designer
|
788 |
|
|
|
789 |
|
|
.WORK IN PROGRESS
|
790 |
|
|
[WARNING]
|
791 |
|
|
This Section Is Under Construction! +
|
792 |
|
|
+
|
793 |
|
|
FIXME!
|
794 |
|
|
|
795 |
|
|
|
796 |
|
|
|
797 |
|
|
<<<
|
798 |
|
|
// ####################################################################################################################
|
799 |
|
|
:sectnums:
|
800 |
60 |
zero_gravi |
== Simulating the Processor
|
801 |
|
|
|
802 |
61 |
zero_gravi |
.WORK IN PROGRESS
|
803 |
|
|
[WARNING]
|
804 |
|
|
This Section Is Under Construction! +
|
805 |
|
|
+
|
806 |
|
|
FIXME!
|
807 |
60 |
zero_gravi |
|
808 |
61 |
zero_gravi |
:sectnums:
|
809 |
|
|
=== Testbench
|
810 |
|
|
|
811 |
|
|
The NEORV32 project features a simple default testbench (`sim/neorv32_tb.simple.vhd`) that can be used to simulate
|
812 |
60 |
zero_gravi |
and test the processor setup. This testbench features a 100MHz clock and enables all optional peripheral and
|
813 |
|
|
CPU extensions except for the `E` extension and the TRNG IO module (that CANNOT be simulated due to its
|
814 |
|
|
combinatorial (looped) oscillator architecture).
|
815 |
|
|
|
816 |
|
|
The simulation setup is configured via the "User Configuration" section located right at the beginning of
|
817 |
|
|
the testbench's architecture. Each configuration constant provides comments to explain the functionality.
|
818 |
|
|
|
819 |
|
|
Besides the actual NEORV32 Processor, the testbench also simulates "external" components that are connected
|
820 |
|
|
to the processor's external bus/memory interface. These components are:
|
821 |
|
|
|
822 |
|
|
* an external instruction memory (that also allows booting from it)
|
823 |
|
|
* an external data memory
|
824 |
|
|
* an external memory to simulate "external IO devices"
|
825 |
|
|
* a memory-mapped registers to trigger the processor's interrupt signals
|
826 |
|
|
|
827 |
|
|
The following table shows the base addresses of these four components and their default configuration and
|
828 |
|
|
properties (attributes: `r` = read, `w` = write, `e` = execute, `a` = atomic accesses possible, `8` = byte-accessible, `16` =
|
829 |
|
|
half-word-accessible, `32` = word-accessible).
|
830 |
|
|
|
831 |
|
|
.Testbench: processor-external memories
|
832 |
|
|
[cols="^4,>3,^5,<11"]
|
833 |
|
|
[options="header",grid="rows"]
|
834 |
|
|
|=======================
|
835 |
|
|
| Base address | Size | Attributes | Description
|
836 |
|
|
| `0x00000000` | `imem_size_c` | `r/w/e, a, 8/16/32` | external IMEM (initialized with application image)
|
837 |
|
|
| `0x80000000` | `dmem_size_c` | `r/w/e, a, 8/16/32` | external DMEM
|
838 |
|
|
| `0xf0000000` | 64 bytes | `r/w/e, !a, 8/16/32` | external "IO" memory, atomic accesses will fail
|
839 |
|
|
| `0xff000000` | 4 bytes | `-/w/-, a, -/-/32` | memory-mapped register to trigger "machine external", "machine software" and "SoC Fast Interrupt" interrupts
|
840 |
|
|
|=======================
|
841 |
|
|
|
842 |
|
|
The simulated NEORV32 does not use the bootloader and directly boots the current application image (from
|
843 |
|
|
the `rtl/core/neorv32_application_image.vhd` image file). Make sure to use the `all` target of the
|
844 |
|
|
makefile to install your application as VHDL image after compilation:
|
845 |
|
|
|
846 |
|
|
[source, bash]
|
847 |
|
|
----
|
848 |
|
|
sw/example/blink_led$ make clean_all all
|
849 |
|
|
----
|
850 |
|
|
|
851 |
|
|
.Simulation-Optimized CPU/Processors Modules
|
852 |
|
|
[NOTE]
|
853 |
|
|
The `sim/rtl_modules` folder provides simulation-optimized versions of certain CPU/processor modules.
|
854 |
|
|
These alternatives can be used to replace the default CPU/processor HDL files to allow faster/easier/more
|
855 |
|
|
efficient simulation. **These files are not intended for synthesis!**
|
856 |
|
|
|
857 |
|
|
**Simulation Console Output**
|
858 |
|
|
|
859 |
|
|
Data written to the NEORV32 UART0 / UART1 transmitter is send to a virtual UART receiver implemented
|
860 |
|
|
as part of the testbench. Received chars are send to the simulator console and are also stored to a log file
|
861 |
|
|
(`neorv32.testbench_uart0.out` for UART0, `neorv32.testbench_uart1.out` for UART1) inside the simulator home folder.
|
862 |
|
|
|
863 |
|
|
|
864 |
61 |
zero_gravi |
:sectnums:
|
865 |
|
|
=== Faster Simulation Console Output
|
866 |
|
|
|
867 |
60 |
zero_gravi |
When printing data via the UART the communication speed will always be based on the configured BAUD
|
868 |
|
|
rate. For a simulation this might take some time. To have faster output you can enable the **simulation mode**
|
869 |
|
|
or UART0/UART1 (see section https://stnolting.github.io/neorv32/#_primary_universal_asynchronous_receiver_and_transmitter_uart0[Documentation: Primary Universal Asynchronous Receiver and Transmitter (UART0)]).
|
870 |
|
|
|
871 |
|
|
ASCII data send to UART0 will be immediately printed to the simulator console. Additionally, the
|
872 |
|
|
ASCII data is logged in a file (`neorv32.uart0.sim_mode.text.out`) in the simulator home folder. All
|
873 |
|
|
written 32-bit data is also dumped as 8-char hexadecimal value into a file
|
874 |
|
|
(`neorv32.uart0.sim_mode.data.out`) also in the simulator home folder.
|
875 |
|
|
|
876 |
|
|
ASCII data send to UART1 will be immediately printed to the simulator console. Additionally, the
|
877 |
|
|
ASCII data is logged in a file (`neorv32.uart1.sim_mode.text.out`) in the simulator home folder. All
|
878 |
|
|
written 32-bit data is also dumped as 8-char hexadecimal value into a file
|
879 |
|
|
(`neorv32.uart1.sim_mode.data.out`) also in the simulator home folder.
|
880 |
|
|
|
881 |
|
|
You can "automatically" enable the simulation mode of UART0/UART1 when compiling an application. In this case the
|
882 |
|
|
"real" UART0/UART1 transmitter unit is permanently disabled. To enable the simulation mode just compile
|
883 |
|
|
and install your application and add _UART0_SIM_MODE_ for UART0 and/or _UART1_SIM_MODE_ for UART1 to
|
884 |
|
|
the compiler's _USER_FLAGS_ variable (do not forget the `-D` suffix flag):
|
885 |
|
|
|
886 |
|
|
[source, bash]
|
887 |
|
|
----
|
888 |
|
|
sw/example/blink_led$ make USER_FLAGS+=-DUART0_SIM_MODE clean_all all
|
889 |
|
|
----
|
890 |
|
|
|
891 |
|
|
The provided define will change the default UART0/UART1 setup function in order to set the simulation mode flag in the according UART's control register.
|
892 |
|
|
|
893 |
|
|
[NOTE]
|
894 |
|
|
The UART simulation output (to file and to screen) outputs "complete lines" at once. A line is
|
895 |
|
|
completed with a line feed (newline, ASCII `\n` = 10).
|
896 |
|
|
|
897 |
|
|
|
898 |
61 |
zero_gravi |
:sectnums:
|
899 |
|
|
=== Simulation using GHDL
|
900 |
60 |
zero_gravi |
|
901 |
61 |
zero_gravi |
To simulate the processor using _GHDL_ navigate to the `sim` folder and run the provided shell script.
|
902 |
|
|
Any arguments that are provided while executing this script are passed to GHDL.
|
903 |
|
|
For example the simulation time can be set to 20ms using `--stop-time=20ms` as argument.
|
904 |
60 |
zero_gravi |
|
905 |
|
|
[source, bash]
|
906 |
|
|
----
|
907 |
61 |
zero_gravi |
neorv32/sim$ sh ghdl_sim.sh --stop-time=20ms
|
908 |
60 |
zero_gravi |
----
|
909 |
|
|
|
910 |
|
|
|
911 |
|
|
|
912 |
|
|
<<<
|
913 |
|
|
// ####################################################################################################################
|
914 |
|
|
:sectnums:
|
915 |
|
|
== Building the Documentation
|
916 |
|
|
|
917 |
61 |
zero_gravi |
The documentation (datasheet + user guide) is written using `asciidoc`. The according source files
|
918 |
|
|
can be found in `docs/...`. The documentation of the software framework is written _in-code_ using `doxygen`.
|
919 |
60 |
zero_gravi |
|
920 |
61 |
zero_gravi |
A makefiles in the project's root directory is provided to build all of the documentation as HTML pages
|
921 |
60 |
zero_gravi |
or as PDF documents.
|
922 |
|
|
|
923 |
|
|
[TIP]
|
924 |
61 |
zero_gravi |
Pre-rendered PDFs are available online as _nightly pre-releases_: https://github.com/stnolting/neorv32/releases.
|
925 |
60 |
zero_gravi |
The HTML-based documentation is also available online at the project's https://stnolting.github.io/neorv32/[GitHub Pages].
|
926 |
|
|
|
927 |
|
|
The makefile provides a help target to show all available build options and their according outputs.
|
928 |
|
|
|
929 |
|
|
[source,bash]
|
930 |
|
|
----
|
931 |
|
|
neorv32$ make help
|
932 |
|
|
----
|
933 |
|
|
|
934 |
|
|
.Example: Generate HTML documentation (data sheet) using `asciidoctor`
|
935 |
|
|
[source,bash]
|
936 |
|
|
----
|
937 |
|
|
neorv32$ make html
|
938 |
|
|
----
|
939 |
|
|
|
940 |
|
|
[TIP]
|
941 |
|
|
If you don't have `asciidoctor` / `asciidoctor-pdf` installed, you can still generate all the documentation using
|
942 |
|
|
a _docker container_ via `make container`.
|
943 |
|
|
|
944 |
|
|
|
945 |
|
|
|
946 |
|
|
<<<
|
947 |
|
|
// ####################################################################################################################
|
948 |
|
|
:sectnums:
|
949 |
|
|
== FreeRTOS Support
|
950 |
|
|
|
951 |
|
|
A NEORV32-specific port and a simple demo for FreeRTOS (https://github.com/FreeRTOS/FreeRTOS) are
|
952 |
61 |
zero_gravi |
available in the `sw/example/demo_freeRTOS` folder. See the according documentation (`sw/example/demo_freeRTOS/README.md`)
|
953 |
|
|
for more information.
|
954 |
60 |
zero_gravi |
|
955 |
|
|
|
956 |
|
|
|
957 |
|
|
// ####################################################################################################################
|
958 |
|
|
:sectnums:
|
959 |
|
|
== RISC-V Architecture Test Framework
|
960 |
|
|
|
961 |
|
|
The NEORV32 Processor passes the according tests provided by the official RISC-V Architecture Test Suite
|
962 |
|
|
(V2.0+), which is available online at GitHub: https://github.com/riscv/riscv-arch-test
|
963 |
|
|
|
964 |
|
|
All files required for executing the test framework on a simulated instance of the processor (including port
|
965 |
|
|
files) are located in the `riscv-arch-test` folder in the root directory of the NEORV32 repository. Take a
|
966 |
61 |
zero_gravi |
look at the provided `riscv-arch-test/README.md` (https://github.com/stnolting/neorv32/blob/master/riscv-arch-test/README.md[online at GitHub])
|
967 |
60 |
zero_gravi |
file for more information on how to run the tests and how testing is conducted in detail.
|
968 |
|
|
|
969 |
|
|
|
970 |
|
|
|
971 |
|
|
<<<
|
972 |
|
|
// ####################################################################################################################
|
973 |
|
|
:sectnums:
|
974 |
|
|
== Debugging using the On-Chip Debugger
|
975 |
|
|
|
976 |
61 |
zero_gravi |
The NEORV32 on-chip debugger allows _online_ in-system debugging via an external JTAG access port from a
|
977 |
60 |
zero_gravi |
host machine. The general flow is independent of the host machine's operating system. However, this tutorial uses
|
978 |
|
|
Windows and Linux (Ubuntu on Windows) in parallel.
|
979 |
|
|
|
980 |
61 |
zero_gravi |
[TIP]
|
981 |
|
|
See datasheet section https://stnolting.github.io/neorv32/#_on_chip_debugger_ocd[On Chip Debugger (OCD)]
|
982 |
|
|
for more information.
|
983 |
|
|
|
984 |
60 |
zero_gravi |
[NOTE]
|
985 |
|
|
This tutorial uses `gdb` to **directly upload an executable** to the processor. If you are using the default
|
986 |
|
|
processor setup _with_ internal instruction memory (IMEM) make sure it is implemented as RAM
|
987 |
61 |
zero_gravi |
(_INT_BOOTLOADER_EN_ generic = true).
|
988 |
60 |
zero_gravi |
|
989 |
|
|
|
990 |
|
|
:sectnums:
|
991 |
|
|
=== Hardware Requirements
|
992 |
|
|
|
993 |
|
|
Make sure the on-chip debugger of your NEORV32 setups is implemented (_ON_CHIP_DEBUGGER_EN_ generic = true).
|
994 |
|
|
Connect a JTAG adapter to the NEORV32 `jtag_*` interface signals. If you do not have a full-scale JTAG adapter, you can
|
995 |
|
|
also use a FTDI-based adapter like the "FT2232H-56Q Mini Module", which is a simple and inexpensive FTDI breakout board.
|
996 |
|
|
|
997 |
|
|
.JTAG pin mapping
|
998 |
|
|
[cols="^3,^2,^2"]
|
999 |
|
|
[options="header",grid="rows"]
|
1000 |
|
|
|=======================
|
1001 |
|
|
| NEORV32 top signal | JTAG signal | FTDI port
|
1002 |
|
|
| `jtag_tck_i` | TCK | D0
|
1003 |
|
|
| `jtag_tdi_i` | TDI | D1
|
1004 |
|
|
| `jtag_tdo_o` | TDO | D2
|
1005 |
|
|
| `jtag_tms_i` | TMS | D3
|
1006 |
|
|
| `jtag_trst_i` | TRST | D4
|
1007 |
|
|
|=======================
|
1008 |
|
|
|
1009 |
|
|
[TIP]
|
1010 |
|
|
The low-active JTAG _test reset_ (TRST) signals is _optional_ as a reset can also be triggered via the TAP controller.
|
1011 |
|
|
If TRST is not used make sure to pull the signal _high_.
|
1012 |
|
|
|
1013 |
|
|
|
1014 |
|
|
:sectnums:
|
1015 |
|
|
=== OpenOCD
|
1016 |
|
|
|
1017 |
|
|
The NEORV32 on-chip debugger can be accessed using the https://github.com/riscv/riscv-openocd[RISC-V port of OpenOCD].
|
1018 |
|
|
Prebuilt binaries can be obtained - for example - from https://www.sifive.com/software[SiFive]. A pre-configured
|
1019 |
|
|
OpenOCD configuration file (`sw/openocd/openocd_neorv32.cfg`) is available that allows easy access to the NEORV32 CPU.
|
1020 |
|
|
|
1021 |
|
|
[NOTE]
|
1022 |
|
|
You might need to adapt `ftdi_vid_pid`, `ftdi_channel` and `ftdi_layout_init` in `sw/openocd/openocd_neorv32.cfg`
|
1023 |
|
|
according to your interface chip and your operating system.
|
1024 |
|
|
|
1025 |
|
|
[TIP]
|
1026 |
|
|
If you want to modify the JTAG clock speed (via `adapter speed` in `sw/openocd/openocd_neorv32.cfg`) make sure to meet
|
1027 |
|
|
the clock requirements noted in https://stnolting.github.io/neorv32/#_debug_module_dm[Documentation: Debug Transport Module (DTM)].
|
1028 |
|
|
|
1029 |
|
|
To access the processor using OpenOCD, open a terminal and start OpenOCD with the pre-configured configuration file.
|
1030 |
|
|
|
1031 |
|
|
.Connecting via OpenOCD (on Windows)
|
1032 |
|
|
[source, bash]
|
1033 |
|
|
--------------------------
|
1034 |
|
|
N:\Projects\neorv32\sw\openocd>openocd -f openocd_neorv32.cfg
|
1035 |
|
|
Open On-Chip Debugger 0.11.0-rc1+dev (SiFive OpenOCD 0.10.0-2020.12.1)
|
1036 |
|
|
Licensed under GNU GPL v2
|
1037 |
|
|
For bug reports:
|
1038 |
|
|
https://github.com/sifive/freedom-tools/issues
|
1039 |
|
|
1
|
1040 |
|
|
Info : Listening on port 6666 for tcl connections
|
1041 |
|
|
Info : Listening on port 4444 for telnet connections
|
1042 |
|
|
Info : clock speed 1000 kHz
|
1043 |
|
|
Info : JTAG tap: neorv32.cpu tap/device found: 0x0cafe001 (mfg: 0x000 (), part: 0xcafe, ver: 0x0)
|
1044 |
|
|
Info : datacount=1 progbufsize=2
|
1045 |
|
|
Info : Disabling abstract command reads from CSRs.
|
1046 |
|
|
Info : Examined RISC-V core; found 1 harts
|
1047 |
|
|
Info : hart 0: XLEN=32, misa=0x40801105
|
1048 |
|
|
Info : starting gdb server for neorv32.cpu.0 on 3333
|
1049 |
|
|
Info : Listening on port 3333 for gdb connections
|
1050 |
|
|
--------------------------
|
1051 |
|
|
|
1052 |
|
|
OpenOCD has successfully connected to the NEORV32 on-chip debugger and has examined the CPU (showing the content of
|
1053 |
|
|
the `misa` CSRs). Now you can use `gdb` to connect via port 3333.
|
1054 |
|
|
|
1055 |
|
|
|
1056 |
|
|
:sectnums:
|
1057 |
|
|
=== Debugging with GDB
|
1058 |
|
|
|
1059 |
|
|
This guide uses the simple "blink example" from `sw/example/blink_led` as simplified test application to
|
1060 |
|
|
show the basics of in-system debugging.
|
1061 |
|
|
|
1062 |
|
|
At first, the application needs to be compiled. We will use the minimal machine architecture configuration
|
1063 |
|
|
(`rv32i`) here to be independent of the actual processor/CPU configuration.
|
1064 |
|
|
Navigate to `sw/example/blink_led` and compile the application:
|
1065 |
|
|
|
1066 |
|
|
.Compile the test application
|
1067 |
|
|
[source, bash]
|
1068 |
|
|
--------------------------
|
1069 |
|
|
.../neorv32/sw/example/blink_led$ make MARCH=-march=rv32i clean_all all
|
1070 |
|
|
--------------------------
|
1071 |
|
|
|
1072 |
|
|
This will generate an ELF file `main.elf` that contains all the symbols required for debugging.
|
1073 |
|
|
Furthermore, an assembly listing file `main.asm` is generated that we will use to define breakpoints.
|
1074 |
|
|
|
1075 |
|
|
Open another terminal in `sw/example/blink_led` and start `gdb`.
|
1076 |
61 |
zero_gravi |
The GNU debugger is part of the toolchain (see <<_software_toolchain_setup>>).
|
1077 |
60 |
zero_gravi |
|
1078 |
|
|
.Starting GDB (on Linux (Ubuntu on Windows))
|
1079 |
|
|
[source, bash]
|
1080 |
|
|
--------------------------
|
1081 |
|
|
.../neorv32/sw/example/blink_led$ riscv32-unknown-elf-gdb
|
1082 |
|
|
GNU gdb (GDB) 10.1
|
1083 |
|
|
Copyright (C) 2020 Free Software Foundation, Inc.
|
1084 |
|
|
License GPLv3+: GNU GPL version 3 or later
|
1085 |
|
|
This is free software: you are free to change and redistribute it.
|
1086 |
|
|
There is NO WARRANTY, to the extent permitted by law.
|
1087 |
|
|
Type "show copying" and "show warranty" for details.
|
1088 |
|
|
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=riscv32-unknown-elf".
|
1089 |
|
|
Type "show configuration" for configuration details.
|
1090 |
|
|
For bug reporting instructions, please see:
|
1091 |
|
|
.
|
1092 |
|
|
Find the GDB manual and other documentation resources online at:
|
1093 |
|
|
.
|
1094 |
|
|
|
1095 |
|
|
For help, type "help".
|
1096 |
|
|
Type "apropos word" to search for commands related to "word".
|
1097 |
|
|
(gdb)
|
1098 |
|
|
--------------------------
|
1099 |
|
|
|
1100 |
|
|
Now connect to OpenOCD using the default port 3333 on your local machine.
|
1101 |
|
|
Set the ELF file we want to debug to the recently generated `main.elf` from the `blink_led` example.
|
1102 |
|
|
Finally, upload the program to the processor.
|
1103 |
|
|
|
1104 |
|
|
[NOTE]
|
1105 |
|
|
The executable that is uploaded to the processor is **not** the default NEORV32 executable (`neorv32_exe.bin`) that
|
1106 |
|
|
is used for uploading via the bootloader. Instead, all the required sections (like `.text`) are extracted from `mail.elf`
|
1107 |
|
|
by GDB and uploaded via the debugger's indirect memory access.
|
1108 |
|
|
|
1109 |
|
|
.Running GDB
|
1110 |
|
|
[source, bash]
|
1111 |
|
|
--------------------------
|
1112 |
|
|
(gdb) target remote localhost:3333 <1>
|
1113 |
|
|
Remote debugging using localhost:3333
|
1114 |
|
|
warning: No executable has been specified and target does not support
|
1115 |
|
|
determining executable automatically. Try using the "file" command.
|
1116 |
|
|
0xffff0c94 in ?? () <2>
|
1117 |
|
|
(gdb) file main.elf <3>
|
1118 |
|
|
A program is being debugged already.
|
1119 |
|
|
Are you sure you want to change the file? (y or n) y
|
1120 |
|
|
Reading symbols from main.elf...
|
1121 |
|
|
(gdb) load <4>
|
1122 |
|
|
Loading section .text, size 0xd0c lma 0x0
|
1123 |
|
|
Loading section .rodata, size 0x39c lma 0xd0c
|
1124 |
|
|
Start address 0x00000000, load size 4264
|
1125 |
|
|
Transfer rate: 43 KB/sec, 2132 bytes/write.
|
1126 |
|
|
(gdb)
|
1127 |
|
|
--------------------------
|
1128 |
|
|
<1> Connect to OpenOCD
|
1129 |
|
|
<2> The CPU was still executing code from the bootloader ROM - but that does not matter here
|
1130 |
|
|
<3> Select `mail.elf` from the `blink_led` example
|
1131 |
|
|
<4> Upload the executable
|
1132 |
|
|
|
1133 |
|
|
After the upload, GDB will make the processor jump to the beginning of the uploaded executable
|
1134 |
|
|
(by default, this is the beginning of the instruction memory at `0x00000000`) skipping the bootloader
|
1135 |
|
|
and halting the CPU right before executing the `blink_led` application.
|
1136 |
|
|
|
1137 |
|
|
|
1138 |
|
|
:sectnums:
|
1139 |
|
|
==== Breakpoint Example
|
1140 |
|
|
|
1141 |
|
|
The following steps are just a small showcase that illustrate a simple debugging scheme.
|
1142 |
|
|
|
1143 |
|
|
While compiling `blink_led`, an assembly listing file `main.asm` was generated.
|
1144 |
|
|
Open this file with a text editor to check out what the CPU is going to do when resumed.
|
1145 |
|
|
|
1146 |
|
|
The `blink_led` example implements a simple counter on the 8 lowest GPIO output ports. The program uses
|
1147 |
|
|
"busy wait" to have a visible delay between increments. This waiting is done by calling the `neorv32_cpu_delay_ms`
|
1148 |
|
|
function. We will add a _breakpoint_ right at the end of this wait function so we can step through the iterations
|
1149 |
|
|
of the counter.
|
1150 |
|
|
|
1151 |
|
|
.Cut-out from `main.asm` generated from the `blink_led` example
|
1152 |
|
|
[source, assembly]
|
1153 |
|
|
--------------------------
|
1154 |
|
|
00000688 <__neorv32_cpu_delay_ms_end>:
|
1155 |
|
|
688: 01c12083 lw ra,28(sp)
|
1156 |
|
|
68c: 02010113 addi sp,sp,32
|
1157 |
|
|
690: 00008067 ret
|
1158 |
|
|
--------------------------
|
1159 |
|
|
|
1160 |
|
|
The very last instruction of the `neorv32_cpu_delay_ms` function is `ret` (= return)
|
1161 |
|
|
at hexadecimal `690` in this example. Add this address as _breakpoint_ to GDB.
|
1162 |
|
|
|
1163 |
|
|
[NOTE]
|
1164 |
|
|
The address might be different if you use a different version of the software framework or
|
1165 |
|
|
if different ISA options are configured.
|
1166 |
|
|
|
1167 |
|
|
.Adding a GDB breakpoint
|
1168 |
|
|
[source, bash]
|
1169 |
|
|
--------------------------
|
1170 |
|
|
(gdb) b * 0x690
|
1171 |
|
|
Breakpoint 1 at 0x690
|
1172 |
|
|
--------------------------
|
1173 |
|
|
|
1174 |
|
|
Now execute `c` (= continue). The CPU will resume operation until it hits the break-point.
|
1175 |
|
|
By this we can "step" from increment to increment.
|
1176 |
|
|
|
1177 |
|
|
.Iterating from breakpoint to breakpoint
|
1178 |
|
|
[source, bash]
|
1179 |
|
|
--------------------------
|
1180 |
|
|
Breakpoint 1 at 0x690
|
1181 |
|
|
(gdb) c
|
1182 |
|
|
Continuing.
|
1183 |
|
|
|
1184 |
|
|
Breakpoint 1, 0x00000690 in neorv32_cpu_delay_ms ()
|
1185 |
|
|
(gdb) c
|
1186 |
|
|
Continuing.
|
1187 |
|
|
|
1188 |
|
|
Breakpoint 1, 0x00000690 in neorv32_cpu_delay_ms ()
|
1189 |
|
|
(gdb) c
|
1190 |
|
|
Continuing.
|
1191 |
|
|
--------------------------
|
1192 |
|
|
|
1193 |
|
|
include::../legal.adoc[]
|