How to use and customize the library
Peripheral driver access
In this model the application code uses the peripheral driver API to control the peripheral
configuration and operation. It allows any device to be used in the user application without
the need for in-depth study of each peripheral specification. As a result, using the
peripheral drivers saves significant time that would otherwise be spent in coding, while
reducing the application development and integration cost.
However, since the drivers are generic and cover all peripherals functionalities, the size
and/or execution speed of the application code may not be optimized.
To use this model, proceed as follows:
1. Add the line #define USE_STDPERIPH_DRIVER in the compiler preprocessor section
or uncomment the line #define USE_STDPERIPH_DRIVER in stm32f30x.h.
2. In stm32f30x_conf.h file, select the peripherals to include their header file (by default
all header files are included in the template file)
3. Use the peripheral drivers API provided by stm32f30x_ppp.h/.c files under
Libraries\STM32F30xx_StdPeriph_Driver to build your application. For more
information, refer to the detailed description of each peripheral driver.
4. In addition to the peripheral drivers, you can reuse/adapt the rich set of examples
available within the library. This reduces your application development time and allows
you to start within few hours.
For many applications, the peripheral drivers can be used as is. However, for applications
having tough constraints in terms of code size and/or execution speed, these drivers
should be used as reference on how to configure the peripherals and tailor them to specific
application requirements, in combination with peripheral direct register access.
The application code performance in terms of size and/or speed depends also on the C
compiler optimization settings. To help you make the application code smaller, faster or
balanced between size and speed, fine tune the optimizations according to your application
needs. For more information please refer to your C compiler documentation.
2.3 Peripheral initialization and configuration
This section describes step by step how to initialize and configure a peripheral. The
peripheral is referred to as PPP.
Before configuring a peripheral, its clock must be enabled by calling one of the following
functions:
RCC_AHBPeriphClockCmd(RCC_AHB1Periph_PPPx, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_PPPx, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PPPx, ENABLE);
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 to
initialize one or more PPP instances.
2. Fill the PPP_InitStructure variable with the allowed values of the structure member.
Two solutions are possible:
a. Configure 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 */