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
- Install CubeIDE and open it.
- Create a new STM32 project → “Board Selector” tab.
- Search for
Nucleo-F411REand click Next. - Give your project a name (e.g.,
Micromouse_Main) → Finish. - 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:
- Click Project > Generate Code (gear icon).
- CubeIDE will create startup files and a default
main.ctemplate.
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
- Click Build Project (hammer icon) to compile.
- Connect your Nucleo board via USB.
- Click Run > Debug As > STM32 MCU C/C++ Application.
- 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
.iocfile — it regenerates hardware setup automatically. - Add comments in
main.cbetween:
to prevent overwriting when regenerating code./* USER CODE BEGIN */ /* USER CODE END */
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.