STM32CubeIDE Guide - CSULB-EATS/micromouse_template GitHub Wiki

STM32CubeIDE Module

Overview

This module covers how to configure and program your STM32 microcontroller using STM32CubeIDE.
By the end, you’ll be able to set up a project, configure pins, generate code, and upload firmware to your Nucleo board.


Requirements

  • STM32CubeIDE (download from STMicroelectronics)
  • STM32 Nucleo-F411RE development board
  • ST-Link USB cable for programming

Step 1: Install and Launch

  1. Install CubeIDE and open it.
  2. Create a new STM32 project → “Board Selector” tab.
  3. Search for Nucleo-F411RE and click Next.
  4. Give your project a name (e.g., Micromouse_Main) → Finish.
  5. When asked to open CubeMX configuration view, click Yes.

Step 2: Configure Pins

You’ll see a graphical pinout of the STM32F411RE MCU.

  • PC13 → User Button (set as GPIO_EXTI13)
  • PA5 → User LED (set as GPIO_Output)
  • Configure all other pins for motors, encoders, and IR sensors based on your schematic.

After setting pins:

  1. Click Project > Generate Code (gear icon).
  2. CubeIDE will create startup files and a default main.c template.

Step 3: Write Your First Program

Example: Button → LED Toggle

#include "main.h"

int main(void) {
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();

  while (1) {
    if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == GPIO_PIN_RESET) {
        HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
        HAL_Delay(100);
    }
  }
}

Explanation:

  • Reads the user button on PC13.
  • Toggles onboard LED (PA5) when button is pressed.

Step 4: Build and Upload

  1. Click Build Project (hammer icon) to compile.
  2. Connect your Nucleo board via USB.
  3. Click Run > Debug As > STM32 MCU C/C++ Application.
  4. Wait for flashing to complete. The LED should now toggle on button press.

Optional Setup Tips

  • Use “Live Expressions” under the Debug tab to monitor variables in real time.
  • Save your .ioc file — it regenerates hardware setup automatically.
  • Add comments in main.c between:
    /* USER CODE BEGIN */
    /* USER CODE END */
    
    to prevent overwriting when regenerating code.

Deliverable

A functioning CubeIDE project that compiles, flashes, and blinks the LED using button input.
You’ll use this project as the base for future Micromouse firmware development.