Keil project setup for STM32F4 Discovery
— April 20, 2013ST Microelectronics provides a rich firmware support with its Discovery Promotion Kits. Its easy to modify the example codes to customize an application. However, here i am trying to explain, How to setup Keil MDK ARM Project for stm32f4 Discovery.
Step 1 : Open latest version of Keil uVision 4 ARM MDK IDE, Older version do not list stm32f407vgt6 device.
Step 2 : Save the project using a suitable name. You need a few libraries to work with STM32F4 or any other ARM Cortex Family. I recommend you to download the standard STM32F4 board support package provided by ST Micro. This BSP has all the necessary library including CMSIS and board specific drivers. Download STM32F4 Discovery BSP here.
Step 3: Extract the stm32f4 discovery bsp package on your local disk. You will find 3 major directories as Libraries, Project and Utilities. We are going to use Libraries and Utilities in further steps. Project directory contains various example projects, but we will be making our own project, still we need Libraries and Utilities directory as it is. So keep these two directories as it is and Make a new folder inside Project directory for new Project.
Step 4 : Choose the Device as STM32F407VG. Keil will ask you whether to copy Startup.s into new project or not. Choose Yes here.
Step 5 : You may have various Source Groups in one project. By default only a single Source group is there, I prefer to make separate source groups each for User sources, MDK codes like StartUp.s and other for other libraries like Third party libraries, Board specific drivers.
Step 6 : Add your own code e.g. main.c into User Codes source group. Add other files into different source groups as shown in figure below.
Almost all the stm32f4 projects require these files named
stm32f4xx_it.c, stm32f4xx_it.h
system_stm32f4xx.c,
stm32f4xx_conf.h,
and misc.c.
Add these 5 files in Other source group as shown in figure above.
Now we are ready to perform some setting in the Project options section.
What all those paths in Include Paths section of C/C++ Tab? Well these are the location of files, which your project compilation depends on. So here is a list of directories that you must include as path in your Keil Project fir stm32f4 Discovery.
- Libraries\CMSIS\Include
- Libraries\CMSIS\ST\STM32F4xx\Include
- Libraries\STM32F4xx_StdPeriph_Driver\inc
- Libraries\STM32F4xx_StdPeriph_Driver\src
- Utilities\STM32F4-Discovery
- The Project folder itself, which has main source code and stm32f4xx_it.c, system_stm32f4xx.c etc.










4 Comments
Very helpful and appreciate your time and effort in putting this tutorial online.
Jim
Hi;
I’m unable to find “The Project folder itself, which has main source code and stm32f4xx_it.c, system_stm32f4xx.c etc.”
Where is its original file?
I keep getting this output from trying to compile. No idea why I keep getting it…
.\test.axf: Error: L6218E: Undefined symbol main (referred from entry9a.o).
Hi,
This is a really great overview. I just wanted to let you know Keil was recently updated and they don’t ask if you want to include the a start up file(step 5). Instead they open a package installer and you get to choose which libraries to initially start with. You might want to update your post.