STM32CubeIDE Tutorial: Setup, Code, and Debugging Explained
Learn STM32CubeIDE step by step. Setup guide, code generation, and debugging explained with beginner-friendly examples for STM32 microcontrollers.

Many beginners who start with STM32 microcontrollers feel lost when they first open STM32CubeIDE. The interface seems complex, the project setup looks tricky, and debugging often fails with cryptic errors. This can make learning STM32 programming frustrating. The truth is, STM32CubeIDE is a powerful tool, and once you understand its workflow, coding and debugging STM32 projects becomes simple.

This STM32CubeIDE tutorial explains everything step by step. You’ll learn how to install CubeIDE, set up your first project, write code, configure peripherals, and debug with ease. By the end, you’ll be ready to build real projects on STM32.

What is STM32CubeIDE?

STM32CubeIDE is the official integrated development environment (IDE) provided by STMicroelectronics. It combines three powerful tools in one package:

  • Eclipse-based IDE – for writing, compiling, and debugging code.

  • STM32CubeMX – for graphical configuration of pins and peripherals.

  • Debugger support – with ST-Link and other debuggers.

With STM32CubeIDE, you don’t need separate tools for configuration, coding, and debugging — everything is in one place.


Installing STM32CubeIDE

Step 1: Download

Go to the official STMicroelectronics website and download the latest version of STM32CubeIDE for your operating system (Windows, Linux, or macOS).

Step 2: Install

Run the installer and follow the setup wizard. Make sure to install additional drivers if prompted, especially for ST-Link programmers.

Step 3: Launch

After installation, open STM32CubeIDE. On first launch, it will ask you to select a workspace folder where all your projects will be stored.


Creating Your First STM32 Project

Step 1: Start a New Project

  • Click File → New → STM32 Project.

  • Select your microcontroller or development board (for example, STM32F103C8T6 or Nucleo-F401RE).

Step 2: Configure Pins

STM32CubeIDE includes CubeMX, so you can set up pins using a graphical interface:

  • Choose GPIO pins for LEDs or buttons.

  • Enable peripherals like UART, ADC, or I2C.

  • Save and generate initialization code.

Step 3: Project Structure

CubeIDE generates code with the HAL (Hardware Abstraction Layer) libraries. The main file is main.c, where you add your application code.


Writing Your First Code in STM32CubeIDE

LED Blink Example

  1. Configure an LED pin as GPIO Output in CubeIDE.

  2. Generate code.

  3. Add this loop to main.c:

 
while (1) { HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13); HAL_Delay(500); }

This code toggles the LED every 500 ms.


Adding UART in STM32CubeIDE

UART is commonly used for debugging and communication.

  1. In CubeIDE, enable USART2.

  2. Set TX and RX pins.

  3. Generate code.

  4. Add this in main.c:

 
char msg[] = "Hello from STM32CubeIDE!\r\n"; HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);

Now, open a serial terminal at 115200 baud rate to see the output.


Using ADC in STM32CubeIDE

ADC lets you read analog values from sensors.

  1. Enable ADC1 Channel in CubeIDE.

  2. Generate code.

  3. Add this in main.c:

 
uint32_t adcValue; HAL_ADC_Start(&hadc1); HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY); adcValue = HAL_ADC_GetValue(&hadc1);

This reads the voltage level and stores it in adcValue.


Debugging in STM32CubeIDE

One of the most powerful features of CubeIDE is debugging.

Hardware Requirements

  • ST-Link V2 debugger (or onboard debugger in Nucleo boards).

  • USB cable for connection.

Debugging Steps

  1. Connect STM32 board to PC.

  2. Click the Debug icon in CubeIDE.

  3. The program will flash to the microcontroller.

  4. The IDE switches to Debug mode, where you can:

    • Set breakpoints.

    • Step through code line by line.

    • Watch variables in real time.

    • Inspect memory and registers.

This makes troubleshooting much easier than using only printf statements.


STM32CubeIDE Features You Should Know

  • Project Manager – for organizing files and settings.

  • Code Auto-completion – speeds up programming.

  • Peripheral Configuration – graphical setup instead of manual register editing.

  • RTOS Support – CubeIDE supports FreeRTOS configuration directly.

  • Integrated Debugging – no need for third-party debuggers.

Common Errors in STM32CubeIDE and Fixes

  • Project Won’t Compile: Make sure CubeIDE generated HAL files correctly.

  • ST-Link Not Found: Install drivers and check USB connection.

  • Baud Rate Errors in UART: Match baud rates in both STM32 and terminal software.

  • Debugging Stops Unexpectedly: Check if code runs into HardFault. Use breakpoints to locate the issue.

STM32CubeIDE vs Arduino IDE

Many beginners compare STM32CubeIDE with Arduino IDE.

  • Arduino IDE: Easier for small projects, less setup.

  • STM32CubeIDE: More powerful, full control of hardware, professional debugging tools.

If your goal is real-world embedded projects, STM32CubeIDE is the better choice.

Who Should Learn STM32CubeIDE?

  • Students learning embedded programming.

  • Hobbyists building STM32-based projects.

  • Engineers designing industrial systems.

  • Arduino users moving to advanced hardware.

Pros and Cons of STM32CubeIDE

Pros

  • Free official IDE.

  • Complete workflow (config, code, debug).

  • HAL libraries make development easier.

  • Supports advanced debugging.

Cons

  • Learning curve for beginners.

  • Large software size (~1 GB).

FAQ on STM32CubeIDE

What is STM32CubeIDE used for?
It is used for configuring, coding, and debugging STM32 microcontrollers.

Is STM32CubeIDE free?
Yes, it is free to download from STMicroelectronics.

Can I use STM32CubeIDE on Windows and Linux?
Yes, it works on Windows, Linux, and macOS.

What programming language is used in STM32CubeIDE?
You mainly use C and sometimes C++.

Does STM32CubeIDE support debugging?
Yes, with ST-Link or onboard debuggers.

Can I use STM32CubeIDE for RTOS projects?
Yes, FreeRTOS can be configured within CubeIDE.

Which boards are supported by STM32CubeIDE?
Almost all STM32 microcontrollers and official development boards.

Can STM32CubeIDE be used instead of Arduino IDE?
Yes, it gives more control and advanced features than Arduino IDE.

How do I add UART in STM32CubeIDE?
Enable USART in CubeMX, generate code, and use HAL UART functions.

Does STM32CubeIDE replace CubeMX?
Yes, CubeMX is integrated into CubeIDE.

Conclusion

This STM32CubeIDE tutorial explained setup, code generation, and debugging with simple examples. By now, you should know how to create a new project, configure peripherals, write code, and debug it effectively. STM32CubeIDE may look complex at first, but once you practice, it becomes a powerful tool for embedded projects.

 

If you want more tutorials and STM32 projects with code, check ControllersTech for detailed step-by-step guides.

disclaimer

What's your reaction?