After unzip the library you see a file named: stm32f4xx_dsp_stdperiph_lib um.chm (see below) that is the Library Manual.
documentation file is generated in automatic by using DOXYGEN.
Inside the Library
Inside the directory where you have unzipped the library there are some other directory like below.
STM releases the library in ANSI C, this means that it is possible to use them with any IDE.
STM to help developers, has released the ready-to-use initialization for: IAR, KEIL, RAISONANCE, TASKING and ATOLLIC.
See the blue box upstairs.
The complete list of subfolders is below.
This folder contains all packages html page resources.
This folder contains all CMSIS files and STM32F4_DSP_StdPeriph_Lib.V1.0.0.
This folder contains the STM32F4 CMSIS files: device peripheral, access layer and core peripheral access layer.
This folder contains all the subdirectories and files that make up the core of the library:
inc sub-folder contains the Peripheral's Drivers header files. They do not need to be modified by the user.
src sub-folder contains the Peripheral's Drivers source files. They do not need to be modified by the user.
All STM32F4_DSP_StdPeriph drivers are coded in strict ANSI-C and are independent from the software toolchain.
This folder contains template projects and STM32F10x Standard Peripheral's examples.
STM32F4_StdPeriph_Template subfolder This
folder contains, for each peripheral sub-folder, the minimum set of
files needed to run a typical example on how to use this peripheral.
There is also a: readme.txt that is brief text file describing the example and how to make it work.
For each peripherals there are a lot of example for different mode of use them (polling, interrupt, DMA, etc) see below.
folder contains standard template projects for IAR, KEIL, RAISONANCE,
TASKING and TrueSTUDIO toolchains.
stm32f4xx_conf.h - configuration header file
stm32f4xx_it.c - source file containing the interrupt handlers
stm32f4xx_it.h - header file including all interrupt handlers prototypes
main.c - main program body
main.h - header file for main.c
system_stm32f4xx.c - clock tree initialization
, configure the PLL, system clock, initialize the Embedded Flash Interface, etc.
To generate this file automatically use: Clock configuration tool for STM32F40x/41x that is here
Implement an abstraction layer to interact with the Human Interface resources; buttons, LEDs, LCD and COM ports (USARTs) available on STM32F4-Discovery, STM3240G-EVAL and STM3241G-EVAL.
A common API is provided
to manage the LCD across the supported boards, with a separate driver
for each board stm324xg_eval_lcd.c.
Minimum requirement for STM32 to start is to fill two first words in its vector table:
First word is always initial Main Stack Pointer value
It is recommended to implement as well main fault vectors (HardFault at least)
Second word is always Address of Reset Procedure
In STM32 std library implementation with CMSIS standard, vector table
is defined in startup file, which is prepared for each family member
and each toolchain.
In case of STM32F407VGT6 (we suppose to use STM32F4-Discovery) and Atollic it is startup_stm32f4xx.s file located in the folder src inside the project, see below.
In ST library there are some additional operations put before main() function will be executed.
The most important is SystemInit() function coming from system_stm32f4xx.c file.
This function is doing configuration of clock system and some GPIO pins
in order to cooperate with external components of the MCU.
This is not necessary for standard application running.
To switch off this procedure, line “bl SystemInit” in startup_stm32f4xx.s file should be commented (line 104 in startup file).
For each peripheral there are separate source and header files, i.e.:
To use them, it is required to use:
add to the project source files for used peripherals, i.e. stm32f4xx_gpio.c for GPIO, see below
To use the peripheral PPP in stm32f4xx_conf.h uncomment lines with peripherals you are using in applications, i.e.:
Empty interrupt procedures are present in stm32f4xx_it.c file.
All interrupt functions should be put there.
Interrupt function do not require any special coding and are: void function(void) type
Most of the peripherals has predefined from one or to two data structures which are used for the configuration.
After fill up the structure it is possible to use in PPP_Init() functions to configure registers in the peripherals.
Function and constant for each peripheral have prefix with its name, like: GPIO, TIM1 ie.:
Most of the settings is in 1fromN convention and allow to use concatenation, like:
GPIO_Pin_0 | GPIO_Pin_1
what means that pins 0 and 1 from will be configured in the same time
Most of the peripherals (PPP) has set of instruction:
PPP_DeInit(...) – set all PPP register to its reset state
PPP_Init(...) – validation of the configuration for the peripheral
PPP_Cmd(ENABLE/DISABLE) – turn on/off PPP peripheral (not affects its clock)
PPP_ITConfig(...) – configuration (on/off) of sources of interrupts for PPP peripheral
PPP_GetFlagStatus(...) – read flags from the peripheral (polling)
PPP_ClearFlag(...) – clear flags from the peripheral
PPP_ClearITPendingBit(...) – clear IRQ flag
In your project you have to declare a PPP_InitTypeDef structure, e.g:
The PPP_InitStructure is a working variable located in data memory that allows you to initialize one or more instance of PPPs.
Before configuring a peripheral, you have to enable its clock by calling one of the following functions:
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_PPPx , ENABLE);
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_PPPx , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_PPPx , ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PPPx , ENABLE);
There are predefined types in stm32f4xx.h file, like:
u8 – unsigned char
u16 – unsigned short
RESET / SET
FALSE / TRUE
DISABLE / ENABLE
Consulting the Library Manual
To consult, for example, the function available for GPIO, you must choose:
STM32F4xx_StdPeriph_Driver -> GPIO -> Functions
To see the GPIO_SetBits you must select:
Below we need to see the function GPIO_Init.
To do this, select:
GPIO_Init and next GPIO_InitTypeDef
From the new window that appears, we see that there are 5 parameters to be setted, see below.
Now for a complete description of the Pin, Mode, Speed, etc, it is necessary to click on it.
Below there is an example concerning the setup of GPIO.
REMEMBER: before it is necessary to define the structure and clock, see here.
Use the library examples
For use the examples present in the Library directory: STM32F4xx_StdPeriph_Examples
it is necessary only a Copy and Past... see the example below.
First ensure that the library directory is not read-only, see below.
We suppose to use the GPIO example: IOToggle
First copy all the files present in IOToggle directory into the directory: STM32F4xx_StdPeriph_Templates
From the box that appears select: Yes to All (see below).
Below we explain you how to use KEIL and ATOLLIC IDE.
If you want to use KEIL IDE enter in the directory: MDK-ARM
and double click on: Project_uvproj
Automatically start KEIL IDE and you are ready to compile and debug the project.
Below we compile the project for STM324G-EVAL board.
Before starting the debug, configure the emulator that you will use.
First start your ATOLLIC IDE ( v.2.2.0 or higher) and click on: Browse
and select the TrueSTUDIO directory (see below).
From the window that appears click: Start using TrueSTUDIO
Now click on File and next on Import (see below).
From the new window that appears select:
General -> Existing Project into Workspace -> Next
From the new window that appears select:
Select root directory
From the new window that appears chose:
Now press Finish
Now ATOLLIC import and compile the project and if all is OK, you must see somethig like below.
Before starting the debug, configure the emulator that you will use, see here.
Library - FAQ
If Compiler is reporting a lot of errors like:
Please check whether in stm32f4xx_conf.h all used library modules are uncommented
Please check, whether USE_STDPERIPH_DRIVER constant is defined in your environment
If Linker is reporting a lot of errors like:
Lab_library.lkf:1 symbol _GPIO_WriteHigh not defined (Debug/main.o)
Please check whether all library source files are added, stm32f4xx_gpio.c in this case.