Just to be clear, Windows for any software development SUCKS!!!!!, the following guide present a good alternative since allow us to use many of the feature presented in Linux, with certain limitation but at the end of the day much better than using Windows. The guide assumes you are using windows 11 and you have all the freedom to run program in admin mode

Open a Windows PowerShell terminal as an administrator, then type the following commands to enable WSL on your machine, entering each line separately.

> dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
> dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Restart your computer, then open PowerShell as an administrator to update the Windows Subsystem for Linux (WSL). If it's not already installed, this process will install it for you.

> wsl --update

Installing Arch Linux

Download the files ArchWSL-AppX_24.4.28.0_x64.appx and ArchWSL-AppX_24.4.28.0_x64.cer from the official ArchWSL repo Releases · yuk7/ArchWSL (always look for the latest release), install the cer file first, remember to install at local machine level

then select the certification store, then finish and OK.

After the last steps you can install the appx just like any other windows installer and then launch, a wild terminal will appear, just hit enter to close it

At this point Arch is installed in our system, we just need to configure a few things. Open a Windows Terminal and type Arch and then passwd to set up the root password

> Arch
[root@PC-NAME]# passwd

Then set up your default user with its corresponding password, where {username} is the username, you want to provide

[root@PC-NAME]# echo "%wheel ALL=(ALL) ALL" > /etc/sudoers.d/wheel
[root@PC-NAME]# useradd -m -G wheel -s /bin/bash {username}
[root@PC-NAME]# passwd {username}
[root@PC-NAME]# exit

Set the your user as default to init with arch

> Arch config --default-user {username}

Set up pacman package manager and update

> Arch
[user@PC-NAME]$ sudo pacman-key --init
[user@PC-NAME]$ sudo pacman-key --populate
[user@PC-NAME]$ sudo pacman -Sy archlinux-keyring
[user@PC-NAME]$ sudo pacman -Su

Install base tool for software development (like gcc, make, bison, etc..), this is also necessary to install some packages with pacman or manually

[user@PC-NAME]$ sudo pacman -S base-devel 

Install USB utilities because we are embedded and we need to connect our boards.

[user@PC-NAME]$ sudo pacman -S usbutils

And naturally, proficiency in Python is essential, as without it one cannot be regarded as a proficient developer and also git.

[user@PC-NAME]$ sudo pacman -S python git

paru is another must to install, is an extra package manager when the official repos in pacman does not have available some of the software

$ git clone https://aur.archlinux.org/paru.git
$ cd paru
$ makepkg -si
$ cd ..
$ rm -r paru

Installing USB support

by default WSL does not support USB devices, making impossible to flash or debug our beloved microcontroller, but there is an alternative installing an extra package, go to Connect USB devices look for the link to USB-WIN project and download de latest version to proceed to install.

I have connected my Nucleo-G0 board with a preprogramed JLink debugger, if we type the following in PowerShell (admin privileges is required) we should see a USB Serial Device (COM5), BULK interface (i don’t have installed any driver yet) and yes, I also have a Lauterbach $$$$

> usbipd list
Connected:
BUSID  VID:PID    DEVICE                                                        STATE
5-2    1366:0105  USB Serial Device (COM5), BULK interface                      Not shared
5-3    8087:0029  Intel(R) Wireless Bluetooth(R)                                Not shared
6-3    0897:0005  Lauterbach PODBUS USB Controller (USB3,PRO)                   Not shared

If we follow the steps in the Microsoft page we should “share“ the 5-2 device usign the command usbipd bind, after that, list again to see is already share

> usbipd bind --busid 5-2
> usbipd list
Connected:
BUSID  VID:PID    DEVICE                                                        STATE
5-2    1366:0105  USB Serial Device (COM5), BULK interface                      Shared
5-3    8087:0029  Intel(R) Wireless Bluetooth(R)                                Not shared
6-3    0897:0005  Lauterbach PODBUS USB Controller (USB3,PRO)                   Not shared

Next we need to attach to our WSL instance with Arch Linux, but before this open another terminal and run your Arch instance

> usbipd attach --wsl --busid 5-2
usbipd: info: Using WSL distribution 'Arch' to attach; the device will be available in all WSL 2 distributions.
usbipd: info: Using IP address 172.19.0.1 to reach the host.
> usbipd list
Connected:
BUSID  VID:PID    DEVICE                                                        STATE
5-2    1366:0105  USB Serial Device (COM5), BULK interface                      Attached
5-3    8087:0029  Intel(R) Wireless Bluetooth(R)                                Not shared
6-3    0897:0005  Lauterbach PODBUS USB Controller (USB3,PRO)                   Not shared

On your Arch terminal type the linux command lsusb to display the usb devices, you can see Linux does not need any driver and already detects our JLink out of the box

[diego@DESKTOP-0VPDF6R ~]$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 1366:0105 SEGGER J-Link
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

WSL package for VSCode

I assume you're using VSCode, search for the WSL extension and install it. If that's not the case, there's no need to worry—simply continue using the terminal independently alongside your preferred editor.

Once the extension is installed, click the icon in the bottom left corner and then select 'Connect to a remote option' from the popup menu. When you open a terminal, you will notice that we are now in our lovely Arch environment.

From this point, you can generally follow the instructions we use in our various trainings when we mention to install tools in linux. Just keep in mind that we are not using Linux, and several features that reference the kernel will not be available. However, it is very similar to Microsoft, and it is a much better alternative than using Windows.

BTW, the cortex-debug plugin works out the box with WSL, like if it was running on your windows machine.

One last thing, where in the heck are located all the files we create and edit in our Linux subsytem (WSL), it is easy just open a Windows explorer and type \\wsl$ then hit enter. You just need to navigate to Arch/home/username

Here is a nice video from Abstract Programmer How to access WSL files from windows and Windows files from WSL with a good explanation. But do not mess around with files in Linux and Windows, if you want to share something use Git or something like that. Here is another video to install Arch just in case Using Linux on Windows with WSL 2 🐧 – Debian and Arch Linux

Additionally, you can execute Windows programs from your WSL terminal, specifically CLI programs, by adding their extension, which can be a bit annoying. For example, I have this fancy compiler from Hightec that only runs on Windows, at least the version I possess.

$ tricore-gcc.exe -v
HTC_GCC_OPTIONS=-v
Using built-in specs.
COLLECT_GCC=tricore-gcc.exe
COLLECT_LTO_WRAPPER=c:/hightec/toolchains/tricore/v4.9.3.0-infineon-1.0/bin/../libexec/gcc/tricore/4.9.4/lto-wrapper.exe
Target: tricore
Configured with: ../../sources/gcc/configure --host=x86_64-w64-mingw32 --build=x86_64-linux-gnu --with-pkgversion=HDP-v4.9.3.0-infineon-1.0-fb21a99 --with-bugurl=support@hightec-rt.com --target=tricore --prefix=/data/distribution/HDP-v4.9.3.0-infineon-1.0/tricore-win64/htc/tricore/win64/HDP-v4.9.3.0-infineon-1.0 --program-prefix=tricore- --with-local-prefix=/data/distribution/HDP-v4.9.3.0-infineon-1.0/tricore-win64/htc/tricore/win64/HDP-v4.9.3.0-infineon-1.0 --disable-shared --with-gnu-as --with-gnu-ld --disable-threads --enable-languages=c,c++ --disable-libssp --enable-nls --with-headers=yes --with-newlib=yes --enable-newlib-elix-level=3 --enable-newlib-io-long-long --disable-newlib-supplied-syscalls
Thread model: single
gcc version 4.9.4 build on 2019-06-07 (HighTec Release HDP-v4.9.3.0-infineon-1.0-fb21a99) 

Multiple Instances

You could have more than one instance of your Arch linux WSL, to achieve this you need to download the zip file version from GitHub - yuk7/ArchWSL: ArchLinux based WSL Distribution. Supports multiple install. Extract the files to some place you like and rename the Arch.exe to any name you what to provide to the new instance, double click to install as usual and it is done, now you have two instances

> wsl --list
Windows Subsystem for Linux Distributions:
Arch (Default)
Zephyr

Since your new distro have been installed manually to run you should use

> wsl -d Zephyr 

To set a default user you should open the file (with any editor like nano in you WS instance) $ nano /etc/wsl.conf in the instance with the following setting: (Changing, of course, username to be your default username). Exit your distro/instance, then issue a wsl --terminate <distroname> from PowerShell or CMD. When you restart, the default user should be set. procced to install and configure the rest of the stuff like we did before

[user]
default=username

I strongly recommend this installation method over the previous one it offer more control on your instances specially if you have more than one, I personally like to make a new directory called Wsl right at C:\Wsl and put there my instances.

[diego@DESKTOP-VD3GS75 Wsl]$ tree -L 2
/mnt/c/Wsl
├── Arch.zip            # Arch wsl base distro
├── Stm32               # WSL for STM32 Mcus developemnt with stm32cube, freertos, ceedling, etc..
│   ├── ext4.vhdx
│   ├── rootfs.tar.gz
│   └── Stm32.exe
└── Zephyr              # WSL for Zephyr + Nordic development
    ├── ext4.vhdx
    ├── rootfs.tar.gz
    └── Zephyr.exe

As a final note I tent to use WSL like docker containers for certain situations when I do not have more remedy than using windows, but I would like to recommend the use of docker instead and leave WSL for some special use cases but is up to you at the end.

Basic commands for WSL
Reference for the basic commands included with Windows Subsystem for Linux (WSL).