Sunday, June 30, 2013

Keil-Project-Setup-for-STM32F4-discovery


ST 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.

Make a New uVision Project Goto Project->New uVision Project

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.


Save your project within a folder inside Project folder

Step 4 : Choose the Device as STM32F407VG.  Keil will ask you whether to copy Startup.s into new project or not. Choose Yes here. 

Choose the device as STM32F407VG


Choose Yes when it asks to include Startup.s into the Project
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.

Different Source Groups (Optional)
 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.

Include Paths in C/C++ Tab under Project Options
We are almost done, now try to build your project. Do not forget to add any required source file as explained in Step 8 . Any issues in compilation ? Comment below !

No comments:

Post a Comment