Skip to content
Shop

STM32 MCU: STM32CubeIDE Setup

Set up with your favorite AI

Gemini & other AI

Copy the setup prompt into your AI. Work through each step together, from checking your kit to getting it running.

Open Gemini

Copy the prompt, then paste it into Gemini’s message box.

View prompt

Use the Eclipse-based STM32CubeIDE to build a program for AP03 / STM32L452REI6, upload it using STM32CubeProgrammer, and display Hello World every second over a serial connection. For a first Arduino sketch, use the Arduino IDE or PlatformIO guide instead.

The original screenshots and workspace names use STM32CubeIDE 1.11.2. From version 2.0.0, STM32CubeMX is a separate tool: configure peripherals and generate the project there, then open it in STM32CubeIDE. See ST’s release announcement. Use the branch below that matches your tools.

  • AP03 STM32 MCU, a USB leaf, and a data-capable USB cable (swap the AVR MCU if using Basic Kit 2)
  • A computer supported by the tools below
  • STM32CubeIDE, STM32CubeMX for project generation, and STM32CubeProgrammer
  • A serial terminal such as Tera Term on Windows

Download the Eclipse-based edition from the ST product page and follow the installer for your OS. Install STM32CubeMX separately for the 2.x workflow. Use the installation requirements for the version you selected.

Install STM32CubeProgrammer for UART uploads through the USB leaf.

For Windows, obtain Tera Term from the official project. On macOS or Linux, use a serial terminal that can select the connected port and a baud rate of 115200.

You can start from the existing Hello_World project using Import a project, or generate your own project as follows.

  1. For CubeIDE 2.x: open STM32CubeMX and create a project for MCU STM32L452REI6. For the original 1.x integrated UI: choose File → New → STM32 Project, use MCU/MPU Selector, enter STM32L452REI6 in Commercial Part Number, then select the device.
  2. Name the project Hello_World and choose a local folder. With separate CubeMX, select STM32CubeIDE as the toolchain. With the original integrated wizard, the example used C++, Executable and STM32Cube.
  3. Continue with peripheral settings below. Generate the project from CubeMX or the integrated UI, then open it in STM32CubeIDE.

Configure the device and generate initialization code

Section titled “Configure the device and generate initialization code”
  1. In Pinout & Configuration, assign PA2 to USART2_TX and PA3 to USART2_RX.
  2. Open Connectivity → USART2, choose Asynchronous, disable hardware flow control, and set the baud rate to 115200.

USART2 configuration in the original guide

  1. Generate code and open the generated main.c. Locate it in the project tree; source and build-output folders serve different purposes.

Add code in the matching USER CODE blocks so you can identify it when regenerating code. Line numbers depend on the tool version and generated configuration.

Include the standard I/O header:

/* USER CODE BEGIN Includes */
#include <stdio.h>
/* USER CODE END Includes */

Before calling printf, disable output buffering:

/* USER CODE BEGIN 1 */
setbuf(stdout, NULL);
/* USER CODE END 1 */

Inside the generated main loop, print once per second:

/* USER CODE BEGIN 3 */
printf("Hello World\r\n");
HAL_Delay(1000);

Add _write to send printf output through USART2:

/* USER CODE BEGIN 4 */
int _write(int file, char *ptr, int len)
{
HAL_UART_Transmit(&huart2, (uint8_t *)ptr, len, 10);
return len;
}
/* USER CODE END 4 */

Choose Project → Build All. Fix any build errors and locate the generated Hello_World.elf in the active build output folder, commonly Debug. Use the actual filename and path from your project.

Uploading replaces the program on the MCU. See Restore the demo if you want to run the kit demo again later.

  1. Connect the USB leaf as shown in Connect to PC. Set AP03’s program switch to Program, then press Reset.
  2. Open STM32CubeProgrammer and choose UART. Select the connected port, baud rate 115200, even parity, 8 data bits, 1 stop bit and no flow control, then select Connect.
  3. In Erasing & Programming, select your generated .elf and enable Verify programming.
  4. Select Start Programming and check for Download verified successfully. A completed build alone does not confirm an upload.
  5. Disconnect STM32CubeProgrammer, return the AP03 switch to Run, then press Reset.
  1. Open the serial terminal and select the same port. Close other applications that hold the port.
  2. Set it to 115200 baud, 8 data bits, no parity, 1 stop bit and no flow control.
  3. Check that Hello World appears once per second. If it does not, check the Run switch, Reset, selected port and baud rate.
  1. Start STM32CubeIDE and choose your workspace.
  2. Use File → Open Projects from File System (the menu may also mention archives) to select the downloaded project folder, then finish importing.
  3. Open Window → Show View → Project Explorer if the project list is hidden.
  4. Build the imported project, then use the upload procedure above. If migration is requested, retain a copy of the original project and review changes before rebuilding.

For debugging instead of UART uploads, see Connecting the debugger.