1 / 8

STR91X – Library Structure

STR91X – Library Structure. MCD Application. STR91x Software Library Features. STR91x Library - All in Strict ANSI-C - Independent from any SW tool chain - Self documented. STR91x Project template An empty project is provided for each Tool chain Getting Started document

gavin-hale
Download Presentation

STR91X – Library Structure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. STR91X – Library Structure MCD Application

  2. STR91x Software Library Features STR91x Library - All in Strict ANSI-C - Independent from any SW tool chain - Self documented • STR91x Project template • An empty project is provided for each Tool chain • Getting Started document • Start-up files / linker file • STR91x Examples • An example for each STR91x peripheral • Independent from any SW tool chain • Running on STMicroelectronics STR910-Eval board and can be easily tailored to any other hardware

  3. Coding conventions • All software is coded in ANSI-C • Strict ANSI-C for all library peripheral files. • PPPis used to reference any peripheral acronym, e.g. TIM for Timer. • Registers & Structures • STR91x registers : • SW library registers have the same names as in STR91x 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 more Than 4 timers.

  4. Common types and constants • Peripheral API code : • Bit fields / Masks • Peripheral user Structure • Low-level & API functions to perform basic operations offered by the peripheral : e.g. :I2C_ReceiveData() • Global headers (includes all) • Peripheral registers’ addresses : • Organized in structures with a base address • Configuration file • Interrupt functions source code • User application source code • Peripherals pointers initialization if #DEBUG defined Application Layer 91x_it.c 91x_lib.h API Layer 91x_it.h Library Structure application.c 91x_conf.h 91x_map.h 91x_type.h 91x_ppp.h 91x_lib.c 91x_ppp.c Hardware Layer PPP

  5. Using the Library (1) • Common files (map/lib/type) have to be included to the working directory project • To use the peripheral PPPx • 91x_ppp.c and 91x_ppp.h files must be included to the working project • Edit the 91x_conf.h file and uncomment the following lines : • #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 91x_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 <91x_lib.h>

  6. 91x_conf.h #define DEBUG #define _GPIO /* include gpio.h file */ #define _GPIO0 /* use GPIO0 peripheral */ 91x_map.h typedef volatile struct { u8 DR[1021] ; u16 EMISR; ; u32 DDR; ; u16 EMPTY13;; u16 ISR; u16 AMR; .....; u16 EMPTY14; } GPIO_TypeDef; #define GPIO0_BASE (AHB_APB_BRDG0_U + APB_GPIO0_OFST) #ifdef DEBUG #ifdef _GPIO0 EXT GPIO_TypeDef *GPIO0; #endif /* _GPIO0 */ #else /* NON DEBUG */ #define GPIO0 ((GPIO_TypeDef *)GPIO0_BASE) #endif /* DEBUG */ Using the Library (2) • 91x_lib.h #include "91x_type.h" #include "91x_conf.h" #include "91x_map.h" #ifdef _GPIO #include "91x_gpio.h" #endif To be modified by user Do not modify this file Do not modify this file Define _GPIO in 91x_conf.h to include gpio.h in your project • main.c #include "91x_lib.h" int main { #ifdef DEBUG debug(); #endif /* main program*/ } User file Include 91x_lib.h only Pointers to peripherals structures are used in DEBUG mode Initialize peripheral pointers when in DEBUG mode Constants are used in NON DEBUG mode

  7. Using the Library (3) • In the main file , you have to declare a PPP_InitTypeDef structure, e.g: PPP_InitTypeDef PPP_InitStructure; • The PPP_InitStructure is a working variable located in data memory that allows you to initialize one or more instance of PPPs. • You has to fill the PPP_InitStructure variable with the allowed values of the structure member. • Configuration of the whole structure: • PPP_InitStructure.member1 = val1; • PPP_InitStructure.member2 = val2; • ... • PPP_InitStructure.memberN = valN; Note : The previous initialization could be merged in only one line like the following : • PPP_InitTypeDef PPP_InitStructure = { val1, val2, …, valn} • Configuration of few structure’s members: • PPP_StructInit(&PPP_InitStructure); • PPP_InitStructure.memberX = valX; • PPP_InitStructure.memberY = valY;

  8. Using the Library (4) • You have to initialize the PPP peripheral by calling the PPP_Init(..) function : • PPP_Init(PPP, &PPP_InitStructure); • At this stage the PPP peripheral is initialized and can be enabled by making a call to PPP_Cmd(..) function. • PPP_Cmd(PPP, ENABLE); • To access the functionality of the PPP peripheral, the user can use a set of dedicated functions. These functions are specific to the peripheral. Notes : 1) For some peripherals the PPP_Cmd(..) function is not implemented (e.g. Peripheral enabled after receiving the Clock). 2) Before configuring a peripheral, you have to make sure that it’s not under Reset and enable its clock by calling the following functions : SCU_APBPeriphClockConfig(__PPP,ENABLE); SCU_APBPeriphReset(__PPP,DISABLE); 3) PPP_DeInit(..) function can be used to set all PPP’s peripheral registers to their reset values: PPP_DeInit(PPP); 4) 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(PPP, &PPP_InitStructure);

More Related