Fundamentals 9 min read

Quickly Build a Reusable STM32 HAL MDK Project Template

This step‑by‑step guide shows how to create a reusable STM32F103C8T6 HAL‑based MDK project template, covering source download, folder structure, required files, MDK configuration, and verification to streamline future STM32 development.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Quickly Build a Reusable STM32 HAL MDK Project Template

1. Prerequisites

Download the STM32Cube firmware package for the STM32F1 series from ST’s official site (https://www.st.com/content/st_com/en.html). Install an ARM development environment such as Keil MDK‑ARM and the ST‑Link flashing utility.

2. Project directory layout

Create a root folder (for example stm32f103c8t6_template) and inside it create the following five sub‑folders:

Drivers – hardware‑related driver sources

Middlewares – optional middleware components (left empty for the template)

Output – compiler output files (.hex, .bin, .o, etc.)

Projects – IDE project files

User – HAL user configuration, main.c, interrupt handlers and other user code

2.1 Drivers folder

The Drivers folder contains four sub‑folders:

BSP – board‑support package (empty in the template)

CMSIS – core CMSIS files, including the startup assembly file and system_stm32f1xx.c SYSTEM – system‑level drivers such as clock configuration, delay utilities and UART

STM32F1xx_HAL_Driver – ST‑provided HAL source; keep only the Inc and Src sub‑folders

2.2 Middlewares folder

Intended for components such as FATFS, USB, LWIP, FreeRTOS, etc.; the template leaves it empty.

2.3 Output folder

Used by the compiler to store intermediate build artifacts; no manual files are required.

2.4 Projects folder

Create a sub‑folder MDK-ARM (or an equivalent for another IDE) to hold the MDK project files.

2.5 User folder

Copy the three source files from the reference example into this folder: main.c – application entry point stm32f1xx_hal_conf.h – HAL configuration header stm32f1xx_it.c – interrupt service routines

3. Create the MDK project

In Keil MDK‑ARM, create a new project inside Projects/MDK-ARM. Define the following groups and add the corresponding files:

Startup – startup assembly file ( startup_stm32f103xb.s) and linker script ( STM32F103C8Tx.sct)

User – main.c, stm32f1xx_hal_conf.h, stm32f1xx_it.c SYSTEM – clock, delay and UART source files from the SYSTEM folder

Driver – peripheral driver sources from STM32F1xx_HAL_Driver/Src If any files show a lock icon, clear the read‑only attribute (e.g., via file properties) so they can be edited.

4. Project options

Configure the following tabs in the Keil project options:

Target – select device STM32F103C8Tx Output & Listing – enable desired output formats such as .hex and .bin C/C++ – add include paths for:

Drivers/STM32F1xx_HAL_Driver/Inc
Drivers/CMSIS/Include
User

and define the macro USE_HAL_DRIVER Debug – select the appropriate debugger (e.g., ST‑Link)

Utilities – configure flash programming settings for the selected debugger

5. Build, flash and verify

Build the project. Resolve any read‑only file issues before compilation. Use the ST‑Link utility (or the Keil “Download” button) to flash the generated binary to the STM32F103C8T6 board.

Run the program; the template’s example toggles an LED on the board every 500 ms. Verify the LED blinks at the expected interval to confirm a successful build and flash.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

HALSTM32Project TemplateMDKSTM32F103C8T6
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.