Skip to content

Commit

Permalink
Merge PR #196 felipe-m/iss195-cam
Browse files Browse the repository at this point in the history
Tut3 verilator+imgui+camera
  • Loading branch information
felipe-m authored Jun 4, 2023
2 parents 13963ca + 2b90cb4 commit 58c2439
Showing 27 changed files with 1,436 additions and 7 deletions.
19 changes: 12 additions & 7 deletions sim_fpga/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# A proof of concept on building simulators with verilator
This is a proof of concept on how to build hardware simulators using [verilator](https://www.veripool.org/verilator/).
The project includes a simple verilog rtl design that implements a pixel processor.
The design is as simplistic as possible, up to the point that it might not be correct nor very useful,
but enough to showcase a simulator where inputs and outputs are not straighforward, such us images.
# Building simulators with verilator
In this project we build hardware simulators using [Verilator](https://www.veripool.org/verilator/).
The project includes verilog RTL designs that implements a pixel processor.

In addition the verilated design is linked againts the popular [ImGui](https://github.com/ocornut/imgui) to create a simulation tool with a graphic UI.

@@ -32,6 +30,13 @@ sim/obj_dir/VTopPixelProcessor

![simulator running](./docs/sim_running.png "Simulator")

---

## Tutorial

In [tutorial](./tutorial) there are some examples with more information on how to use [Verilator](https://www.veripool.org/verilator/) with [ImGui](https://github.com/ocornut/imgui)


---

## Example 6
@@ -41,5 +46,5 @@ Test the processing modules of:

Tested modules are inside the blue area:

![Modules tested](example6.png)
![Modules tested](./examples/poc/example6/example6.png)

6 changes: 6 additions & 0 deletions sim_fpga/tutorial/readme.md
Original file line number Diff line number Diff line change
@@ -14,3 +14,9 @@ More info in its [tutorial 1 readme](./tut01)
We add and show in the GUI the centroid and proximity of the _verilated_ color processing Verilog module.

More info in its [tutorial 2 readme](./tut02)

## [Tutorial 3](./tut03)

In this example, instead of processing still images, the frames from the computer camera is processed by the _verilated_ color processing Verilog module.

More info in its [tutorial 3 readme](./tut03)
64 changes: 64 additions & 0 deletions sim_fpga/tutorial/tut03/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
SIM_DIR := $(realpath $(dir $(MKFILE_PATH))/../..)
PROJECT_DIR := $(realpath $(SIM_DIR)/..)
IMGUI_DIR = $(PROJECT_DIR)/third_party/imgui
EXAMPLE_DIR = $(SIM_DIR)/tutorial/tut03
RTL_DIR = $(EXAMPLE_DIR)/rtl
INC_DIR = $(EXAMPLE_DIR)/include
SRC_DIR = $(EXAMPLE_DIR)/src
ASSETS_DIR := $(SRC_DIR)
SOURCES = $(SRC_DIR)/main.cpp
SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp
SOURCES += $(IMGUI_DIR)/backends/imgui_impl_sdl.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp
V_SOURCES = $(RTL_DIR)/color_proc.v
UNAME_S := $(shell uname -s)
LINUX_GL_LIBS = -lGL

CXXFLAGS = -I$(INC_DIR) -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends -DASSETS_DIR=\\\"$(ASSETS_DIR)\\\" -g
LIBS =

##---------------------------------------------------------------------
## BUILD FLAGS PER PLATFORM
##---------------------------------------------------------------------

ifeq ($(UNAME_S), Linux) #LINUX
ECHO_MESSAGE = "Linux"
LIBS += $(LINUX_GL_LIBS) -ldl `sdl2-config --libs` `pkg-config --libs opencv4`

CXXFLAGS += `sdl2-config --cflags` `pkg-config --cflags opencv4`
CFLAGS = $(CXXFLAGS)
endif

ifeq ($(UNAME_S), Darwin) #APPLE
ECHO_MESSAGE = "Mac OS X"
LIBS += -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo `sdl2-config --libs`
LIBS += -L/usr/local/lib -L/opt/local/lib

CXXFLAGS += `sdl2-config --cflags`
CXXFLAGS += -I/usr/local/include -I/opt/local/include
CFLAGS = $(CXXFLAGS)
endif

ifeq ($(OS), Windows_NT)
ECHO_MESSAGE = "MinGW"
LIBS += -lgdi32 -lopengl32 -limm32 `pkg-config --static --libs sdl2`

CXXFLAGS += `pkg-config --cflags sdl2`
CFLAGS = $(CXXFLAGS)
endif

##---------------------------------------------------------------------
## BUILD RULES
##---------------------------------------------------------------------

all: obj_dir/Vcolor_proc
@echo Build complete for $(ECHO_MESSAGE)

obj_dir/Vcolor_proc.h: $(V_SOURCES)
verilator --cc $(V_SOURCES) -x-assign unique --trace -CFLAGS "$(CXXFLAGS)" --exe $(SOURCES) -I$(RTL_DIR)

obj_dir/Vcolor_proc: obj_dir/Vcolor_proc.h $(SOURCES)
make -j 4 -C obj_dir/ -f Vcolor_proc.mk Vcolor_proc LIBS="$(LIBS)"

clean:
rm -rf obj_dir
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions sim_fpga/tutorial/tut03/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Verilator+GUI Tutorial 3

Instead of images, the program takes the live captures of the computer camera.

The color processing is the same as in tutorial 2.

* [../../../phys_fpga/ulx3s/apio/ov7670x2_colorcentroid_160x120/color_proc.v](../../../phys_fpga/ulx3s/apio/ov7670x2_colorcentroid_160x120/color_proc.v)

The rest is the same as in tutorial 2.

For the ULX3S the color processing module requests a 12-bit RGB444 pixel from a **160x120** memory and in the following clock cycle it sends the processed pixel and its corresponding address to be written in a processed memory. It also includes a 8-bit centroid horizontal position, and a 3-bit proximity level. The larger the proximity, the closer the detected object is.

The input/output schematic is the same as in tutorial 2:

![color processing module](../tut02/color_proc_centr_block.png)


## Easier GUI debugging

The graphical interface allows debugging more easily. For example, the next screenshots show the processing of two different camera captures. The verilator processing is performed on the fly.

![1st camera frame](imgs/camera_proc_03_sm.png)


![2nd camera frame](imgs/camera_proc_06_sm.png)








Loading

0 comments on commit 58c2439

Please sign in to comment.