STM32F4XX Standard Peripheral Firmware Library

Source: Internet
Author: User

STM32F4 Related information:http://www.stmcu.org/document/list/index/category-523

Introduction of standard Firmware Library

This article downloads the stm32f4xx_dsp_stdperiph_lib_v1.5.0, as shown in the folder:

Where the project folder is a template project for each development environment (Mdk-arm, Ewarm, Truestudio), the Utilities folder is the standard firmware library application routine for the official evaluation board, and the true standard firmware library is in the Libraries folder.

In the Libraries folder: The Cmsis folder is primarily contained in kernel-related files, and the Stm32f4xx_stdperiph_driver folder is the underlying driver associated with STM32F4XX processor peripherals.

The following are important source files in the Cmsis folder when code is migrated:

Core_cm4.h: Definition of kernel functions, such as structure and Systick configuration of Nvic related registers. In the Cmsis/include

Core_cm4_simd.h: Contains compiler-related processing. In the Cmsis/include

CORE_CMFUNC.H: Kernel core function is connected to oral file. In the Cmsis/include

Core_cminstr.h: Contains some kernel-core-specific instructions. In the Cmsis/include

Stm32f4xx.h: Contains the definition of the register structure of the STM32F4 (similar to C51 's reg52.h). In the Cmsis\device\st\stm32f4xx\include

SYSTEM_STM32F4XX.H:SYSTEM_STM32F4XX.C's header file. In the Cmsis\device\st\stm32f4xx\include

SYSTEM_STM32F4XX.C:STM32F4 the system clock configuration. In the Cmsis\device\st\stm32f4xx\source\templates

STARTUP_STM32F40_41XXX.S: is a startup file and is a compilation file. Functions include setting the initial value of the SP, setting the initial value of the PC, setting the address of the interrupt vector table, configuring the clock, setting the stack, and calling main.

This boot file first calls the system_stm32f4xx.c inside of Systeminit () before calling main (). In the Cmsis\device\st\stm32f4xx\source\templates\arm

For Stm32f4xx_stdperiph_driver, its important source files are:

Stm32f4xx_ppp.h: Peripheral header file. Here PPP is just a code, in fact a specific peripheral name, such as ADC,DMA. Selective porting according to the required peripherals in actual use. In the Stm32f4xx_stdperiph_driver\inc

STM32F4XX_PPP.C: Peripheral source files. Here PPP is just a code, in fact a specific peripheral name, such as ADC,DMA. Selective porting according to the required peripherals in actual use. In the STM32F4XX_STDPERIPH_DRIVER\SRC

Stm32f4xx_conf.h: Peripheral driver configuration file. The user initiates or disables peripheral drivers by modifying the peripheral header files contained in the file. Additionally, this folder opens the macro definition Use_full_assert, which enables or disables the failure detection of the standard peripheral library runtime through preprocessing.

Stm32f4xx_it.h: Header file. Includes all interrupt handler prototypes.

STM32F4XX_IT.C: Interrupt source program template, the name of the interrupt function is consistent with the name of the interrupt vector table in the startup file. Note: The above three files are in the Project\stm32f4xx_stdperiph_templates project template

In addition, for STM32F4 's standard peripheral firmware library, there is a corresponding DSP library in the Cmsis folder: Dsp_lib and Lib. Dsp_lib mainly for the example of the DSP function library and source code, LIB for the compiled, and for the different kernels of the STM32 series MCU used by the Lib file .

Second, the standard firmware library porting process considerations (here to take KEIL-MDK as an example)

1. In the Stm32f4xx.h file, select the appropriate device by counter-annotation and open the macro definition Use_stdperiph_driver.

#if!defined (stm32f40_41xxx) &&!defined (stm32f427_437xx) &&!defined (stm32f429_439xx) &&! Defined (stm32f401xx) &&!defined (stm32f411xe) &&!defined (stm32f446xx)/*#define STM32F40_41XXX*/   /*!< Stm32f405rg, STM32F405VG, Stm32f405zg, Stm32f415rg, STM32F415VG, STM32F415ZG, STM32F407VG, Stm32f407ve, Stm32f407zg, Stm32f407ze, Stm32f407ig, Stm32f407ie, S TM32F417VG, Stm32f417ve, Stm32f417zg, Stm32f417ze, Stm32f417ig and Stm32f417ie Devices*/  /*#define STM32F427_437XX*/  /*!< Stm32f427vg, Stm32f427vi, Stm32f427zg, Stm32f427zi, Stm32f427ig, Stm32f427ii, STM32F437VG, Stm32f437vi, Stm32f437zg, Stm32f437zi, Stm32f437ig, Stm32f437ii Devices*/  /*#define STM32F429_439XX*/  /*!< Stm32f429vg, Stm32f429vi, Stm32f429zg, Stm32f429zi, STM32F429BG, Stm32f429bi, Stm32f429ng, Stm32f439ni, Stm32f429ig, Stm32f429ii, STM32F439VG, Stm32f439vi, S TM32F439ZG, Stm32f439zi, STM32F439BG, Stm32f439bi, Stm32f439ng, Stm32f439ni, stm32f43 9IG and Stm32f439ii Devices*/  /*#define STM32F401XX*/      /*!< STM32F401CB, stm32f401cc, STM32F401RB, STM32F401RC, STM32F401VB, STM32F401VC STM32F401CD, Stm32f401rd, STM32F401VD, Stm32f401cexx, stm32f401re and Stm32f401ve Devices*/  /*#define STM32F411XE*/      /*!< stm32f411cd, Stm32f411rd, STM32F411VD, Stm32f411ce, stm32f411re and Stm32f411ve Devices*/    /*#define STM32F446XX*/      /*!< STM32F446MC, Stm32f446me, STM32F446RC, Stm32f446re, STM32F446VC, Stm32f446ve, STM32F446ZC and Stm32f446ze Devices*/#endif/*Old stm32f40xx definition, maintained for legacy purpose*/#ifdef STM32F40XX#defineStm32f40_41xxx#endif/* STM32F40XX *//*Old stm32f427x definition, maintained for legacy purpose*/#ifdef stm32f427x#defineStm32f427_437xx#endif/* stm32f427x *//*tip:to Avoid modifying this file each time you need to switch between these devices, you can define the Devi  Ce in your toolchain compiler preprocessor. */#if!defined (stm32f40_41xxx) &&!defined (stm32f427_437xx) &&!defined (stm32f429_439xx) &&! Defined (stm32f401xx) &&!defined (stm32f411xe) &&!defined (stm32f446xx)#error"Please select first the target stm32f4xx device used in your application (in stm32f4xx.h file)"#endif#if!defined (Use_stdperiph_driver)/** * @brief Comment the line below if you won't use the peripherals drivers.  In this case, these drivers won't be included and the application code would be based on direct access to peripherals Registers*/  /*#define Use_stdperiph_driver*/#endif/* Use_stdperiph_driver */

2. Determine the default system external crystal clock Hse_value and internal crystal clock hsi_value in the Stm32f4xx.h file.

#if!defined (Hse_value)#defineHse_value ((uint32_t) 16000000)/*!< VALUE of the External oscillator in Hz */#endif/* Hse_value *//** * @brief in the following line adjust the External-speed oscillator (HSE) Startup Timeout value*/#if!defined (Hse_startup_timeout)#defineHse_startup_timeout ((uint16_t) 0x05000)/*!< Time out for HSE start-up */#endif/* Hse_startup_timeout */#if!defined (Hsi_value)#defineHsi_value ((uint32_t) 16000000)/*!< VALUE of the Internal oscillator in hz*/#endif/* Hsi_value */

3. Configure the Pll_m,pll_q,pll_n and pll_p of the system clock for the selected device in the system_stm32f4xx.c file. For stm32f40_41xxx, the system clock is 168MHZ, and it is generally only required to modify the Pll_m value.

/************************* PLL Parameters *************************************/#ifDefined (stm32f40_41xxx) | | Defined (stm32f427_437xx) | | Defined (stm32f429_439xx) | | Defined (STM32F401XX)/*Pll_vco = (hse_value or hsi_value/pll_m) * Pll_n*/#definePll_m 16#else/* STM32F411XE */#ifDefined (Use_hse_bypass)#definePll_m 8#else/* STM32F411XE */#definePll_m 16#endif/* Use_hse_bypass */#endif/* stm32f40_41xxx | | stm32f427_437xx | | stm32f429_439xx | | STM32F401XX * */*USB OTG FS, SDIO and RNG Clock = Pll_vco/pllq*/#definePll_q 7#ifDefined (STM32F40_41XXX)#definePll_n 336/*SYSCLK = pll_vco/pll_p*/#definePll_p 2#endif/* STM32F40_41XXX */#ifDefined (stm32f427_437xx) | | Defined (STM32F429_439XX)#definePll_n 360/*SYSCLK = pll_vco/pll_p*/#definePll_p 2#endif/* stm32f427_437x | | STM32F429_439XX * *#ifDefined (STM32F401XX)#definePll_n 336/*SYSCLK = pll_vco/pll_p*/#definePll_p 4#endif/* STM32F401XX */#ifDefined (STM32F411XE)#definePll_n 400/*SYSCLK = pll_vco/pll_p*/#definePll_p 4#endif/* STM32F411XX *//******************************************************************************/
#ifDefined (STM32F40_41XXX)uint32_t Systemcoreclock=168000000;#endif/* STM32F40_41XXX */#ifDefined (stm32f427_437xx) | | Defined (STM32F429_439XX)uint32_t Systemcoreclock=180000000;#endif/* stm32f427_437x | | STM32F429_439XX * *#ifDefined (STM32F401XX)uint32_t Systemcoreclock=84000000;#endif/* STM32F401XX */#ifDefined (STM32F411XE)uint32_t Systemcoreclock=100000000;#endif/* STM32F401XX */

4. If you need to use the stm32f40_41xxx FPU, you also need to add the relevant statement at the beginning of the Systeminit function:

/* FPU settings------------------------------------------------------------      */  #if (__fpu_present = = 1) && (__fpu_used = = 1)    SCB->cpacr |= (3UL*2 )| (3UL*2));  /*  */  #endif

STM32F4XX standard Peripheral Firmware library

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.