Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 1 | --- |
Timothy Trippel | 92bbc7b | 2021-07-12 22:59:01 +0000 | [diff] [blame] | 2 | title: "Getting Started on FPGAs" |
Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 3 | --- |
| 4 | |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 5 | Do you want to try out OpenTitan, but don't have a couple thousand or million dollars ready for an ASIC tapeout? |
| 6 | Running OpenTitan on an FPGA board can be the answer! |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 7 | |
Miguel Young de la Sota | 8ff30b8 | 2019-11-25 12:58:34 -0600 | [diff] [blame] | 8 | <!-- TODO: Switch all calls to fusesoc and the Verilated system to refer to Meson, once it supports fusesoc. --> |
| 9 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 10 | ## Prerequisites |
| 11 | |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 12 | To use the OpenTitan on an FPGA you need two things: |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 13 | |
| 14 | * A supported FPGA board |
| 15 | * A tool from the FPGA vendor |
| 16 | |
| 17 | Depending on the design/target combination that you want to synthesize you will need different tools and boards. |
| 18 | Refer to the design documentation for information what exactly is needed. |
| 19 | |
Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 20 | * [Obtain an FPGA board]({{< relref "fpga_boards.md" >}}) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 21 | |
Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 22 | Follow the install instructions to [prepare the system]({{< relref "install_instructions#system-preparation" >}}) and to install the [software development tools]({{< relref "install_instructions#software-development" >}}) and [Xilinx Vivado]({{< relref "install_instructions#xilinx-vivado" >}}). |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 23 | |
| 24 | ## Create an FPGA bitstream |
| 25 | |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 26 | Synthesizing a design for an FPGA board is done with the following commands. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 27 | |
Timothy Chen | 25b0c66 | 2019-10-17 11:06:24 -0700 | [diff] [blame] | 28 | The FPGA build will pull in a program to act as the boot ROM. |
Greg Chadwick | 567cfd6 | 2019-10-31 16:15:33 +0000 | [diff] [blame] | 29 | This must be built before running the FPGA build. |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 30 | This is pulled in from the `sw/device/boot_rom` directory (see the `parameters:` section of the `hw/top_earlgrey/chip_earlgrey_cw310.core` file). |
Greg Chadwick | 567cfd6 | 2019-10-31 16:15:33 +0000 | [diff] [blame] | 31 | |
| 32 | To build it: |
| 33 | ```console |
| 34 | $ cd $REPO_TOP |
Miguel Young de la Sota | 8ff30b8 | 2019-11-25 12:58:34 -0600 | [diff] [blame] | 35 | $ ./meson_init.sh |
Michael Schaffner | 076450b | 2021-02-23 18:16:21 -0800 | [diff] [blame] | 36 | $ ninja -C build-out all |
Greg Chadwick | 567cfd6 | 2019-10-31 16:15:33 +0000 | [diff] [blame] | 37 | ``` |
| 38 | |
Pirmin Vogel | b41684f | 2021-07-20 09:49:50 +0200 | [diff] [blame] | 39 | Only the ChipWhisperer CW310 board with the Xilinx Kintex 7 XC7K410T FPGA can fit the whole Earl Grey design. |
| 40 | When working with the Nexys Video FPGA board, the Earl Grey design has to be modified to reduce its size using a script. |
Timothy Chen | f835aa3 | 2021-01-08 16:27:50 -0800 | [diff] [blame] | 41 | ```console |
| 42 | $ cd $REPO_TOP |
Pirmin Vogel | de15468 | 2021-02-01 11:40:01 +0100 | [diff] [blame] | 43 | $ ./hw/top_earlgrey/util/top_earlgrey_reduce.py --build |
Timothy Chen | f835aa3 | 2021-01-08 16:27:50 -0800 | [diff] [blame] | 44 | ``` |
Pirmin Vogel | de15468 | 2021-02-01 11:40:01 +0100 | [diff] [blame] | 45 | The `--build` argument is optional and ensures that the boot ROM is rebuilt for the reduced design. |
| 46 | Alternatively, the boot ROM can be manually regenerated using the previous command. |
Timothy Chen | f835aa3 | 2021-01-08 16:27:50 -0800 | [diff] [blame] | 47 | |
Pirmin Vogel | b41684f | 2021-07-20 09:49:50 +0200 | [diff] [blame] | 48 | Next, the actual FPGA implementation can be started. |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 49 | In the following example we synthesize the Earl Grey design for the ChipWhisperer CW310 board using Xilinx Vivado {{< tool_version "vivado" >}}. |
| 50 | To target the Nexys Video board, replace `cw310` by `nexysvideo` in the instructions below. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 51 | |
| 52 | ```console |
Pirmin Vogel | 37ee04a | 2021-05-25 13:38:27 +0200 | [diff] [blame] | 53 | $ . /tools/xilinx/Vivado/{{< tool_version "vivado" >}}/settings64.sh |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 54 | $ cd $REPO_TOP |
Miguel Young de la Sota | 8ff30b8 | 2019-11-25 12:58:34 -0600 | [diff] [blame] | 55 | $ ./meson_init.sh |
Michael Schaffner | 076450b | 2021-02-23 18:16:21 -0800 | [diff] [blame] | 56 | $ ninja -C build-out all |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 57 | $ fusesoc --cores-root . run --flag=fileset_top --target=synth lowrisc:systems:chip_earlgrey_cw310 |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 58 | ``` |
Pirmin Vogel | de15468 | 2021-02-01 11:40:01 +0100 | [diff] [blame] | 59 | The `fileset_top` flag used above is specific to the OpenTitan project to select the correct fileset. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 60 | |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 61 | The resulting bitstream is located at `build/lowrisc_systems_chip_earlgrey_cw310_0.1/synth-vivado/lowrisc_systems_chip_earlgrey_cw310_0.1.bit`. |
Garret Kelly | 9eebde0 | 2019-10-22 15:36:49 -0400 | [diff] [blame] | 62 | See the [reference manual]({{< relref "ref_manual_fpga.md" >}}) for more information. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 63 | |
Timothy Chen | 85d8192 | 2021-09-10 11:29:24 -0700 | [diff] [blame] | 64 | ### Dealing with FPGA Congestion Issues |
| 65 | |
| 66 | The default Vivado tool placement may sometimes result in congested FPGA floorplans. |
| 67 | When this happens, the implemenation time and results become unpredictable. |
| 68 | It may become necessary for the user to manually adjust certain placement. |
| 69 | See [this comment](https://github.com/lowRISC/opentitan/pull/8138#issuecomment-916696830) for a thorough analysis of one such situation and what changes were made to improve congestion. |
| 70 | |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 71 | ## Connecting the ChipWhisperer CW310 board |
| 72 | |
| 73 | The ChipWhisperer CW310 board supports different power options. |
| 74 | It is recommended to power the board via the included DC power adapter. |
| 75 | To this end: |
| 76 | 1. Set the *SW2* switch (to the right of the barrel connector) up to the *5V Regulator* option. |
| 77 | 1. Set the switch below the barrel connector to the right towards the *Barrel* option. |
| 78 | 1. Set the *Control Power* switch (bottom left corner, *SW7*) to the right. |
| 79 | 1. Ensure the *Tgt Power* switch (above the fan, *S1*) is set to the right towards the *Auto* option. |
| 80 | 1. Plug the DC power adapter into the barrel jack (*J11*) in the top left corner of the board. |
| 81 | 1. Use a USB-C cable to connect your PC with the *USB-C Data* connector (*J8*) in the lower left corner on the board. |
| 82 | |
| 83 | You can now use `dmesg` to determine which serial ports have been assigned. |
| 84 | They should be named `'/dev/ttyACM*'`, e.g. `/dev/ttyACM1`. |
| 85 | To ensure that you have sufficient access permissions, set up the udev rules as explained in the [Vivado installation instructions]({{< relref "install_instructions#xilinx-vivado" >}}). |
| 86 | |
| 87 | ## Connecting the Nexys Video board |
Tom Roberts | 0ab9e7e | 2019-11-04 13:59:22 +0000 | [diff] [blame] | 88 | |
| 89 | * Use a Micro USB cable to connect the PC with the *PROG*-labeled connector on the board. |
| 90 | * Use a second Micro USB cable to connect the PC with the *UART*-labled connector on the board. |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 91 | * After connecting the UART, use `dmesg` to determine which serial port was assigned. |
| 92 | It should be named `/dev/ttyUSB*`, e.g. `/dev/ttyUSB0`. |
| 93 | * To ensure that you have sufficient access permissions, set up the udev rules as explained in the [Vivado installation instructions]({{< relref "install_instructions#xilinx-vivado" >}}). |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 94 | |
| 95 | ## Flash the bitstream onto the FPGA |
| 96 | |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 97 | To flash the bitstream onto the FPGA you need to use either the command line or the Vivado GUI (Nexys Video board only). |
| 98 | Depending on the FPGA device, the flashing itself may take several seconds. |
| 99 | After completion, a message like this should be visible from the UART: |
Satnam Singh | 145884f | 2019-12-13 15:17:30 -0800 | [diff] [blame] | 100 | |
| 101 | ``` |
| 102 | Version: opentitan-snapshot-20191101-1-366-gca61d28 |
| 103 | Build Date: 2019-12-13, 13:15:48 |
| 104 | Bootstrap requested, initialising HW... |
| 105 | HW initialisation completed, waiting for SPI input... |
| 106 | ``` |
| 107 | |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 108 | ### Using the command line for the ChipWhisperer CW310 board |
| 109 | |
| 110 | Use the following command to program the FPGA with the `cw310_loader` tool. |
| 111 | |
| 112 | ```console |
| 113 | $ cd $REPO_TOP |
| 114 | $ ./util/fpga/cw310_loader.py --bitstream build/lowrisc_systems_chip_earlgrey_cw310_0.1/synth-vivado/lowrisc_systems_chip_earlgrey_cw310_0.1.bit |
| 115 | ``` |
| 116 | |
| 117 | ### Using the command line for the Nexys Video board |
| 118 | |
| 119 | Use the following command to program the FPGA. |
| 120 | |
| 121 | ```console |
| 122 | $ . /tools/xilinx/Vivado/{{< tool_version "vivado" >}}/settings64.sh |
| 123 | $ cd $REPO_TOP |
| 124 | $ util/opentitan-pgm-fpga/opentitan-pgm-fpga xc7a200tsbg484-1 build/lowrisc_systems_chip_earlgrey_nexysvideo/synth-vivado/lowrisc_systems_chip_earlgrey_nexysvideo_0.1.bit |
| 125 | ``` |
| 126 | |
Greg Chadwick | 567cfd6 | 2019-10-31 16:15:33 +0000 | [diff] [blame] | 127 | If you have having trouble with programming using the command line, try the GUI. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 128 | |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 129 | ### Using the Vivado GUI for the Nexys Video board |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 130 | |
| 131 | ```console |
Pirmin Vogel | 37ee04a | 2021-05-25 13:38:27 +0200 | [diff] [blame] | 132 | $ . /tools/xilinx/Vivado/{{< tool_version "vivado" >}}/settings64.sh |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 133 | $ cd $REPO_TOP |
Michael Schaffner | 93fe50c | 2021-03-31 16:25:42 -0700 | [diff] [blame] | 134 | $ make -C build/lowrisc_systems_chip_earlgrey_nexysvideo_0.1/synth-vivado build-gui |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 135 | ``` |
| 136 | |
| 137 | Now the Vivado GUI opens and loads the project. |
| 138 | |
| 139 | * Connect the FPGA board to the PC and turn it on. |
| 140 | * In the navigation on the left, click on *PROGRAM AND DEBUG* > *Open Hardware Manager* > *Open Target* > *Auto Connect*. |
Philipp Wagner | 1edca41 | 2020-12-07 18:36:08 +0000 | [diff] [blame] | 141 | * Vivado now enumerates all boards and connects to it. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 142 | * Click on *Program Device* in the menu on the left (or at the top of the screen). |
Michael Schaffner | 93fe50c | 2021-03-31 16:25:42 -0700 | [diff] [blame] | 143 | * A dialog titled *Program Device* pops up. Select the file `lowrisc_systems_chip_earlgrey_nexysvideo_0.1.bit` as *Bitstream file*, and leave the *Debug probes file* empty. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 144 | * Click on *Program* to flash the FPGA with the bitstream. |
| 145 | * The FPGA is ready as soon as the programming finishes. |
| 146 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 147 | ## Testing the demo design |
| 148 | |
Timothy Chen | d11f4b9 | 2019-10-21 12:53:45 -0700 | [diff] [blame] | 149 | The `hello_world` demo software shows off some capabilities of the design. |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 150 | Depending on the FPGA board, a slightly different set of tools and commands is used for running applications. |
| 151 | |
| 152 | ### Running on the ChipWhisperer CW310 board |
| 153 | |
| 154 | To load `hello_world` into the FPGA on the ChipWhisperer CW310 board follow the steps shown below. |
| 155 | |
| 156 | 1. Generate the bitstream and flash it to the FPGA as described above. |
| 157 | 1. Open a serial console (use the device file determined before) and connect. |
| 158 | Settings: 115200 baud, 8 bits per byte, no software flow-control for sending and receiving data. |
| 159 | ```console |
| 160 | $ screen /dev/ttyACM1 115200,cs8,-ixon,-ixoff |
| 161 | ``` |
| 162 | 1. Run the loading tool. |
| 163 | ```console |
| 164 | $ cd ${REPO_TOP} |
Alexander Williams | ad7f46d | 2021-09-30 09:15:08 -0700 | [diff] [blame^] | 165 | $ ./util/fpga/cw310_loader.py --firmware build-bin/sw/device/examples/hello_world/hello_world_fpga_cw310.bin --set-pll-defaults |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 166 | ``` |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 167 | |
| 168 | This should report how the binary is split into frames: |
| 169 | ``` |
| 170 | CW310 Loader: Attemping to find CW310 FPGA Board: |
| 171 | No bitstream specified |
| 172 | Board found, setting PLL2 to 100 MHz |
Pirmin Vogel | b41684f | 2021-07-20 09:49:50 +0200 | [diff] [blame] | 173 | INFO: Programming firmware file: build-bin/sw/device/examples/hello_world/hello_world_fpga_cw310.bin |
| 174 | Programming OpenTitan with "build-bin/sw/device/examples/hello_world/hello_world_fpga_cw310.bin"... |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 175 | Transferring frame 0x00000000 @ 0x00000000. |
| 176 | Transferring frame 0x00000001 @ 0x000007D8. |
| 177 | Transferring frame 0x00000002 @ 0x00000FB0. |
| 178 | Transferring frame 0x00000003 @ 0x00001788. |
| 179 | Transferring frame 0x00000004 @ 0x00001F60. |
| 180 | Transferring frame 0x00000005 @ 0x00002738. |
| 181 | Transferring frame 0x00000006 @ 0x00002F10. |
| 182 | Transferring frame 0x80000007 @ 0x000036E8. |
| 183 | Loading done. |
| 184 | ``` |
| 185 | |
| 186 | and then output like this should appear from the UART: |
| 187 | ``` |
| 188 | Version: opentitan-snapshot-20191101-1-4549-g504534121 |
| 189 | Build Date: 2021-03-02, 18:15:49 |
| 190 | Bootstrap requested, initialising HW... |
| 191 | HW initialisation completed, waiting for SPI input... |
| 192 | Processing frame #0, expecting #0 |
| 193 | Processing frame #1, expecting #1 |
| 194 | Processing frame #2, expecting #2 |
| 195 | Processing frame #3, expecting #3 |
| 196 | Processing frame #4, expecting #4 |
| 197 | Processing frame #5, expecting #5 |
| 198 | Processing frame #6, expecting #6 |
| 199 | Processing frame #7, expecting #7 |
| 200 | Bootstrap: DONE! |
| 201 | Boot ROM initialisation has completed, jump into flash! |
| 202 | Hello World! |
| 203 | Built at: May 17 2021, 18:44:21 |
| 204 | Watch the LEDs! |
| 205 | Try out the switches on the board |
| 206 | or type anything into the console window. |
| 207 | The LEDs show the ASCII code of the last character. |
| 208 | GPIO switch #0 changed to 1 |
| 209 | GPIO switch #1 changed to 1 |
| 210 | GPIO switch #2 changed to 1 |
| 211 | GPIO switch #3 changed to 1 |
| 212 | GPIO switch #4 changed to 1 |
| 213 | GPIO switch #5 changed to 1 |
| 214 | GPIO switch #6 changed to 1 |
| 215 | GPIO switch #7 changed to 1 |
| 216 | FTDI control changed. Enable JTAG. |
| 217 | ``` |
| 218 | |
| 219 | 1. Observe the output both on the board and the serial console. Type any text into the console window. |
| 220 | 1. Exit `screen` by pressing CTRL-a k, and confirm with y. |
| 221 | |
Jade Philipoom | 05d0d10 | 2021-11-29 14:58:16 +0000 | [diff] [blame] | 222 | #### Troubleshooting |
| 223 | |
| 224 | If the firmware load fails with a message like `Error transferring frame: 0x00000000`, try pressing the "USB RST" button before loading the bitstream. |
| 225 | |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 226 | ### Running on the Nexys Video board |
| 227 | |
| 228 | In order to load `hello_world` into the FPGA on the Nexys Video board, both the binary and the [loading tool]({{< relref "/sw/host/spiflash/README.md" >}}) must be compiled. |
Satnam Singh | 145884f | 2019-12-13 15:17:30 -0800 | [diff] [blame] | 229 | Please follow the steps shown below. |
Timothy Chen | 25b0c66 | 2019-10-17 11:06:24 -0700 | [diff] [blame] | 230 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 231 | * Generate the bitstream and flash it to the FPGA as described above. |
| 232 | * Open a serial console (use the device file determined before) and connect. |
Pirmin Vogel | 8520647 | 2020-10-01 13:02:22 +0200 | [diff] [blame] | 233 | Settings: 115200 baud, 8N1, no hardware or software flow control. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 234 | ```console |
Pirmin Vogel | 8520647 | 2020-10-01 13:02:22 +0200 | [diff] [blame] | 235 | $ screen /dev/ttyUSB0 115200 |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 236 | ``` |
Pirmin Vogel | 8520647 | 2020-10-01 13:02:22 +0200 | [diff] [blame] | 237 | Note that the Nexsys Video demo program that comes installed on the board runs the UART at 115200 baud as well; |
| 238 | expect to see different output if that is running. |
Philipp Wagner | d1fec0a | 2019-10-30 22:57:28 +0000 | [diff] [blame] | 239 | This can happen if you connect the serial console before using Vivado to program your new bitstream or you press the *PROG* button that causes the FPGA to reprogram from the code in the on-board SPI flash. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 240 | * On the Nexys Video board, press the red button labeled *CPU_RESET*. |
Tom Roberts | 0ab9e7e | 2019-11-04 13:59:22 +0000 | [diff] [blame] | 241 | * You should see the ROM code report its commit ID and build date. |
| 242 | * Run the loading tool. |
| 243 | ```console |
| 244 | $ cd ${REPO_TOP} |
Miguel Young de la Sota | 33d52d2 | 2019-12-09 09:15:06 -0600 | [diff] [blame] | 245 | $ ./meson_init.sh |
Miguel Young de la Sota | 76526c3 | 2020-01-28 10:24:41 -0500 | [diff] [blame] | 246 | $ ninja -C build-out sw/device/examples/hello_world/hello_world_export_fpga_nexysvideo |
| 247 | $ ninja -C build-out sw/host/spiflash/spiflash_export |
Michael Schaffner | 6c0679a | 2020-05-06 22:38:53 -0700 | [diff] [blame] | 248 | $ build-bin/sw/host/spiflash/spiflash --input build-bin/sw/device/examples/hello_world/hello_world_fpga_nexysvideo.bin |
Tom Roberts | 0ab9e7e | 2019-11-04 13:59:22 +0000 | [diff] [blame] | 249 | ``` |
Satnam Singh | 145884f | 2019-12-13 15:17:30 -0800 | [diff] [blame] | 250 | |
| 251 | which should report how the binary is split into frames: |
| 252 | |
| 253 | ``` |
| 254 | Running SPI flash update. |
| 255 | Image divided into 6 frames. |
| 256 | frame: 0x00000000 to offset: 0x00000000 |
| 257 | frame: 0x00000001 to offset: 0x000003d8 |
| 258 | frame: 0x00000002 to offset: 0x000007b0 |
| 259 | frame: 0x00000003 to offset: 0x00000b88 |
| 260 | frame: 0x00000004 to offset: 0x00000f60 |
| 261 | frame: 0x80000005 to offset: 0x00001338 |
| 262 | ``` |
| 263 | |
| 264 | and then output like this should appear from the UART: |
| 265 | ``` |
| 266 | Processing frame no: 00000000 exp no: 00000000 |
| 267 | Processing frame no: 00000001 exp no: 00000001 |
| 268 | Processing frame no: 00000002 exp no: 00000002 |
| 269 | Processing frame no: 00000003 exp no: 00000003 |
| 270 | Processing frame no: 00000004 exp no: 00000004 |
| 271 | Processing frame no: 80000005 exp no: 00000005 |
| 272 | bootstrap: DONE! |
| 273 | INFO: Boot ROM initialisation has completed, jump into flash! |
| 274 | Hello World! Dec 13 2019 15:06:29 |
| 275 | Watch the LEDs! |
| 276 | Try out the switches on the board |
| 277 | or type anything into the console window. |
| 278 | The LEDs show the ASCII code of the last character. |
| 279 | GPIO: Switch 7 changed to 1 |
| 280 | FTDI control changed. Enable JTAG |
| 281 | ``` |
| 282 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 283 | * Observe the output both on the board and the serial console. Type any text into the console window. |
| 284 | * Exit `screen` by pressing CTRL-a k, and confirm with y. |
| 285 | |
| 286 | ## Develop with the Vivado GUI |
| 287 | |
| 288 | Sometimes it is helpful to use the Vivado GUI to debug a design. |
| 289 | fusesoc makes that easy, with one small caveat: by default fusesoc copies all source files into a staging directory before the synthesis process starts. |
| 290 | This behavior is helpful to create reproducible builds and avoids Vivado modifying checked-in source files. |
| 291 | But during debugging this behavior is not helpful. |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 292 | The `--no-export` option of fusesoc disables copying the source files into the staging area, and `--setup` instructs fusesoc to not start the synthesis process. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 293 | |
| 294 | ```console |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 295 | $ # only create Vivado project directory |
| 296 | $ cd $REPO_TOP |
| 297 | $ fusesoc --cores-root . run --flag=fileset_top --target=synth --no-export --setup lowrisc:systems:chip_earlgrey_cw310 |
| 298 | ``` |
| 299 | |
| 300 | You can then navigate to the created project directory, and open Vivado |
| 301 | ```console |
| 302 | $ . /tools/xilinx/Vivado/{{< tool_version "vivado" >}}/settings64.sh |
| 303 | $ cd $REPO_TOP/build/lowrisc_systems_chip_earlgrey_cw310_0.1/synth-vivado/ |
| 304 | $ vivado |
| 305 | ``` |
| 306 | |
| 307 | Finally, using the tcl console, you can kick off the project setup with |
| 308 | ```console |
| 309 | $ source lowrisc_systems_chip_earlgrey_cw310_0.1.tcl |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 310 | ``` |
| 311 | |
| 312 | ## Connect with OpenOCD and debug |
| 313 | |
Pirmin Vogel | 6ae9550 | 2021-05-19 19:09:03 +0200 | [diff] [blame] | 314 | To connect the Nexys Video FPGA board with OpenOCD, run the following command |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 315 | |
| 316 | ```console |
| 317 | $ cd $REPO_TOP |
Philipp Wagner | 4a7b5a0 | 2021-03-17 15:06:56 +0000 | [diff] [blame] | 318 | $ openocd -s util/openocd -f board/lowrisc-earlgrey-nexysvideo.cfg |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 319 | ``` |
| 320 | |
Philipp Wagner | 4a7b5a0 | 2021-03-17 15:06:56 +0000 | [diff] [blame] | 321 | See the [install instructions]({{< relref "install_instructions#openocd" >}}) for guidance on installing OpenOCD. |
Alistair Francis | 3c3ee45 | 2019-11-07 13:19:07 -0800 | [diff] [blame] | 322 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 323 | To actually debug through OpenOCD, it must either be connected through telnet or GDB. |
| 324 | |
| 325 | ### Debug with OpenOCD |
| 326 | |
| 327 | The following is an example for using telnet |
| 328 | |
| 329 | ```console |
| 330 | $ telnet localhost 4444 // or whatever port that is specificed by the openocd command above |
| 331 | $ mdw 0x8000 0x10 // read 16 bytes at address 0x8000 |
| 332 | ``` |
| 333 | |
| 334 | ### Debug with GDB |
| 335 | |
| 336 | An example connection with GDB, which prints the registers after the connection to OpenOCD is established |
| 337 | |
| 338 | ```console |
| 339 | $ cd $REPO_TOP |
Tom Roberts | 0ab9e7e | 2019-11-04 13:59:22 +0000 | [diff] [blame] | 340 | $ /tools/riscv/bin/riscv32-unknown-elf-gdb -ex "target extended-remote :3333" -ex "info reg" sw/device/boot_rom/rom.elf |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 341 | ``` |
| 342 | |
| 343 | #### Common operations with GDB |
| 344 | |
| 345 | Examine 16 memory words in the hex format starting at 0x200005c0 |
| 346 | |
| 347 | ```console |
| 348 | (gdb) x/16xw 0x200005c0 |
| 349 | ``` |
| 350 | |
| 351 | Press enter again to print the next 16 words. |
| 352 | Use `help x` to get a description of the command. |
| 353 | |
| 354 | If the memory content contains program text it can be disassembled |
| 355 | |
| 356 | ```console |
| 357 | (gdb) disassemble 0x200005c0,0x200005c0+16*4 |
| 358 | ``` |
| 359 | |
| 360 | Displaying the memory content can also be delegated to OpenOCD |
| 361 | |
| 362 | ```console |
| 363 | (gdb) monitor mdw 0x200005c0 16 |
| 364 | ``` |
| 365 | |
| 366 | Use `monitor help` to get a list of supported commands. |
| 367 | |
Greg Chadwick | 567cfd6 | 2019-10-31 16:15:33 +0000 | [diff] [blame] | 368 | To single-step use `stepi` or `step` |
| 369 | |
| 370 | ```console |
| 371 | (gdb) stepi |
| 372 | ``` |
| 373 | |
| 374 | `stepi` single-steps an instruction, `step` single-steps a line of source code. |
| 375 | When testing debugging against the hello_world binary it is likely you will break into a delay loop. |
| 376 | Here the `step` command will seem to hang as it will attempt to step over the whole delay loop with a sequence of single-step instructions which may take quite some time! |
| 377 | |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 378 | To change the program which is debugged the `file` command can be used. |
| 379 | This will update the symbols which are used to get information about the program. |
Philipp Wagner | 544ac9b | 2019-10-30 22:56:32 +0000 | [diff] [blame] | 380 | It is especially useful in the context of our `rom.elf`, which resides in the ROM region, which will eventually jump to a different executable as part of the flash region. |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 381 | |
| 382 | ```console |
Philipp Wagner | 544ac9b | 2019-10-30 22:56:32 +0000 | [diff] [blame] | 383 | (gdb) file sw/device/examples/hello_world/sw.elf |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 384 | (gdb) disassemble 0x200005c0,0x200005c0+16*4 |
| 385 | ``` |
| 386 | |
| 387 | The output of the disassemble should now contain additional information. |