Sei sulla pagina 1di 12

Prerequisites

 Install the IAR Embedded workbench


 Download the STM32F4-Discovery firmware package :
https://www.st.com/en/embedded-software/stsw-stm32138.html
 Download this file Useful_Files_STM32F429ZI which contain the source and
header interruption handler files and the Library configuration
https://electronicshomemade.com/Downloads/STM32F4/Useful_Files_STM32F42
9ZI.rar
Create new project

1. Launch IAR, select Project/Create new project from the menu. Select in the windows
the C language programming and main then click OK. Save the project under the
“Create_New_Project”.
2. The project and a main file appears in the Workspace windows:

Setting options

1. Right click on the project and select options.

2. Select General Options from categoy, open the target tab and select Device ST
STM32F429ZI (ST/STM32f429/ST STM32F429Zi).
3. Open library configuration and check Use CMSIS.( Tab library Configuration )
Adding Source files

After downloading the STM32F4-Discovery firmware package. Unzip the contents in the
locations of your choice, preferably in a safe place because you will use it in every new
project.
1. Create 3 Groups/folders in the workspace to organize files.
(Right click on the project name, Add/Add Group).
 EWARM : Embedded Workbench ARM, this group include files
configuration.
 STM32F4xx_StdPeriph_Driver : Contains firmware driver for the all
the STM32F429ZiT6 microcontroller peripherals.
 STM32F4-Discovery : Contains firmware driver for the STM32F4-
Discovery board.
 User : Contains the user files.
2. Adding the sources files for the EWARM Group.
C:\Users\NhatTam\Desktop\..\STM32F4_DISCOV\STM32F429I-
Discovery_FW_V1.0.1\Libraries\CMSIS\Device\ST\STM32F4xx\Source\Templates\iar
and select the startup_stm32f4xx.s file.
This file define the vector table for the microcontrollers.

The startup_stm32f4xx.s source file call an extern function SystemInit which is


located in the system_stm32f4xx.c source file. This function setups the system
clock.
3. Adding the system_stm32f4xx.c file for User group.
Go to the link and copy the source file and paste it in the project directory :
C:\Users\NhatTam\Desktop\..\STM32F4_DISCOV\STM32F429I-
Discovery_FW_V1.0.1\Libraries\CMSIS\Device\ST\STM32F4xx\Source\Templates\
system_stm32f4xx.c
4. Adding the source file that contain the interrupt handlers called stm32f4xx_it.c.
You can find this file inside the Useful_Files_STM32. Adding
the stm32f4xx_it.c file for User group.
5. The STM32F4xx_StdPeriph_Driver group must have the file which contains the
firmware functions for microcontrollers peripheral. These files are located here :
STM32F4_DISCOV\STM32F429I-
Discovery_FW_V1.0.1\Libraries\STM32F4xx_StdPeriph_Driver\src

Right click on the STM32F4xx_StdPeriph_Driver group and select Add/Add


files and select the misc.c source file.
We can add for example the driver for microcontroller GPIO called
stm32f4xx_gpio.c.

6. STM32F4-Discovery, which includes files that provides set of firmware functions


to manage Leds, push-button available and 3-axis accelerometer... on
STM32F4-Discovery Kit from STMicroelectronics. These file are located
in STM32F4_DISCOV\STM32F429I-Discovery_FW_V1.0.1\Utilities\
STM32F429I-Discovery.
Adding stm32f4_discovery.c file.
Adding Header files

1. Right click on the project and select options. A new windows options will appears.
Select C/C++ Compiler from categoy, open the Preprocessor tab and go to the
Additional include directories.
a. The first header file to add is the cortex M4 header file and is located under
\ STM32F4_DISCOV\STM32F429I-Discovery_FW_V1.0.1\Libraries
\CMSIS\include.
So we copy the link and we past it in the Additional include directories.
C:\Users\xxx\Desktop\STM32F4-Discovery_FW_V1.1.0\Libraries
\CMSIS\Include or using the project directory location
$PROJ_DIR$\..\STM32F4-Discovery_FW_V1.1.0\Libraries\CMSIS
\Include

b. The second header file to add is the system_stm32f4xx.h from :


\STM32F4_DISCOV\STM32F429I-Discovery_FW_V1.0.1\Libraries\CMSIS\Device
\ST\STM32F4xx\Include
The second file in this folder the stm32f4xx.h is also necessary.

Inside the stm32f4xx.h we have a condition to include the stm32f4xx_conf.h


header file. So we copy the USE_STDPERIPH_DRIVER and the
STM32F429_439xx in the defined symboles.
The stm32f4xx_conf.h is located in the Useful_Files_STM32 folder. We copy this
file under the project directory.
Add the interrupt handlers stm32f4xx_it.h and the Library configuration
file stm32f4xx_conf.h. so we write $PROJ_DIR$ in the Additional include
directoriers to refer to the project directory.

The Library configuration file stm32f4xx_conf.h include the list of all the header
file of the firmware drivers. We have to uncomment all the header files that we need
to, the misc.h and the stm32f4xx_gpio.h.

c. These header file are located in the \STM32F4-


Discovery_FW_V1.1.0\Libraries\STM32F4xx_StdPeriph_Driver\inc.
So we add this link to the Additional include directoriers.
d. The last header file belong to the STM32F4-Discovery firmware and is located in
the \STM32F4-Discovery_FW_V1.1.0\Utilities\STM32F4-Discovery
The last thing you have to include in the main.c file two header
files stm32f4xx.h and stm32f4_discovery.h
Setting the Debugger

Install st-link v2 for stm32 driver download from:


https://www.st.com/content/ccc/resource/technical/software/utility/51/c4/6a/b0/e2/
0f/47/e5/stsw-link004.zip/files/stsw-link004.zip/jcr:content/translations/en.stsw-
link004.zip
After installation, the results are as follows

1. Right click on the project and select options.


Select Debugger from categoy, open the Setup tab and select Device ST-LINK as
driver.
2. Then select the Download tab and check the Verify download and Use flash
loader(s).

3. Go to the ST-LINK tab and select SWD for Serial Wire Debug.
Linker

Note: If edit Linker please make sure the addresses are correct (refer Reference
manual is needed). if not you should use the linker provided by IAR for Stm32F429i

1. Select Linker from category, open the Config tab. In the linker configuration
file check Override default and click Edit to display the Linker configuration file
editor.

2. Click Save to save linker options (in IAR folder of the project)
Putt the file name and save it.
Reference

https://electronics-homemade.com

Potrebbero piacerti anche