Examples of using cocotb for functional verification of VHDL designs with GHDL.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
6.3 KiB

  1. The original repository is now located on my own git-server at [https://git.goodcleanfun.de/tmeissner/cocotb_with_ghdl](https://git.goodcleanfun.de/tmeissner/cocotb_with_ghdl)
  2. It is mirrored to github with every push, so both should be in sync.
  3. # cocotb_with_ghdl
  4. *At the moment, this repo is in an early state and serves as a learning tool for me. So it contains a a lot of quirks and code which can be done much better by cocotb-professionals.*
  5. A collection of examples of using [cocotb](https://www.cocotb.org/) for functional verification of VHDL designs with [GHDL](https://github.com/ghdl/ghdl).
  6. This is a project with the purpose to learn using cocotb with GHDL. It is intended for my simple (and more complex in future) experiments with using the Python language instead of VHDL or SV to verify digital designs.
  7. It is recommended to use an up-to-date version of GHDL as potential bugs are fixed very quickly. You can build GHDL from source or use one of the Docker images of the [hdl containers project](https://hdl.github.io/containers/) (recommended). For example the `hdlc/sim:scipy` docker image. This image contains a recent version of cocotb and a C++ compiler (needed to build some wheels during installing requirements with pip).
  8. Have fun!
  9. ## Quickstart guide
  10. ### Dependencies
  11. *cocotb_with_ghdl* uses external libraries to get the components to verify. They are shipped as git submodules. You have to use the `--recursive` option when clone
  12. the *cocotb_with_ghdl* repository to get them: `git clone --recursive https://git.goodcleanfun.de/tmeissner/cocotb_with_ghdl`
  13. Another useful tool is GTKWave, install it if you want to use the waveform files generated by some of the tests.
  14. ### Change into docker container & install requirements
  15. ```
  16. $ git clone --recursive https://git.goodcleanfun.de/tmeissner/cocotb_with_ghdl.git
  17. $ cd cocotb_with_ghdl
  18. $ ./env-setup.sh
  19. $ docker run --rm -ti --volume=$(pwd):/build -e DISPLAY=$DISPLAY \
  20. --volume /tmp/.X11-unix:/tmp/.X11-unix hdlc/sim:scipy /bin/bash
  21. $ cd /build
  22. $ ./docker-setup.sh
  23. Collecting cocotb-bus
  24. Downloading cocotb-bus-0.2.1.tar.gz (28 kB)
  25. Installing build dependencies ... done
  26. Getting requirements to build wheel ... done
  27. Preparing wheel metadata ... done
  28. ...
  29. Successfully built cocotb-bus wavedrom python-constraint
  30. Installing collected packages: lxml, cocotb-bus, toposort, svgwrite, pyyaml, pyucis, python-constraint, pyboolector, cocotbext-axi, attrdict, wavedrom, pyvsc, pyuvm, cocotbext-uart, cocotbext-spi, cocotbext-pcie, cocotbext-eth, cocotb-coverage
  31. Successfully installed attrdict-2.0.1 cocotb-bus-0.2.1 cocotb-coverage-1.1.0 cocotbext-axi-0.1.18 cocotbext-eth-0.1.18 cocotbext-pcie-0.1.20 cocotbext-spi-0.1.2 cocotbext-uart-0.1.2 lxml-4.7.1 pyboolector-3.2.2.20220125.14 python-constraint-1.4.0 pyucis-0.0.5.20211020.1 pyuvm-2.6.1 pyvsc-0.6.7.1792877175 pyyaml-6.0 svgwrite-1.4.1 toposort-1.7 wavedrom-2.0.3.post2
  32. ```
  33. ### Run default test (UART TX)
  34. ```
  35. root@6ee2bee145d4:~# cd /build/tests/
  36. root@6ee2bee145d4:/build/tests# make
  37. make -f Makefile results/uarttx.xml
  38. make[1]: Entering directory '/build/tests'
  39. mkdir -p results
  40. mkdir -p work
  41. /usr/local/bin/ghdl -i --std=08 --workdir=work --work=libvhdl ../libvhdl/common/UtilsP.vhd && \
  42. /usr/local/bin/ghdl -i --std=08 --workdir=work --work=work ../libvhdl/syn/*.vhd && \
  43. /usr/local/bin/ghdl -m --std=08 --workdir=work -Pwork --work=work uarttx
  44. analyze ../libvhdl/common/UtilsP.vhd
  45. analyze ../libvhdl/syn/UartTx.vhd
  46. elaborate uarttx
  47. MODULE=tb_uarttx TESTCASE= TOPLEVEL=uarttx TOPLEVEL_LANG=vhdl \
  48. /usr/local/bin/ghdl -r --workdir=work -Pwork --work=work uarttx --vpi=/usr/local/lib/python3.9/dist-packages/cocotb/libs/libcocotbvpi_ghdl.so --wave=results/uarttx.ghw --psl-report=results/uarttx_psl.json --vpi-trace=results/uarttx_vpi.log
  49. loading VPI module '/usr/local/lib/python3.9/dist-packages/cocotb/libs/libcocotbvpi_ghdl.so'
  50. -.--ns INFO cocotb.gpi ..mbed/gpi_embed.cpp:76 in set_program_name_in_venv Did not detect Python virtual environment. Using system-wide Python interpreter
  51. -.--ns INFO cocotb.gpi ../gpi/GpiCommon.cpp:99 in gpi_print_registered_impl VPI registered
  52. VPI module loaded!
  53. 0.00ns INFO Running on GHDL version 2.0.0-dev (v1.0.0-974-g0e46300c) [Dunoon edition]
  54. 0.00ns INFO Running tests with cocotb v1.7.0.dev0 from /usr/local/lib/python3.9/dist-packages/cocotb
  55. 0.00ns INFO Seeding Python random module with 1644236947
  56. ...
  57. 0.00ns INFO Found test tb_uart.test_uarttx
  58. 0.00ns INFO running test_uarttx (1/1)
  59. First simple test
  60. 0.00ns INFO Valid-accept driver
  61. 0.00ns INFO cocotbext-vai version 0.0.1
  62. 0.00ns INFO Copyright (c) 2022 Torsten Meissner
  63. 0.00ns INFO UART receiver
  64. 0.00ns INFO cocotbext-uart version 0.0.1
  65. 0.00ns INFO Copyright (c) 2022 Torsten Meissner
  66. 0.00ns INFO Hold reset
  67. 100.00ns INFO Released reset
  68. 110.00ns INFO Sending data: 0xaf
  69. 1170.00ns INFO Received data: 0xaf
  70. 1190.00ns INFO Sending data: 0x56
  71. 2280.00ns INFO Received data: 0x56
  72. ...
  73. 10070.00ns INFO Sending data: 0x70
  74. 11160.00ns INFO Received data: 0x70
  75. 11160.00ns INFO test_uarttx passed
  76. 11160.00ns INFO **************************************************************************************
  77. ** TEST STATUS SIM TIME (ns) REAL TIME (s) RATIO (ns/s) **
  78. **************************************************************************************
  79. ** tb_uart.test_uarttx PASS 11160.00 0.23 48943.29 **
  80. **************************************************************************************
  81. ** TESTS=1 PASS=1 FAIL=0 SKIP=0 11160.00 0.31 35939.72 **
  82. **************************************************************************************
  83. make[1]: Leaving directory '/build/tests
  84. ```
  85. ## Available Tests
  86. ### AES
  87. Simple tests of AES of the *cryptocores* project
  88. * `make DUT=aes`
  89. ### UART
  90. Simple tests of UART transmitter & receiver of the *libvhdl* project
  91. * `make DUT=uarttx` or `make`
  92. * `make DUT=uartrx`
  93. ### Wishbone
  94. Simple tests of Wishbone slave of the *libvhdl* project
  95. * `make DUT=wishbone`