All firmware is coded in ANSI-C
Strict ANSI-C for all library peripheral files
Relaxed ANSI-C for projects & Examples files.
PPP is used to reference any peripheral acronym, e.g. TIM for Timer.
Registers & Structures
STM32F10x registers are mapped in the microcontroller address space
FW library registers have the same names as in STM32F10x Datasheet & reference manual.
All registers hardware accesses are performed through a C structures :
Work with only one base address and indirect addressing
Improve code re-use : e.g. the same structure to handle and initialize 3 USARTs.
Common files (map/lib/type) have to be included to the working directory project
To use the peripheral PPPx
stm32f10x_ppp.c and stm32f10x_ppp.h files must be included to the working project
Edit the stm32f10x_conf.h file and uncomment the following lines relatetd to the peripheral that you need to use:
#define _PPP (mandatory)
#define _PPPx (optional, depending on the peripheral)
If you want to debug your application, you have to define the label DEBUG in the stm32f10x_conf.h file :
#define DEBUG
This creates a pointer, in
memory, to the peripheral structure, so debug become easier and dumping
a peripheral variable provides all registers settings.
Include this line in your application source code :
#include “stm32f10x_lib.h”
In the main file , 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.
You have to fill the PPP_InitStructure variable with the allowed values of the structure member.
PPP_InitStructure.member1 = val1;
PPP_InitStructure.member2 = val2;
...
PPP_InitStructure.memberN = valN;
You have to initialize the PPP peripheral by calling the PPP_Init(..) function :
To access the functionality of the PPP peripheral, the user can use a set of dedicated functions.
These functions are specific to the peripheral and for more details refer to STM32F10x Firmware Library User Manual.
Notes :
1) Before configuring a peripheral, you have to enable its clock 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);
2) PPP_DeInit(..) function can be used to set all PPP’s peripheral registers to their reset values:
PPP_DeInit(PPPx);
3) If after peripheral configuration, the user wants to modify one or more peripheral settings he should proceed as following:
PPP_InitStucture.memberX = valX;
PPP_InitStructure.memberY = valY;
PPP_Init(PPPx, &PPP_InitStructure);
Exampe:
// Enable CLK to port ADC1, GPIOC/A, USART1, SPI1
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1
|
RCC_APB2Periph_SPI1, ENABLE);
/* Enable DMA1 clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
/* Fills the RCC_ClockFreq structure with the current frequencies of different on chip clocks (for debug purpose) */
RCC_GetClocksFreq(&RCC_ClockFreq);