Guide for using Cahute and fxlink on WSL 2
Posté le 15/09/2024 20:32
This tutorial guides you to enable USB communication in WSL 2 for Cahute and fxlink, which is not supported natively by WSL as of this writing (updated 2025-3-6).
Pre-requisites
As the title suggests, this guide is intended for developers using WSL 2. This is because
usbipd-win and
WSLg do not support WSL 1 distros. It is also not applicable to
Windows on ARM computers as the author of
usbipd-win has no plans to support ARM64. Although there is
a non-production solution for ARM64 PCs, this article only covers
usbipd-win for now as the writer does not have any ARM64 device for verifying.
For Windows 10 users, you must be running version 21H2 or higher, which is the minimum requirement for
WSLg to work.
Setting up WSL 2
If you are new to WSL, open PowerShell as administrator and execute the following commands to enable it:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Restart your PC to apply these changes.
The latest release of WSL 2 (v2.4.11) does not come with USB mass storage modules. Only pre-releases
v2.3.11-2.3.14 provide them for now.
Set the default install version for new distros to WSL 2:
wsl --set-default-version 2
You can type
wsl --list --online and select your preferred distro from the list by
wsl --install <distro> --web-download, or install other third-party WSL distros like ArchWSL. The guide will be using Ubuntu 24.04 LTS for demonstration.
Installing Cahute and fxlink
Make sure to
sudo apt update && sudo apt upgrade to have the latest libraries before going through all these instructions.
Go to
the README of GiteaPC and install it. Since we will be using the full version of fxlink, install the following dependencies:
% sudo apt-get install cmake python3-pil libusb-1.0-0-dev libudev-dev libsdl2-dev libpng-dev libncurses-dev libudisks2-dev libglib2.0-dev
Then continue with the remaining instructions as usual.
Lastly, follow
these instructions to install Cahute.
Instructions for using usbipd-win
The following instructions are for CLI users. If you prefer GUI, you can take a look at
this GUI application or
this VSCode integration.
On the Windows host, go to the
release page for the
usbipd-win project and download the latest .msi installer.
After installing
usbipd-win, connect your calculator with USB and select any connection mode. Then open PowerShell/Command Prompt as administrator and run
usbipd list (no admin privilege required here). The list should look like the following:
Look for the USB device with a VID of
07cf (highlighted in yellow). This is
Casio's vendor ID used for their products with USB. Jot down its corresponding bus ID (highlighted in green) for later use.
Click any one of the spoilers according to the version of
usbipd-win you are using.
For usbipd-win 4.2.0+
For usbipd-win 4.2.0+
This version adds the policy option that allows you to attach your calculators to WSL without manually binding them in advance. The usage is
usbipd policy add -e Allow -o 'AutoBind' [-b <bus-id> / -i <VID>:<PID>] (admin privilege required).
You can execute either
usbipd policy add -e Allow -o 'AutoBind' -b 1-7 or
usbipd policy add -e Allow -o 'AutoBind' -i 07cf:6103. The former option assigns a particular USB port to WSL (suitable if you want to attach other USB devices to WSL through this port as well), while the latter one allows Casio devices in any port with a PID of 6103.
Once the policy is successfully configured, the Casio USB device will have
Allowed state instead:
If you want a no-brainer solution to allow all Casio graphing calculators and their protocols, execute the following commands:
usbipd policy add -e Allow -o 'AutoBind' -i 07cf:6101
usbipd policy add -e Allow -o 'AutoBind' -i 07cf:6102
usbipd policy add -e Allow -o 'AutoBind' -i 07cf:6103
For usbipd-win 4.0.0-4.1.0
For usbipd-win 4.0.0-4.1.0
Copy its bus ID and bind the calculator with usbipd bind -b <bus-id>. Note that you have to repeat the bind command for each connection mode as they have different PIDs.
While your WSL instance is active, attach your calculator by
usbipd attach -w -b <bus-id>.
To let your calculator always connect to WSL instance instead of the host, add
-a flag after
usbipd attach. This will start an endless attach loop until you press Ctrl+C to terminate it.
For
usbipd 4.4.0+, the
-u flag allows you to start the attach loop, even if your calculator is not connected to that port. Note that this flag requires
-a and
-b.
For calculators that use CESG502, type
p7 info in WSL terminal to confirm that Cahute can detect the calculator connection. If your calculator is in USB Flash mode, enter
lsblk to see if its storage appears under
sdx directory.
Possible issues and workarounds
1. If you have installed
USBPcap in Windows (which is used for debugging with Cahute),
usbipd will prompt you:
usbipd: warning: USB filter 'USBPcap' is known to be incompatible with this software; 'bind --force' will be required.
If you prefer not to force bind your calculator to WSL instance, do not use both components simultaneously.
2. If
usbipd-win cannot automatically load
vhci_hcd module, edit the module config file:
% sudo nano /etc/modules-load.d/modules.conf
Add
vhci_hcd module at a new line, save the config file and restart your WSL session.
3. Since fxlink is installed in your home directory,
fxsdk build-cg -s may not work properly as it requires sudo privileges. In this case, execute the following workaround in WSL terminal:
% which fxlink
Copy its path and enter the following command at your fxSDK project directory as sudo:
% sudo /full/path/to/fxlink -sw <your-addin>.g3a
Another way (but not recommended) is to start as root and install fxSDK there instead.
4. If
p7screen prompts you:
Segmentation fault (core dumped)
You probably have encountered the bug that has been
upstreamed to libsdl's bug tracker (thanks Cakeisalie5 for the report). For now to work around it, create a
WSLg config file:
% sudo nano /etc/tmpfiles.d/wslg.conf
Save the config file with the following content and restart your WSL session:
# Type Path Mode UID GID Age Argument
L+ /tmp/.X11-unix - - - - /mnt/wslg/.X11-unix
Citer : Posté le 05/10/2024 16:24 | #
Hey, thanks for this tutorial! I've added issue #48 on Cahute to integrate this directly in Cahute's documentation, in addition to the udev rule warning your original topic helped me identify and add to the GiteaPC install section
As described in #projets, I'm kind of worried about this section of the instructions though:
4. If p7screen prompts you:
Segmentation faults are never an expected behaviour, and it feels like something I should either fix in p7screen, or make an upstream report about in libsdl's bug tracker, depending on which is at fault here.
In order to do this, I would be glad if you could reproduce the issue with the following parameters:
For reference, you've quoted this to be the source of the issue, and this for being the source of the solution you've provided here, and the issue only occurs on ArchWSL, and not Ubuntu WSL.
Mon blog ⋅ Mes autres projets
Citer : Posté le 05/03/2025 19:42 | #
Updated the usbipd-win section with the usage of policy subcommand, which is faster than manually binding every single USB protocol of your calculators