mcb32tools on Windows Subsystem for Linux (WSL)

Installing WSL

(Thanks to Martin Larsson for providing the following text)

To install WSL on Windows, follow this guide Links to an external site.. Ubuntu is the recommended distribution. Once installed the bash shell can be switched to by entering bash or wsl. The bash shell will have its working directory set to the same directory the command was issued from (So if the command is run in Documents, the shell will start in Documents). In bash the entire Windows file system can be navigated freely (mounted under /mnt/c), as well as the rest of the linux file system. This means you can keep all your code in one place and not have to move them to and from WSL. To return back to Powershell/CMD, use the command exit.

Installing mcb32tools

  1. Install additional packages by running the following commands one by one.
echo "deb-src http://archive.ubuntu.com/ubuntu/ xenial main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list
sudo apt update
sudo apt-get install bzip2 make libftdi-dev
  1. Download the linux .run file from the mcb32tools Github Links to an external site..
  2. Install the toolchain by running the file in bash with super user privileges. sudo ./path_to_file/mcbtools-vX.X...-linux.gnu.run

Using the toolchain

  1. In bash navigate to the folder with the code to compile and install
  2. Enter the cross compile environment . /opt/mcb32tools/environment (Important space after the dot)
  3. Connect your chipkit device
  4. In Windows Device Manager, under "Ports (COM & LTP)" look for your device, and note the COM number (ex COM4)
  5. Compile your code with make
  6. Install your code with make install TTYDEV=/dev/ttySX, replace the X with the COM number for your device (ex TTYDEV=/dev/ttyS4)

Problems with WSL2 (thanks to Benedek Boldizsár)

The problem with WSL2 is that apparently they just do not support windows USB ports, (while WSL1 did).

The solution of this is essentially a partly microsoft-developed 3rd party software called USBIPD, which is a "Windows software for sharing locally connected USB devices to other machines, including Hyper-V guests and WSL 2." (as the README states)

You can download from github the following .msi installer for usbipd4.0.0

https://github.com/dorssel/usbipd-win/releases

Then run it/install it (probably requires admin access), and in administratory powershell, you can run the following:

>usbipd list

You should see something like this:

image.png

Here you can see the different BUSid-s you can host into your WSL. You need to look for the BUSid of the USB Serial Converter, then run the following commands. Note that, obviously, you need to connect the USB Serial COnverter ports to your WSL, in the example above thatisport  2-2.

>usbipd bind -b <bus-id>

>usbipd attach --wsl -b <bus-id>

You will see something like this:
image.png

Now, your WSL2 should have access to your usb serial ports, and can run the make install TTYDEV... command.

You can find out which ports appear in your WSL2 with the command $lsusb (if the usbipd works you should see something besides the two basic roothubs).

The command

$make install

works also.

If you want to detach and unbind from >usbipd, then you can run the following commands in the powershell

>usbipd detach --busid <bus-id>

>usbipd unbind --busid <bus-id>

And then by >usbipd list should show that those ports are no longer shared.

Here's a microsoft devblog with YouTube video also (please note that they are using a different version of usbipd where the syntax is a bit different, you are fine if you put two dashes before the keyword wsl, that is --wsl; or just use and understand >usbipd --help, or of course the README on github).

https://devblogs.microsoft.com/commandline/connecting-usb-devices-to-wsl/

Good luck!