Notes on Wren6991’s Hazard3 Soft RISC-V with JTAG

See the YosysHQ OSS CAD Suite Installation

Be sure to use the -L with curl. See Dealing with HTTP 301 redirected file.

Reminder that the ULX3S needs to have FTDI drivers to program the FPGA, but libusbK drivers to use OpenOCD on Windows. Zadig is your friend. See prior blog.

First install the YosysHQ OSS CAD Suite

# set your preferred location for the download & extracted binary:
export MYOSSCADSUITE=/mnt/c/download/yosyshq


# See, this version is the Sept 4, 2022 build:
curl -L ""
tar -zxvf oss-cad-suite-linux-x64-20220904.tgz
source $MYOSSCADSUITE/oss-cad-suite/environment
export MY_GITHUB_NAME=gojimmypi
export WORKSPACE="/mnt/c/workspace"
export MY_HAZARD3_NAME="hazard3-$MY_GITHUB_NAME" 


git clone --recursive$MY_GITHUB_NAME/Hazard3.git "$MY_HAZARD3_NAME"


# if the above is your fork, then add upstream
git remote add upstream

# fetch upstream master
git fetch upstream
git pull upstream master


Fetch Luke’s Hazard3 repo:

git clone --recursive$MY_GITHUB_NAME/Hazard3.git 

Perform the install steps:

# Set up some paths, add RISC-V toolchain to PATH
. sourceme

cd test/sim/tb_cxxrtl

# yes, make can be slow on some systems. patience:

Later, once installed, revisit with:

git fetch
git pull

# edit for your own download:
export MYOSSCADSUITE=/mnt/c/download/yosyshq
source $MYOSSCADSUITE/oss-cad-suite/environment

export DISPLAY=:0
/mnt/c/cygwin64/bin/run.exe --quote /usr/bin/bash.exe -l -c " exec /usr/bin/startxwin -- -listen tcp -nowgl"

There was a small problem encountered. Although quickly resolved, for reference, this blog uses the commit at f48177c.

Note that the Makefile in hazard3\test\sim\hellow may need to be adjusted:

SRCS := ../common/init.S main.c
APP  := hellow
CCFLAGS = -march=rv32i -Os
AFLAGS = -march=rv32i

include ../common/

The RISC-V toolchain that was already installed did not support the z-opcodes, so the -march=rv32i_zicsr_zba_zbb_zbc_zbs parameter was changed to -march=rv32i for this exercise. The specific version of the riscv32 compiler used:

0 $  riscv32-unknown-elf-gcc --version
riscv32-unknown-elf-gcc (GCC) 10.1.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

X-Windows Server for WSL

This section won’t apply to native Linux.

Windows Store X-Server

Launch the Windows X-Server from the Microsoft Store. Just click the Open button. There’s no obvious UI, and nothing appears to happen. There should be a X410 Background Process running as viewed in Windows Task Manager.

This text is from the Windows Store as a reminder:

X410 is an X-Window server for Windows 10 and later. When you want to use X-Window GUI apps on your server from Windows, simply start X410 and connect to the server via SSH with X11 forwarding; your GUI apps are automatically forwarded to Windows as you launch them. X410 also works flawlessly with your locally installed virtual machines and WSL (Windows Subsystem for Linux) as well as Docker containers.


  • While X410 is in desktop mode, you can maximize or restore the X410 window by pressing CTRL+ALT+BACKSPACE.
  • Running X410 on HiDPI/4K Screens:
  • Opening Ubuntu Desktop in Hyper-V VM on X410 over VSOCK; no need for TCP/IP network or firewall permissions!

For more tips and usage examples, please visit


sudo apt-get install gdb-multiarch gdb-multiarch

CygwinX X-Server

I also have a gist for doing this with the CygwinX in a makefile, basically just need to:

export DISPLAY=:0
/mnt/c/cygwin64/bin/run.exe --quote /usr/bin/bash.exe -l -c " exec /usr/bin/startxwin -- -listen tcp -nowgl"

May need to do this once:

cp /mnt/c/cygwin64/home/$(shell cmd.exe /c "echo $$USER")/.Xauthority   ~/.Xauthority

Here’s the entire makefile section:

PROJ = ulx3s_adda
	rm -f $(PROJ).vcd
	iverilog  -o $(PROJ).vvp $(PROJ).v $(PROJ)_tb.v
	vvp $(PROJ).vvp
	export DISPLAY=:0

## if we are running in WSL, we need a bit of help for GUI XWindows
## and sometimes the WSL username is not the same as the Windows username & we need the *windows* user path.
## this is the Windows %USER% environment variable when called from makefile: $(shell cmd.exe /c "echo $$USER")
	@if [ "$(shell grep Microsoft /proc/version)" != "" ]; then   \
			cp /mnt/c/cygwin64/home/$(shell cmd.exe /c "echo $$USER")/.Xauthority   ~/.Xauthority; \

	(gtkwave $(PROJ).vcd $(PROJ)_savefile.gtkw)&

## launch the Windows cygwin64 startxwin when WSL is detected
	@if [ "$(shell grep Microsoft /proc/version)" != "" ]; then   \
		echo "Launching Windows XServer from WSL...";         \
		(/mnt/c/cygwin64/bin/run.exe --quote /usr/bin/bash.exe -l -c " exec /usr/bin/startxwin -- -listen tcp -nowgl")&  \
	else                                                          \
		echo "Not launching WSL XServer!" ;                   \

I ended up running into an error I could not resolve. Thank you, Luke for the prompt resolution!.

Next, install RISC-C OpenOCD, in this case for WSL2:

cd /mnt/c/workspace/

git clone
cd riscv-openocd
# Prefix is optional
./configure --enable-remote-bitbang --enable-ftdi --program-prefix=riscv-
make -j $(nproc)

# this next command took a LONG time for me on WSL1 (perhaps because a slow shared file system)
sudo make install

For users of WSL1, well, there’s no native USB driver support for the FTDI, so there will likely be an error like this:

0 $  riscv-openocd -f ../icebreaker-openocd.cfg
Open On-Chip Debugger 0.11.0+dev-02440-gd6bf02256 (2022-11-27-11:01)
Licensed under GNU GPL v2
For bug reports, read
DEPRECATED! use 'ftdi tdo_sample_edge' not 'ftdi_tdo_sample_edge'
DEPRECATED! use 'ftdi device_desc' not 'ftdi_device_desc'
DEPRECATED! use 'ftdi vid_pid' not 'ftdi_vid_pid'
DEPRECATED! use 'ftdi channel' not 'ftdi_channel'
DEPRECATED! use 'ftdi layout_init' not 'ftdi_layout_init'
Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
Error: libusb_init() failed with LIBUSB_ERROR_OTHER

For WSL1, we’ll need to cross-compile the Windows native app:

./configure --host=i686-w64-mingw32   --enable-remote-bitbang --enable-ftdi --program-prefix=riscv-
make -j $(nproc)

First build libusb install from see other releases

sudo apt install libudev-dev 

cd libusb-1.0.21



./configure --enable-shared=no --enable-static=yes --enable-examples-build  --host=i686-w64-mingw32 --build=i686-pc-linux-gnu
make clean
make -j $(nproc)

cd examples

undefined reference:

# export LIBUSB1_LIBS="-L/mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb"
export LIBUSB_VER=libusb-1.0.21
export LIBUSB1_LIBS="-lusb-1.0 -L/mnt/c/temp/riscv-openocd/libusb-1.0.26/libusb"
export LIBUSB1_CFLAGS="-lusb-1.0.21 -isystem /mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb"


export LIBUSB_VER=libusb-1.0.21

#export LIBUSB1_LIBS="-L/mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb/.libs"
export LIBUSB1_LIBS="-L/mnt/c/workspace/riscv-openocd/$LIBUSB_VER/libusb/.libs"

# export LIBUSB1_CFLAGS="-lusb -lusb-1.0.21 -isystem /mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb/.libs"
export LIBUSB1_CFLAGS="-lusb -lusb-1.0 -isystem /mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb/.libs"
export LDFLAGS=-L/mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb/.libs
export CPPFLAGS=-I/mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb

export LD_LIBRARY_PATH=/mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb/.libs
export CFLAGS=-I/mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb

# export LIBUSB1_CFLAGS="-lusb -lusb-1.0 -isystem /mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb"
export LIBUSB1_CFLAGS="-lusb -lusb-1.0 -isystem /mnt/c/workspace/riscv-openocd/$LIBUSB_VER/libusb"

echo "LIBS               = $LIBS"
echo "LIBUSB_VER        = $LIBUSB_VER"
echo "LIBUSB1_LIBS      = $LIBUSB1_LIBS"
echo "LDFLAGS           = $LDFLAGS"
echo "CPPFLAGS          = $CPPFLAGS"

# testing this one
 ./configure --enable-maintainer-mode --build=i686-pc-linux-gnu --host=i686-w64-mingw32 --libdir=/mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb/.libs  --disable-werror   --with-ftd2xx-win32-zipdir="/mnt/c/download/FTDI/CDM v2.12.24 WHQL Certified/i386"  --with-ftd2xx-lib=static  --enable-ft2232_ftd2xx   --disable-at91rm9200  --enable-remote-bitbang --enable-ftdi --program-prefix=riscv- --enable-debug-log --disable-usb-blaster 

# this is failing:
i686-w64-mingw32-gcc -Wall -Wstrict-prototypes -Wformat-security -Wshadow -Wextra -Wno-unused-parameter -Wbad-function-cast -Wcast-align -Wredundant-decls -Wpointer-arith -Wundef -Wno-error=deprecated-declarations -DFD_SETSIZE=128 -I/mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb -o src/openocd.exe src/main.o  -L/mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb/.libs src/.libs/libopenocd.a -L/mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb -lws2_32 ./jimtcl/libjim.a

# consider x86_64-w64-mingw32

# TADA!!
i686-w64-mingw32-gcc -Wall -Wstrict-prototypes -Wformat-security -Wshadow -Wextra -Wno-unused-parameter -Wbad-function-cast -Wcast-align -Wredundant-decls -Wpointer-arith -Wundef -Wno-error=deprecated-declarations -DFD_SETSIZE=128 -I/mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb -o src/openocd.exe src/main.o  -L/mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb/.libs src/.libs/libopenocd.a libusb-1.0.21/libusb/.libs/libusb-1.0.a   -L/mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb -lws2_32 ./jimtcl/libjim.a

next test with libusb

The message: configure: error: libusb-1.x is required for the MPSSE mode of FTDI based devices, means this is needed:

export LIBUSB1_LIBS=-L/mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb/.libs
export LIBUSB1_CFLAGS="-lusb -lusb-1.0 -isystem /mnt/c/workspace/riscv-openocd/libusb-1.0.21/libusb"

Final test:

install from (copy zip contents into riscv-openocd )

export MY_FTDI_ZIP="/mnt/c/download/FTDI/CDM v2.12.24 WHQL Certified/i386"
export LIBUSB_VER=libusb-1.0.26

# export LIBUSB1_LIBS="-lusb-1.0 -L/mnt/c/temp/riscv-openocd/libusb-1.0.26/libusb"

# -lusb-1.0 -L/mnt/c/temp/riscv-openocd/libusb-1.0.26/libusb
export LIBUSB1_LIBS="-lusb-1.0 -L$PWD/$LIBUSB_VER/libusb"

# LIBUSB1_CFLAGS, for example:
#    -lusb -lusb-1.0 -isystem /mnt/c/temp/riscv-openocd/libusb-1.0.26/libusb
export LIBUSB1_CFLAGS="-lusb -lusb-1.0 -isystem $PWD/$LIBUSB_VER/libusb"


./configure --enable-maintainer-mode --build=i686-pc-linux-gnu --host=i686-w64-mingw32 --disable-werror   --with-ftd2xx-win32-zipdir="/mnt/c/download/FTDI/CDM v2.12.24 WHQL Certified/i386"  --with-ftd2xx-lib=static  --enable-ft2232_ftd2xx   --disable-at91rm9200  --enable-remote-bitbang --enable-ftdi --program-prefix=riscv-
make clean
make -j $(nproc)