All firmware is coded in ANSI-C
Strict ANSI-C for all library peripheral files
PPP is used to reference any peripheral acronym, e.g. TIM for Timer.
Registers & Structures
Relaxed ANSI-C for projects & Examples files.
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:
If you want to debug your application, you have to define the label DEBUG in the stm32f10x_conf.h file :
#define _PPP (mandatory)
#define _PPPx (optional, depending on the peripheral)
Include this line in your application source code :
This creates a pointer, in
memory, to the peripheral structure, so debug become easier and dumping
a peripheral variable provides all registers settings.
In the main file , you have to declare a PPP_InitTypeDef structure, e.g:
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;
You have to initialize the PPP peripheral by calling the PPP_Init(..) function :
PPP_InitStructure.member2 = val2;
PPP_InitStructure.memberN = valN;
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.
1) Before configuring a peripheral, you have to enable its clock by calling one of the following functions:
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_PPPx , ENABLE);
2) PPP_DeInit(..) function can be used to set all PPP’s peripheral registers to their reset values:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_PPPx , ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PPPx , ENABLE);
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;
// Enable CLK to port ADC1, GPIOC/A, USART1, SPI1
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1
/* Enable DMA1 clock */
/* Fills the RCC_ClockFreq structure with the current frequencies of different on chip clocks (for debug purpose) */