STM32F4 Library

Embed Size (px)

Citation preview

  • 7/27/2019 STM32F4 Library

    1/29

    STM32F4 Library

    Home Page

    STM32F4xx Page

    STM32 Page

    If this is your first time that you look this page I suggest to reading from top to bottom.

    The link below are for go direct to a topics but first is necessary a global vision of the library.

    How to find the STM Library

    The Library Manual

    Inside the Library

    API

    Structure

    Consulting the Library ManualUse the library examples

    Library - FAQ

    Vic ti FrieslandCampina

    www.JobStreet.com

    FrieslandCampina ang tuyn dng nhiu v tr. ng tuyn ngay!

    http://www.google.com/url?ct=abg&q=https://www.google.com/adsense/support/bin/request.py%3Fcontact%3Dabg_afc%26url%3Dhttp://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html%26gl%3DVN%26hl%3Den%26client%3Dca-pub-9272963378822527%26ai0%3DCYBiaBEA1UZfiF8rCigfoiYG4CM7DyY8DprS78UToh4WeCxABIJTAkRdQpt6Ynv3_____AWDBBaABuv7n5APIAQGoAwHIA98EqgSMAU_Q_mEy1w4w_NdsYwgb323tiEQqwtR2tIFPNkt0s8qx-0wU2f1HScBG1L_C1QrVWAVt7RxPZO_9wN-V8p3BlrrdDtGB-sz--Q-qxCUgLvxtm_AO6oRg50Hg0_x4D0D2UBHOJACk5a3cT7mtMuM922rmbsKy8Vlndhfczb1L70C53ToOYxBxBU-6Tj3kgAeugZgb&usg=AFQjCNG2_SCHMUk1B0XYRtklXTawS5PHMwhttp://googleads.g.doubleclick.net/aclk?sa=l&ai=CYBiaBEA1UZfiF8rCigfoiYG4CM7DyY8DprS78UToh4WeCxABIJTAkRdQpt6Ynv3_____AWDBBaABuv7n5APIAQGoAwHIA98EqgSMAU_Q_mEy1w4w_NdsYwgb323tiEQqwtR2tIFPNkt0s8qx-0wU2f1HScBG1L_C1QrVWAVt7RxPZO_9wN-V8p3BlrrdDtGB-sz--Q-qxCUgLvxtm_AO6oRg50Hg0_x4D0D2UBHOJACk5a3cT7mtMuM922rmbsKy8Vlndhfczb1L70C53ToOYxBxBU-6Tj3kgAeugZgb&num=1&sig=AOD64_2zJLA8x3hDb8tEEpPxNDDGiMG9tA&client=ca-pub-9272963378822527&adurl=http://myjobstreet.jobstreet.vn/registration/quick-register.php%3Fsite%3Dvn%26deposit_through%3Dv%26language_code%3D135%26eb%3D6151&nm=2http://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#Library_-_FAQhttp://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#Use_the_library_exampleshttp://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#Consulting_the_Library_Manualhttp://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#To_use_the_peripheral_PPPhttp://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#APIhttp://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#Inside_the_Libraryhttp://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#After_unzip_the_library_you_see_a_filehttp://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#STM_provide_for_all_Cortex_thehttp://www.emcu.it/STM32.htmlhttp://www.emcu.it/STM32F4xx/STM32F4xx.htmlhttp://www.emcu.it/index.html
  • 7/27/2019 STM32F4 Library

    2/29

    STM provide for all Cortex the appropriate firmware library for configure and use the peripherals.

    The STM32F4xx firmware library is here, in the window that appears download the library (see below).

    Go on Top

    The Library Manual

    After unzip the library you see a file named: stm32f4xx_dsp_stdperiph_lib um.chm(see below) that is the Library Manual.

    http://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#STM32F4_Libraryhttp://www.st.com/stonline/stappl/resourceSelector/app?page=resourceSelectorPage&doctype=st_software_rsrc&SubClassID=1521
  • 7/27/2019 STM32F4 Library

    3/29

    The documentation file is generated in automatic by using DOXYGEN.

    Go on Top

    http://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#STM32F4_Libraryhttp://www.stack.nl/~dimitri/doxygen/index.html
  • 7/27/2019 STM32F4 Library

    4/29

    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, TASKINGand ATOLLIC.

    See the blue box upstairs.

    The complete list of subfolders is below.

  • 7/27/2019 STM32F4 Library

    5/29

    _htmrescfolder

    This folder contains all packages html page resources.

    Librariesfolder

    This folder contains all CMSISfiles and STM32F4_DSP_StdPeriph_Lib.V1.0.0.

    CMSIS subfolder

    This folder contains the STM32F4 CMSIS files: device peripheral, access layer and core peripheral access layer.STM32F4_DSP_StdPeriph_Lib.V1.0.0 subfolder

    This folder contains all the subdirectories and files that make up the core of the library:

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

    Project folder

    This folder contains template projects and STM32F10x Standard Peripheral's examples.

  • 7/27/2019 STM32F4 Library

    6/29

    STM32F4_StdPeriph_Examplessubfolder

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

    STM32F4_StdPeriph_Templatesubfolder

    This 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/41xthat is here

    Utilities folder

    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.

    Go on Top

    http://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#STM32F4_Libraryhttp://www.st.com/stonline/stappl/resourceSelector/app?page=resourceSelectorPage&doctype=st_software_rsrc&SubClassID=1521
  • 7/27/2019 STM32F4 Library

    7/29

    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

    Second word is always Address of Reset ProcedureIt is recommended to implement as well main fault vectors (HardFault at least)

    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 Atollicit is startup_stm32f4xx.sfile located in the folder srcinside the project, see below.

  • 7/27/2019 STM32F4 Library

    8/29

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

    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.sfile should be commented (line 104 in startup file).

    For each peripheral there are separate source and header files, i.e.:

    stm32f4xx_gpio.c

    stm32f4xx_gpio.h

    To use them, it is required to use:

    #include stm32f4xx.h

    add to the project source files for used peripherals, i.e. stm32f4xx_gpio.c for GPIO, see below

  • 7/27/2019 STM32F4 Library

    9/29

    To use the peripheral PPPin stm32f4xx_conf.huncomment lines with peripherals you are using in applications, i.e.:

    #include "stm32f4xx_gpio.h"

    see below.

  • 7/27/2019 STM32F4 Library

    10/29

    Emptyinterrupt proceduresare 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 totwo data structureswhich are used for the configuration.

    After fill up the structure it is possible to use inPPP_Init()functions to configure registers in the peripherals.

    Function and constant for each peripheral have prefix with its name, like: GPIO, TIM1 ie.:

    GPIO_Init()

    ADC_Channel_0

    USART_IT_TXE

  • 7/27/2019 STM32F4 Library

    11/29

    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 peripheralPPP_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:

    GPIO_InitTypeDef GPIO_InitStructure;

    The PPP_InitStructure is a working variable located in data memory that allows you to initialize one or more instance of PPPs.

  • 7/27/2019 STM32F4 Library

    12/29

    NOTE:

    Before configuring a peripheral, you have to enable its clockby 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 typesin stm32f4xx.h file, like:

    u8 unsigned char

    u16 unsigned short

  • 7/27/2019 STM32F4 Library

    13/29

    RESET / SET

    FALSE / TRUE

    DISABLE / ENABLE

    Go on Top

    Consulting the Library Manual

    To consult, for example, the function available for GPIO, you must choose:

    STM32F4xx_StdPeriph_Driver -> GPIO -> Functions

    see below

    http://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#STM32F4_Library
  • 7/27/2019 STM32F4 Library

    14/29

    To see the GPIO_SetBits you must select:

    GPIO_SetBits

    see below

  • 7/27/2019 STM32F4 Library

    15/29

    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.

  • 7/27/2019 STM32F4 Library

    16/29

    Now for a complete description of the Pin, Mode, Speed, etc, it i s 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.

    http://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#In_your_project_you_have_to_declare_a
  • 7/27/2019 STM32F4 Library

    17/29

    Go on Top

    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 notread-only, see below.

    http://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#STM32F4_Library
  • 7/27/2019 STM32F4 Library

    18/29

    We suppose to use the GPIO example: IOToggle

    First copy all the files present in IOToggle directory into the directory: STM32F4xx_StdPeriph_Templates

    see below

  • 7/27/2019 STM32F4 Library

    19/29

    From the box that appears select: Yes to All (see below).

  • 7/27/2019 STM32F4 Library

    20/29

    Below we explain you how to use KEIL and ATOLLIC IDE.

    KEIL IDE

    If you want to use KEIL IDE enter in the directory: MDK-ARM

    and double click on: Project_uvproj

    see below.

    Automatically start KEIL IDE and you are ready to compile and debug the project.

    Below we compile the project for STM324G-EVAL board.

  • 7/27/2019 STM32F4 Library

    21/29

    Remember:

    Before starting the debug, configure the emulator that you will use.

    ATOLLIC IDE

    First start your ATOLLIC IDE ( v.2.2.0 or higher) and click on: Browseand select the TrueSTUDIOdirectory (see below).

  • 7/27/2019 STM32F4 Library

    22/29

    From the window that appears click: Start using TrueSTUDIO

    Now click on Fileand next on Import(see below).

  • 7/27/2019 STM32F4 Library

    23/29

    From the new window that appears select:

    General-> Existing Project into Workspace-> Next

    See below.

  • 7/27/2019 STM32F4 Library

    24/29

    From the new window that appears select:

    Select root directory

    and press:

    Browse

    see below.

  • 7/27/2019 STM32F4 Library

    25/29

    From the new window that appears chose:

    STM32F4xG_EVAL

    next press:

    OK

  • 7/27/2019 STM32F4 Library

    26/29

    Now press Finish

    See below.

  • 7/27/2019 STM32F4 Library

    27/29

    Now ATOLLIC import and compile the project and if all is OK, you must see somethig like below.

  • 7/27/2019 STM32F4 Library

    28/29

    Remember:

    Before starting the debug, configure the emulator that you will use, see here.

    Go on Top

    Library - FAQ

    If Compiler is reporting a lot of errors like:

    Missing prototype

    GPIO_Pin_0 undefined

    Solution

    Please check whether in stm32f4xx_conf.hall used library modules are uncommented

    http://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#STM32F4_Libraryhttp://www.emcu.it/STM32F4xx/Exe1/EXE1.html#Now_is_necessary_configure_the_Debugger
  • 7/27/2019 STM32F4 Library

    29/29

    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)

    Solution

    Please check whether all library source files are added, stm32f4xx_gpio.c in this case.

    Go on Top

    Home Page

    STM32 Page

    http://www.histats.com/http://www.emcu.it/STM32.htmlhttp://www.emcu.it/index.htmlhttp://www.emcu.it/STM32F4xx/STM32F4-Library/STM32F4-Library.html#STM32F4_Library