OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [docs/] [userguide/] [content.adoc] - Blame information for rev 62

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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 62 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_PREFIX_ variable in the application
18 60 zero_gravi
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 62 zero_gravi
This guide shows how to compile an example C-code application into a NEORV32 executable that
268 61 zero_gravi
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 62 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 62 zero_gravi
* make sure that the memory components (like block RAM) the IMEM is mapped to support an initialization via the bitstream
459 61 zero_gravi
 
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 62 zero_gravi
`INT_BOOTLOADER_EN` generic to `false`. This will also modify the processor-internal IMEM so it is initialized with the executable during synthesis.
473 61 zero_gravi
 
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 62 zero_gravi
generic (set `true`) you need to add the `c` extension also to the `MARCH` ISA string in order to make the compiler
575 61 zero_gravi
emit compressed instructions.
576 60 zero_gravi
 
577 62 zero_gravi
.Privileged Architecture Extensions
578
[IMPORTANT]
579
Privileged architecture extensions like `Zicsr` or `Zifencei` are "used" _implicitly_ by the compiler. Hence, according
580
instruction will only be generated when "encoded" via inline assembly or when linking according libraries. In this case,
581
these instruction will _always_ be emitted (even if the according extension is not specified in `MARCH`). +
582
**I recommend to _not_ specify any privileged architecture extensions in `MARCH`.**
583
 
584 61 zero_gravi
[WARNING]
585
ISA extension enabled in hardware can be a superset of the extensions enabled in software, but not the other way
586
around. For example generating compressed instructions for a CPU configuration that has the `c` extension disabled
587
will cause _illegal instruction exceptions_ at runtime.
588 60 zero_gravi
 
589 61 zero_gravi
You can also override the default `MARCH` and `MABI` configurations from the makefile when invoking the makefile:
590
 
591 60 zero_gravi
[source,bash]
592
----
593
$ make MARCH=-march=rv32ic clean_all all
594
----
595
 
596
[NOTE]
597 62 zero_gravi
The RISC-V ISA string for `MARCH` follows a certain _canonical_ structure:
598
`rev32[i/e][m][a][f][d][g][q][c][b][v][n]...` For example `rv32imac` is valid while `rv32icma` is not.
599 60 zero_gravi
 
600
 
601
 
602
<<<
603
// ####################################################################################################################
604
:sectnums:
605 61 zero_gravi
== Customizing the Internal Bootloader
606 60 zero_gravi
 
607 61 zero_gravi
The NEORV32 bootloader provides several options to configure and customize it for a certain application setup.
608
This configuration is done by passing _defines_ when compiling the bootloader. Of course you can also
609
modify to bootloader source code to provide a setup that perfectly fits your needs.
610 60 zero_gravi
 
611 61 zero_gravi
[IMPORTANT]
612
Each time the bootloader sources are modified, the bootloader has to be re-compiled (and re-installed to the
613
bootloader ROM) and the processor has to be re-synthesized.
614 60 zero_gravi
 
615 61 zero_gravi
[NOTE]
616
Keep in mind that the maximum size for the bootloader is limited to 32kB and should be compiled using the
617
base ISA `rv32i` only to ensure it can work independently of the actual CPU configuration.
618 60 zero_gravi
 
619 61 zero_gravi
.Bootloader configuration parameters
620
[cols="<2,^1,^2,<6"]
621
[options="header", grid="rows"]
622
|=======================
623
| Parameter | Default | Legal values | Description
624
4+^| Serial console interface
625
| `UART_EN`   | `1` | `0`, `1` | Set to `0` to disable UART0 (no serial console at all)
626
| `UART_BAUD` | `19200` | _any_ | Baud rate of UART0
627
4+^| Status LED
628
| `STATUS_LED_EN`  | `1` | `0`, `1` | Enable bootloader status led ("heart beat") at `GPIO` output port pin #`STATUS_LED_PIN` when `1`
629
| `STATUS_LED_PIN` | `0` | `0` ... `31` | `GPIO` output pin used for the high-active status LED
630
4+^| Boot configuration
631
| `AUTO_BOOT_SPI_EN`  | `0` | `0`, `1` | Set `1` to enable immediate boot from external SPI flash
632
| `AUTO_BOOT_OCD_EN`  | `0` | `0`, `1` | Set `1` to enable boot via on-chip debugger (OCD)
633
| `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
634
4+^| SPI configuration
635
| `SPI_FLASH_CS`          | `0` | `0` ... `7` | SPI chip select output (`spi_csn_o`) for selecting flash
636
| `SPI_FLASH_SECTOR_SIZE` | `65536` | _any_ | SPI flash sector size in bytes
637
| `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)
638
| `SPI_BOOT_BASE_ADDR`    | `0x08000000` | _any_ 32-bit value | Defines the _base_ address of the executable in external flash
639
|=======================
640 60 zero_gravi
 
641 61 zero_gravi
Each configuration parameter is implemented as C-language `define` that can be manually overridden (_redefined_) when
642
invoking the bootloader's makefile. The according parameter and its new value has to be _appended_
643
(using `+=`) to the makefile's `USER_FLAGS` variable. Make sure to use the `-D` prefix here.
644 60 zero_gravi
 
645 61 zero_gravi
For example, to configure a UART Baud rate of 57600 and redirecting the status LED to output pin 20
646
use the following command (_in_ the bootloader's source folder `sw/bootloader`):
647 60 zero_gravi
 
648 61 zero_gravi
.Example: customizing, re-compiling and re-installing the bootloader
649
[source,console]
650 60 zero_gravi
----
651 61 zero_gravi
$ make USER_FLAGS+=-DUART_BAUD=57600 USER_FLAGS+=-DSTATUS_LED_PIN=20 clean_all bootloader
652 60 zero_gravi
----
653
 
654 61 zero_gravi
[NOTE]
655
The `clean_all` target ensure that all libraries are re-compiled. The `bootloader` target will automatically
656
compile and install the bootloader to the HDL boot ROM (updating `rtl/core/neorv32_bootloader_image.vhd`).
657 60 zero_gravi
 
658 61 zero_gravi
:sectnums:
659
=== Bootloader Boot Configuration
660 60 zero_gravi
 
661 61 zero_gravi
The bootloader provides several _boot configurations_ that define where the actual application's executable
662
shall be fetched from. Note that the non-default boot configurations provide a smaller memory footprint
663
reducing boot ROM implementation costs.
664 60 zero_gravi
 
665 61 zero_gravi
:sectnums!:
666
==== Default Boot Configuration
667 60 zero_gravi
 
668 61 zero_gravi
The _default_ bootloader configuration provides a UART-based user interface that allows to upload new executables
669
at any time. Optionally, the executable can also be programmed to an external SPI flash by the bootloader (see
670
section <<_programming_an_external_spi_flash_via_the_bootloader>>).
671 60 zero_gravi
 
672 61 zero_gravi
This configuration also provides an _automatic boot sequence_ (auto-boot) which will start fetching an executable
673
from external SPI flash using the default SPI configuration. By this, the default bootloader configuration
674
provides a "non volatile program storage" mechanism that automatically boot from external SPI flash
675
(after `AUTO_BOOT_TIMEOUT`) while still providing the option to re-program SPI flash at any time
676
via the UART interface.
677 60 zero_gravi
 
678 61 zero_gravi
:sectnums!:
679
==== `AUTO_BOOT_SPI_EN`
680 60 zero_gravi
 
681 61 zero_gravi
The automatic boot from SPI flash (enabled when `AUTO_BOOT_SPI_EN` is `1`) will fetch an executable from an external
682
SPI flash (using the according _SPI configuration_) right after reset. The bootloader will start fetching
683
the image at SPI flash base address `SPI_BOOT_BASE_ADDR`.
684 60 zero_gravi
 
685 61 zero_gravi
Note that there is _no_ UART console to interact with the bootloader. However, this boot configuration will
686
output minimal status messages via UART (if `UART_EN` is `1`).
687 60 zero_gravi
 
688 61 zero_gravi
:sectnums!:
689
==== `AUTO_BOOT_OCD_EN`
690 60 zero_gravi
 
691 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.
692
After initializing the hardware, the CPU waits in this endless loop until the on-chip debugger takes control over
693
the core (to upload and run the actual executable). See section <<_debugging_using_the_on_chip_debugger>>
694
for more information on how to use the on-chip debugger to upload and run executables.
695 60 zero_gravi
 
696 61 zero_gravi
[NOTE]
697
All bootloader boot configuration support uploading new executables via the on-chip debugger.
698 60 zero_gravi
 
699 61 zero_gravi
[WARNING]
700
Note that this boot configuration does not load any executable at all! Hence,
701 62 zero_gravi
this boot configuration is intended to be used with the on-chip debugger only.
702 60 zero_gravi
 
703
 
704
 
705 61 zero_gravi
<<<
706
// ####################################################################################################################
707
:sectnums:
708
== Programming an External SPI Flash via the Bootloader
709 60 zero_gravi
 
710 61 zero_gravi
The default processor-internal NEORV32 bootloader supports automatic booting from an external SPI flash.
711
This guide shows how to write an executable to the SPI flash via the bootloader so it can be automatically
712
fetched and executed after processor reset. For example, you can use a section of the FPGA bitstream configuration
713
memory to store an application executable.
714 60 zero_gravi
 
715 61 zero_gravi
[NOTE]
716
This section assumes the _default_ configuration of the NEORV32 bootloader.
717
See section <<_customizing_the_internal_bootloader>> on how to customize the bootloader and its setting
718
(for example the SPI chip-select port, the SPI clock speed or the flash base address for storing the executable).
719 60 zero_gravi
 
720
 
721 61 zero_gravi
:sectnums:
722
=== SPI Flash
723 60 zero_gravi
 
724 61 zero_gravi
The bootloader can access an SPI compatible flash via the processor top entity's SPI port. By default, the flash
725
chip-select line is to `spi_csn_o(0)` and uses 1/8 of the processor's main clock as clock frequency.
726
The SPI flash has to support single-byte read and write, 24-bit addresses and at least the following standard commands:
727 60 zero_gravi
 
728 61 zero_gravi
* READ `0x03`
729
* READ STATUS `0x05`
730
* WRITE ENABLE `0x06`
731
* PAGE PROGRAM `0x02`
732
* SECTOR ERASE `0xD8`
733
* READ ID `0x9E`
734 60 zero_gravi
 
735 61 zero_gravi
Compatible (FGPA configuration) SPI flash memories are for example the "Winbond W25Q64FV2 or the "Micron N25Q032A".
736 60 zero_gravi
 
737
 
738
:sectnums:
739 61 zero_gravi
=== Programming an Executable
740 60 zero_gravi
 
741
[start=1]
742
. At first, reset the NEORV32 processor and wait until the bootloader start screen appears in your terminal program.
743
. Abort the auto boot sequence and start the user console by pressing any key.
744 61 zero_gravi
. Press u to upload the executable that you want to store to the external flash:
745 60 zero_gravi
 
746
[source]
747
----
748
CMD:> u
749
Awaiting neorv32_exe.bin...
750
----
751
 
752
[start=4]
753 61 zero_gravi
. Send the binary in raw binary via your terminal program. When the upload is completed and "OK"
754 60 zero_gravi
appears, press `p` to trigger the programming of the flash (do not execute the image via the `e`
755
command as this might corrupt the image):
756
 
757
[source]
758
----
759
CMD:> u
760
Awaiting neorv32_exe.bin... OK
761
CMD:> p
762
Write 0x000013FC bytes to SPI flash @ 0x00800000? (y/n)
763
----
764
 
765
[start=5]
766
. The bootloader shows the size of the executable and the base address inside the SPI flash where the
767
executable is going to be stored. A prompt appears: Type `y` to start the programming or type `n` to
768 61 zero_gravi
abort.
769 60 zero_gravi
 
770 61 zero_gravi
[TIP]
771
Section <<_customizing_the_internal_bootloader>> show the according C-language `define` that can be modified
772
to specify the base address of the executable inside the SPI flash.
773
 
774 60 zero_gravi
[source]
775
----
776
CMD:> u
777
Awaiting neorv32_exe.bin... OK
778
CMD:> p
779 61 zero_gravi
Write 0x000013FC bytes to SPI flash @ 0x08000000? (y/n) y
780 60 zero_gravi
Flashing... OK
781
CMD:>
782
----
783
 
784
[start=6]
785
. If "OK" appears in the terminal line, the programming process was successful. Now you can use the
786
auto boot sequence to automatically boot your application from the flash at system start-up without
787
any user interaction.
788
 
789
 
790
 
791
<<<
792
// ####################################################################################################################
793
:sectnums:
794 61 zero_gravi
== Packaging the Processor as IP block for Xilinx Vivado Block Designer
795
 
796 62 zero_gravi
[start=1]
797
. Import all the core files from `rtl/core` and assign them to a _new_ design library `neorv32`.
798
. Instantiate the `rtl/wrappers/neorv32_top_axi4lite.vhd` module.
799
. Then either directly use that module in a new block-design ("Create Block Design", right-click -> "Add Module",
800
thats easier for a first try) or package it ("Tools", "Create and Package new IP") for the use in other projects.
801
. Connect your AXI-peripheral directly to the core's AXI4-Interface if you only have one, or to an AXI-Interconnect
802
(from the IP-catalog) if you have multiple peripherals.
803
. Connect ALL the `ACLK` and `ARESETN` pins of all peripherals and interconnects to the processor's clock and reset
804
signals to have a _unified_ clock and reset domain (easier for a first setup).
805
. Open the "Address Editor" tab and let Vivado assign the base-addresses for the AXI-peripherals (you can modify them
806
according to your needs).
807
. For all FPGA-external signals (like UART signals) make all the connections you need "external"
808
(right-click on the signal/pin -> "Make External").
809
. Save everything, let VIVADO create a HDL-Wrapper for the block-design and choose this as your _Top Level Design_.
810
. Define your constraints and generate your bitstream.
811 61 zero_gravi
 
812 62 zero_gravi
[NOTE]
813
Guide provided by GitHub user https://github.com/AWenzel83[`AWenzel83`] from
814
https://github.com/stnolting/neorv32/discussions/52#discussioncomment-819013
815 61 zero_gravi
 
816
 
817 62 zero_gravi
 
818 61 zero_gravi
<<<
819
// ####################################################################################################################
820
:sectnums:
821 60 zero_gravi
== Simulating the Processor
822
 
823 61 zero_gravi
.WORK IN PROGRESS
824
[WARNING]
825
This Section Is Under Construction! +
826
 +
827
FIXME!
828 60 zero_gravi
 
829 61 zero_gravi
:sectnums:
830
=== Testbench
831
 
832
The NEORV32 project features a simple default testbench (`sim/neorv32_tb.simple.vhd`) that can be used to simulate
833 60 zero_gravi
and test the processor setup. This testbench features a 100MHz clock and enables all optional peripheral and
834
CPU extensions except for the `E` extension and the TRNG IO module (that CANNOT be simulated due to its
835
combinatorial (looped) oscillator architecture).
836
 
837
The simulation setup is configured via the "User Configuration" section located right at the beginning of
838
the testbench's architecture. Each configuration constant provides comments to explain the functionality.
839
 
840
Besides the actual NEORV32 Processor, the testbench also simulates "external" components that are connected
841
to the processor's external bus/memory interface. These components are:
842
 
843
* an external instruction memory (that also allows booting from it)
844
* an external data memory
845
* an external memory to simulate "external IO devices"
846
* a memory-mapped registers to trigger the processor's interrupt signals
847
 
848
The following table shows the base addresses of these four components and their default configuration and
849
properties (attributes: `r` = read, `w` = write, `e` = execute, `a` = atomic accesses possible, `8` = byte-accessible, `16` =
850
half-word-accessible, `32` = word-accessible).
851
 
852
.Testbench: processor-external memories
853
[cols="^4,>3,^5,<11"]
854
[options="header",grid="rows"]
855
|=======================
856
| Base address | Size          | Attributes           | Description
857
| `0x00000000` | `imem_size_c` | `r/w/e,  a, 8/16/32` | external IMEM (initialized with application image)
858
| `0x80000000` | `dmem_size_c` | `r/w/e,  a, 8/16/32` | external DMEM
859
| `0xf0000000` |      64 bytes | `r/w/e, !a, 8/16/32` | external "IO" memory, atomic accesses will fail
860
| `0xff000000` |       4 bytes | `-/w/-,  a,  -/-/32` | memory-mapped register to trigger "machine external", "machine software" and "SoC Fast Interrupt" interrupts
861
|=======================
862
 
863
The simulated NEORV32 does not use the bootloader and directly boots the current application image (from
864
the `rtl/core/neorv32_application_image.vhd` image file). Make sure to use the `all` target of the
865
makefile to install your application as VHDL image after compilation:
866
 
867
[source, bash]
868
----
869
sw/example/blink_led$ make clean_all all
870
----
871
 
872
.Simulation-Optimized CPU/Processors Modules
873
[NOTE]
874
The `sim/rtl_modules` folder provides simulation-optimized versions of certain CPU/processor modules.
875
These alternatives can be used to replace the default CPU/processor HDL files to allow faster/easier/more
876
efficient simulation. **These files are not intended for synthesis!**
877
 
878
**Simulation Console Output**
879
 
880
Data written to the NEORV32 UART0 / UART1 transmitter is send to a virtual UART receiver implemented
881
as part of the testbench. Received chars are send to the simulator console and are also stored to a log file
882
(`neorv32.testbench_uart0.out` for UART0, `neorv32.testbench_uart1.out` for UART1) inside the simulator home folder.
883
 
884
 
885 61 zero_gravi
:sectnums:
886
=== Faster Simulation Console Output
887
 
888 60 zero_gravi
When printing data via the UART the communication speed will always be based on the configured BAUD
889
rate. For a simulation this might take some time. To have faster output you can enable the **simulation mode**
890
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)]).
891
 
892
ASCII data send to UART0 will be immediately printed to the simulator console. Additionally, the
893
ASCII data is logged in a file (`neorv32.uart0.sim_mode.text.out`) in the simulator home folder. All
894
written 32-bit data is also dumped as 8-char hexadecimal value into a file
895
(`neorv32.uart0.sim_mode.data.out`) also in the simulator home folder.
896
 
897
ASCII data send to UART1 will be immediately printed to the simulator console. Additionally, the
898
ASCII data is logged in a file (`neorv32.uart1.sim_mode.text.out`) in the simulator home folder. All
899
written 32-bit data is also dumped as 8-char hexadecimal value into a file
900
(`neorv32.uart1.sim_mode.data.out`) also in the simulator home folder.
901
 
902
You can "automatically" enable the simulation mode of UART0/UART1 when compiling an application. In this case the
903
"real" UART0/UART1 transmitter unit is permanently disabled. To enable the simulation mode just compile
904
and install your application and add _UART0_SIM_MODE_ for UART0 and/or _UART1_SIM_MODE_ for UART1 to
905
the compiler's _USER_FLAGS_ variable (do not forget the `-D` suffix flag):
906
 
907
[source, bash]
908
----
909
sw/example/blink_led$ make USER_FLAGS+=-DUART0_SIM_MODE clean_all all
910
----
911
 
912
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.
913
 
914
[NOTE]
915
The UART simulation output (to file and to screen) outputs "complete lines" at once. A line is
916
completed with a line feed (newline, ASCII `\n` = 10).
917
 
918
 
919 61 zero_gravi
:sectnums:
920
=== Simulation using GHDL
921 60 zero_gravi
 
922 61 zero_gravi
To simulate the processor using _GHDL_ navigate to the `sim` folder and run the provided shell script.
923
Any arguments that are provided while executing this script are passed to GHDL.
924
For example the simulation time can be set to 20ms using `--stop-time=20ms` as argument.
925 60 zero_gravi
 
926
[source, bash]
927
----
928 61 zero_gravi
neorv32/sim$ sh ghdl_sim.sh --stop-time=20ms
929 60 zero_gravi
----
930
 
931
 
932
 
933
<<<
934
// ####################################################################################################################
935
:sectnums:
936
== Building the Documentation
937
 
938 61 zero_gravi
The documentation (datasheet + user guide) is written using `asciidoc`. The according source files
939
can be found in `docs/...`. The documentation of the software framework is written _in-code_ using `doxygen`.
940 60 zero_gravi
 
941 62 zero_gravi
A makefiles in the project's `docs` directory is provided to build all of the documentation as HTML pages
942 60 zero_gravi
or as PDF documents.
943
 
944
[TIP]
945 61 zero_gravi
Pre-rendered PDFs are available online as _nightly pre-releases_: https://github.com/stnolting/neorv32/releases.
946 60 zero_gravi
The HTML-based documentation is also available online at the project's https://stnolting.github.io/neorv32/[GitHub Pages].
947
 
948
The makefile provides a help target to show all available build options and their according outputs.
949
 
950
[source,bash]
951
----
952 62 zero_gravi
neorv32/docs$ make help
953 60 zero_gravi
----
954
 
955
.Example: Generate HTML documentation (data sheet) using `asciidoctor`
956
[source,bash]
957
----
958 62 zero_gravi
neorv32/docs$ make html
959 60 zero_gravi
----
960
 
961
[TIP]
962
If you don't have `asciidoctor` / `asciidoctor-pdf` installed, you can still generate all the documentation using
963
a _docker container_ via `make container`.
964
 
965
 
966
 
967
<<<
968
// ####################################################################################################################
969
:sectnums:
970
== FreeRTOS Support
971
 
972
A NEORV32-specific port and a simple demo for FreeRTOS (https://github.com/FreeRTOS/FreeRTOS) are
973 61 zero_gravi
available in the `sw/example/demo_freeRTOS` folder. See the according documentation (`sw/example/demo_freeRTOS/README.md`)
974
for more information.
975 60 zero_gravi
 
976
 
977
 
978
// ####################################################################################################################
979
:sectnums:
980
== RISC-V Architecture Test Framework
981
 
982
The NEORV32 Processor passes the according tests provided by the official RISC-V Architecture Test Suite
983
(V2.0+), which is available online at GitHub: https://github.com/riscv/riscv-arch-test
984
 
985
All files required for executing the test framework on a simulated instance of the processor (including port
986 62 zero_gravi
files) are located in the `sw/isa-test` folder of the NEORV32 repository. The test framework is executed via the
987
`sim/run_riscv_arch_test.sh` script. Take a look at the provided `sim/README.md`
988
(https://github.com/stnolting/neorv32/tree/master/sim[online at GitHub])
989 60 zero_gravi
file for more information on how to run the tests and how testing is conducted in detail.
990
 
991
 
992
 
993
<<<
994
// ####################################################################################################################
995
:sectnums:
996
== Debugging using the On-Chip Debugger
997
 
998 61 zero_gravi
The NEORV32 on-chip debugger allows _online_ in-system debugging via an external JTAG access port from a
999 60 zero_gravi
host machine. The general flow is independent of the host machine's operating system. However, this tutorial uses
1000
Windows and Linux (Ubuntu on Windows) in parallel.
1001
 
1002 61 zero_gravi
[TIP]
1003
See datasheet section https://stnolting.github.io/neorv32/#_on_chip_debugger_ocd[On Chip Debugger (OCD)]
1004
for more information.
1005
 
1006 60 zero_gravi
[NOTE]
1007
This tutorial uses `gdb` to **directly upload an executable** to the processor. If you are using the default
1008
processor setup _with_ internal instruction memory (IMEM) make sure it is implemented as RAM
1009 61 zero_gravi
(_INT_BOOTLOADER_EN_ generic = true).
1010 60 zero_gravi
 
1011
 
1012
:sectnums:
1013
=== Hardware Requirements
1014
 
1015
Make sure the on-chip debugger of your NEORV32 setups is implemented (_ON_CHIP_DEBUGGER_EN_ generic = true).
1016
Connect a JTAG adapter to the NEORV32 `jtag_*` interface signals. If you do not have a full-scale JTAG adapter, you can
1017
also use a FTDI-based adapter like the "FT2232H-56Q Mini Module", which is a simple and inexpensive FTDI breakout board.
1018
 
1019
.JTAG pin mapping
1020
[cols="^3,^2,^2"]
1021
[options="header",grid="rows"]
1022
|=======================
1023
| NEORV32 top signal | JTAG signal | FTDI port
1024
| `jtag_tck_i`       | TCK         | D0
1025
| `jtag_tdi_i`       | TDI         | D1
1026
| `jtag_tdo_o`       | TDO         | D2
1027
| `jtag_tms_i`       | TMS         | D3
1028
| `jtag_trst_i`      | TRST        | D4
1029
|=======================
1030
 
1031
[TIP]
1032
The low-active JTAG _test reset_ (TRST) signals is _optional_ as a reset can also be triggered via the TAP controller.
1033
If TRST is not used make sure to pull the signal _high_.
1034
 
1035
 
1036
:sectnums:
1037
=== OpenOCD
1038
 
1039
The NEORV32 on-chip debugger can be accessed using the https://github.com/riscv/riscv-openocd[RISC-V port of OpenOCD].
1040
Prebuilt binaries can be obtained - for example - from https://www.sifive.com/software[SiFive]. A pre-configured
1041
OpenOCD configuration file (`sw/openocd/openocd_neorv32.cfg`) is available that allows easy access to the NEORV32 CPU.
1042
 
1043
[NOTE]
1044
You might need to adapt `ftdi_vid_pid`, `ftdi_channel` and `ftdi_layout_init` in `sw/openocd/openocd_neorv32.cfg`
1045
according to your interface chip and your operating system.
1046
 
1047
[TIP]
1048
If you want to modify the JTAG clock speed (via `adapter speed` in `sw/openocd/openocd_neorv32.cfg`) make sure to meet
1049
the clock requirements noted in https://stnolting.github.io/neorv32/#_debug_module_dm[Documentation: Debug Transport Module (DTM)].
1050
 
1051
To access the processor using OpenOCD, open a terminal and start OpenOCD with the pre-configured configuration file.
1052
 
1053
.Connecting via OpenOCD (on Windows)
1054
[source, bash]
1055
--------------------------
1056
N:\Projects\neorv32\sw\openocd>openocd -f openocd_neorv32.cfg
1057
Open On-Chip Debugger 0.11.0-rc1+dev (SiFive OpenOCD 0.10.0-2020.12.1)
1058
Licensed under GNU GPL v2
1059
For bug reports:
1060
        https://github.com/sifive/freedom-tools/issues
1061
1
1062
Info : Listening on port 6666 for tcl connections
1063
Info : Listening on port 4444 for telnet connections
1064
Info : clock speed 1000 kHz
1065
Info : JTAG tap: neorv32.cpu tap/device found: 0x0cafe001 (mfg: 0x000 (), part: 0xcafe, ver: 0x0)
1066
Info : datacount=1 progbufsize=2
1067
Info : Disabling abstract command reads from CSRs.
1068
Info : Examined RISC-V core; found 1 harts
1069
Info :  hart 0: XLEN=32, misa=0x40801105
1070
Info : starting gdb server for neorv32.cpu.0 on 3333
1071
Info : Listening on port 3333 for gdb connections
1072
--------------------------
1073
 
1074
OpenOCD has successfully connected to the NEORV32 on-chip debugger and has examined the CPU (showing the content of
1075
the `misa` CSRs). Now you can use `gdb` to connect via port 3333.
1076
 
1077
 
1078
:sectnums:
1079
=== Debugging with GDB
1080
 
1081
This guide uses the simple "blink example" from `sw/example/blink_led` as simplified test application to
1082
show the basics of in-system debugging.
1083
 
1084
At first, the application needs to be compiled. We will use the minimal machine architecture configuration
1085
(`rv32i`) here to be independent of the actual processor/CPU configuration.
1086
Navigate to `sw/example/blink_led` and compile the application:
1087
 
1088
.Compile the test application
1089
[source, bash]
1090
--------------------------
1091
.../neorv32/sw/example/blink_led$ make MARCH=-march=rv32i clean_all all
1092
--------------------------
1093
 
1094
This will generate an ELF file `main.elf` that contains all the symbols required for debugging.
1095
Furthermore, an assembly listing file `main.asm` is generated that we will use to define breakpoints.
1096
 
1097
Open another terminal in `sw/example/blink_led` and start `gdb`.
1098 61 zero_gravi
The GNU debugger is part of the toolchain (see <<_software_toolchain_setup>>).
1099 60 zero_gravi
 
1100
.Starting GDB (on Linux (Ubuntu on Windows))
1101
[source, bash]
1102
--------------------------
1103
.../neorv32/sw/example/blink_led$ riscv32-unknown-elf-gdb
1104
GNU gdb (GDB) 10.1
1105
Copyright (C) 2020 Free Software Foundation, Inc.
1106
License GPLv3+: GNU GPL version 3 or later 
1107
This is free software: you are free to change and redistribute it.
1108
There is NO WARRANTY, to the extent permitted by law.
1109
Type "show copying" and "show warranty" for details.
1110
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=riscv32-unknown-elf".
1111
Type "show configuration" for configuration details.
1112
For bug reporting instructions, please see:
1113
.
1114
Find the GDB manual and other documentation resources online at:
1115
    .
1116
 
1117
For help, type "help".
1118
Type "apropos word" to search for commands related to "word".
1119
(gdb)
1120
--------------------------
1121
 
1122
Now connect to OpenOCD using the default port 3333 on your local machine.
1123
Set the ELF file we want to debug to the recently generated `main.elf` from the `blink_led` example.
1124
Finally, upload the program to the processor.
1125
 
1126
[NOTE]
1127
The executable that is uploaded to the processor is **not** the default NEORV32 executable (`neorv32_exe.bin`) that
1128
is used for uploading via the bootloader. Instead, all the required sections (like `.text`) are extracted from `mail.elf`
1129
by GDB and uploaded via the debugger's indirect memory access.
1130
 
1131
.Running GDB
1132
[source, bash]
1133
--------------------------
1134
(gdb) target remote localhost:3333 <1>
1135
Remote debugging using localhost:3333
1136
warning: No executable has been specified and target does not support
1137
determining executable automatically.  Try using the "file" command.
1138
0xffff0c94 in ?? () <2>
1139
(gdb) file main.elf <3>
1140
A program is being debugged already.
1141
Are you sure you want to change the file? (y or n) y
1142
Reading symbols from main.elf...
1143
(gdb) load <4>
1144
Loading section .text, size 0xd0c lma 0x0
1145
Loading section .rodata, size 0x39c lma 0xd0c
1146
Start address 0x00000000, load size 4264
1147
Transfer rate: 43 KB/sec, 2132 bytes/write.
1148
(gdb)
1149
--------------------------
1150
<1> Connect to OpenOCD
1151
<2> The CPU was still executing code from the bootloader ROM - but that does not matter here
1152
<3> Select `mail.elf` from the `blink_led` example
1153
<4> Upload the executable
1154
 
1155
After the upload, GDB will make the processor jump to the beginning of the uploaded executable
1156
(by default, this is the beginning of the instruction memory at `0x00000000`) skipping the bootloader
1157
and halting the CPU right before executing the `blink_led` application.
1158
 
1159
 
1160
:sectnums:
1161
==== Breakpoint Example
1162
 
1163
The following steps are just a small showcase that illustrate a simple debugging scheme.
1164
 
1165
While compiling `blink_led`, an assembly listing file `main.asm` was generated.
1166
Open this file with a text editor to check out what the CPU is going to do when resumed.
1167
 
1168
The `blink_led` example implements a simple counter on the 8 lowest GPIO output ports. The program uses
1169
"busy wait" to have a visible delay between increments. This waiting is done by calling the `neorv32_cpu_delay_ms`
1170
function. We will add a _breakpoint_ right at the end of this wait function so we can step through the iterations
1171
of the counter.
1172
 
1173
.Cut-out from `main.asm` generated from the `blink_led` example
1174
[source, assembly]
1175
--------------------------
1176
00000688 <__neorv32_cpu_delay_ms_end>:
1177
 688:   01c12083                lw      ra,28(sp)
1178
 68c:   02010113                addi    sp,sp,32
1179
 690:   00008067                ret
1180
--------------------------
1181
 
1182
The very last instruction of the `neorv32_cpu_delay_ms` function is `ret` (= return)
1183
at hexadecimal `690` in this example. Add this address as _breakpoint_ to GDB.
1184
 
1185
[NOTE]
1186
The address might be different if you use a different version of the software framework or
1187
if different ISA options are configured.
1188
 
1189
.Adding a GDB breakpoint
1190
[source, bash]
1191
--------------------------
1192
(gdb) b * 0x690
1193
Breakpoint 1 at 0x690
1194
--------------------------
1195
 
1196
Now execute `c` (= continue). The CPU will resume operation until it hits the break-point.
1197
By this we can "step" from increment to increment.
1198
 
1199
.Iterating from breakpoint to breakpoint
1200
[source, bash]
1201
--------------------------
1202
Breakpoint 1 at 0x690
1203
(gdb) c
1204
Continuing.
1205
 
1206
Breakpoint 1, 0x00000690 in neorv32_cpu_delay_ms ()
1207
(gdb) c
1208
Continuing.
1209
 
1210
Breakpoint 1, 0x00000690 in neorv32_cpu_delay_ms ()
1211
(gdb) c
1212
Continuing.
1213
--------------------------
1214
 
1215
include::../legal.adoc[]

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.