Linux MDK6 Environment Setup Tutorial
(本教程为2024年1月创建的,可能与以后的版本有些出入)
Software to prepare
- CubeMX latest version
- The latest version of VScode
- vcpkg package management tool
- pyOcd (see tutorial below for installation instructions)
- ST-Link driver (see tutorial below for installation instructions)
vcpkg Installation and Environment Setup
- Download the dependency packages
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential tar curl zip unzip
sudo apt-get install default-jre
- Clone the vcpkg repository
https://github.com/microsoft/vcpkg/tree/master
git clone https://github.com/microsoft/vcpkg.git
- Generate the vcpkg program.
cd vcpkg
sudo chmod a+x ./bootstrap-vcpkg.sh
sudo ./bootstrap-vcpkg.sh
- Set up the environment
vim ~/.bashrc

This VCPKG_HOME is the directory of vcpkg.
#配置vcpkg环境
export VCPKG_HOME=/home/tungchiahui/user/applications/vcpkg #目录需要改为你的vcpkg的目录
export PATH=$VCPKG_HOME:$PATH

source ~/.bashrc
vcpkg --version
If the prompt shown in the image appears, the installation was successful!

MDK5 Project Generation and ARMCLANG (AC6) Compiler Configuration
Project Generation and Compiler Configuration
- Method 1: The compiler configuration tutorial needs to be done on Windows, as it is currently difficult to modify compiler options on Linux. You can refer to the Windows tutorial below for generating the project and configuring the default compiler. (Essentially, this means changing the compiler from the default AC5 to AC6.)
- Method 2: Clone a pre-generated template (currently only a few common models are available).
Repository link:
https://github.com/TungChiahuiMCURepos/CubeMX\_CMake\_Template
git clone https://github.com/TungChiahuiMCURepos/CubeMX_CMake_Template.git


Project configuration (e.g., initializing a GPIO pin and creating a task to toggle its level)
First, make a copy of the project template.

Rename the project

Open CubeMX (and click File -> Load Project at the top, or directly click the icon shown in the image below).

Find the project and load it, then configure the project.



Open a terminal in the MDK-ARM folder.
cd MDK-ARM
code .
Install and activate the MDK6 plugin.
Download the ARM Keil Studio Pack.

Activate the MDK6 plugin


First-time conversion of an MDK5 project and downloading dependency packages.

In the bottom right corner, install all the packages that need to be installed, and allow any prompts that appear.
When installing Packs, you need to ensure a good network environment (one with internet access to bypass restrictions).
This stage will last 5–20 minutes, so please wait patiently. (Depends on the speed of your proxy service.)
(These operations are only needed for the first run)

This survey can be skipped.

As shown in the figure, the installation was successful.

If the environment below is already configured, right-click on uvprojx and select Convert.


If the environment is not configured properly, right-click this file and select active environment (in the image, since my environment is already configured, it shows deactivate).
Then execute the Convert step from the previous step.

As shown in the figure, initialization has been successful.

Compile
Clicking the build button and finding the file size is the same means the compilation was successful.
If compilation fails, check whether the project file list has an extra dot configured. (Refer to the advanced tutorial below on adding source files to resolve this.)


How to configure debuggers like ST-Link on Linux?
Install pyOCD (Linux)
https://github.com/pyocd/pyOCD
First, open the terminal and enter (if you are using a Debian-based system, such as Ubuntu, please refer to the tutorial below).
sudo apt install python3-pip
python3 -mpip install -U pyocd
# 如果上面的不行,则输入下方的
pip3 install -U pyocd
If it still doesn't work, and the prompt says
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
then use (a Debian-based system)
sudo apt install python3-pyocd
Or simply clone the repository.
git clone https://github.com/pyocd/pyOCD.git
cd pyOCD
pip3 install .
You can also install pyOCD this way.
Next, we need to install the driver for the ST-Link debugger and similar tools.
pyOCD Debugger Driver Installation Official Tutorial
https://github.com/pyocd/pyOCD/tree/main/udev
You still need to use the files from the pyOCD repository.
If you haven't cloned the repository yet, please do so as soon as possible.
In the repository directory, enter the following command:
cd udev
sudo cp *.rules /etc/udev/rules.d
#重启udev
sudo udevadm control --reload
sudo udevadm trigger
Now the ST-Link can be detected normally.

If it is not detected, please unplug and re-plug the ST-Link, then click Add Device to add the device.

Update the latest ST-Link driver (Linux)
https://www.st.com/en/development-tools/stsw-link007.html#get-software
Unable to display this content outside of Feishu documents for now.

After downloading, extract the files.

sudo apt install ./st-stlink-udev-rules-1.0.3-2-linux-all.deb
Simply restart VSCode.
(Scroll down for more related tutorial operations below.)