Overview
Windows users develop Ai-WB2 with the officially supported (the SDK ships a Windows toolchain) MSYS2 solution: install one MSYS2 terminal (so Windows can run Linux-style make commands), then clone the SDK, build, and flash inside it — no virtual machine needed. This tutorial follows the complete workflow (install MSYS2 → clone SDK → configure environment variables → build → flash) and walks you through your first program using the official helloworld example.
In plain words: Windows' built-in command prompt can't do the "compiling" job; MSYS2 is like installing a "mini Linux command line" inside Windows — the SDK's build commands only run in this environment. After this tutorial, your Windows computer has full development capability, and all later tutorials are "cooking by the recipe".
This tutorial is based on the official Ai-Thinker SDK (Ai-Thinker-Open/Ai-Thinker-WB2, version
release_bl_iot_sdk_1.6.40). The SDK's own Windows toolchain lives undertoolchain/riscv/MSYS/(MSYS = Linux emulation environment on Windows); this tutorial is the officially supported Windows development solution.
Open the MSYS2 website (https://www.msys2.org/) in a browser, download the installer (file name like msys2-x86_64-*.exe), double-click and click “Next” all the way through; keeping the default install directory is recommended (e.g. C:\msys64).
After installation, open MSYS2 MINGW64 from the Start menu (the one with MINGW64 in its name, not MSYS2 MSYS) — a black terminal window appears, meaning success.
Note: MSYS2 is a “Linux-style command line environment” on Windows; the SDK’s build commands (
make) must run inside this terminal. Running them in the ordinary Command Prompt (cmd) reports'make' is not recognized as an internal or external command.
Then install the two packages needed for building (run inside the MSYS2 terminal):
pacman -S git make
Note:
pacmanis MSYS2’s built-in software install command,-Smeans install;git(fetching code) andmake(the build command) are required by the official solution. Press Enter to confirm when you seeProceed with installation? [Y/n]. If downloads are slow on a domestic network, search for “MSYS2 change to Tsinghua mirror” guides to speed up.
Run inside the MSYS2 terminal (--recursive is required to fetch submodules):
git clone --recursive https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2.git
Note:
git cloneis the “download repository” command. ⚠️ Always clone with thegit clonecommand — never manually download the Zip archive from the GitHub page: the SDK’stoolchain/directory is an empty directory (populated by git submodule mechanism); unzipping manually leaves the toolchain missing and the later build will definitely fail. If GitHub is slow or fails on a domestic network, use the official Gitee mirror instead — content is identical:
git clone --recursive https://gitee.com/Ai-Thinker-Open/Ai-Thinker-WB2.git
After the download finishes (progress bar completes, prompt returns), confirm the directory exists:
ls ~/Ai-Thinker-WB2
Seeing directories like applications, components, toolchain means the clone succeeded.
💡 In MSYS2,
~maps to your Windows user directory (C:\Users\your-username\). All later tutorials usecd ~/Ai-Thinker-WB2/applications/...based on this location.
This step lets the system find the compiler in the toolchain. Open Windows Settings → System → About → Advanced system settings → Environment Variables, then in “User variables” do two steps:
Step 1: click “New”, variable name MSYS2_PATH_TYPE, variable value inherit (so MSYS2 inherits Windows environment variables; otherwise the flash script can’t find the serial port).
Step 2: select the Path variable → click “Edit” → “New”, and add these two lines (adjust paths to your actual install location):
C:\msys64\usr\bin
C:\Users\your-username\Ai-Thinker-WB2\toolchain\riscv\MSYS\bin
Note: the first line is MSYS2’s common command directory (so
git/makealso work in the ordinary command line); the second is the SDK’s Windows toolchain directory (containingriscv64-unknown-elf-gcc.exeand other compilers, officially packaged for Windows). Add both lines — missing either one causes “command not found” later.
After adding, restart the MSYS2 terminal (close and reopen) so the new environment variables take effect.
Enter the official getting-started example project in the (restarted) MSYS2 terminal and build:
cd ~/Ai-Thinker-WB2/applications/get-started/helloworld
make -j8
Note:
makeis the “build” command (turning C code into firmware the board can run);-j8builds with 8 parallel tasks for speed. It must run inside the helloworld project directory (entered with thecdabove). The first build takes a few minutes (it compiles the entire SDK components); subsequent incremental builds are fast.
On success a firmware build_out/helloworld.bin is generated, and you’ll see:
✓ Built target helloworld
Seeing this line means the build succeeded.
⚠️ If you get
make: command not foundorriscv64-unknown-elf-gcc: No such file or directory, the environment variables from step ③ aren’t set correctly or the terminal wasn’t restarted — check the paths and retry.
Connect the board with a Type-C data cable, then confirm the COM port: open Windows Device Manager (right-click the Start menu → Device Manager), expand “Ports (COM & LPT)”, find an entry like USB-SERIAL CH340 (COM3), and note the COM number in parentheses (e.g. COM3).
Note: if no serial device appears in Device Manager, the cable only charges and can’t transfer data, or the USB-to-serial driver isn’t installed (the Ai-WB2 board commonly uses the CH340 chip — drivers are available from the chip vendor’s site or Driver Booster); try another cable / install the driver and retry.
Then flash in the MSYS2 terminal (p= is your COM number):
make flash p=COM3 b=921600
Note:
p=is the COM port (Windows usesCOMplus a number, unlike Linux’s/dev/ttyUSB0format);b=is the flash baud rate (transfer speed), officially fixed at921600.
When you see a prompt like Waiting for download..., press and hold the EN button (RST reset button) on the board for about 1 second then release — the board enters download mode and the progress bar starts moving.
⏳ A progress bar reaching 100% with a completion message means success. If it keeps waiting, the EN button probably wasn’t pressed right — try pressing it again.
After flashing, the board automatically restarts and runs the program. There are many serial tools; here we recommend installing screen right inside MSYS2 (same as the Linux tutorial):
pacman -S screen
Note:
screenis a serial viewing tool; after installing, open the serial port with it in the MSYS2 terminal to watch the output.
screen /dev/ttyS2 921600
Note: watch out for the port name change — Windows’
COM3is written as/dev/ttyS2in MSYS2 (COMbecomes/dev/ttyS, and the number minus 1: COM1 → /dev/ttyS0, COM2 → /dev/ttyS1, COM3 → /dev/ttyS2… This is the easiest trap to fall into; if unsure, runls /dev/ttyS*first to see the actual device names).921600is the baud rate — it must match the one used for flashing, otherwise you’ll see garbled text.
The screen keeps printing boot logs; focus on these lines:
Hello World.
Restarting in 10 seconds...
Restarting in 9 seconds...
Seeing Hello World. and the countdown means your board is running — your first program is a success!
💡 The official example counts down 10 seconds and then automatically restarts the board (effectively testing soft reset) — this is normal. To exit screen after viewing, press
Ctrl + AthenK(pressyto confirm when prompted).
Commands Used in This Tutorial
pacman -S(package-name)
MSYS2's software install command (used here to install git, make, and screen).
Parameters:
- package-name: space-separated package names, e.g.
git make
Return: success when the prompt returns after installation; press Enter to confirm Proceed? [Y/n]
git clone --recursive(repository-url)
Downloads the SDK repository and all submodules to the current directory (Gitee mirror recommended on domestic networks).
Parameters:
--recursive: recursively fetch submodules; required (otherwise the toolchain directory is empty)- repository-url:
https://github.com/Ai-Thinker-Open/Ai-Thinker-WB2.gitor the Gitee mirror
Return: success when the progress bar completes and the prompt returns
make -j8
Builds the firmware inside the example project directory (-j8 parallel build is faster).
Parameters:
-j8: number of parallel cores; can be changed to-j4/-j16etc.
Return: ✓ Built target xxx means success; on errors fix as suggested and retry
make flash(p=com-port b=baud-rate)
Flashes the firmware into the board (Windows COM port format is COMx; press the EN button on the board to enter download mode when flashing).
Parameters:
p=: COM port, e.g.COM3(see it under Device Manager "Ports (COM & LPT)")b=: baud rate, officially fixed at921600
Return: progress bar reaching 100% means success; if it keeps waiting, the board didn't enter download mode
screen(/dev/ttySx baud-rate)
Opens the serial port to view the board's runtime logs (in MSYS2 the port is written as /dev/ttyS + "COM number minus 1", e.g. COM3 → /dev/ttyS2).
Parameters:
- serial-device:
/dev/ttyS+ "COM number minus 1", e.g./dev/ttyS2(confirm withls /dev/ttyS*) - baud-rate: must match flashing,
921600
Return: logs scroll in real time; press Ctrl + A then K to exit
Full Code (Reference: helloworld/main.c)
Below is the official helloworld example source, identical to the official (applications/get-started/helloworld/helloworld/main.c). It prints Hello World. then counts down 10 seconds and restarts the board automatically — it's the "health check program" that verifies your environment is set up:
📜 Click to expand the full helloworld/main.c code
/*
* @Author: xuhongv@yeah.net xuhongv@yeah.net
* @Date: 2022-10-03 15:02:19
* @LastEditors: xuhongv@yeah.net xuhongv@yeah.net
* @LastEditTime: 2022-10-08 14:55:16
* @FilePath: \bl_iot_sdk_for_aithinker\applications\get-started\helloworld\helloworld\main.c
* @Description: Hello world
*/
#include <stdio.h>
#include <string.h>
#include <FreeRTOS.h>
#include <task.h>
#include <blog.h>
#include "bl_sys.h"
void main(void)
{
printf("Hello World.\r\n");
for (int i = 10; i >= 0; i--)
{
printf("Restarting in %d seconds...\r\n", i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
printf("Restarting now.\r\n");
bl_sys_reset_por();
}FAQ & Troubleshooting
⚠️ The Start menu shows several MSYS2 entries — which one do I click?
Cause: MSYS2 creates multiple terminal shortcuts after installation (MSYS2 MSYS / MINGW64 / MINGW32 / UCRT64)
Fix: choose MSYS2 MINGW64 (a must for 64-bit Windows); run all subsequent commands in this one terminal
⚠️ Downloaded the GitHub Zip manually; the build reports the toolchain is missing
Cause: the Zip downloaded from the web page doesn't contain the toolchain/ directory (it's a git submodule, only fetched by git clone)
Fix: delete the directory and re-clone with git clone --recursive (use the Gitee mirror if GitHub is slow)
⚠️ Build reports make: command not found or gcc: No such file or directory
Cause: the environment variables from step ③ aren't set correctly, or the MSYS2 terminal wasn't restarted after setting them
Fix: check the two Path entries (C:\msys64\usr\bin and ...\Ai-Thinker-WB2\toolchain\riscv\MSYS\bin); after setting them close the terminal and reopen before retrying
⚠️ No serial (COM) port in Device Manager
Cause: the cable only charges and can't transfer data, or the USB-to-serial driver is missing
Fix: try a Type-C cable that can transfer data; the Ai-WB2 board commonly uses the CH340 chip — download and install the CH340 driver from the chip vendor's site (or Driver Booster), then reboot
⚠️ Flashing keeps Waiting for download / the progress bar doesn't move
Cause: the EN button wasn't pressed to enter download mode, or the COM port is wrong
Fix: when the waiting prompt appears, press and hold EN (RST) for about 1 second then release; confirm p= matches the COM port shown in Device Manager (note that MSYS2 writes the port as /dev/ttyS3, but the flash parameter p= still uses the COM3 format)
⚠️ screen reports can't open /dev/ttyS3 (or opens with no response)
Cause: the COM number was copied directly into the device name — in MSYS2 the serial device name is "COM number minus 1"
Fix: COM3 corresponds to /dev/ttyS2 (COM1 → ttyS0, COM2 → ttyS1, COM3 → ttyS2); if unsure, run ls /dev/ttyS* in the terminal to see the actual listed device names
⚠️ Opening the serial port shows garbled text
Cause: baud rate mismatch (defaults like 115200 are wrong)
Fix: the baud rate for opening the serial port must match flashing — use 921600
Self-Check
After flashing, seeing Hello World. and the Restarting in 10 seconds... countdown on the serial port means the Windows environment is verified — you can start GPIO Output (Blink LED).

