Contributed by WangChong, curated by Ai-Thinker
First, the official documentation already explains how to build the Ai-WB2 series environment very clearly, so I won't repeat it here.
The link is as follows https://blog.csdn.net/Boantong_/article/details/128480919. I personally tested it and it works; please strictly follow the official steps. Also, to avoid errors, try not to pull the project yourself from Git or Gitee. Just use the Baidu Cloud link provided officially in the link above to download it.
Some friends may also own other modules, such as the Xiao An Pai, or modules based on Ai-M61 or Ai-M62. The environment for other chips is similar. When switching context between different chips, you may encounter compilation failures or errors (because you have configured development environments for multiple chips, and some tools are in the Windows system environment variables. Due to configuration priority, Windows searches from the first configured environment variable; if the corresponding command or file is found earlier, Windows won't look further down). As a result, when you make project A, the toolchain actually used may be from project B. (To complain: the chip is great, but the ecosystem is so-so; it can't integrate everything together like Keil and then provide the corresponding chip's HAL functions.)
To solve the compilation errors above, we need to switch the priority of the environment variables.
As shown below, these are the environment variables of my computer (system environment variables apply to every logged-in user, while user environment variables only apply to the user themselves).

Let's mainly look at the first five environment variables. The first three are the toolchain environment variables for Ai-M61/M62. As shown above, if I enter make in CMD now, according to Windows' file search rules, make from the M61/M62 toolchain will be called and executed. If at this time you run make on a WB2 project, make will fail!
The third and fourth entries are the WB2 toolchain configurations. So what should we do if we want to compile a WB2 project now?
Just move the fourth and fifth environment variables above the first three, and Windows will load the make command from the WB2 toolchain first. As shown below:

Ps: placeholders can also be used when configuring environment variables here, as shown below
Operation Steps
First, click New under system environment variables; use an uppercase variable name, for example JAVA_HOME. Then set the variable value to your actual directory.
The environment variable named JAVA_HOME has now been defined, but it is not being used yet. We need to add this environment variable to the system’s PATH variable.
Select PATH and click Edit.
Click New and enter the value %JAVA_HOME%. If you want to use the bin directory under JAVA_HOME, just enter %JAVA_HOME%\bin%, and so on.
This way we can register the defined environment variable name into the system environment variables, avoiding the situation where a very long variable appears in the system environment variables and you don’t know where it belongs.
Note: after setting the environment variables, if you have any open terminals, close and reopen them so that the newly set environment variables are loaded properly. If any big shot could write a script to automate the environment switching above, that would be great.
Have questions?
For other questions, please visit the unified discussion area: Ai-Thinker Discussions

