Close-up of colorful programming code on a computer screen, showcasing digital technology.

STM32 Tutorials #2: Setting Up the Development Environment

Whether you’re a professional developer or an embedded hobbyist, STM32 microcontrollers offer immense flexibility, power efficiency, and ecosystem support. Before diving into firmware development, setting up your STM32 development environment correctly is critical. This blog focuses only on setting up the environment, not project creation. We’ll discuss IDEs, drivers, tools, OS-specific settings, and useful optional additions.

βœ… What You’ll Set Up:

STM32CubeIDEMain integrated development environment
ST-Link DriversInterface for debugging and flashing firmware
STM32CubeMXMCU configuration GUI (comes integrated with STM32CubeIDE)
GNU ARM ToolchainCompiles your C/C++ code to ARM binaries
USB/UART DriversInterface for serial communication (e.g., CH340, CP210x)
Optional: OpenOCD, PlatformIO, or CLI-based developmentFor advanced/alternative workflows

πŸ’» Supported Operating Systems:

  • Windows 10/11 (64-bit)
  • Ubuntu/Linux (18.04+ recommended)
  • macOS (Catalina and later)

🧱 1. Install STM32CubeIDE (Official IDE)

STM32CubeIDE is ST’s official IDE built on Eclipse and includes:

  • STM32CubeMX (graphical config tool)
  • GCC-based toolchain
  • Integrated ST-Link debugging
  • Peripheral code generator

πŸ”— Download:

πŸ‘‰ https://www.st.com/en/development-tools/stm32cubeide.html

πŸ“¦ Installation Steps:

Windows:

  1. Download .exe the installer.
  2. Run the installer with Administrator privileges.
  3. It automatically installs STM32CubeMX and ST-Link USB drivers.
  4. On first run, it may prompt for updatesβ€”accept them.

🐧 Linux (Ubuntu):

sudo apt update
sudo apt install libusb-1.0-0
chmod +x en.st-stm32cubeide_*.sh
./en.st-stm32cubeide_*.sh

Creates shortcut in applications menu.

If not, run manually:

/opt/st/stm32cubeide/stm32cubeide

🍏 macOS:

  1. Download .dmg file.
  2. Drag and drop STM32CubeIDE to Applications.
  3. macOS may block it initially. Go to System Preferences > Security & Privacy > Allow Anyway.

πŸ”Œ 2. Install ST-Link USB Drivers

ST-Link is the USB-to-debug interface built into most STM32 development boards (Nucleo, Discovery, etc.).

πŸͺŸ Windows:

  • Comes bundled with STM32CubeIDE.
  • If needed separately:
    πŸ‘‰ STSW-LINK009

🐧 Linux:

Create a udev rule:

sudo nano /etc/udev/rules.d/49-stlinkv2.rules

Paste:

SUBSYSTEM=="usb", ATTR{idVendor}=="0483", ATTR{idProduct}=="3748", MODE="0666", GROUP="plugdev"

Then:

sudo udevadm control --reload-rules
sudo udevadm trigger

πŸ” Verify:

Connect board β†’ run:

lsusb

You should see something like: Bus 001 Device 005: ID 0483:3748 STMicroelectronics ST-LINK/V2

πŸ”— 3. Install GNU ARM Toolchain (If Working Outside CubeIDE)

If you use Makefiles or CMake or want lightweight development, install this separately.

🧰 Toolchain:

πŸ‘‰ https://developer.arm.com/downloads/-/gnu-rm

Windows:

  • Add the bin/ folder (e.g., C:\Program Files (x86)\GNU Arm Embedded Toolchain\X.X\bin) to your PATH.

Linux/macOS:

sudo tar -xjf gcc-arm-none-eabi-*.tar.bz2 -C /opt
echo 'export PATH=$PATH:/opt/gcc-arm-none-eabi-X/bin' >> ~/.bashrc
source ~/.bashrc

πŸ” Verify:

arm-none-eabi-gcc --version

πŸ§ͺ 4. Install USB to UART Drivers (Optional but Useful)

Some STM32 boards (especially Blue Pill) use USB-to-Serial ICs for UART output/debugging.

Common Drivers:

Verify on Linux:

dmesg | grep tty

Linux alternative:

st-info --probe  # from stlink utilities

🧩 6. Optional Tools for Advanced Users

STM32CubeProgrammerFlash/debug STM32 without IDE
OpenOCDOpen-source debugger interface
stlink CLI toolsLightweight debug/flash tools
PlatformIO (VS Code)Cross-platform embedded development

🧰 STM32CubeProgrammer:

πŸ‘‰ https://www.st.com/en/development-tools/stm32cubeprog.html

🧰 stlink-tools (Linux CLI):

sudo apt install stlink-tools
st-info --probe
st-flash write my_firmware.bin 0x8000000

🧰 PlatformIO:

pip install platformio
platformio init --board nucleo_f103rb
platformio run
platformio run --target upload

πŸ“‚ Suggested Folder Layout for Bare-Metal Projects

project-root/
β”‚
β”œβ”€β”€ Makefile or CMakeLists.txt
β”œβ”€β”€ src/
β”‚   └── main.c
β”œβ”€β”€ inc/
β”‚   └── main.h
β”œβ”€β”€ startup/
β”‚   └── startup_stm32f103xb.s
β”œβ”€β”€ linker/
β”‚   └── stm32f103xb.ld
β”œβ”€β”€ drivers/
β”‚   └── hal/
β”‚   └── cmsis/
└── build/

With this setup complete, your machine is now STM32-ready. You can use STM32CubeIDE, VS Code + PlatformIO, or makefile-based development environments depending on your comfort level.