Aller au contenu

Lab Hardware

Before starting this lab you should have already compiled your application (mnist or other) to be run on the FPGA board : Zybo Z7-20.

Setup the environment

To setup the environment, we will use a bash script.

Go to your project folder created in the previous session Lab Software /homes/$USER/AIRV/cva6-softcore-contest/, and create a the file setup.sh with the content:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#!/usr/bin/env bash

export PROJECTROOT=/homes/$USER/AIRV/cva6-softcore-contest

SETUP MEE_VIVADO_CLASSROOM
SETUP MEE_OPENOCD
SETUP MEE_QUESTA10.7d

export PATH="$PATH:$PROJECTROOT/util/gcc-toolchain-builder/riscv_toolchain/bin/"

export RISCV=riscv_toolchain

Then do:

1
source /homes/$USER/AIRV/cva6-softcore-contest/setup.sh

Tip

You will need to do that command each time you open a new terminal to work on that project

Generate the bitstream of the FPGA platform

1
2
cd $PROJECTROOT #repertoire racine du projet cva6-softcore-contest
SETUP MEE_VIVADO_CLASSROOM     # only if you did not used the `setup.sh` file.

In the $PROJECTROOT/Makefile file, modify the line 87 :

1
XILINX_BOARD   := digilentinc.com:zybo-z7-20:part0:1.2
should become

1
XILINX_BOARD   := digilentinc.com:zybo-z7-20:part0:1.1
Then generate the bitstream :

1
make cva6_fpga

Warning

This step may take around 25 minutes.

Connecting the board to the PC

You will need to connect :

  1. The power cable
  2. The Pmod USBUART (the blue little board)
  3. The HS2 cable

Warning

Connect in this order or it will lead to connections error in the future

Then switch it on (Red LED).

Board connection

Program the Zybo board

1
make program_cva6_fpga

When the bitstream is loaded, the green LED done lights up.

Opening a communication terminal

In a new terminal execute :

1
2
3
4
5
# To know which USB port is connected to the UART cable :
ls -l /dev/serial/by-id/ | grep -i uart

# Then according to the indicated USBx port of the previous command :
tio /dev/ttyUSBx

This terminal will serve as a hyperterminal to receive information from the board.

Running the tools

Back to the main terminal : Start OpenOCD :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
cd $PROJECTROOT/sw/app

SETUP MEE_OPENOCD     # only if you did not used the `setup.sh` file.

openocd -f openocd_digilent_hs2.cfg &

[1] 90
Open On-Chip Debugger 0.11.0-dirty (2023-11-23-09:23)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
DEPRECATED! use 'adapter driver' not 'interface'
DEPRECATED! use 'adapter speed' not 'adapter_khz'
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
Info : clock speed 1000 kHz
Info : JTAG tap: riscv.cpu tap/device found: 0x249511c3 (mfg: 0x0e1 (Wintec Industries), part: 0x4951, ver: 0x2)
Info : datacount=2 progbufsize=8
Info : Examined RISC-V core; found 1 harts
Info :  hart 0: XLEN=32, misa=0x40141101
Info : starting gdb server for riscv.cpu on 3333
Info : Listening on port 3333 for gdb connections
Ready for Remote Connections
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections

(If there are connection errors : reboot the board and try again from step 3 and skip step 5)

Then launch gdb (GNU debugger) below (Even if there is no new line) for the mnist application:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
$PROJECTROOT/util/gcc-toolchain-builder/riscv_toolchain/bin/riscv-none-elf-gdb mnist.riscv

GNU gdb (GDB) 14.0.50.20230114-git
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=riscv-none-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from mnist.riscv...
(gdb)

Then link it to OpenOCD :

1
2
3
4
5
(gdb) target extended-remote :3333
Remote debugging using :3333
Info : accepting 'gdb' connection on tcp/3333
0x00010ec4 in ?? ()
(gdb)

Running the MNIST application

Load the mnist application into the CV32A6 FPGA platform :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
(gdb) load
Loading section .vectors, size 0x80 lma 0x80000000
Loading section .init, size 0x60 lma 0x80000080
Loading section .text, size 0xe518 lma 0x800000e0
Loading section .rodata, size 0x11c2c lma 0x8000e5f8
Loading section .eh_frame, size 0x3c lma 0x80020224
Loading section .data, size 0x91c lma 0x80020260
Loading section .sdata, size 0x60 lma 0x80020b80
Start address 0x80000080, load size 134108
Transfer rate: 57 KB/sec, 9579 bytes/write.
(gdb)

Finally, you can run mnist :

1
2
(gdb) c
Continuing.

On the hyperterminal configured on /dev/ttyUSB0, you should see:

1
2
3
4
5
6
Expected  = 4
Predicted = 4
Result : 1/1
credence: 82
image env0003: 1731593 instructions
image env0003: 2353038 cycles

If you do not : if the board is not connected in the tio terminal it can be because you plugged the connectors in the wrong order (see step 1)

You can stop gdb by pressing ^C and quitting with :

1
2
(gdb) kill
(gdb) q

If OpenOCD remains open too long, the terminal gets flooded by LIBUSB_ERROR_NO_DEVICE. To avoid that, use ps to see all processes running in this terminal, search for OpenOCD, copy his PID (on the left) and run kill <PID>.

This result is obtained just after the FPGA bitstream loading. When MNIST is rerun system is not at initial state. For instance, cache is preloaded.