Back to main page

STM32F10x Standard Peripherals Library

 How to use the Library


Copyright 2010 STMicroelectronics



How to use the Standard Peripherals Library

Create a project and setup all your toolchain's start-up files (or use the template project provided within the Library, under

Select the corresponding startup file depending of the used device:

- startup_stm32f10x_ld_vl.s:    for STM32 Low density Value line devices

- startup_stm32f10x_ld.s:        for STM32 Low density devices

- startup_stm32f10x_md_vl.s:  for STM32 Medium density Value line devices

- startup_stm32f10x_md.s:      for STM32 Medium density devices

- startup_stm32f10x_hd_vl.s:       for STM32 High density Value line devices
- startup_stm32f10x_hd.s:       for STM32 High density devices

- startup_stm32f10x_xl.s:        for STM32 XL density devices

- startup_stm32f10x_cl.s:        for STM32 Connectivity line devices


The Library entry point is stm32f10x.h (under Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x), user has to include it in the application main and configure it:

Select the target product family to be used, comment/uncomment the right define:


 #if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD) && !defined (STM32F10X_MD_VL) && !defined (STM32F10X_HD) && !defined (STM32F10X_XL) && !defined (STM32F10X_CL)
  /* #define STM32F10X_LD */          /*!< STM32F10X_LD: STM32 Low density devices */
  /* #define STM32F10X_LD_VL */    /*!< STM32F10X_LD_VL: STM32 Low density Value Line devices */ 
  /* #define STM32F10X_MD */         /*!< STM32F10X_MD: STM32 Medium density devices */
  /* #define STM32F10X_MD_VL */   /*!< STM32F10X_MD_VL: STM32 Medium density Value Line devices */ 

  /* #define STM32F10X_HD_VL */          /*!< STM32F10X_HD: STM32 High density Value line devices */
  /* #define STM32F10X_HD */          /*!< STM32F10X_HD: STM32 High density devices */
  /* #define STM32F10X_XL  */               /*!< STM32F10X_CL: STM32 XL-density devices */
  /* #define STM32F10X_CL */           /*!< STM32F10X_CL: STM32 Connectivity line devices */


Then user has the choice to use or not the Peripheral’s Drivers

- Case1: application code based on Standard Peripheral’s drivers API (files under Libraries\STM32F10x_StdPeriph_Driver)

    - Uncomment #define USE_PERIPH_LIBRARY (default)

    - In stm32f10x_conf.h file, select the peripherals to include their header file

    - Use Peripheral’s drivers API to build the application; refer to next section for more information.

    -  In addition to the Peripheral’s drivers you can reuse/adapt the rich set of examples available within the Library to speed      

       your development, this allow you to started within few hours. Refer to the complete list of available examples

- Case2: application code based on Peripheral’s registers direct access

    - Comment #define USE_PERIPH_LIBRARY

    - Use Peripheral’s registers structure and bits definition available within stm32f10x.h to build the application


Add the system_stm32f10x.c (under  Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x) file in your application, this file provide functions to setup the STM32 system: configure the PLL, system clock and initialize the Embedded Flash Interface. This file provides multiple choice for the system clock  frequency, you can selected the frequency needed for your application from the list below (common frequencies that covers the major of the applications):

#if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
/* #define SYSCLK_FREQ_HSE    HSE_Value */
 #define SYSCLK_FREQ_24MHz  24000000
/* #define SYSCLK_FREQ_HSE    HSE_Value */
/* #define SYSCLK_FREQ_24MHz  24000000 */
/* #define SYSCLK_FREQ_36MHz  36000000 */
/* #define SYSCLK_FREQ_48MHz  48000000 */
/* #define SYSCLK_FREQ_56MHz  56000000 */
#define SYSCLK_FREQ_72MHz  72000000


Note: The System clock configuration functions provided within this file assume that:

            - For Low-density Value line, Low-density, Medium-density Value line, Medium-density, High-density Value line and High-density devices 

              an external 8MHz crystal is used to drive the System clock.

            - For Connectivity line devices an external 25MHz crystal is used to drive the System clock.

         If you are using different crystal you have to change the value of the define HSE_VALUE in stm32f10x.h file and adapt those functions


 Back to Top

Peripheral initialization and configuration

This section describes step-by-step how to initialize and configure a peripheral using the Peripheral’s Drivers. The peripheral will be referred to as PPP.

  1. In the main application file, declare a PPP_InitTypeDef structure, for example: PPP_InitTypeDef PPP_InitStructure;

The PPP_InitStructure is a working variable located in data memory area. It allows initializing one or more PPP instances.

  1. Fill the PPP_InitStructure variable with the allowed values of the structure member.

There are two ways of doing this:

  • Configuring the whole structure by following the procedure described below:

PPP_InitStructure.member1 = val1;
PPP_InitStructure.member2 = val2;
PPP_InitStructure.memberN = valN; /* where N is the number of the structure members */

The previous initialization step can be merged in one single line to optimize the code size:

PPP_InitTypeDef PPP_InitStructure = { val1, val2,.., valN}

  • Configuring only a few members of the structure: in this case the user should modify the PPP_InitStructure variable that has been already filled by a call to the PPP_StructInit(..) function. This ensures that the other members of the PPP_InitStructure variable are initialized to the appropriate values (in most cases their default values).

PP_InitStructure.memberX = valX;
PPP_InitStructure.memberY = valY; /*where X and Y are the members the user wants to configure*/

  1. Initialize the PPP peripheral by calling the PPP_Init(..) function.

PPP_Init(PPP, &PPP_InitStructure);

  1. At this stage the PPP peripheral is initialized and can be enabled by making a call to PPP_Cmd(..) function.


The PPP peripheral can then be used through a set of dedicated functions. These functions are specific to the peripheral. 


  1. Before configuring a peripheral, its clock must be enabled by calling one of the following functions:

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_PPPx, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_PPPx, ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_PPPx, ENABLE);

  1. PPP_DeInit(..) function can be used to set all PPP peripheral registers to their default values:


  1. To modify the peripheral settings after configuring the peripheral, the user can proceed as follows:

PPP_InitStucture.memberX = valX;
PPP_InitStructure.memberY = valY; /* where X and Y are the only members that user wants to modify*/
PPP_Init(PPP, &PPP_InitStructure);


 Back to Top


For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit