on 2026-03-18 10:00 AM
This article provides a step-by-step guide on generating STM32 project code for IAR Embedded Workbench using the STM32CubeMX2 tool. It covers creating and configuring the project within STM32CubeMX2. This includes selecting the IAR toolchain, generating compatible project files, and importing them into IAR Embedded Workbench. Additionally, the article explains how to build and debug the generated project in IAR, offering practical tips to streamline your STM32 development workflow with this powerful combination.
STM32CubeMX2 is a powerful graphical tool from STMicroelectronics that simplifies the configuration and initialization of STM32 microcontrollers. It enables developers to generate initialization code based on their selected peripherals, middleware, and project settings, accelerating embedded application development.
IAR Embedded Workbench is a widely used integrated development environment (IDE) known for its highly optimizing C/C++ compiler and comprehensive debugging capabilities tailored for embedded systems. It offers robust support for STM32 microcontrollers, making it a preferred choice for many professional developers seeking efficient code generation and reliable debugging.
By combining STM32CubeMX2 with IAR Embedded Workbench, developers can benefit from the ease of graphical configuration and code generation alongside the powerful build and debug features of IAR. This article guides you through the workflow of creating STM32 projects in STM32CubeMX2, generating code compatible with IAR, and seamlessly importing, building, and debugging the project within the IAR environment.
Before starting the workflow to generate STM32 project code for IAR Embedded Workbench using STM32CubeMX2, ensure that you have the following installed and configured:
This section guides you through creating a new STM32 project using STM32CubeMX2, configuring peripherals, and preparing the project for IAR Embedded Workbench.
STM32CubeMX2 generatess the source code, header files, and essential project configuration files such as .ewp (IAR Embedded Workbench project) and .eww (workspace) files. These files are structured to be fully compatible with IAR Embedded Workbench, enabling seamless project import, build, and debug operations.
After generating your STM32CubeMX2 project with the IAR project format, follow these steps to open and configure it in IAR Embedded Workbench:
After importing and configuring your STM32CubeMX2 project in IAR Embedded Workbench, you can proceed with building your application using the integrated tools.
Add a simple LED toggle code:
Before building, for this example, let’s add a simple LED toggle implementation to verify the setup. In the user_modifiable/Application/STM32C562RET6 folder, open the main.c file and add the following code inside the while (1) loop to toggle the user LED (PA5)
while (1) {
HAL_GPIO_TogglePin(HAL_GPIOA, HAL_GPIO_PIN_5); // Toggle User LED (PA5)
HAL_Delay(500); // Delay 500ms
}
Select the Make Configuration:
Select the desired make configuration from the workspace dropdown.
Make the project:
Use the [Project] → [Make] menu option, press F7, or click the [Make] button to make the active project. This action builds all necessary files and dependencies.
Connect the debugger:
Connect your STM32 board to your PC using the STLINK or compatible debug interface. Ensure drivers and firmware are up to date.
Start debugging:
Select [Project] → [Download and Debug], press Ctrl+D, or click the [Download and Debug] button. IAR programs the device and halts at the reset vector or the first breakpoint.
Set Breakpoints:
Click in the left margin next to the code lines where you want to pause execution.
Step through code:
Use the debugging toolbar to:
View call stack:
Open the [Call Stack] view from the [View] menu to see the sequence of function calls leading to the current execution point. This helps trace program flow and debug complex call hierarchies.
Inspect variables:
Use the [Watch], [Live Watch], and [Quick Watch] views to monitor variables and expressions during execution. The [Auto], [Locals], and [Statics] views display variables in different scopes for easier inspection.
Inspect registers:
Use the [Registers] view to examine and modify CPU register values, providing insight into processor state and control.
Inspect memory:
Open the [Memory] view to inspect memory contents directly during debugging. This is useful for low-level verification and troubleshooting.
Disassembly:
The [Disassembly] view shows the assembly code corresponding to your source, aiding in low-level debugging and performance analysis.
Stack:
The [Stack] view displays the current call stack and stack usage, helping detect stack overflows or memory issues.
Fault Exception Viewer:
Use this view to analyze faults and exceptions during debugging, assisting in diagnosing critical errors.
Serial communication:
IAR does not include a full UART serial monitor.
You can use the [Terminal I/O] view for debugger/semihosting output, and an external terminal program for standard UART communication, configuring the COM port and baud rate to match your device.
RTOS Debugging (if applicable):
If your project uses FreeRTOS™ or another RTOS, IAR provides RTOS‑aware debugging features.
When RTOS awareness is enabled and you start a debug session, an additional RTOS/Tasks window becomes available (via the View menu). This window lists all active tasks and shows, in real time, their state (Running, Ready, Blocked, Suspended), priority, and stack usage. This makes it easier to understand and debug the system’s runtime behavior.
This article has provided a comprehensive guide on generating STM32 project code for IAR Embedded Workbench using STM32CubeMX2. You can create and configure a project using STM32CubeMX2. Then, you can import, compile, and debug the project in IAR. This process helps you establish an efficient and reliable development environment for STM32 microcontrollers.
Leveraging STM32CubeMX2’s intuitive configuration capabilities alongside IAR’s powerful compiler and debugging tools enables developers to accelerate embedded application development while maintaining high code quality and debugging precision.
Adopting this integrated workflow helps streamline your STM32 development process, reduce setup complexity, and enhance productivity.