Skip to content
two1zero3 edited this page Apr 13, 2024 · 19 revisions

In general, for minichlink, the flashing/debugging utility, you can use the pre-compiled minichlink or go to minichlink dir and make it.

Debian and WSL

apt-get install build-essential libnewlib-dev gcc-riscv64-unknown-elf libusb-1.0-0-dev libudev-dev gdb-multiarch

Note that gdb-multiarch is only needed/useful if you want to use gdb. You can still semihost/debug printf without gdb.

Arch/Manjaro

sudo pacman -S base-devel libusb Then from AUR install riscv64-unknown-elf-gcc, riscv64-unknown-elf-binutils, riscv64-unknown-elf-newlib (will compile for a long time).

Note

If you are on a system that doesn't have plugdev (like Arch) or your user is not in plugdev, you will need to add the plugdev group and add your user to it:

sudo groupadd plugdev
sudo usermod -aG plugdev YOUR_USERNAME

More info can be found here: https://github.com/cnlohr/ch32v003fun/pull/287

Fedora

dnf install libusb1-devel systemd-devel arm-none-eabi-newlib gcc-riscv64-linux-gnu binutils-riscv64-linux-gnu make

From Source

dnf install libusb1-devel systemd-devel

Install prerequisites from riscv-gnu-toolchain.

git clone https://github.com/riscv-collab/riscv-gnu-toolchain
cd riscv-gnu-toolchain
./configure --prefix=~/riscv
make

Be sure to add "$HOME/riscv/bin" to your PATH in your startup scripts

Linux with manual risc-v GCC build (not recommended)

Install prerequisites from riscv-gnu-toolchain.

You can build the RISC-V toolchain yourself, but be aware it will take about 1-2 hours and use 15GB!

git clone https://github.com/riscv-collab/riscv-gnu-toolchain
cd riscv-gnu-toolchain
git submodule update --init
./configure --prefix=/opt/rv32ec --with-arch=rv32ec --with-abi=ilp32e
make

Maybe some day soon xw will be available?

Windows

Download and install (to system) this copy of GCC10. The minichlink.exe file is already ready to go in the minichlink folder. It requires Microsoft Visual C++ Redistributable to be installed.

In Windows, if you want to use minichlink with the LinkE, you will need to use Zadig to install WinUSB to the WCH-Link interface 0.

MacOS

install the RISC-V toolchain with homebrew following these instructions

To get minichlink, please go to the minichlink directory and make it or you can use the pre-compiled minichlink.

You might need to install pkg-config using brew install pkg-config to compile minichlink.

After installation you can move on to Building and Flashing

WCH-Link Hardware access in WSL

To use the WCH-Link in WSL, it is required to "attach" the USB hardware on the Windows side to WSL. This is achieved using a tool called usbipd.

  1. On windows side, install the following MSI https://github.com/dorssel/usbipd-win/releases
  2. Install the WSL side client:
    • For Debian: sudo apt-get install usbip hwdata usbutils
    • For Arch-based: sudo pacman -S usbip hwdata usbutils
    • For Ubuntu (not tested):
        sudo apt install linux-tools-5.4.0-77-generic linux-tools-virtual hwdata usbutils
        sudo update-alternatives --install /usr/local/bin/usbip usbip `ls /usr/lib/linux-tools/*/usbip | tail -n1` 20
  1. Plug in the WCH-Link to USB
  2. Run Powershell as admin and use the usbipd list command to list all connected devices
  3. Find the this device: 1a86:8010 WCH-Link (Interface 0) and note the busid it is attached to
  4. In powershell, use the command usbipd wsl attach --busid=<BUSID> to attach the device at the busid from previous step
  5. You will hear the windows sound for the USB device being removed (and silently attached to WSL instead)
  6. In WSL, you will now be able to run lsusb and see that the SCH-Link is attached
  7. For unknown reasons, you must run make under root access in order to connect to the programmer with minichlink. Recommend running sudo make when building and programming projects using WSL. This may work too (to be confirmed):

Non-root access on linux

Unlike serial interfaces, by default, the USB device is owned by root, has group set to root and everyone else may only read by default. The way to allow non-root users/groups to be able to access devices is via udev rules.

minichlink provides a list of udev rules that allows any user in the plugdev group to be able to interact with the programmers it supports.

You can install and load the required udev rules for minichlink by executing the following commands in the root of this Git repository:

sudo cp minichlink/99-minichlink.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules && sudo udevadm trigger

If you add support for another programmer in minichlink, you will need to add more rules here.

Note: This readme used to recommend manually making these rules under 80-USB_WCH-Link.rules. If you wish to use the new rules file shipped in this repo, you may want to remove the old rules file.

WCH-Link (E)

It enumerates as 2 interfaces.

  1. the programming interface. I can't get anything except the propreitary interface to work.
  2. the built-in usb serial port. You can hook up UART D5=TX to RX and D6=RX to TX of the CH32V003 for printf/debugging, default speed is 115200. Both are optional, connect what you need.

If you want to mess with the programming code in Windows, you will have to install WinUSB to the interface 0. Then you can uninstall it in Device Manager under USB Devices.

On linux you find the serial port with ls -l /dev/ttyUSB* /dev/ttyACM* and connect to it with screen /dev/ttyACM0 115200
Disconnect with CTRL+a :quit.

Adding your user to these groups will remove the need to sudo for access to the serial port: debian-based sudo usermod -a -G dialout $USER arch-based sudo usermod -a -G uucp $USER

You'll need to log out and in to see the change.