Skip to content

⚠️ 产品声明 / Product Disclaimer

非量产产品,仅供工程验证,不承诺符合 RoHS。 Non-mass-production product; for engineering verification only. RoHS compliance is not guaranteed.

Overview ​

Before you start developing, install all the software used in this tutorial in one go. Every build, flash, and other command in this tutorial runs in a WSL (Ubuntu) terminal, so setting up the environment is the top priority.

Once you have installed all the software on this page, you can start STM32 CMake Project Creation.

🎯Page GoalInstall WSL2, Git, the ARM cross compiler, CMake, Ninja, OpenOCD, VSCode, STM32CubeMX, and Seahi-Serial — 8 pieces of software in total.
🧰Prerequisites① A Windows 10/11 PC (virtualization must be enabled) ② Internet access (GitHub / ST's official website).
🔗RelatedOnce the software is installed, go to [STM32 CMake Project Creation](./cmake-project) to get the base project.

①
Install WSL2 and Ubuntu (Core Environment)

WSL2 is the Linux runtime built into Windows; every command in this tutorial (git clone, building, flashing) runs inside it.

  1. Press the Win key, type PowerShell, right-click Run as administrator.

  2. Run this command and press Enter:

    wsl --install -d Ubuntu-22.04
    

    If it says no distribution was found, run wsl --update first and retry.

  3. After installation, reboot your PC; on startup you enter the Ubuntu terminal automatically. Set your username and password as prompted (remember the password — you’ll need it for sudo later).

  4. Update the software sources and verify:

    sudo apt update
    cat /etc/os-release
    

Once installed, open the Ubuntu terminal (search for Ubuntu in the Start menu) to enter the WSL environment.

Open the Ubuntu terminal

WSL directory basics: inside Linux, /mnt/c/ is the Windows C: drive; WSL’s own files live under /home/YourName/.

WSL directory structure

②
Install Git and the Build Toolchain (inside WSL)

Run sudo apt update once first. If it is very slow or fails, the default software source is overseas — first follow the “Switch to a China-based mirror” steps below, then come back and install the toolchain.

📖 Guide to switching to a China-based mirror (run this when apt is slow or failing — pick either one)

① Tsinghua mirror (recommended):

# Back up the original configuration
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
# Replace with the Tsinghua mirror
sudo sed -i 's@//.*archive.ubuntu.com@//mirrors.tuna.tsinghua.edu.cn@g; s@//security.ubuntu.com@//mirrors.tuna.tsinghua.edu.cn@g' /etc/apt/sources.list
# Update
sudo apt update

② Aliyun mirror:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo sed -i 's@//.*archive.ubuntu.com@//mirrors.aliyun.com@g; s@//security.ubuntu.com@//mirrors.aliyun.com@g' /etc/apt/sources.list
sudo apt update

After switching mirrors, sudo apt update should finish quickly. Then install the 4 toolchains below one by one (each has its own copy box — install one, verify one):

1️⃣ Install Git (to pull the code)

sudo apt install -y git
git --version

2️⃣ Install the ARM cross compiler (compiles C into STM32 machine code)

sudo apt install -y gcc-arm-none-eabi
arm-none-eabi-gcc --version

3️⃣ Install CMake and Ninja (build system)

sudo apt install -y cmake ninja-build
cmake --version
ninja --version

4️⃣ Install OpenOCD (works with ST-Link for flashing/debugging)

sudo apt install -y openocd
openocd --version

Version requirements: gcc-arm-none-eabi ≥ 10.3, cmake ≥ 3.22, ninja ≥ 1.10, openocd ≥ 0.12. If all four commands print their versions normally, the toolchain installation is complete.

③
Install and Configure VSCode (install WSL first, then connect, then add extensions)

Order matters: WSL was already installed in step ①. VSCode extensions fall into two groups — UI extensions go on the Windows side (the Chinese language pack and the WSL extension), while development extensions must be installed on the WSL side (C/C++, CMake Tools, etc., which provide building and IntelliSense). So you must connect to WSL first, then install the development extensions.

  1. Download and install VSCode: https://code.visualstudio.com/ (Windows version, default installation).

  2. Open VSCode, click the “Extensions” icon on the left, and install these 2 Windows-side extensions first:

    Extension Publisher Install on Purpose
    Chinese (Simplified) Language Pack Microsoft Windows side Simplified Chinese UI (restart VSCode after installing)
    WSL Microsoft Windows side The bridge to WSL — required

    VSCode extensions panel

  3. Click the green Remote Window button in the lower-left corner → Connect to WSL. Once connected, the lower-left corner shows WSL: Ubuntu (you are now inside the WSL environment).

    Connected to WSL

  4. While connected to WSL, continue installing the development extensions below (the Extensions panel shows “Install in WSL: Ubuntu”; just click install on each one and it is installed on the WSL side):

    Extension Publisher Install on Purpose
    C/C++ Microsoft WSL side Code highlighting and IntelliSense (reads compile_commands.json)
    CMake Tools Microsoft WSL side Graphical button-based building
    Cortex-Debug marus25 WSL side On-chip STM32 debugging (with OpenOCD + ST-Link)

Configuration is a one-time job. To verify: the lower-left corner shows WSL: Ubuntu, and the Extensions panel shows C/C++ and CMake Tools installed in WSL: Ubuntu.

Extensions installed in WSL

Tip: if sudo apt update is slow or fails, follow the mirror-switching guide in step ② before installing the toolchain.

④
Install STM32CubeMX (Windows)

Go to ST’s official download page: https://www.st.com/en/development-tools/stm32cubemx.html

  1. Click Download (register a free ST account first if you don’t have one) and download the Windows version (en.stm32cubemx-win64-v6.x.x.zip).

  2. Unzip it, double-click the installer, and accept the defaults all the way through.

  3. On first launch, install the F1 firmware package: menu Help → Manage embedded software packages → find STM32Cube MCU Package for STM32F1 Series → click Install (version V1.8.7) and wait for it to turn green.

    Install the F1 firmware package

The “9Mod” MCP Verification Board’s .ioc file was generated with CubeMX 6.18.0 and FW_F1 V1.8.7; using the same or a newer version is recommended.

⑤
Install Seahi-Serial (serial assistant + WSL mapping in one)

Seahi-Serial is a Windows tool that combines a serial assistant with WSL serial/USB mapping: it lets you view debug logs and send MCP commands manually, and it can mount Windows COM ports / USB devices into WSL (solving the problem that WSL2 cannot access serial ports directly).

Download and install directly: https://github.com/SeaHi-Mo/Seahi-Serial/releases (grab the latest Windows .exe installer and double-click it).

Seahi-Serial download page

How to use it: for serial usage see the “Serial Manual Test” section in each chapter; the debug serial baud rate is 1500000 and the AI module serial is 115200; the WSL mapping feature is used for serial debugging and ST-Link flashing.


FAQ & Troubleshooting ​

🔧 wsl --install says no distribution was found
Cause: The WSL kernel / components are not updated
Fix: Run wsl --update first, then retry; or use wsl --install -d Ubuntu (the latest version by default)

🔧 You didn't reboot after installing WSL
Cause: The installer requires a restart
Fix: Ubuntu only appears after you reboot the PC

🔧 Opening the Ubuntu terminal says it is not installed
Cause: The installation process was not completed
Fix: Run wsl --install -d Ubuntu-22.04 again and reboot

🔧 No WSL option in the VSCode lower-left corner / connection fails
Cause: The WSL extension is not installed, or your WSL version is old
Fix: Install Microsoft's WSL extension; confirm wsl --version reports WSL2; on older Windows 10 builds you must enable the WSL2 components manually

🔧 sudo apt update is very slow or fails
Cause: The default software source is overseas
Fix: Switch to a China-based mirror (Tsinghua / Aliyun), then run the install commands again

🔧 arm-none-eabi-gcc --version reports 9.x
Cause: Older systems such as Ubuntu 20.04 ship an outdated default version
Fix: This tutorial uses Ubuntu 22.04 (default 10.3+); on older systems you can install the xpack toolchain instead

🔧 ST-Link is not detected when flashing
Cause: WSL2 cannot access Windows USB devices directly by default
Fix: Use the Seahi-Serial installed in step ⑤ to map the ST-Link into WSL, then you can flash from inside WSL (via the Cortex-Debug GUI or the OpenOCD command line; see Build and Flash the Project)

Self-Check

In the WSL terminal, run git --version && arm-none-eabi-gcc --version && cmake --version && ninja --version && openocd --version; if all five commands print a version, the toolchain is ready. And if the lower-left corner of VSCode shows WSL: Ubuntu, the environment is connected.

Released under the MIT License. Build Time 2026-09-30 17:31:25