STM32

STM32 — Windows Setup

Install STM32CubeIDE on Windows — the official all-in-one IDE from STMicroelectronics. Everything you need (compiler, debugger, peripheral configurator) is bundled in one installer.


Prerequisites

  • Windows 10 or 11 (64-bit)
  • At least 4 GB of free disk space (8 GB recommended)
  • A free account on st.com (required to download the installer)
  • Administrator privileges for installation

Step 1 — Download STM32CubeIDE

  1. Go to st.com/en/development-tools/stm32cubeide.html
  2. Scroll down and click "Get Software"
  3. If prompted, log in with your ST account (free registration)
  4. Under "STM32CubeIDE-Win", click Download
  5. Run the downloaded .exe installer

Step 2 — Run the Installer

  1. Double-click the downloaded st-stm32cubeide-*.exe
  2. Accept the license agreement
  3. Choose installation path (default C:\ST\STM32CubeIDE_1.xx.x is fine)
  4. Select components to install:
    • ✅ STM32CubeIDE (required)
    • ✅ ST-LINK server (required for debugging)
    • ✅ SEGGER J-Link (optional — only if you have a J-Link probe)
  5. Click Install

Installation takes 5–15 minutes

STM32CubeIDE is a large download (>1 GB). The actual installation after download takes another 5–10 minutes. Do not close the installer window.


The installer should install ST-LINK USB drivers automatically. Verify by connecting your NUCLEO or ST-LINK to USB:

  1. Open Device Manager (Win + X → Device Manager)
  2. Expand Universal Serial Bus devices
  3. You should see "STMicroelectronics STLink Virtual COM Port" and "STM32 STLink"

If not listed, manually install drivers:

  1. Open STM32CubeIDE → Help → ST-LINK Upgrade
  2. Or download STSW-LINK009 from st.com directly

Step 4 — Launch STM32CubeIDE

  1. Open STM32CubeIDE from the Start Menu
  2. On first launch, select a workspace directory (where your projects will be stored)
    • Example: C:\Users\<you>\STM32CubeIDE\workspace
  3. Click Launch

Step 5 — Create Your First Project (NUCLEO Board)

Let's create a simple LED blink project using the HAL library.

5.1 — New STM32 Project

  1. Go to File → New → STM32 Project
  2. In the Board Selector tab:
    • Search for your board (e.g., NUCLEO-F446RE)
    • Select it from the list
    • Click Next
  3. Set Project Name: hello_blink
  4. Select Targeted Language: C
  5. Click Finish

STM32CubeMX will open with your board's pin configuration pre-set.

5.2 — Configure the LED Pin (CubeMX)

For NUCLEO-F446RE, the onboard LED is on PA5 (already configured as GPIO_Output by default).

Click Generate Code (the gear icon or Project → Generate Code) to create the HAL-based project.

Open Core/Src/main.c. Inside the while(1) loop in main(), add:

c
1/* USER CODE BEGIN WHILE */
2while (1)
3{
4 HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5); // Toggle the LED on PA5
5 HAL_Delay(500); // Wait 500ms
6 /* USER CODE END WHILE */
7
8 /* USER CODE BEGIN 3 */
9}
10/* USER CODE END 3 */

Always write code inside USER CODE sections

STM32CubeMX regenerates code when you modify pin/clock settings. Any code outside the /* USER CODE BEGIN */ ... /* USER CODE END */ blocks will be deleted on regeneration.

5.4 — Build the Project

Press Ctrl+B or go to Project → Build All.

Expected output in the Console:

text
Finished building: hello_blink.elf

5.5 — Flash and Debug

  1. Connect your NUCLEO board via USB
  2. Click the Debug button (bug icon) or press F11
  3. STM32CubeIDE will flash the binary and halt at main()
  4. Press F8 (Resume) to run the program
  5. The LED on your NUCLEO board should blink at 1 Hz!

To stop debugging: Press Ctrl+F2 or click the red stop button.


Step 6 — Serial Output (Optional)

To print debug messages over UART:

  1. In CubeMX, enable USART2 (on PA2/PA3 — connected to ST-LINK on NUCLEO boards)
  2. Regenerate code
  3. Add printf redirect by adding to main.c:
c
1// Redirect printf to USART2
2int _write(int file, char *ptr, int len)
3{
4 HAL_UART_Transmit(&huart2, (uint8_t *)ptr, len, HAL_MAX_DELAY);
5 return len;
6}

Now open Window → Show View → Console and use the serial terminal at 115200 baud.


Troubleshooting

ST-LINK not detected

  • Check Device Manager for the ST-LINK entry
  • Try unplugging and replugging the USB cable
  • Use the shorter CN1 USB port on NUCLEO boards (not the Arduino shield connectors)
  • Run Help → ST-LINK Upgrade inside STM32CubeIDE

No source available for "main()" during debug

This means the binary was flashed but source mapping is wrong. Make sure you built in Debug configuration, not Release.

Workspace locked error on startup

Another instance of CubeIDE may be running. Close all instances and relaunch.


Next Steps

Previous
Introduction to STM32