DEV Community

Hedy
Hedy

Posted on

How do I use STM32CubeIDE to flash and debug firmware?

Here’s a step-by-step guide on how to flash and debug firmware using STM32CubeIDE, the official development environment for STM32 microcontrollers by STMicroelectronics.

Image description

1. Install STM32CubeIDE

  • Download from STMicroelectronics' website
  • Install the IDE and any required drivers (e.g., ST-LINK USB driver)

2. Create or Import a Project
You can either:

Create a new project

  • File > New > STM32 Project
  • Select your STM32 MCU or board (e.g., STM32F103C8T6 or Nucleo-F401RE)
  • Configure peripherals using STM32CubeMX interface inside the IDE

Import existing project
File > Import > Existing Projects into Workspace

3. Configure Debugger & Flash Settings
Connect your board via ST-LINK, J-Link, or other debugger

In the project explorer, right-click project > Properties > Run/Debug Settings

Make sure:

  • Debugger: ST-LINK (or your tool)
  • Interface: SWD or JTAG
  • Reset mode: Software System Reset (default)

4. Build the Project

  • Click the hammer icon or use Project > Build Project
  • This compiles your code and generates a .elf binary

5. Flash the Firmware
Click the green “Run” button ▶️ or use:

mathematica

Run > Run As > STM32 Cortex-M C/C++ Application
Enter fullscreen mode Exit fullscreen mode

The firmware is flashed via ST-LINK (or your configured debugger)

6. Debug Your Firmware
Click the bug icon or use:

mathematica

Run > Debug As > STM32 Cortex-M C/C++ Application
Enter fullscreen mode Exit fullscreen mode

The IDE will:

  • Flash the firmware
  • Switch to Debug Perspective
  • Halt at main() by default

You can now:

  • Step through code (F5 = Step Into, F6 = Step Over)
  • Set breakpoints
  • Watch variables
  • View registers and memory

7. Stop Debugging / Restart

  • Use the terminate (red square) button to stop debugging
  • You can reflash or restart the MCU without reloading the IDE

Summary Table

Image description

Top comments (0)