Back to Home

Launching RISC-V K1921VG015: toolchain and OpenOCD

Instructions for setting up riscv-gnu-toolchain and OpenOCD to launch demo on K1921VG015. Describes build with multilib, patches for DirtyJTAG and GCC14, flashing via WSL. Suitable for debugging RISC-V projects.

RISC-V K1921VG015: launching demo with DirtyJTAG
Advertisement 728x90

Setting Up Toolchain and OpenOCD for Running RISC-V on K1921VG015

A demo project is launched on development boards with the K1921VG015 microcontroller based on RISC-V architecture. This requires a DirtyJTAG JTAG adapter, the riscv-gnu-toolchain compiler, and OpenOCD with patches from NIIET. The work is done in WSL on Windows 11 with Debian 13 (trixie).

Installing basic packages ensures the toolchain can be built:

sudo apt install autoconf automake autotools-dev curl python3 python3-pip python3-tomli libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat1-dev ninja-build git cmake libglib2.0-dev libslirp-dev libncurses-dev libusb-1.0-0-dev libusb-1.0-0 cmake

Building the riscv-gnu-toolchain Compiler

Clone the repository with recursive submodules:

Google AdInline article slot
git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
cd riscv-gnu-toolchain
./configure --prefix=/opt/riscv --enable-multilib
sudo make

The --enable-multilib flag enables support for RV32 and RV64. Building as root ensures installation in /opt/riscv. After this, add /opt/riscv/bin to PATH to access riscv64-unknown-elf-gcc and other tools.

Compiling OpenOCD with DirtyJTAG Support

Use the OpenOCD fork from NIIET (commit ed64294116beb6bc335a6c5809b46a87add8042a):

git clone --recursive https://gitflic.ru/project/niiet/openocd.git
cd openocd/
git apply --verbose 0001-jtag-add-support-for-adapter-DirtyJTAG.patch
git apply --verbose 0002-fix-correct-calloc-argument-order-for-GCC-14-compati.patch
./bootstrap
./configure --prefix=/usr/
make -j$(nproc)
sudo make install

Patch 0001 adds the driver for DirtyJTAG. Patch 0002 fixes the calloc argument order for compatibility with GCC 14. Copy the k1921vg015.cfg configuration to /usr/share/openocd/scripts/target/ — chip support is not included in the base NIIET version.

Google AdInline article slot

Building and Flashing the Demo Project

The demo is generated in Syntacore Development Toolkit, with CMakeLists.txt added manually. Build it:

mkdir build
cd build
cmake ../CMakeLists.txt
make

The resulting Run_leds.bin is ready for loading. In WSL, connect the USB device:

usbipd list  # Find DirtyJTAG BUSID, e.g., 1-3
usbipd attach --wsl --busid 1-3

Launch the firmware via OpenOCD:

Google AdInline article slot
sudo openocd -f interface/dirtyjtag.cfg -f target/k1921vg015.cfg -c "program Run_leds.bin 0x80000000 verify reset exit"

This command programs at address 0x80000000, verifies integrity, resets, and exits. On pure Linux, skip the usbipd step.

Key setup steps in a list:

  • Install Debian packages for the toolchain.
  • Build the multilib compiler in /opt/riscv.
  • Patching and compiling OpenOCD with DirtyJTAG support.
  • Adding k1921vg015.cfg to scripts.
  • CMake project build and USB attach in WSL.
  • Flashing with verify and reset.

What's Important

  • --enable-multilib is essential for RV32/RV64 on a single toolchain.
  • OpenOCD patches are critical: DirtyJTAG and GCC14-calloc.
  • Load address 0x80000000 is standard for K1921VG015.
  • WSL requires usbipd for JTAG access.
  • Config k1921vg015.cfg is added manually.

Further debugging involves studying the chip architecture through similar toolchain steps.

— Editorial Team

Advertisement 728x90

Read Next