February 2009 Rev 4 1/303 UM0233 User manual STR91xFA firmware library Introduction About this manual This document is the STR91xFA firmware library user manual. It describes the STR91xFA peripheral firmware library: a collection of routines, data structures and macros that cover the features of each peripheral. This manual is structured as follows: some definitions, document conventions and firmware library rules are provided in Section 1. Section 2 provides a detailed description of the Firmware library: The package content, the installation steps, the library structure and an example on how to use the library. Finally, Sections 3 to 20 describe the firmware library, peripheral configuration structure and functions description for each peripheral in detail. About STR91xFA library The STR91xFA Firmware library is a firmware package consisting of device drivers for all standard STR91xFA peripherals. You can use any STR91xFA device in applications without in-depth study of each peripheral specification. As a result, using this library can save you a lot of the time that you would otherwise spend in coding and also the cost of developing and integrating your application. Each device driver consists of a set of functions covering the functionality of the peripheral. Since all the STR91xFA peripherals and their corresponding registers are memory-mapped, a peripheral can be easily controlled using ‘C’ code. The source code, developed in ‘C’, is fully documented. A basic knowledge of ‘C’ programming is required. The library contains a complete firmware in ‘C’ that can be easily ported to any ARM compatible ‘C’ compiler. www.st.com
303
Embed
STR91xFA firmware library - st.com · STR91xFA firmware library Introduction ... a collection of routines, data structures and macros that cover ... 14.1 SSP register structure ...
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
February 2009 Rev 4 1/303
UM0233User manual
STR91xFA firmware library
Introduction
About this manual
This document is the STR91xFA firmware library user manual. It describes the STR91xFA peripheral firmware library: a collection of routines, data structures and macros that cover the features of each peripheral.
This manual is structured as follows: some definitions, document conventions and firmware library rules are provided in Section 1. Section 2 provides a detailed description of the Firmware library: The package content, the installation steps, the library structure and an example on how to use the library. Finally, Sections 3 to 20 describe the firmware library, peripheral configuration structure and functions description for each peripheral in detail.
About STR91xFA library
The STR91xFA Firmware library is a firmware package consisting of device drivers for all standard STR91xFA peripherals. You can use any STR91xFA device in applications without in-depth study of each peripheral specification. As a result, using this library can save you a lot of the time that you would otherwise spend in coding and also the cost of developing and integrating your application.
Each device driver consists of a set of functions covering the functionality of the peripheral. Since all the STR91xFA peripherals and their corresponding registers are memory-mapped, a peripheral can be easily controlled using ‘C’ code. The source code, developed in ‘C’, is fully documented. A basic knowledge of ‘C’ programming is required.
The library contains a complete firmware in ‘C’ that can be easily ported to any ARM compatible ‘C’ compiler.
The user manual document and the Firmware library use the conventions described in the sections below.
1.1 AbbreviationsThe table below describes the different abbreviations used in this document.
Table 1. List of abbreviations
Acronym Peripheral / unit
ADC Analog-to-Digital Converter
CAN Controller Area Network
SCU System Control Unit
DMA DMA Controller
VIC Vectored Interrupt Controller
GPIO General Purpose I/O Ports
I2C I2C Interface module
RTC Real Time Clock
WIU Wake-Up Interrupt Unit
AHBAPB AHB/APB Bridges
MC 3-phase induction Motor Controller (MC)
FMI Flash Memory Interface
EMI External Memory Interface
SSP Synchronous Serial Peripheral
TIM Standard Timer
UART Universal Asynchronous Receiver Transmitter
WDG Watchdog Timer
Document and library rules UM0233
14/303
The Firmware library uses the following naming conventions:
● PPP is used as reference to any peripheral acronym, e.g. ADC. See the section above for more information on peripheral acronyms.
● System and source/header file names are preceded by ‘91x_’, e.g. 91x_conf.h.
● Constants used in one file are defined within this file. A constant used in more than one file is defined in a header file.
● Registers are considered as constants. Their names are in upper case letters and have in most cases the same acronyms as in the STR91xFA reference manual document.
● Peripheral function names are preceded with the corresponding peripheral acronym in upper case followed by an underscore. The first letter in each word is upper case, e.g. SSP_SendData. Only one underscore is allowed in a function name to separate the peripheral acronym from the rest of the function name.
● Functions for initializing PPP peripheral according to the specified parameters in the PPP_InitTypeDef are named PPP_Init, e.g. TIM_Init.
● Functions for deinitializing PPP peripheral registers to their default reset values are named PPP_DeInit, e.g. TIM_DeInit.
● Functions for filling the PPP_InitTypeDef structure with the reset value of each member are named PPP_StructInit, e.g. UART_StructInit.
● Functions for enabling or disabling the specified PPP peripheral are named PPP_Cmd, e.g. SSP_Cmd.
● Functions for enabling or disabling an interrupt source of the specified PPP peripheral are named PPP_ITConfig, e.g. DMA_ITConfig.
● Functions for enabling or disabling the DMA interface of the specified PPP peripheral are named PPP_DMACmd, e.g. SSP_DMACmd.
● Functions used to configure a peripheral function end with Config, e.g. UART_DTRConfig.
● Functions for checking whether the specified PPP flag is set or not are named PPP_GetFlagStatus, e.g. I2C_GetFlagStatus.
● Functions for clearing a PPP flag are named PPP_ClearFlag, e.g. I2C_ClearFlag.
● Functions for checking whether the specified PPP interrupt has occurred or not are named PPP_GetITStatus, e.g. DMA_GetITStatus.
● Functions for clearing a PPP interrupt pending bit are named PPP_ClearITPendingBit, e.g. WDG_ClearITPendingBit.
UM0233 Document and library rules
15/303
1.2 Coding rulesThe following rules are used in the Firmware library.
● Specific types are defined for variables whose type and size are fixed. These types are defined in the file 91x_type.h:
typedef unsigned long u32; typedef unsigned short u16; typedef unsigned char u8;
typedef signed long s32; typedef signed short s16; typedef signed char s8;
typedef volatile unsigned long vu32; typedef volatile unsigned short vu16; typedef volatile unsigned char vu8;
typedef volatile signed long vs32; typedef volatile signed short vs16; typedef volatile signed char vs8;
● bool type is defined in the file 91x_type.h as:typedef enum{ FALSE = 0, TRUE = !FALSE} bool;
● FlagStatus & ITStatus types are defined in the file 91x_type.h. Two values can be assigned to this variable: SET or RESET.typedef enum{ RESET = 0, SET = !RESET} FlagStatus, ITStatus;
● FunctionalState type is defined in the file 91x_type.h. Two values can be assigned to this variable: ENABLE or DISABLE.typedef enum{ DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
● ErrorStatus type is defined in the file 91x_type.h. Two values can be assigned to this variable: SUCCESS or ERROR.typedef enum { ERROR = 0, SUCCESS = !ERROR} ErrorStatus;
● Pointers to peripherals are used to access the peripheral control registers. Peripheral pointers point to data structures that represent the mapping of the peripheral control registers. A structure is defined for each peripheral in the file 91x_map.h. The example below illustrates the SSP register structure declaration:/*----------------------- Synchronous Serial Peripheral ----------------------*/typedef struct{ vu16 CR0; /* Control Register 1 */
Document and library rules UM0233
16/303
vu16 EMPTY1; vu16 CR1; /* Control Register 2 */ vu16 EMPTY2; vu16 DR; /* Data Register */ vu16 EMPTY3; vu16 SR; /* Status Register */ vu16 EMPTY4; vu16 PR; /* Clock Prescaler Register */ vu16 EMPTY5; vu16 IMSCR; /* Interrupt Mask Set or Clear Register */ vu16 EMPTY6; vu16 RISR; /* Raw Interrupt Status Register */ vu16 EMPTY7; vu16 MISR; /* Masked Interrupt Status Register */ vu16 EMPTY8; vu16 ICR; /* Interrupt Clear Register */ vu16 EMPTY9; vu16 DMACR; /* DMA Control Register */ vu16 EMPTY10;}SSP_TypeDef;
Register names are the register acronyms written in upper case for each peripheral. EMPTYi (i is an integer that indexes the reserved field) replaces a reserved field.
Peripherals are declared in 91x_map.h file. The following example shows the declaration of the SSP peripheral:
To enter debug mode you have to define the label DEBUG in the file 91x_conf.h. Debug mode allows you to see the contents of peripheral registers but it uses more memory space. In both cases SSP0 is a pointer to the first address of SSP0 peripheral.
UM0233 Document and library rules
17/303
The DEBUG variable is defined in the file 91x_conf.h as follows:#define DEBUG 1
DEBUG mode is initialized as follows in the 91x_lib.c file:#ifdef DEBUGvoid debug(void){ ... #ifdef _SSP0 SSP0 = (SSP_TypeDef *)SSP0_BASE; #endif /*_SSP0 */ ...}#endif /* DEBUG*/
To include the SSP peripheral library in your application, define the label _SSP and to access the SSPn peripheral registers, define the label _SSPn, i.e to access the registers of SSP1 peripheral, _SSP1 label must be defined in 91x_conf.h file. _SSP and _SSPn labels are defined in the file 91x_conf.h as follows:
#define _SSP#define _SSPn
Each peripheral has several dedicated registers which contain different flags. Registers are defined within a dedicated structure for each peripheral. Flag definition is adapted to each peripheral case (In almost cases defined in 91x_ppp.h file). Flags are defined as acronyms written in upper case and prefixed by ‘PPP_Flag_’ prefix.
Firmware library UM0233
18/303
2 Firmware library
2.1 Package descriptionThe Firmware library is supplied in one single zip package. The extraction of the zip file will give the one folder "STR91xFWLib\FWLib" containing the following sub-directories:
Figure 1. Firmware library directory structure
2.2 ExamplesThis directory contains for each peripheral sub-directory, the minimum set of files needed torun a typical example on how to use a peripheral:
– Readme.txt: a brief text file describing the example and how to make it work,– 91x_conf.h: the header file to configure the used peripherals and miscellaneous
defines,– 91x_it.c: the source file containing the interrupt handlers (the function bodies may be
empty if not used),– main.c: the example program,
Note: All examples are independent from any software tool chain.
UM0233 Firmware library
19/303
2.3 Library This directory contains all the subdirectories and files that form the core of the library:
● inc sub-directory contains the Firmware library header files that do not need to be modified by the user:
– 91x_type.h: Contains the common data types and enumeration used in all other files,– 91x_map.h: Contains the peripheral memory mapping and register data structures,– 91x_lib.h: Main header file including all other headers, – 91x_ppp.h (one header file per peripheral): contains the function prototypes, data
structures and enumeration.
● src sub-directory contains the Firmware library source files that do not need to be modified by the user:
– 91x_ppp.c (one source file per peripheral): contains the function bodies of each peripheral.
Note: All library files are independent from any software toolchain.
2.4 ProjectThis directory contains a standard template project program that compiles all library files and also all the user modifiable files needed to create a new project:
– 91x_conf.h: The configuration header file with all peripherals defined by default.– 91x_it.c: The source file containing the interrupt handlers (the function bodies are
empty in this template).– main.c: The main program body.
● EWARM, EWARMv5, HiTOP, RIDE, RIDEv7, RVMDK: For each toolchain usage, refer to the Readme.txt file available in the same sub-directory.
Firmware library UM0233
20/303
2.5 File descriptionThe following table enumerates and describes the different files used in the Firmware library.
Table 2. Library files
File name Description
91x_conf.hParameter configuration file. It should be modified by the user to specifyseveral parameters to interface with the library before running any application.
You can enable or disable peripherals if you use the template.
main.c The main example program body.
91x_it.c
Peripheral interrupt functions file. You can modify it by including the code ofinterrupt functions used in your application. In case of multiple interruptrequests mapped on the same interrupt vector, the function polls the interruptflags of the peripheral to establish the exact source of the interrupt. Thenames of these functions are already provided in the Firmware library.
91x_lib.hHeader file including all the peripheral header files. It is the only file to beincluded in the user application to interface with the library.
91x_lib.c
Debug mode initialization file. It includes the definition of variable pointerseach one pointing to the first address of a specific peripheral and the definitionof one function called when you choose to enter debug mode. This functioninitializes the defined pointers.
91x_map.hThis file implements memory mapping and physical registers addressdefinition for both development and debug modes. This file is supplied with allperipherals.
91x_type.hCommon declarations file. It includes common types and constants used by allperipheral drivers.
91x_ppp.c Driver source code file of PPP peripheral written in C language.
91x_ppp.hHeader file of PPP peripheral. It includes the definition of PPP peripheralfunctions and variables used within these functions.
UM0233 Firmware library
21/303
The Firmware library architecture and file inclusion relationship are shown in Figure 2.
Figure 2. Firmware library file architecture
Each peripheral has a source code file 91x_ppp.c and a header file 91x_ppp.h. The 91x_ppp.c file contains all the firmware functions required to use the corresponding peripheral. A single memory mapping file 91x_map.h is supplied for all peripherals. This file contains all the register declarations for both development and debug modes.
The header file 91x_lib.h includes all the peripheral header files. This is the only file that needs to be included in the user application to interface with the library.
Application layer
API layer
Hardware layer
Appication.c
91x_conf.h
91x_it.c
91x_lib.h
91x_map.h 91x_type.h91x_ppp.h
91x_ppp.c 91x_Lib.c
ppp
Firmware library UM0233
22/303
2.6 How to use the libraryThis section describes step-by-step how to configure and initialize a PPP peripheral.
■ In your main application file, 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 toinitialize one or more PPP instances.
■ Fill the PPP_InitStructure variable with the allowed values of the structure member.
There are two ways of doing this:– Configuration of the whole structure: in this case you should proceed as follows:PPP_InitStructure.member1 = val1;
PPP_InitStructure.member2 = val2; PPP_InitStructure.memberN = valN; /* where N is the number of the structure members */
Note: The previous initialization could be merged in only one line like the following:PPP_InitTypeDef PPP_InitStructure = { val1, val2, …, valN}
This reduces and optimizes code size.
– Configuration of a few members of a structure: in this case you should modify the
PPP_InitStructure variable that has been already filled by a call to thePPP_StructInit(..) function. This ensures that the other members of thePPP_InitStructure variable have appropriate values (in most case their defaultvalues).
PPP_StructInit(&PPP_InitStructure); PPP_InitStructure.memberX = valX; PPP_InitStructure.memberY = valY; /* where X and Y are the only members that you want to configure */
■ 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 (if applicable) by makinga call to PPP_Cmd(..) function.PPP_Cmd(PPP, ENABLE);
To use the PPP peripheral, you can use a set of dedicated functions. These functions arespecific to the peripheral and for more details refer to Section 3 on page 23.
Note: 1 Before configuring a peripheral, you have to enable its clock by calling the following function: SCU_APBPeriphClockConfig(__PPP, ENABLE); /* For APB Peripheral */
OR: SCU_AHBPeriphClockConfig(__PPP, ENABLE); /* For AHB Peripheral */
2 PPP_DeInit(..) function can be used to set all PPP peripheral registers to their reset values: PPP_DeInit(PPP);
3 If after peripheral configuration, you want to modify one or more peripheral settings you should 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);
UM0233 Peripheral firmware overview
23/303
3 Peripheral firmware overview
The following chapters describe each peripheral Firmware library in detail. The related functions are fully documented. An example of use of the function is given and some important considerations are also provided.
Functions are described in the format below:
Function name The name of the peripheral function
Function prototype Prototype declaration
Behavior description Brief explanation of how the functions are executed
Input parameter {x} Description of the input parameters
Output parameter {x} Description of the output parameters
Return Value Value returned by the function
Required preconditions Requirements before calling the function
Called functions Other library functions called by the function
Flash memory interface (FMI) UM0233
24/303
4 Flash memory interface (FMI)
The Flash Memory Interface of the STR91xFA contains two banks( with a total capacity of 256+32 ,512+32,1024+128 or 2048+128Kbytes) can be 32-bit burst read accessed and 16-bit write accessed.
4.1 FMI register structure
4.1.1 FMI register structure
The FMI register structure FMI_TypeDef is defined in the 91x_map.h file as follows:typedef struct{ vu32 BBSR; vu32 NBBSR; vu32 EMPTY1; vu32 BBADR; vu32 NBBADR; vu32 EMPTY2; vu32 CR; vu32 SR; vu32 BCE5ADDR;} FMI_TypeDef;
The following table presents the FMI registers:
Table 3. FMI registers
Register Description
BBSR Boot Bank Size Register
NBBSR Non-Boot Bank Size Register
BBADR Boot Bank Base Address Register
NBBADR Non-Boot Bank Base Address Register
CR Control Register
SR Status Register
BCE5ADDR BC Fifth Entry Target Address Register
UM0233 Flash memory interface (FMI)
25/303
The FMI interface are declared in the same file:#ifndef EXT #define EXT extern#endif /* EXT */
When debug mode is used, FMI pointer is initialized in 91x_lib.c file:#ifdef _FMI FMI = (FMI_TypeDef *)FMI_BASE#endif /* _FMI */
_FMI must be defined, in 91x_conf.h file, to access the peripheral registers as follows:...#define _FMI...
Flash memory interface (FMI) UM0233
26/303
4.2 Firmware library functionsThe following table enumerates the different functions of the FMI library.
Table 4. FMI library functions
Function name Description
FMI_BankRemapConfig Configures the sizes and addresses of bank 0 and bank 1.
FMI_Config Configures the FMI.
FMI_EraseSector Erases a sector.
FMI_EraseBank Erases a bank.
FMI_WriteHalfWord Writes a halfword to a Flash memory address.
FMI_WriteOTPHalfWord Writes a halfword to an OTP sector address.
FMI_ReadWord Reads the corresponding data.
FMI_ReadOTPData Reads data from the OTP sector.
FMI_GetFlagStatus Checks whether the specified FMI flag is set or not.
FMI_GetReadWaitStateValue Gets the current Read wait state value.
FMI_GetWriteWaitStateValue Gets the current write wait state value.
FMI_SuspendEnable Enables the Suspend command.
FMI_ResumeEnable Resumes the suspended command.
FMI_ClearFlag Clears the FMI flags on the corresponding bank.
FMI_WriteProtectionCmd Enables or disables the write protection for the specified sector.
FMI_WaitForLastOperationWaits until the last Operation (Write halfword, Erase sector and Erase bank) completion.
FMI_ReadRSIGDataReads the Electronic Signature stored in the user configuration sector of Bank 1.
UM0233 Flash memory interface (FMI)
27/303
4.2.1 FMI_BankRemapConfig
Function name FMI_BankRemapConfig
Function prototypevoid FMI_BankRemapConfig(u8 FMI_BootBankSize, u8 FMI_NonBootBankSize, u32 FMI_BootBankAddress, u32 FMI_NonBootBankAddress)
Behavior description Configures the addresses and sizes of bank 0 and bank 1.
Input parameter1FMI_BootBankSize: specifies the boot bank size.
Refer to Table 5: FMI_BootBankSize parameter values for the allowed values of this parameter.
Input parameter2FMI_NonBootBankSize: specifies the non boot bank size.
Refer to Table 6: FMI_NonBootBankSize parameter values for the allowed values of this parameter.
Input parameter3 FMI_BootBankAddress: specifies the boot bank address.
Input parameter4 FMI_BootBankAddress: specifies the non boot bank address.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Table 5. FMI_BootBankSize parameter values
Value Meaning
0 32 KBytes
1 64 KBytes
2 128 KBytes
3 256 KBytes
4 512 KBytes
... ...
0xB 64 MBytes
Table 6. FMI_NonBootBankSize parameter values
Value Meaning
0 8 KBytes
1 16 KBytes
2 32 KBytes
3 64 KBytes
... ...
0xD 64 MBytes
Flash memory interface (FMI) UM0233
28/303
Example:
/*To configure bank 1 (32KByte) at address 0x0 and bank 0 (512KBytes) at address 0x80000 , where bank 0 is the boot bank*/FMI_BankConfig(0x4, 0x2, 0x80000, 0x0);
Note: 1 When bank 1 is hardware remapped to address 0 (bank 1 is the boot bank), in the 91x_conf.h file, the //#define Boot_Bank_1 line should be uncommented.
2 In the same file, you have also to uncomment either //#define Flash_512KB_256KB or //#define Flash_2MB_1MB lines to select your Flash size.
Input parameter 1FMI_ReadWaitState: specifies the read wait state value.
Refer to Table 7: FMI_ReadWaitState parameter values” for the allowed values of this parameter.
Input parameter 2FMI_WriteWaitState: specifies the read wait state value.
Refer to Table 8: FMI_WriteWaitState parameter values” for the allowed values of this parameter.
Input parameter 3FMI_PWD: specifies the power down mode status. Refer to Table 9: FMI_PWD parameter values” for the allowed values of this parameter.
Input parameter 4FMI_LVDEN: specifies the low voltage detector mode status.
Refer to Table 10: FMI_LVDEN parameter values” for the allowed values of this parameter.
Input parameter 5FMI_FreqRange: specifies the working frequency range. Refer to Table 11: FMI_FreqRange parameter values” for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Table 7. FMI_ReadWaitState parameter values
FMI_ReadWaitState Meaning
FMI_READ_WAIT_STATE_1 1 read wait state
FMI_READ_WAIT_STATE_2 2 read wait states
FMI_READ_WAIT_STATE_3 3 read wait states
Table 8. FMI_WriteWaitState parameter values
FMI_WriteWaitState Meaning
FMI_WRITE_WAIT_STATE_0 0 write wait state
FMI_WRITE_WAIT_STATE_1 1 write wait states
Table 9. FMI_PWD parameter values
FMI_PWD Meaning
FMI_PWD_ENABLE Enable the PWD
FMI_PWD_DISABLE Disable the PWD
Flash memory interface (FMI) UM0233
30/303
Example:/*To configure the FMI as follows: 2 read wait states, 1 write wait state, PWD enabled, LVD enabled and a low working frequency*/FMI_Config(FMI_READ_WAIT_STATE_2, FMI_WRITE_WAIT_STATE_1, FMI_PWD_ENABLE, FMI_LVD_ENABLE, FMI_FREQ_LOW);
Table 10. FMI_LVDEN parameter values
FMI_LVDEN Meaning
FMI_LVD_ENABLE Enable the LVD
FMI_LVD_DISABLE Disable the LVD
Table 11. FMI_FreqRange parameter values
FMI_FreqRange Meaning
FMI_FREQ_LOW Low working frequency (up to 66 MHz)
FMI_FREQ_HIGH High working frequency (above 66 MHz)
UM0233 Flash memory interface (FMI)
31/303
4.2.3 FMI_EraseSector
Example:/*To erase sector 3 in bank 0*/u8 FMI_Timeout_Status;FMI_EraseSector(FMI_B0S3);FMI_Timeout_Status = FMI_WaitForLastOperation(FMI_BANK_0);
Function name FMI_EraseSector
Function prototype void FMI_EraseSector(vu32 FMI_Sector)
Behavior description Erases a sector.
Input parameterFMI_Sector: specifies the sector to be erased.
Refer to Table 12 and Table 13 for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Table 12. FMI_Sector values for devices with 1 MByte or 2 MByte internal Flash
Value Meaning
FMI_B0S0...FMI_B0S31 FMI bank 0 sector 0...FMI bank 0 sector 31.
FMI_B1S0...FMI_B1S7 FMI bank 1sector 0...FMI bank 1 sector 7.
Table 13. FMI_Sector values for devices with 256 KByte or 512 KByte internal Flash
Value Meaning
FMI_B0S0...FMI_B0S7 FMI bank 0 sector 0...FMI bank 0 sector 7.
FMI_B1S0...FMI_B1S3 FMI bank 1sector 0...FMI bank 1 sector 3.
Flash memory interface (FMI) UM0233
32/303
4.2.4 FMI_EraseBank
Example:/*To erase bank 0*/u8 FMI_Timeout_Status;FMI_EraseBank(FMI_BANK_0);FMI_Timeout_Status = FMI_WaitForLastOperation(FMI_BANK_0);
4.2.5 FMI_WriteHalfWord
Example:/*To write the data 0x1234 to the address 0x4000*/u8 FMI_Timeout_Status;FMI_WriteHalfWord(0x4000,0x1234);FMI_Timeout_Status = FMI_WaitForLastOperation(FMI_BANK_0);
Function name FMI_EraseBank
Function prototype void FMI_EraseBank(vu32 FMI_Bank)
Behavior description Erases a bank.
Input parameterFMI_Bank: specifies the bank to be erased.
Refer to Table 14 for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Table 14. FMI_Bank parameter values
Value Meaning
FMI_BANK_0 FMI bank 0
FMI_BANK_1 FMI bank 1
Function name FMI_WriteHalfWord
Function prototype void FMI_WriteHalfWord(u32 FMI_Address, u16 FMI_Data)
Behavior description Writes a halfword to a Flash memory address.
Input parameter1FMI_Address: specifies the address offset where the data are to be written.
Input parameter2 FMI_Data: the data to be written.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
UM0233 Flash memory interface (FMI)
33/303
4.2.6 FMI_WriteOTPHalfWord
Example:/*To write the data 0x1234 to the LSB of the word 2*/u8 FMI_Timeout_Status;FMI_WriteOTPHalfWord(FMI_OTP_LOW_HALFWORD_2,0x1234);FMI_Timeout_Status = FMI_WaitForLastOperation(FMI_BANK_1);
Function name FMI_WriteOTPHalfWord
Function prototype void FMI_WriteOTPHalfWord(u8 FMI_OTPHWAddress, u16 FMI_OTPData)
Behavior description Writes a halfword to the specified OTP sector address.
Input parameter1
FMI_OTPHWAddress: specifies the address offset where the data is to be written.Refer to Table 15: FMI_OTPHWAddress parameter values” for the allowed values of this parameter.
Input parameter2 FMI_OTPData: the data to be written.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Table 15. FMI_OTPHWAddress parameter values
Value Meaning
FMI_OTP_LOW_HALFWORD_0 FMI OTP low halfword 0
FMI_OTP_HIGH_HALFWORD_0 FMI OTP high halfword 0
FMI_OTP_LOW_HALFWORD_1 FMI OTP low halfword 1
FMI_OTP_HIGH_HALFWORD_1 FMI OTP high halfword 1
FMI_OTP_LOW_HALFWORD_2 FMI OTP low halfword 2
FMI_OTP_HIGH_HALFWORD_2 FMI OTP high halfword 2
FMI_OTP_LOW_HALFWORD_3 FMI OTP low halfword 3
FMI_OTP_HIGH_HALFWORD_3 FMI OTP high halfword 3
FMI_OTP_LOW_HALFWORD_4 FMI OTP low halfword 4
FMI_OTP_HIGH_HALFWORD_4 FMI OTP high halfword 4
FMI_OTP_LOW_HALFWORD_5 FMI OTP low halfword 5
FMI_OTP_HIGH_HALFWORD_5 FMI OTP high halfword 5
FMI_OTP_LOW_HALFWORD_6 FMI OTP low halfword 6
FMI_OTP_HIGH_HALFWORD_6 FMI OTP high halfword 6
FMI_OTP_LOW_HALFWORD_7 FMI OTP low halfword 7
FMI_OTP_HIGH_HALFWORD_7 FMI OTP high halfword 7
Flash memory interface (FMI) UM0233
34/303
4.2.7 FMI_ReadWord
Example:/*To read the data contained in the address 0x6000*/u32 DATA;DATA = FMI_ReadWord(0x6000);
4.2.8 FMI_ReadOTPData
Function name FMI_ReadWord
Function prototype u32 FMI_ReadWord(u32 FMI_Address)
Behavior description Reads the corresponding data.
Input parameter FMI_Address: specifies the address of the word to be read.
Output parameter None
Return parameter The data contained in the specified address.
Required preconditions ...
Called functions None
Function name FMI_ReadOTPData
Function prototype u32 FMI_ReadOTPData(u8 FMI_OTPAddress)
Behavior description Reads data from the OTP sector.
Input parameterFMI_OTPAddress: specifies the address of the data to be read.
Refer to Table 16: FMI_OTPAddress parameter values” for the allowed values of this parameter.
Output parameter None
Return parameter The data to be read from the OTP sector.
Required preconditions ...
Called functions None
Table 16. FMI_OTPAddress parameter values
Value Meaning
FMI_OTP_WORD_0 FMI OTP word 0
FMI_OTP_WORD_1 FMI OTP word 1
FMI_OTP_WORD_2 FMI OTP word 2
FMI_OTP_WORD_3 FMI OTP word 3
FMI_OTP_WORD_4 FMI OTP word 4
FMI_OTP_WORD_5 FMI OTP word 5
FMI_OTP_WORD_6 FMI OTP word 6
FMI_OTP_WORD_7 FMI OTP word 7
UM0233 Flash memory interface (FMI)
35/303
Example:/*To read the 2nd word from the OTP sector*/vu16 OTP_Data;OTP_Data= FMI_ReadOTPData(FMI_OTP_WORD_2);
4.2.9 FMI_GetFlagStatus
Example:/*To get the FMI program status for bank 1*/FlagStatus FMI_Flag;FMI_Flag = GetFlagStatus(FMI_FLAG_PS, FMI_BANK_1);
Function name FMI_GetFlagStatus
Function prototype FlagStatus FMI_GetFlagStatus(u8 FMI_Flag, vu32 FMI_Bank)
Behavior description Checks whether the specified FMI flag is set or not.
Input parameter1FMI_Flag: specifies the flag to check. Refer to Table 17: FMI_Flag parameter values for the allowed values of this parameter.
Input parameter2FMI_Bank: specifies the corresponding bank.
Refer to Table 14: FMI_Bank parameter values on page 32 for the allowed values of this parameter.
Output parameter None
Return parameter The new state of FMI_Flag (SET or RESET).
Required preconditions ...
Called functions None
Table 17. FMI_Flag parameter values
Value Meaning
FMI_FLAG_SPS Sector protection status
FMI_FLAG_PSS Program suspend status
FMI_FLAG_PS Program status
FMI_FLAG_ES Erase status
FMI_FLAG_ESS Erase suspend status
FMI_FLAG_PECS FPEC status
Flash memory interface (FMI) UM0233
36/303
4.2.10 FMI_GetReadWaitStateValue
Example:/*To get the current read wait state value*/u16 FMI_ReadWaitState;FMI_ReadWaitState = FMI_GetReadWaitStateValue();
4.2.11 FMI_GetWriteWaitStateValue
Example:/*To get the current write wait state value*/u16 FMI_WriteWaitState;FMI_WriteWaitState = FMI_GetWriteWaitStateValue();
Function name FMI_GetReadWaitStateValue
Function prototype u16 FMI_GetReadWaitStateValue(void)
Behavior description Gets the current read wait state value.
Input parameter None
Output parameter None
Return parameter The current read wait state value.
Required preconditions ...
Called functions None
Function name FMI_GetWriteWaitStateValue
Function prototype u16 FMI_GetWriteWaitStateValue(void)
Behavior description Gets the current write wait state value.
Input parameter None
Output parameter None
Return parameter The current write wait state value.
Required preconditions ...
Called functions None
UM0233 Flash memory interface (FMI)
37/303
4.2.12 FMI_SuspendEnable
Example:/*To suspend the current command in the bank 1*/FMI_SuspendEnanble(FMI_BANK_1);
4.2.13 FMI_ResumeEnable
Example:/*To resume the suspended command in the bank 1*/FMI_ResumeEnanble(FMI_BANK_1);
Function name FMI_SuspendEnable
Function prototype void FMI_SuspendEnable(vu32 FMI_Bank)
Behavior description Enables the Suspend command.
Input parameterFMI_Bank: specifies the bank to be suspended.
Refer to Table 14: FMI_Bank parameter values on page 32 for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Function name FMI_ResumeEnable
Function prototype void FMI_ResumeEnable(vu32 FMI_Bank)
Behavior description Resumes the suspended command.
Input parameterFMI_Bank: specifies the suspended bank.Refer to Table 14: FMI_Bank parameter values on page 32 for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Flash memory interface (FMI) UM0233
38/303
4.2.14 FMI_ClearFlag
Example:/*To clear the status register on bank 0*/FMI_ClearFlag(FMI_BANK_0);
4.2.15 FMI_WriteProtectionCmd
Example:/*To disable the write protection of the sector 3*/FMI_WriteProtectionCmd(FMI_B0S3, DISABLE);
Function name FMI_ClearFlag
Function prototype void FMI_ClearFlag(vu32 FMI_Bank)
Behavior description Clears the FMI flags in the corresponding bank.
Input parameterFMI_Bank: specifies the corresponding bank.
Refer to Table 14: FMI_Bank parameter values on page 32 for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Function name FMI_WriteProtectionCmd
Function prototype void FMI_WrieProtectionCmd(vu32 FMI_Sector, FunctionalState FMI_NewState)
Behavior description Enables or disables the write protection for a specified sector.
Input parameter1FMI_Sector: specifies the sector to be protected or unprotected.Refer to Table 12 and Table 13 on page 31 for the allowed values of this parameter.
Input parameter2NewState: specifies the protection status.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
UM0233 Flash memory interface (FMI)
39/303
4.2.16 FMI_WaitForLastOperation
Example:/*To wait until the write operation completion*/u8 FMI_Timeout_Status;FMI_WriteProtectionCmd(FMI_B1S0, DISABLE);FMI_WriteHalfWord(0x80000,0x1234);FMI_Timeout_Status = FMI_WaitForLastOperation(FMI_BANK_1);
Function name FMI_WaitForLastOperation
Function prototype u8 FMI_WaitForLastOperation(vu32 FMI_Bank)
Behavior descriptionWaits for the last operation (Write halfword, Write OTP halfword, Erase sector and Erase bank) to be completed.
Input parameterFMI_Bank: specifies the corresponding bank. Refer to Table 14: FMI_Bank parameter values on page 32 for the allowed values of this parameter.
Output parameter None
Return parameterThe timeout status. This parameter can be one of the following values:
– FMI_TIME_OUT_ERROR: Timeout error occurred.– FMI_NO_TIME_OUT_ERROR: No timeout error.
Required preconditions ...
Called functions None
Flash memory interface (FMI) UM0233
40/303
4.2.17 FMI_ReadRSIGData
Example:/*To read the Flash configuration register for 512Kb Flash*/u16 FMI_ConfigRegister;FMI_ConfigRegister = FMI_ReadRSIGData(FMI_ReadRSIGData_5);
Function name FMI_ReadRSIGData
Function prototype u32 FMI_ReadRSIGData(u8 FMI_LSB_RSIGAddress)
Behavior descriptionRead the Electronic Signature stored in the user configuration sector of Bank 1.
Input parameter1FMI_LSB_RSIGAddress : Specifies the low byte of the address to select the register. Refer to Table 18: FMI_LSB_RSIGAddress parameter values for the allowed values of this parameter.
Output parameter None
Return parameter The requested RSIG data.
Required preconditions ...
Called functions None
Table 18. FMI_LSB_RSIGAddress parameter values
Value Meaning
FMI_ReadRSIGData_0 Manufacturer Code
FMI_ReadRSIGData_1 Device Code
FMI_ReadRSIGData_2 Die Revision Code
FMI_ReadRSIGData_3Protection Level 2 Register for 512KB Flash or Protection Level 1 Register (sectors of bank0) for 2MB flash.
FMI_ReadRSIGData_4Protection Level 1 Register for 512KB Flash
or Protection Level 1 Register (sectors of bank1) for 2MB flash.
FMI_ReadRSIGData_5Protection Status Register(sectors of bank0) for 2MB flash or Flash Configuration Register for 512KB flash.
FMI_ReadRSIGData_6Protection Status Register (sectors of bank1) (available only for 2MB flash)
FMI_ReadRSIGData_7Flash Configuration Register(available only for 2MB flash).
UM0233 External memory interface (EMI)
41/303
5 External memory interface (EMI)
The EMI provides an interface between the AHB system bus and external memory devices supporting up to four memory banks that you can configure independently. Each memory bank supports: SRAM (asynchronous memory) , PSRAM (synchronous memory), ROM and Flash.
You can configure each memory bank to use 8-bit non multiplexed or 16-bit multiplexed data paths.
You can configure the EMI memory banks to support:
There are 4 banks in the EMI interface, so there are 28 registers without taking into account EMI_CCR and SCU registers used to configure the EMI clock and GPIO mode for EMI bus.
Table 19. EMI registers
Register Description
EMI_ICRx Bankx Idle Cycle Control Register
EMI_RCRx Bankx Read Wait State Control Register
EMI_WCRx Bankx Write Wait State Control Register
EMI_OECRx Bankx Output Enable Assertion Delay Control Register
EMI_WECRx Bankx Write Enable Assertion Delay Control Register
External memory interface (EMI) UM0233
42/303
The EMI interface is declared in the same file:
#ifndef EXT #define EXT extern#endif /* EXT */
#define AHB_EMI_U (0x74000000) /* EMI UnBuffered Space */#define AHB_EMI_B (0x64000000) /* EMI Buffered Space */
#define AHB_EMIB3_OFST (0x00000040) /* Offset of EMI bank3 */#define AHB_EMIB2_OFST (0x00000020) /* Offset of EMI bank2 */#define AHB_EMIB1_OFST (0x00000000) /* Offset of EMI bank1 */#define AHB_EMIB0_OFST (0x000000E0) /* Offset of EMI bank0 */...#ifndef Buffered #define EMI_BASE (AHB_EMI_U)...#else /* Buffered */
This member controls the number of bus turnaround cycles added between read and write accesses. It is coded with 4 bits, the minimum value is 0x3.
EMI_Bank_WSTRD
For SRAM and ROM, this member controls the number of wait states for read accesses, and the external wait assertion timing for reads. For burst ROM, it controls the number of wait states for the first read access only. It is coded with 5 bits (32 values: 0x01, 0x02, 0x03, .... 0x1F)
EMI_Bank_WSTWR
For SRAM, this member controls the number of wait states for write accesses, and the external wait assertion timing for writes.
It does not apply to read-only devices such as ROM.
It is coded with 5 bits (32 values: 0x01, 0x02, 0x03, .... 0x1F)
EMI_Bank_WSTROEN
External memory interface (EMI) UM0233
46/303
Output enable assertion delay from chip select assertion.
It is coded with 4 bits (16 values: 0x01, 0x02, 0x03, ....0xF)
EMI_Bank_WSTWEN
Write Enable Assertion Delay From Chip Select Assertion.
It is coded with 4 bits (16 values: 0x01, 0x02, 0x03, ....0xF)
EMI_Bank_BRDCR
This member controls the number of wait states for burst read accesses after the first read.
It is coded with 5 bits (32 values: 0x01, 0x02, 0x03, .... 0x1F).
EMI_Burst_and_PageModeRead_TransferLength
This member controls the page and burst read transfer length.
It can be one of the following values:
EMI_Burst_and_PageModeRead_Selection
Select or deselect burst and page mode read.
This member can be one of the following values:
EMI_Bank_MemWidth
This member controls the memory width.
This member can be one of the following values:
EMI_PageModeRead_TransferLength Value Meaning
EMI_Read_4Data 0x00000000 4 -transfer burst
EMI_Read_8Data 0x00000400 8-transfer burst
EMI_Read_16Data (only for burst mode) 0x00000800 16-transfers burst
EMI_Read_Continuous (only for burst mode) 0x00000C00 Continuous (synchronous only)
EMI_PageModeRead_Selection Value Meaning
EMI_NormalMode 0x00000000 Normal Mode
EMI_Burst_and_PageModeRead 0x00000100 Page and burst Mode Read
EMI_Bank_MemWidth Value Meaning
EMI_Width_Byte 0x00000000 8-bit width
EMI_Width_HalfWord 0x00000010 16-bit width
UM0233 External memory interface (EMI)
47/303
EMI_Bank_WriteProtect
This member controls the write protection feature.
This member can be one of the following values:
EMI_BurstModeWrite_TransferLength
This member controls the burst write transfer length.
EMI_BurstModeWrite_Selection
Select or deselect burst mode write.
This member can be one of the following values:
EMI_AccessRead_Support
This member controls the access read support.
This member can be one of the following values:
EMI_AccessWrite_Support
This member controls the access read support.
This member can be one of the following values:
EMI_Bank_WriteProtect Value Meaning
EMI_Bank_NonWriteProtect 0x00000000 No write protection,
EMI_Bank_WriteProtection 0x00000008 Bank is write protected.
Function prototype void EMI_StructInit(EMI_InitTypeDef* EMI_InitStruct)
Behavior description Fills each EMI_InitStruct member with its reset value.
Input parameterEMI_InitStruct: pointer to a EMI_InitTypeDef structure which will be initialized.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name EMI_BCLKCmd
Function prototype void EMI_BCLKCmd(FunctionalState NewState)
Behavior description Enable or Disable the activation of BCLK clock (LFBGA only).
Input parameter NewState : ENABLE or DISABLE
Output parameter None
Return parameter None
Required preconditions None
Called functions None
System control unit (SCU) UM0233
50/303
6 System control unit (SCU)
The System control unit (SCU) provides the control logic for the STR91xFA power, reset and clocks, also it controls a large number of miscellaneous features.
6.1 Register structure
6.1.1 SCU register structure
The SCU register structure SCU_TypeDef is defined in the 91x_map.h file as follows:typedef struct{ vu32 CLKCNTR; /* Clock Control Register */ vu32 PLLCONF; /* PLL Configuration Register */ vu32 SYSSTATUS; /* System Status Register */ vu32 PWRMNG; /* Power Management Register */ vu32 ITCMSK; /* Interrupt Mask Register */ vu32 PCGR0; /* Peripheral Clock Gating Register 0 */ vu32 PCGR1; /* Peripheral Clock Gating Register 1 */ vu32 PRR0; /* Peripheral Software Reset Register 0 */
When debug mode is used, SCU pointer is initialized in 91x_lib.c file:#ifdef _SCU SCU = (SCU_TypeDef *)SCU_BASE#endif /* _SCU */
_SCU must be defined, in 91x_conf.h file, to access the peripheral registers as follows:#define _SCU
...
UM0233 System control unit (SCU)
53/303
6.2 Firmware library functions
Table 22. SCU library functions
Function name Description
SCU_MCLKSourceConfig Selects the Master clock source: OSC, PLL, or RTC
SCU_PLLFactorsConfig Configures the PLL factors M,N and P
SCU_PLLCmd Enables or disables the PLL
SCU_RCLKDivisorConfig Configures the RCLK divisor: 1,2,4,8,16 or 1024
SCU_HCLKDivisorConfig Configures the HCLK divisor: 1,2 or 4
SCU_PCLKDivisorConfig Configures the PCLK divisor: 1,2,4 or 8
SCU_FMICLKDivisorConfig Configures the FMI clock divisor: 1 or 2
SCU_EMIBCLKDivisorConfig Configures the EMI bus clock divisor : 1 or 2
SCU_BRCLKDivisorConfig Selects the Baud Rate clock divisor: 1 or 2
SCU_TIMExtCLKCmd Enables or disables the TIMx clock source
SCU_USBCLKConfig Selects the USBClock source: external 48MHz, MCLK or MCLK/2
SCU_PHYCLKConfig Enables or disables the output PHY clock
SCU_APBPeriphClockConfig Enables or disables the APB peripheral clocks
SCU_AHBPeriphClockConfig Enables or disables the AHB peripheral clocks
SCU_APBPeriphIdleConfig Enables or disables the APB peripheral clocks during Idle mode
SCU_AHBPeriphIdleConfig Enables or disables the AHB peripherals clocks during Idle mode
SCU_APBPeriphDebugConfigEnables or disables the APB peripherals clocks during debug mode
SCU_AHBPeriphDebugConfig Enables or disables AHB peripheral clocks during debug mode
SCU_APBPeriphReset Enables or disables Reset state for APB peripherals
SCU_AHBPeriphReset Enables or disables Reset state for AHB peripherals
SCU_EMIModeConfig Configures EMI mode : Multiplexed or Demultiplexed mode
SCU_EMIALEConfig Configures EMI ALE signal length and polarity
SCU_GetPLLFreqValue Gets the current PLL frequency value (unit = KHz)
SCU_GetMCLKFreqValue Gets the current MCLK frequency value (unit = KHz)
SCU_GetHCLKFreqValue Gets the current HCLK frequency value (unit = KHz)
SCU_GetPCLKFreqValue Gets the current PCLK frequency value (unit = KHz)
SCU_GetRCLKFreqValue Gets the current RCLK frequency value (unit = KHz)
SCU_WakeUpLineConfig Configures an external interrupt as wake-up line
SCU_SpecIntRunModeConfig Enables or disables the Special interrupt Run mode
SCU_EnterIdleMode Puts the MCU in Idle mode
SCU_EnterSleepMode Puts the MCU in Sleep mode
SCU_UARTIrDASelect Selects UARTx operation : UART or IrDA
System control unit (SCU) UM0233
54/303
Note: The SCU_GPIOOUT, SCU_GPIOIN, SCU_GPIOTYPE, SCU_GPIOEMI and SCU_GPIOANA registers are not supported by the SCU library functions, they are supported by the GPIO driver functions.
6.2.1 SCU_MCLKSourceConfig
SCU_PFQBCCmd Enables or disables PFQBC
SCU_ITConfig Enables or disables SCU interrupts
SCU_GetFlagStatus Gets a flag status
SCU_ClearFlag Clears a status flag
SCU_EMIByte_Select_Pinconfig Enable or Disable the Byte selection pins behaviour(LFBGA only)
SCU_EMIclock_Pinconfig Enable or Disable the BCLK pin clock driving (LFBGA only)
Table 22. SCU library functions
Function name Description
Function name SCU_MCLKSourceConfig
Function prototype ErrorStatus SCU_MCLKSourceConfig(u32 MCLK_Source)
Behavior description Selects the MCLK clock source: OSC, RTC, or PLL
Input parameterMCLK_Source
Refer to Table 23: MCLK_Source parameter values for the allowed values of this parameter.
Output parameter None
Return parameterErrorStatus: ERROR or SUCCESS
– Function returns ERROR when selecting the PLL clock as MCLK source while PLL is either disabled or not locked.
Required preconditionsWhen selecting the PLL as MCLK clock source, make sure that the PLL is enabled and locked, you can do this using the SCU_PLLCmd(ENABLE) function.
Called functions None
Table 23. MCLK_Source parameter values
Value Meaning
SCU_MCLK_PLL MCLK source = PLL clock
SCU_MCLK_RTC MCLK source = RTC clock
SCU_MCLK_OSC MCLK source = Oscillator clock
UM0233 System control unit (SCU)
55/303
6.2.2 SCU_PLLFactorsConfig
Note: This function disables the PLL before programming the PLL factors. To enable the PLL use the SCU_PLLCmd(ENABLE) function after programming the PLL factors.
6.2.3 SCU_PLLCmd
Note: After enabling the PLL, the PLL lock bit is polled to ensure that the PLL is locked before exiting the function.
Before disabling the PLL a “security” delay is inserted, this to guarantee that the system clock has already switched to OSC or RTC before disabling the PLL.
Function name SCU_PLLFactorsConfig
Function prototype ErrorStatus SCU_PLLFactorsConfig(u8 PLLN, u8 PLLM, u8 PLLP)
Behavior description Configures the PLL factors
Input parameter1 PLLN: PLL Feedback divider
Input parameter2 PLLM: PLL Pre-divider
Input parameter3 PLLP: PLL Post-divider
Output parameter None
Return parameterErrorStatus: ERROR or SUCCESS
– Function returns ERROR when trying to set new PLL factors while PLL selected as MCLK source clock
Required preconditions PLL must not be selected as MCLK clock
Called functions SCU_PLLCmd(DISABLE) : Disables the PLL
Function name SCU_PLLCmd
Function prototype ErrorStatus SCU_PLLConfig(FunctionnalState NewState)
Behavior description Enables or disables the PLL
Input parameter NewState : ENABLE or DISABLE
Output parameter None
Return parameter
ErrorStatus: ERROR or SUCCESS
The function returns ERROR when:– Disabling the PLL while PLL is selected as MCLK source– Enabling the PLL while PLL already enabled & locked
Required preconditions
– When enabling the PLL, you must have already configured the PLL factors using the SCU_PLLFactorsConfig function.
– When disabling the PLL, make sure that the PLL is not selected as MCLK.
Called functions None
System control unit (SCU) UM0233
56/303
6.2.4 SCU_RCLKDivisorConfig
6.2.5 SCU_HCLKDivisorConfig
Function name SCU_RCLKDivisorConfig
Function prototype void SCU_RCLKDivisorConfig(u32 RCLK_Divisor)
Behavior description Selects the RCLK divisor 1, 2, 4, 8, 16 or 1024
Input parameterRCLK_DivisorRefer to Table 24: RCLK_Divisor parameter values for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Table 24. RCLK_Divisor parameter values
RCLK_Divisor Meaning
SCU_RCLK_Div1 RCLK Divisor = 1
SCU_RCLK_Div2 RCLK Divisor = 2
SCU_RCLK_Div4 RCLK Divisor = 4
SCU_RCLK_Div8 RCLK Divisor = 8
SCU_RCLK_Div16 RCLK Divisor = 16
SCU_RCLK_Div1024 RCLK Divisor = 1024
Function name SCU_HCLKDivisorConfig
Function prototype void SCU_HCLKDivisorConfig(u32 HCLK_Divisor)
Behavior description Selects the HCLK divisor: 1,2 or 4.
Input parameterHCLK_Divisor
Refer to Table 25: HCLK_Divisor parameter values for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Table 25. HCLK_Divisor parameter values
Value Meaning
SCU_HCLK_Div1 HCLK Divisor = 1
SCU_HCLK_Div2 HCLK Divisor = 2
SCU_HCLK_Div4 HCLK Divisor = 4
UM0233 System control unit (SCU)
57/303
6.2.6 SCU_PCLKDivisorConfig
6.2.7 SCU_FMICLKDivisorConfig
Function name SCU_PCLKDivisorConfig
Function prototype void SCU_PCLKDivisorConfig(u32 PCLK_Divisor)
Behavior description Selects the PCLK divisor: 1,2,4 or 8
Input parameterPCLK_DivisorRefer to Table 26: PCLK_Divisor parameter values for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Table 26. PCLK_Divisor parameter values
Value Meaning
SCU_PCLK_Div1 PCLK Divisor = 1
SCU_PCLK_Div2 PCLK Divisor = 2
SCU_PCLK_Div4 PCLK Divisor = 4
SCU_PCLK_Div8 PCLK Divisor = 8
Function name SCU_FMICLKDivisorConfig
Function prototype void SCU_FMICLKDivisorConfig(u32 FMICLK_Divisor)
Behavior description Selects the FMI clock Divisor: 1 or 2
Input parameterFMICLK_DivisorRefer to Table 27: FMICLK_Divisor parameter values for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Table 27. FMICLK_Divisor parameter values
Value Meaning
SCU_FMICLK_Div1 FMICLK Divisor = 1
SCU_FMICLK_Div2 FMICLK Divisor = 2
System control unit (SCU) UM0233
58/303
6.2.8 SCU_EMIBCLKDivisorConfig
6.2.9 SCU_BRCLKDivisorConfig
Function name SCU_EMIBCLKDivisorConfig
Function prototype void SCU_EMIBCLKDivisorConfig(u32 EMIBCLK_Divisor)
Behavior description Selects the EMI Bus clock Divisor: 1 or 2
Input parameterEMIBCLK_DivisorRefer to Table 28: EMIBCLK_Divisor parameter values for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Table 28. EMIBCLK_Divisor parameter values
Value Meaning
SCU_EMIBCLK_Div1 EMIBCLK Divisor = 1
SCU_EMIBCLK_Div2 EMIBCLK Divisor = 2
Function name SCU_BRCLKDivisorConfig
Function prototype void SCU_BRCLKDivisorConfig(u32 BRCLK_Divisor)
Behavior description Selects the Baud rate clock Divisor : 1 or 2
Input parameterBRCLK_Divisor
Refer to Table 29: BRCLK_Divisor parameter values for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Table 29. BRCLK_Divisor parameter values
Value Meaning
SCU_BRCLK_Div1 BRCLK Divisor = 1
SCU_BRCLK_Div2 BRCLK Divisor = 2
UM0233 System control unit (SCU)
59/303
6.2.10 SCU_TIMExtCLKCmd
6.2.11 SCU_USBCLKConfig
Function name SCU_TIMExtCLKCmd
Function prototype void SCU_TIMExtCLKCmd (u8 TIMx, FunctionalState NewState)
Behavior description Enable or disable the TIMx external clock source.
Input parameter1TIMx Refer to Table 30: TIMx parameter values for the allowed values of this parameter.
Input parameter2 NewState: ENABLE or DISABLE
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Table 30. TIMx parameter values
Value Meaning
SCU_TIM01 TIMER 0 & 1
SCU_TIM23 TIMER 2 & 3
Function name SCU_USBCLKConfig
Function prototype void SCU_USBCLKConfig(u32 USBCLK_Source)
Behavior description Selects the USB clock source
Input parameterUSBCLK_SourceRefer to Table 31: USBCLK_Source parameter values for the allowed values of this parameter.
Example:/*Deinitializes the GPIO0 peripheral registers to their default reset values*/GPIO_DeInit(GPIO0);
Table 40. GPIO library functions
Function name Description
GPIO_DeInit Deinitializes the GPIOx peripheral registers to their default reset values.
GPIO_InitInitializes the GPIOx peripheral according to the specified parameters in the GPIO_InitStruct.
GPIO_StructInit Fills each GPIO_InitStruct member with its reset value.
GPIO_Read Reads the specified GPIO data port
GPIO_ReadBit Reads the specified port pin
GPIO_WriteBit Sets or clears the selected data port bit.
GPIO_Write Write data to the specified GPIO data port
GPIO_ANAPinConfig Enables or disables pins from GPIO 4 in Analog mode.
GPIO_EMIConfig Enables or disables GPIO 8 and 9 in EMI mode.
Function name GPIO_DeInit
Function prototype void GPIO_DeInit(GPIO_TypeDef* GPIOx)
Behavior description Deinitializes the GPIOx peripheral registers to their default reset values.
Input parameter GPIOx: where x can be 0,1,..,9 to select the GPIO peripheral.
Output parameter None
Return parameter None
Required preconditions None
Called functions SCU_APBPeriphReset()
General purpose I/O ports (GPIO) UM0233
76/303
7.2.2 GPIO_Init
GPIO_InitTypeDef
The GPIO_InitTypeDef structure is defined in the 91x_GPIO.h file:typedef struct{vu8 GPIO_Pin;vu8 GPIO_Direction;vu8 GPIO_Type;vu8 GPIO_IPInputConnected; vu16 GPIO_Alternate;} GPIO_InitTypeDef;
GPIO_Pin
Specifies GPIO pins to configure, (allows multiple pin configuration with the | operator).
This member can be one of the following values:
Function name GPIO_Init
Function prototype void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
Behavior descriptionInitializes the GPIOx peripheral according to the specified parameters in the GPIO_InitStruct .
Input parameter1 GPIOx: where x can be 0,1, .., 9 to select the GPIO peripheral.
Input parameter2
GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that contains the configuration information for the specified GPIO peripheral. Refer to section “GPIO_InitTypeDef on page 76” for more details on the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
GPIO_Pin Meaning
GPIO_Pin_None No pin selected
GPIO_Pin_0 Pin 0 Selected
GPIO_Pin_1 Pin 1 Selected
GPIO_Pin_2 Pin 2 Selected
GPIO_Pin_3 Pin 3 Selected
GPIO_Pin_4 Pin 4 Selected
GPIO_Pin_5 Pin 5 Selected
GPIO_Pin_6 Pin 6 Selected
GPIO_Pin_7 Pin 7 Selected
GPIO_Pin_All All pins Selected
UM0233 General purpose I/O ports (GPIO)
77/303
GPIO_Direction
Specifies GPIO pin direction.
This member can be one of the following values:
GPIO_Type
Specifies the pin output type.
This member can be one of the following values:
GPIO_IPInputConnected
Specifies the IP function to receive the input from a port pin. Only GPIO pins on P0 thru P7 use this function.
This member can be one of the following values:
GPIO_Alternate
Specifies the IP function to be assigned to port pin. Only GPIO pins on P0 thru P7 use this function.
This member can be one of the following values:
Example:/* Configure all the GPIO0 in Input Push pull mode*/GPIO_InitTypeDef GPIO_InitStruct;GPIO_InitStruct.GPIO_Pin = GPIO_Pin_All;GPIO_InitStruct.GPIO_Direction = GPIO_PinInput;GPIO_InitStruct.GPIO_Type = GPIO_Type_PushPull;GPIO_InitStruct.GPIO_IPInputConnected = GPIO_IPInputConnected_Disable;GPIO_InitStruct.GPIO_Alternate = GPIO_InputAlt1;GPIO_Init (GPIO0, &GPIO_InitStruct);
GPIO_Direction Meaning
GPIO_PinOutput Configures corresponding pin to be an output.
GPIO_PinInput Configures corresponding pin to be an input
GPIO_Type Meaning
GPIO_Type_PushPull Configures the GPIO in push pull type.
GPIO_Type_OpenCollector Configures the GPIO in open collector type.
GPIO_IPConnected Meaning
GPIO_IPInputConnected_Enable IP connected to the input
GPIO_IPInputConnected_Disable IP unconnected to the input.
GPIO_Out Meaning
GPIO_InputAlt1 Configures the GPIO pin in input
GPIO_OutputAlt1 Configures the GPIO pin in output alternate function 1
GPIO_OutputAlt2 Configures the GPIO pin in output alternate function 2
GPIO_OutputAlt3 Configures the GPIO pin in output alternate function 3
General purpose I/O ports (GPIO) UM0233
78/303
7.2.3 GPIO_StructInit
Example:/*Initialize the GPIO Init Structure parameters*/GPIO_InitTypeDef GPIO_InitStruct;GPIO_StructInit(&GPIO_InitStruct);
Function name GPIO_StructInit
Function prototype void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
Behavior description Fills each GPIO_InitStruct member with its reset value.
Input parameterGPIO_InitStruct: pointer to a GPIO_InitTypeDef structure which
will be initialized.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
UM0233 General purpose I/O ports (GPIO)
79/303
7.2.4 GPIO_ReadBit
Example:/* Reads the seventh pin of the GPIO1 and store it in Read_Value variable*/u8 Read_Value;Read_Value = GPIO_ReadBit(GPIO1, GPIO_Pin_7);
7.2.5 GPIO_Read
Example:/* Read the GPIO2 data port and store it in Read_Value variable*/u8 Read_Value;Read_Value = GPIO_Read(GPIO2);
Function name GPIO_ReadBit
Function prototype u8 GPIO_ReadBit(GPIO_TypeDef* GPIOx, u8 GPIO_Pin)
Behavior description Reads the specified data port bit.
Input parameter1 GPIOx: where x can be 0,1,...,9 to select the GPIO peripheral.
Input parameter2 GPIO_Pin: Specifies the port bit to read.
Output parameter None
Return parameter The port pin value
Required preconditions None
Called functions None
Function name GPIO_Read
Function prototype u8 GPIO_Read(GPIO_TypeDef* GPIOx)
Behavior description Reads the specified GPIO data port
Input parameter GPIOx: where x can be 0,1,...,9 to select the GPIO peripheral.
Output parameter None
Return parameter GPIO data port byte value.
Required preconditions None
Called functions None
General purpose I/O ports (GPIO) UM0233
80/303
7.2.6 GPIO_WriteBit
Example:/*Set the GPIO0 port pin 7*/GPIO_WriteBit(GPIO0, GPIO_Pin_7, Bit_SET);
7.2.7 GPIO_Write
Example:/*Write data to GPIO0 data port*/GPIO_Write(GPIO0, 0xFD);
Function name GPIO_WriteBit
Function prototype void GPIO_WriteBit(GPIO_TypeDef* GPIOx,u8 GPIO_Pin, BitAction BitVal)
Behavior description Sets or clears the selected data port bit
Input parameter1 GPIOx: where x can be 0,1, ..., 9 to select the GPIO peripheral.
Input parameter2 GPIO_Pin: specifies the port bit to be written.
Input parameter3
BitVal: this parameter specifies the value to be written to the selected bit.
Port_Val must be one of the BitAction enum values:
Bit_RESET: to clear the port pinBit_SET: to set the port pin
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name GPIO_Write
Function prototype void GPIO_Write(GPIO_TypeDef* GPIOx, u8 Port_Val)
Behavior description Write the passed value in to the selected data GPIOx port register
Input parameter1 GPIOx: where x can be 0,1, ..., 9 to select the GPIO peripheral.
Input parameter2 Port_Val: The value to be written to the data port register.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
UM0233 General purpose I/O ports (GPIO)
81/303
7.2.8 GPIO_ANAPinConfig
GPIO_ANAChannel
Example:/* Enable Analog channel 3 */GPIO_ANAPinConfig(GPIO_ANAChannel3, ENABLE);
Function name GPIO_ANAPinConfig
Function prototype void GPIO_ANAPinConfig(u8 GPIO_ANAChannel, FunctionalState NewState)
Behavior description Enables or disables pins from GPIO 4 in Analog mode.
Input parameter1GPIO_ANAChannel: Specifies the port bit to be configured in Analog input. Refer to Table 41: GPIO_ANAChannel parameter values for the allowed values of this parameter.
Input parameter2NewState: new state of the specified analog channel.This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Table 41. GPIO_ANAChannel parameter values
Value Meaning
GPIO_ANAChannel0 Configure the analog channel 0
GPIO_ANAChannel1 Configure the analog channel 1
GPIO_ANAChannel2 Configure the analog channel 2
GPIO_ANAChannel3 Configure the analog channel 3
GPIO_ANAChannel4 Configure the analog channel 4
GPIO_ANAChannel5 Configure the analog channel 5
GPIO_ANAChannel6 Configure the analog channel 6
GPIO_ANAChannel7 Configure the analog channel 7
GPIO_ANAChannelALL Configure the all analog channel
General purpose I/O ports (GPIO) UM0233
82/303
7.2.9 GPIO_EMIConfig
Example:/* Enable GPIO 8 and 9 in EMI mode */GPIO_EMIConfig(ENABLE);
Function name GPIO_EMIConfig
Function prototype void GPIO_EMIConfig(FunctionalState NewState)
Behavior description Enables or disables GPIO 8 and 9 in EMI mode.
Input parameter3NewState: new state of the specified GPIO 8 and 9 is EMI interface. This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
UM0233 Vectored interrupt controller (VIC)
83/303
8 Vectored interrupt controller (VIC)
The driver may be used for several purposes, such as enabling and disabling interrupts (IRQ) and fast interrupts (FIQ), enabling and disabling individual IRQ channels, changing IRQ channel priorities, saving and restoring context and installing IRQ handlers.
The first section describes the data structures used in the VIC Firmware library. The second one presents the Firmware library functions.
8.1 VIC register structure The VIC register structure VIC_TypeDef is defined in the 91x_map.h file as follows:typedef struct{vu32 ISR; vu32 FSR; vu32 RINTSR; vu32 INTSR; vu32 INTER; vu32 INTECR; vu32 SWINTR vu32 SWINTCR; vu32 PER; vu32 EMPTY1[3];vu32 VAR; vu32 DVAR; vu32 EMPTY2[50];vu32 VAiR[16]; vu32 EMPTY3[48];vu32 VCiR[16]; } VIC_TypeDef;
Table 42. VIC registers
Register Description
ISR IRQ Status Register
FSR FIQ Status Register
RINTSR Raw Interrupt Status Register
INTSR Interrupt Select Register
INTER Interrupt Enable Register
INTECR Interrupt Enable Clear Register
SWINTR Software Interrupt Register
SWINTCR Software Interrupt clear Register
PER Protection Enable Register
VAR Vector Address Register
DVAR Default Vector Address Register
VAiR Vector Address 0-15 Register
VCiR Vector Control 0-15 Register
Vectored interrupt controller (VIC) UM0233
84/303
The 2 VIC interfaces are declared in the same file:
_VIC, _VIC0 and _VIC1 must be defined, in 91x_conf.h file, to access the peripheral registers as follows:#define _VIC#define _VIC0#define _VIC1...
UM0233 Vectored interrupt controller (VIC)
85/303
8.2 Firmware library functions
8.2.1 VIC_DeInit
Example:/* Deinitialize the VIC */VIC_DeInit();
Table 43. VIC library functions
Function name Description
VIC_DeInit Deinitializes the VIC module registers to their default reset values.
VIC_GetIRQStatus Gets the status of interrupts after IRQ masking.
VIC_GetFIQStatus Gets the status of interrupts after FIQ masking.
VIC_GetSourceITStatus Gets the status of the source interrupts before masking.
VIC_ITCmd Enables or disables the interrupt request lines.
VIC_SWITConfigGenerates a software interrupt for the specific source interrupt before interrupt masking.
VIC_ProtectionCmd Enables or disables the register access protection.
VIC_GetCurrentISRAdd Gets the address of the currently active ISR.
VIC_GetISRVectAdd Gets the ISR vector addresses.
VIC_ConfigConfigures the ISR, the line, the mode and the priority for each interrupt.
Function name VIC_DeInit
Function prototype void VIC_DeInit(void)
Behavior description Deinitializes the VIC module registers to their default reset values.
Input parameter None
Output parameter None
Return parameter None
Required preconditions ...
Called functions SCU_AHBPeriphReset()
Vectored interrupt controller (VIC) UM0233
86/303
8.2.2 VIC_GetIRQStatus
The VIC_Source parameter can take one of the following values defined in the 91x_vic.h file:
Function name VIC_GetIRQStatus
Function prototype FlagStatus VIC_GetIRQStatus(u16 VIC_Source)
Behavior description Gets the status of interrupts after IRQ masking.
Input parameterVIC_Source: specifies the number of the source line.
Refer to Table 44: VIC_Source parameter values on page 86 for the allowed values of this parameter.
Output parameter None
Return parameter The status of the IRQ interrupt after masking (SET or RESET).
Required preconditions ...
Called functions None
Table 44. VIC_Source parameter values
Value Meaning
WDG_ITLine WDG interrupt line
SW_ITLine Software interrupt line
ARMRX_ITLine ARM RX interrupt line
ARMTX_ITLine ARM TX interrupt line
TIM0_ITLine TIM0 interrupt line
TIM1_ITLine TIM1 interrupt line
TIM2_ITLine TIM2 interrupt line
TIM3_ITLine TIM3 interrupt line
USBHP_ITLine High priority USB interrupt line
USBLP_ITLine Low priority USB interrupt line
SCU_ITLine SCU interrupt line
MAC_ITLine MAC interrupt line
DMA_ITLine DMA interrupt line
CAN_ITLine CAN interrupt line
MC_ITLine Motor Control interrupt line
ADC_ITLine ADC interrupt line
UART0_ITLine UART0 interrupt line
UART1_ITLine UART1 interrupt line
UART2_ITLine UART2 interrupt line
I2C0_ITLine I2C0 interrupt line
I2C1_ITLine I2C1 interrupt line
SSP0_ITLine SSP0 interrupt line
UM0233 Vectored interrupt controller (VIC)
87/303
Example:FlagStatus RTC_IT_Status;/* Get the RTC interrupt status after IRQ masking */RTC_IT_Status = VIC_GetIRQStatus(RTC_ITLine);
8.2.3 VIC_GetFIQStatus
Example:FlagStatus SSP1_IT_Status;/* Get the SSP1 interrupt status after FIQ masking */SSP1_IT_Status = VIC_GetFIQStatus(SSP1_ITLine);
SSP1_ITLine SSP1 interrupt line
LVD_ITLine LVD interrupt line
RTC_ITLine RTC interrupt line
WIU_ITLine WIU interrupt line
EXTIT0_ITLine EXTIT0 interrupt line
EXTIT1_ITLine EXTIT1 interrupt line
EXTIT2_ITLine EXTIT2 interrupt line
EXTIT3_ITLine EXTIT3 interrupt line
USBWU_ITLine USBWU interrupt line
PFQBC_ITLine PFQBC interrupt line
Table 44. VIC_Source parameter values (continued)
Value Meaning
Function name VIC_GetFIQStatus
Function prototype FlagStatus VIC_GetFIQStatus(u16 VIC_Source)
Behavior description Gets the status of interrupts after FIQ masking.
Input parameterVIC_Source: specifies the number of the source line.
Refer to Table 44: VIC_Source parameter values on page 86 for the allowed values of this parameter.
Output parameter None
Return parameter The status of the FIQ interrupt after masking (SET or RESET).
Required preconditions ...
Called functions None
Vectored interrupt controller (VIC) UM0233
88/303
8.2.4 VIC_GetSourceITStatus
Example:FlagStatus RTC_IT_Status;/* Get the RTC interrupt status before masking */RTC_IT_Status = VIC_GetSourceITStatus(RTC_ITLine);
8.2.5 VIC_ITCmd
Example:/* Enable the SSP1 interrupt request line */VIC_ITCmd(SSP1_ITLine, ENABLE);/* Disable the SSP2 interrupt request line */VIC_ITCmd(SSP2_ITLine, DISABLE);
Function name VIC_GetSourceITStatus
Function prototype FlagStatus VIC_GetSourceITStatus(u16 VIC_Source)
Behavior description Gets the status of the source interrupts before masking.
Input parameterVIC_Source: specifies the number of the source line.
Refer to Table 44: VIC_Source parameter values on page 86 for the allowed values of this parameter.
Output parameter None
Return parameter The status of the source interrupt before masking (SET or RESET).
Required preconditions ...
Called functions None
Function name VIC_ITCmd
Function prototypevoid VIC_ITCmd(u16 VIC_Source, FunctionalState VIC_NewState)
Behavior description Enables or disables the interrupt request lines.
Input parameter1VIC_Source: specifies the number of the source line.
Refer to Table 44: VIC_Source parameter values on page 86 for the allowed values of this parameter.
Input parameter2VIC_NewState: specifies the line status. This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
UM0233 Vectored interrupt controller (VIC)
89/303
8.2.6 VIC_SWITCmd
Example:/* Generate a software interrupt in the SSP1 interrupt request line before masking */VIC_SWITCmd(SSP1_ITLine, ENABLE);/* Generate a software interrupt in the SSP2 interrupt request line before masking */VIC_SWITCmd(SSP2_ITLine, ENABLE);
8.2.7 VIC_ProtectionCmd
Example:/* Enable the registers access protection */VIC_ProtectionCmd(ENABLE);
Function name VIC_SWITCmd
Function prototype void VIC_SWITCmd(u16 VIC_Source, FunctionalState VIC_NewState)
Behavior descriptionGenerates a software interrupt for the specific source interrupt before interrupt masking.
Input parameter1VIC_Source: specifies the number of the source line.Refer to Table 44: VIC_Source parameter values on page 86 for the allowed values of this parameter.
Input parameter2VIC_NewState: specifies the software interrupt status.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Function name VIC_ProtectionCmd
Function prototype void VIC_ProtectionCmd(FuncionalState VIC_NewState)
Behavior description Enables or disables the register access protection.
Input parameterVIC_NewState: specifies the protection status.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Vectored interrupt controller (VIC) UM0233
90/303
8.2.8 VIC_GetCurrentISRAdd
Example:u32 Address_Active_ISR/* Get the address of the current active ISR for the VIC0 */Address_Active_ISR = VIC_GetCurrentISRAdd(VIC0);
Note: Lines 0 to 15 are mapped on VIC0 and Lines 16 to 31 are mapped on VIC1.
8.2.9 VIC_GetISRVectAdd
Example:u32 ISR_Address; /* Get the ISR vector address of the RTC */ISR_Address = VIC_GetISRVectAdd(RTC_ITLine, 0);
Function name VIC_GetCurrentISRAdd
Function prototype u32 VIC_GetCurrentISRAdd(VIC_TypeDef* VICx)
Behavior description Gets the address of the current active ISR.
Input parameter
VICx: specifies the VIC peripheral. This parameter can one of the following values:- VIC0: To select VIC0.
- VIC1: To select VIC1.
Output parameter None
Return parameter The address of the active ISR.
Required preconditions ...
Called functions None
Function name VIC_GetISRVectAdd
Function prototype u32 VIC_GetISRVectAdd(u16 VIC_Source, u16 VIC_Priority)
Behavior description Configuration of the ISR vector addresses.
Input parameter1VIC_Source: specifies the number of the source line.Refer to Table 44: VIC_Source parameter values on page 86 for the allowed values of this parameter.
Input parameter2VIC_Priority: specifies the priority of the interrupt, it can be a value from 0 to 15, 0 is the highest priority.
Output parameter None
Return parameter The corresponding ISR vector address.
Required preconditions ...
Called functions None
UM0233 Vectored interrupt controller (VIC)
91/303
8.2.10 VIC_Config
Example:void SSP1_ITHandler(void) {...}/* Configure the SSP1 interrupt as IRQ and set its priority to 5 */VIC_Config(SSP1_ITLine,VIC_IRQ,5);
Function name VIC_Config
Function prototype void VIC_Config(u16 VIC_Source, VIC_ITLineMode VIC_LineMode, u8 VIC_Priority)
Behavior descriptionConfigures the ISR, the line, the mode and the priority for each interrupt.
Input parameter1VIC_Source: specifies the number of the source line.Refer to Table 44: VIC_Source parameter values on page 86 for the allowed values of this parameter.
Input parameter2
VIC_LineMode: specifies the type of interrupt of the source line. This parameter can be one of the following values:
- VIC_IRQ: To configure the line as IRQ.
- VIC_FIQ: To configure the line as FIQ.
Input parameter3VIC_Priority: specifies the priority of the interrupt, it can be a value from 0 to 15, 0 is the highest priority.
Output parameter None
Return parameter None
Required preconditions ...
Called functions
VIC_ITModeConfig
VIC_ISRVecAddConfigVIC_VecEnableConfig
VIC_ITSourceConfig
Wake-up interrupt unit (WIU) UM0233
92/303
9 Wake-up interrupt unit (WIU)
The WIU driver may be used for several purposes, such as enabling and disabling interrupt lines, selecting the edge sensitivity, interrupt or wake-up mode.
9.1 WIU register structure The WIU register structure WIU_TypeDef is defined in the 91x_map.h file as follows:typedef struct{vu32 CTRL; /* Control Register */vu32 MR; /* Mask Register */vu32 TR; /* Trigger Register */vu32 PR; /* Pending Register */vu32 INTR; /* Software Interrupt Register */} WIU_TypeDef;
When debug mode is used, WIU pointer is initialized in 91x_lib.c file:#ifdef _WIU WIU = (WIU_TypeDef *)WIU_BASE#endif /* _WIU */
_WIU must be defined, in 91x_conf.h file, to access the peripheral registers as follows:#define _WIU...
9.2 Firmware library functions
Table 46. WIU library functions
Function name Description
WIU_InitInitializes the WIU according to the specified parameters in the WIU_InitTypeDef structure
WIU_DeInit Deinitializes the WIU registers to their default reset values
WIU_StructInit Fills each WIU_InitStruct member with its reset value.
WIU_Cmd Enables or disables the WIU peripheral.
WIU_GetITStatus Checks whether the specified WIU line is asserted or not
WIU_ClearITPendingBit Clears the pending bit of the selected WIU line
WIU_GenerateSWInterrupt Generates a Software interrupt for the specified line
WIU_GetFlagStatus Checks whether the specified WIU line flag is set or not.
WIU_ClearFlag Clears the WIU line pending flag.
Wake-up interrupt unit (WIU) UM0233
94/303
9.2.1 WIU_Init
WIU_initTypeDef
The WIU_InitTypeDef structure defines the control setting for the WIU cell, it is defined in the 91x_WIU.htypedef struct{u8 WIU_TriggerEdge;u32 WIU_Line;}WIU_InitTypeDef;
WIU_TriggerEdge
Specifies the triggering edge of the Wake-up line.
This member can be one of the following values.
Function name WIU_Init
Function prototype void WIU_Init(WIU_InitTypeDef* WIU_InitStruct)
Behavior descriptionInitializes WIU peripheral according to the specified parameters in the WIU_InitTypeDef structure.
Input parameter
WIU_InitStruct: Pointer to a WIU_InitTypeDef structure that contains the configuration information for the WIU peripheral. Refer to section “WIU_initTypeDef on page 94” for more details on the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
WIU_TriggerEdge Meaning
WIU_FallingEdge Wake-up lines trigger on falling edge.
WIU_RisingEdge Wake-up lines trigger on rising edge
UM0233 Wake-up interrupt unit (WIU)
95/303
WIU_Line
Specifies the Wake-up line to be configured, it can be one of the following values:Lines value Corresponding Line
WIU_Line0 Wake-up line 0
WIU_Line1 Wake-up line 1
WIU_Line2 Wake-up line 2
WIU_Line3 Wake-up line 3
WIU_Line4 Wake-up line 4
WIU_Line5 Wake-up line 5
WIU_Line6 Wake-up line 6
WIU_Line7 Wake-up line 7
WIU_Line8 Wake-up line 8
WIU_Line9 Wake-up line 9
WIU_Line10 Wake-up line 10
WIU_Line11 Wake-up line 11
WIU_Line12 Wake-up line 12
WIU_Line13 Wake-up line 13
WIU_Line14 Wake-up line 14
WIU_Line15 Wake-up line 15
WIU_Line16 Wake-up line 16
WIU_Line17 Wake-up line 17
WIU_Line18 Wake-up line 18
WIU_Line19 Wake-up line 19
WIU_Line20 Wake-up line 20
WIU_Line21 Wake-up line 21
WIU_Line22 Wake-up line 22
WIU_Line23 Wake-up line 23
WIU_Line24 Wake-up line 24
WIU_Line25 Wake-up line 25
WIU_Line26 Wake-up line 26
WIU_Line27 Wake-up line 27
WIU_Line28 Wake-up line 28
WIU_Line29 Wake-up line 29
WIU_Line30 Wake-up line 30
WIU_Line31 Wake-up line 31
Wake-up interrupt unit (WIU) UM0233
96/303
Example:
The following example illustrates how to configure the WIU unit :{... /* Set the WIU_InitTypeDef structure with the needed configuration */WIU_InitStructure.WIU_Line = WIU_Line1;WIU_InitStructure.WIU_TriggerEdge = WIU_FallingEdge;/* Configure the WIU unit */WIU_Init(&WIU_InitStructure);
...}
9.2.2 WIU_DeInit
9.2.3 WIU_StructInit
Function name WIU_DeInit
Function prototype void WIU_DeInit(void)
Behavior description Deinitalizes WIU peripheral registers to their default reset values
Output parameter None
Return parameter None
Required preconditions None
Called functions SCU_APBPeriphReset()
Function name WIU_StructInit
Function prototype void WIU_StructInit(WIU_InitTypeDef* WIU_InitStruct)
Behavior description Fills each WIU_InitStruct member with its reset value.
Input parameterWIU_InitStruct: pointer to a WIU_InitTypeDef structure which
will be initialized.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
UM0233 Wake-up interrupt unit (WIU)
97/303
9.2.4 WIU_Cmd
9.2.5 WIU_GenerateSWInterrupt
Example:
WIU_GenerateSWInterrupt (WIU_Line0);
9.2.6 WIU_GetFlagStatus
Example:
WIU_GetFlagStatus (WIU_Line0);
Function name WIU_Cmd
Function prototype void WIU_Cmd(FunctionalState NewState)
Behavior description Enables or disables the specified WIU peripheral.
Input parameter1NewState: new state of the WIU peripheral.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name WIU_GenerateSWInterrupt
Function prototype void WIU_GenerateSWInterrupt(u32 WIU_Line)
Behavior description Generates a software interrupt for the specified line.
Input parameter2 WIU_Line : Wake-up line.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name WIU_GetFlagStatus
Function prototype void WIU_GetFlagStatus(u32 WIU_Line)
Behavior description Checks whether the specified WIU line flag is set or not
Input parameter2 WIU_Line: Wake-up line.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Wake-up interrupt unit (WIU) UM0233
98/303
9.2.7 WIU_ClearFlag
Example:
WIU_ClearFlag (WIU_Line0);
9.2.8 WIU_GetITStatus
Example:WIU_GetITStatus(WIU_Line0);
9.2.9 WIU_ClearITPendingBit
Example:
The following example clears the WIU line0 pending bit:WIU_ClearITPendingBit(WIU_Line0);
Function name WIU_ClearFlag
Function prototype void WIU_ClearFlag(u32 WIU_Line)
Behavior description Clears the WIU’s line pending flag.
Input parameter2 WIU_Line : Wake-up line.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name WIU_GetITStatus
Function prototype void WIU_GetITStatus(u32 WIU_Line)
Behavior description Checks whether the specified WIU line is asserted or not.
Input parameter2 WIU_Line: Wake-up line
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name WIU_ClearITPendingBit
Function prototype void WIU_ClearITPendingBit(u32 WIU_Line)
Behavior description Clears the pending bit of the selected WIU line
Input parameter2 WIU_Line: Wake-up line to clear its pending bit.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
UM0233 Real time clock (RTC)
99/303
10 Real time clock (RTC)
The RTC block combines a complete time of day clock with alarm, periodic interrupt, tamper detection and 9999-year calendar. The time is in 24 hour mode, and time/calendar values are stored in binary-coded decimal format.
10.1 RTC register structure The RTC register structure RTC_TypeDef is defined in the 91x_map.h file as follows:typedef struct{ vu32 TR; /* Time Register */ vu32 DTR; /* Date Register */ vu32 ATR; /* Alarm time Register */ vu32 CR; /* Control Register */ vu32 SR; /* Status Register */ vu32 MILR; /* Milliseconds Register */}RTC_TypeDef;
Function prototype void RTC_ITConfig(u32 RTC_IT, FunctionalState NewState)
Behavior description Enables or disables the specified RTC interrupts.
Input parameter1RTC_IT: specifies the RTC interrupts sources to be enabled or disabled. Refer to Table 53: RTC_IT parameter values section for the allowed values.
Input parameter2NewState: new state of the specified RTC interrupts. This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Table 53. RTC_IT parameter values
Value Meaning
RTC_IT_Per Periodic interrupt
RTC_IT_Alarm Alarm interrupt
RTC_IT_Tamper Tamper interrupt
Real time clock (RTC) UM0233
110/303
10.2.15 RTC_GetFlagStatus
10.2.16 RTC_ClearFlag
Function name RTC_GetFlagStatus
Function prototype FlagStatus RTC_GetFlagStatus(u32 RTC_FLAG)
Behavior description Checks whether the specified RTC flag is set or not.
Input parameterRTC_FLAG: specifies the flag to check.
Refer to Table 54: RTC_FLAG parameter values section for the allowed values.
Output parameter None
Return parameter The new state of RTC_FLAG (SET or RESET).
Required preconditions None
Called functions None
Table 54. RTC_FLAG parameter values
Value Meaning
RTC_FLAG_Per Periodic interrupt flag
RTC_FLAG_Alarm Alarm flag
RTC_FLAG_Tamper Tamper flag
Function name RTC_ClearFlag
Function prototype void RTC_ClearFlag(u32 RTC_FLAG)
Behavior description Clears a RTC flag
Input parameter2RTC_FLAG: specifies the flag to clear.
Refer to Table 54: RTC_FLAG parameter values section for the allowed values.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
UM0233 Watchdog timer (WDG)
111/303
11 Watchdog timer (WDG)
The Watchdog Timer peripheral can be used as free-running timer or as Watchdog to resolve processor malfunctions due to hardware or software failure.
The Watchdog supports the following features:
16-bit down-counter
8-bit clock prescaler
Safe reload sequence
Free-running timer mode
End of Count interrupt generation
The first section describes the data structure used in the WDG Firmware library. The second one presents the Firmware library functions.
11.1 WDG register structure The WDG register structure WDG_TypeDef is defined in the 91x_map.h file as follows:typedef struct{ vu16 WDG_CR; /* Control Register */ vu16 EMPTY1; vu16 WDG_PR; /* Presclar Register */ vu16 EMPTY2; vu16 WDG_VR; /* Pre-load Value Register */ vu16 EMPTY3; vu16 WDG_CNT; /* Counter Register */ vu16 EMPTY4; vu16 WDG_SR; /* Status Register */ vu16 EMPTY5; vu16 WDG_MR; /* Mask Register */ vu16 EMPTY6; vu16 WDG_KR; /* Key Register */ vu16 EMPTY7;} WDG_TypeDef;
Table 55. WDG registers
Register Description
WDG_CR This register controls and enables Watchdog Timer operations
WDG_PR 8-bit prescaler, WDG clock divider
WDG_VR This register contains the 16-bit preload value to the WDG
WDG_CNT This register contains the current counter value
WDG_SR WDG Status register
WDG_MR WDG Mask register
WDG_KR Key Register: The WDG is loaded with VR value when the Key Register
Function prototype void WDG_ITConfig(FunctionalState NewState)
Behavior description Enables or disables the WDG End of Count(EC) interrupt.
Input parameter1 NewState: This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name WDG_GetFlagStatus
Function prototype ITStatus WDG_GetITStatus(void)
Behavior descriptionChecks whether the WDG End of Count(EC) interrupt has occurred or not.
Input parameter1 None
Output parameter None
Return parameterThe new state of WDG End of Count(EC) interrupt
(SET or RESET).
Required preconditions None
Called functions None
Watchdog timer (WDG) UM0233
118/303
11.2.7 WDG_ClearITPendingBit
Example:
The following example illustrates how to clear the end of count flag:... WDG_ClearITPendingBit();...
11.2.8 WDG_GetCounter
Example:
The following example illustrates how to get the counter value of the WDG timer:...u16 CounterValue = WDG_GetCounter();
Function name WDG_ClearITPendingBit
Function prototype void WDG_ClearITPendingBit(void)
Behavior description Clears the WDG End of Count(EC) interrupt pending bit.
Input parameter1 None
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name WDG_GetCounter
Function prototype u16 WDG_GetCounter(void)
Behavior description Gets the WDG current counter value.
Input parameter None
Output parameter None
Return parameter WDG current counter value.
Required preconditions None
Called functions None
UM0233 Watchdog timer (WDG)
119/303
11.2.9 WDG_GetFlagStatus
Example:
Example illustrating the use of WDG_GetFlagStaus function:/*wait for the end of count on mode free running timer*/while(WDG_GetFlagStatus()== RESET); ...
11.2.10 WDG_GetFlagStatus
Example:
...WDG_ClearFlag();...
Function name WDG_GetFlagStaus
Function prototype FlagStatus WDG_GetFlagStatus(void)
Behavior description Checks whether the WDG End of Count(EC) flag is set or not.
Input parameter None
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name WDG_ClearFlag
Function prototype void WDG_ClearFlag(void)
Behavior description Clears the WDG End of Count(EC) Flag.
Input parameter None
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Watchdog timer (WDG) UM0233
120/303
11.2.11 WDG_Reload
Function name WDG_Reload
Function prototype void WDG_Reload(void)
Behavior description Reloads the watchdog counter in watchdog mode
Input parameter None
Output parameter None
Return parameter None
Required preconditions None
Called functions None
UM0233 16-bit timer (TIM)
121/303
12 16-bit timer (TIM)
The TIM driver may be used for a variety of purposes, including timing operation, Input capture, output compare and PWM generation.
12.1 TIM register structure The TIM register structure TIM_TypeDef is defined in the 91x_map.h file as follows:typedef struct{ vu16 IC1R; vu16 EMPTY1; vu16 IC2R; vu16 EMPTY2; vu16 OC1R; vu16 EMPTY3; vu16 OC2R; vu16 EMPTY4; vu16 CNTR; vu16 EMPTY5; vu16 CR1; vu16 EMPTY6; vu16 CR2; vu16 EMPTY7; vu16 SR; vu16 EMPTY8;} TIM_TypeDef;
The four TIM interfaces are declared in the same file:
#ifndef EXT #Define EXT extern#endif...#define AHB_APB_BRDG0_U (0x58000000) /* AHB/APB Bridge 0 UnBuffered Space */#define AHB_APB_BRDG0_B (0x48000000) /* AHB/APB Bridge 0 Buffered Space */...#define APB_TIM0_OFST (0x00002000) /* Offset of TIM0 */
Table 57. TIM registers
Register Description
IC1R Input Capture 1 Register
IC2R Input Capture 2 Register
OC1R Output Compare 1 Register
OC2R Output Compare 2 Register
CNTR Counter Register
CR1 Control Register 1
CR2 Control Register 2
SR Status Register
16-bit timer (TIM) UM0233
122/303
#define APB_TIM1_OFST (0x00003000) /* Offset of TIM1 */#define APB_TIM2_OFST (0x00004000) /* Offset of TIM0 */#define APB_TIM3_OFST (0x00005000) /* Offset of TIM1 */
TIM_DeInit Deinitializes TIM peripheral registers to their default reset values.
TIM_InitInitializes TIM peripheral according to the specified parameters in the TIM_InitTypeDef structure.
TIM_StructInitFills a TIM_InitTypeDef structure with the reset value of each parameter (which depend on the register reset value)
TIM_ClockSourceConfig Configures the TIM clock source.
TIM_PrescalerConfig Configures the TIM prescaler Value.
TIM_GetPrescalerValue Gets the TIM prescaler Value.
TIM_GetICAP1Value Reads and returns the Input Capture 1 value.
TIM_GetICAP2Value Reads and returns the Input Capture 2 value.
TIM_GetPWMIPulse Reads and returns the PWM input pulse value.
TIM_GetPWMIPeriod Reads and returns the PWM input period value.
TIM_CounterCmd Configures the TIM counter.
TIM_SetPulse Set the new pulse value.
TIM_GetFlagStatus Checks whether the specified TIM flag is set or not.
TIM_ClearFlag Clears the specified TIM flag.
TIM_ITConfig Configures the TIM interrupts.
TIM_GetCounterValue Gets the TIM counter value.
TIM_DMAConfig Configures the TIM DMA source.
TIM_DMACmd Enables or disables the TIMx DMA interface.
16-bit timer (TIM) UM0233
124/303
12.2.1 TIM_DeInit
Example:/*To deinitialize the TIM0 and TIM1*/TIM_DeInit (TIM0);TIM_DeInit (TIM1);
12.2.2 TIM_Init
Function name TIM_DeInit
Function prototype void TIM_DeInit(TIM_TypeDef *TIMx);
Behavior description Deinitializes the TIMx peripheral registers to their default reset values.
Input parameter TIMx: where x can be 0,1, 2 or 3 to select the TIM peripheral.
Output parameter None
Return parameter None
Required preconditions ...
Called functions SCU_APBPeriphReset()
Function name TIM_Init
Function prototype void TIM_Init(TIM_TypeDef* TIMx, TIM_InitTypeDef* TIM_InitStruct)
Behavior descriptionInitializes the TIMx peripheral according to the specified parameters in the TIM_InitStruct .
Input parameter1 TIMx: where x can be 0,1, 2 or 3 to select the TIM peripheral.
Input parameter2
TIM_InitStruct: pointer to a TIM_InitTypeDef structure that contains the configuration information for the specified TIM peripheral. Refer to section “TIM_InitTypeDef on page 125” for more details on the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
UM0233 16-bit timer (TIM)
125/303
TIM_InitTypeDef
The TIM_InitTypeDef structure is defined in the 91x_tim.h file:{ u16 TIM_Mode; /* Timer mode */ u16 TIM_OC1_Modes; /* Output Compare 1 Mode: Timing or Wave */ u16 TIM_OC2_Modes; /* Output Compare 2 Mode: Timing or Wave */ u16 TIM_Clock_Source; /* Timer Clock source APB/SCU/EXTERNAL */ u16 TIM_Clock_Edge; /* Timer Clock Edge: Rising or Falling Edge */ u16 TIM_OPM_INPUT_Edge; /* Timer Input Capture 1 Edge used in OPM Mode */ u16 TIM_ICAP1_Edge; /* Timer Input Capture 1 Edge used in ICAP1 Mode */ u16 TIM_ICAP2_Edge; /* Timer Input Capture 2 Edge used in ICAP2 Mode */ u8 TIM_Prescaler; /* Timer Prescaler factor */ u16 TIM_Pulse_Level_1; /* Level applied on the Output Compare Pin 1 */ u16 TIM_Pulse_Level_2; /* Level applied on the Output Compare Pin 2 */ u16 TIM_Period_Level; /* Level applied during the Period of a PWM Mode */ u16 TIM_Pulse_Length_1; /* Pulse 1 Length used in Output Compare 1 Mode */ u16 TIM_Pulse_Length_2; /* Pulse 2 Length used in Output Compare 2 Mode */ u16 TIM_Full_Period; /* Period Length used in PWM Mode */} TIM_InitTypeDef;
TIM_Mode
Specifies the TIM operating mode. This parameter can be one of the following values:
TIM_OC1_Modes
Specifies the operating mode of the OCMP1 pin. This member can be one of the following values:
TIM_Wave OCMP1 pin is dedicated to the OC1 capability of the TIM
16-bit timer (TIM) UM0233
126/303
TIM_OC2_Modes
Specifies the operating mode of the OCMP2 pin. This member can be one of the following values:
TIM_ICAP1_EDGE
Specifies the trigger mode for Input Capture 1. This member can be one of the following values:
TIM_ICAP2_EDGE
Specifies the trigger mode for Input Capture 1. This member can be one of the following values:
TIM_OPM_INPUT_Edge
Specifies the input edges for one pulse mode. This member can be one of the following values:
TIM_Clock_Source
Specifies the clock source of the TIM peripheral. This member can be one of the following values:
TIM_OC2_Modes Meaning
TIM_Timing OCMP2 pin is a general I/O
TIM_Wave OCMP2 pin is dedicated to the OC2 capability of the TIM
TIM_ICAP1_EDGE Meaning
TIM_ICAP1_EDGE_RISING A rising edge triggers the capture
TIM_ICAP1_EDGE_FALLING A falling edge triggers the capture
TIM_ICAP2_EDGE Meaning
TIM_ICAP2_EDGE_RISING A rising edge triggers the capture
TIM_ICAP2_EDGE_FALLING A falling edge triggers the capture
TIM_OPM_INPUT_Edge Meaning
TIM_Rising A rising edge triggers the counter initialization
TIM_Falling A falling edge triggers the counter initialization
TIM_Clock_Source Meaning
TIM_CLK_EXTERNAL Reference clock source is used
TIM_CLK_APB APB clock source is used
UM0233 16-bit timer (TIM)
127/303
TIM_Clock_Edge
Specifies which type of level transition on the reference clock will trigger the counter. This member can be one of the following values:
TIM_Prescaler
Specifies the Prescaler value to divide the APB clock. Timer clock will be equal to
TIM_Pulse_Level_1
When using PWM, OPM, OCM1 or OCM12 mode, this parameter specifies the pulse level of the signal generated on the OCMP1 pin. This member can be one of the following values:
TIM_Pulse_Level_2
When using OCM2 or OCM12 mode, this parameter specifies the pulse level of the signal generated on OCMP2 pin. This member can be one of the following values:
TIM_Period_Level
When using OPM mode, this parameter specifies the signal level after the pulse generated on the OCMP1 pin. This member can be one of the following values:
TIM_Pulse_Length_1
When using PWM, OPM, OCM1 or OCM1&2 mode, this parameter specifies the pulse length to be loaded in the OC1R register.
TIM_Clock_Edge Meaning
TIM_CLK_EDGE_RISING A rising edge triggers the counter
TIM_CLK_EDGE_FALLING A falling edge triggers the counter
Example:/*To clear the TIM1 overflow flag*/TIM_ClearFlag(TIM1, TIM_FLAG_TO);
12.2.14 TIM_ITConfig
TIM_FLAG_TO Timer Overflow
TIM_FLAG_IC2 Input Capture Flag channel 2
TIM_FLAG_OC2 Output Compare Flag channel 2
Table 59. TIM_FLAG parameter values
Values Meaning
Function name TIM_ClearFlag
Function prototype void TIM_ClearFlag(TIM_TypeDef* TIMx, u16 TIM_FLAG)
Behavior description Clears the TIMx pending flags.
Input parameter1 TIMx: where x can be 0,1, 2 or 3 to select the TIM peripheral.
Input parameter2TIM_FLAG: specifies the flag to clear. To clear TIM flags, use a combination of one or more of the values in Table 59: TIM_FLAG parameter values on page 133.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Function name TIM_ITConfig
Function prototype void TIM_ITConfig(TIM_TypeDef* TIMx, u16 TIM_IT, FunctionalState TIM_NewState)
Behavior description Enables or disables the specified TIM interrupts.
Input parameter1 TIMx: where x can be 0,1, 2 or 3 to select the TIM peripheral.
Input parameter2TIM_IT: specifies the TIM interrupts sources to be enabled or disabled.
Refer to Table 60: TIM_IT parameter values for the allowed values of this parameter.
Input parameter3TIM_NewState: new state of the specified TIMx interrupts. This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
UM0233 16-bit timer (TIM)
135/303
To enable or disable TIM interrupts, use a combination of one or more of the following values:
Example:/*To enable the overflow IT and the input capture 2 of the TIM3*/TIM_ITConfig(TIM3, TIM_IT_TO|TIM_IT_IC2, ENABLE);
Required preconditions ...
Called functions None
Table 60. TIM_IT parameter values
Value Meaning
TIM_IT_IC1 Input Capture IT channel 1
TIM_IT_OC1 Output Compare IT channel 1
TIM_IT_TO Timer Overflow IT
TIM_IT_IC2 Input Capture IT channel 2
TIM_IT_OC2 Output Compare IT channel 2
16-bit timer (TIM) UM0233
136/303
12.2.15 TIM_GetCounterValue
Example:/*To get the counter value of the TIM2*/u16 MyCounter; MyCounter = TIM_GetCounterValue(TIM2);
12.2.16 TIM_DMAConfig
Example:/*To configure the DMA for the TIM0 peripheral and to choose ICAP1 as a DMA source*/TIM_DMAConfig(TIM0, TIM_DMA_ICAP1);
Function name TIM_GetCounterValue
Function prototype u16 TIM_GetCounterValue(TIM_TypeDef* TIMx)
Behavior description Gets the TIM counter value.
Input parameter TIMx: where x can be 0,1, 2 or 3 to select the TIM peripheral.
Output parameter None
Return parameter The TIM counter value
Required preconditions ...
Called functions None
Function name TIM_DMAConfig
Function prototypevoid TIM_DMAConfig (TIM_TypeDef *TIMx, u16 TIM_DMA_Souces);
Behavior description This routine is used to enable the DMA.
Input parameter1 TIMx: where x can be 0,1, 2 or 3 to select the TIM peripheral.
Input parameter2TIM_DMASources: specifies the DMA source to be used.Refer to Table 61: TIM_DMASources parameter values for the allowed values of this parameter.
Function prototype void TIM_DMACmd(TIM_TypeDef* TIMx, FunctionalState TIM_NewState)
Behavior description Enables or disables the TIMx DMA interface.
Input parameter1 TIMx: where x can be 0,1, 2 or 3 to select the TIM peripheral.
Input parameter2TIM_NewState: new state of the DMA interface. This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
DMA controller (DMA) UM0233
138/303
13 DMA controller (DMA)
The DMA enables memory-to-memory, memory-to-peripheral, peripheral-to-memory, and peripheral-to-peripheral transactions. Each DMA stream provides unidirectional serial DMA transfers for a single source and destination. A bidirectional port requires one stream for transmit and one for receive. The source and destination areas can each be either a memory region or a peripheral.
13.1 DMA register structureThe DMA register structures DMA_TypeDef and DMA_Channel_TypeDef are defined in the 91x_map.h file as follows:
DMA_DeInitInitializes the DMA peripheral registers to their default reset val-ues.
DMA_InitInitializes the DMA Channelx according to the specified parame-ters in the DMA_InitStruct.
DMA_StructInit Fills each DMA_InitStruct member with its reset value.
DMA_Cmd Enables or disables the DMA peripheral.
DMA_ITMaskConfig Enables or disables the specified DMA Mask interrupt.
DMA_ITConfigEnables or disables the Terminal count interrupt for specified DMA channelx.
DMA_SRCIncConfigEnables or disables the source Address incrementing for the specified DMA channelx.
DMA_DESIncConfigEnables or disables the destination Address incrementing for the specified DMA channelx.
DMA_GetITStatus Checks the status of the specified interrupt.
DMA_ClearIT Clears the pending bit of the specified interrupt.
DMA_SyncConfigEnables or disables the synchronization logic for the corresponding DMA Request Signal.
DMA_GetSReq Checks for a specific source if it requests a Single transfer or not.
DMA_GetLSReqChecks for a specific source if it requests a Last Single transfer or not.
DMA_GetBReq Checks for a specific source if it requests a Burst transfer or not.
DMA_GetLBReqChecks for a specific source if it requests a Last Burst transfer or not.
DMA_SetSReqSets the DMA to generate a Single transfer request for the corresponding DMA Request Source.
DMA_SetLSReqSets the DMA to generate a Last Single transfer request for the corresponding DMA Request Source.
DMA_SetBReqSets the DMA to generate a Burst transfer request for the corresponding DMA Request Source.
DMA_SetLBReqSets the DMA to generate a Last Burst transfer request for the corresponding DMA Request Source.
DMA_ChannelCmd Enables or disables the specified DMA Channelx
DMA_ChannelHaltEnables DMA requests or ignore extra source DMA requests for
the specified channelx.
DMA_ChannelBufferingEnables or disables the access Cache ability for the specified channelx.
DMA_ChannelModeEnables the access in User or Privileged mode for the specified channelx.
UM0233 DMA controller (DMA)
143/303
13.2.1 DMA_DeInit
Example:...DMA_DeInit(); /* set all DMA Peripheral registers to their reset value */...
DMA_ChannelLockTrsf Enables or disables locked transfers.
DMA_ChannelCacheEnables or disables the access Cache ability for the specified channelx.
DMA_GetChannelActiveStatusChecks if the DMA_Channelx FIFO is empty or not.
Returns SET while the corresponding channel FIFO is not empty.
DMA_GetChannelStatus Checks the status of DMA channelx (Enabled or Disabled)
DMA_LLI_CCR_InitReturns linked list's control word according to the specified parameters in the LLI_CCR_InitStruct
Table 63. DMA library functions
Function name Description
Function name DMA_DeInit
Function prototype void DMA_DeInit()
Behavior description Deinitializes the DMA peripheral registers to their default reset values.
Input parameter None
Output parameter None
Return parameter None
Required preconditions None
Called functions SCU_AHBPeriphReset()
DMA controller (DMA) UM0233
144/303
13.2.2 DMA_Init
Function name DMA_Init
Function prototype void DMA_Init(DMA_Channel_TypeDef * DMA_Channelx, DMA_InitTypeDef * DMA_InitStruct);
Behavior description
Initializes the DMA_Channelx according to the specified parameters in the DMA_InitStruct.
Input parameter1 DMA_Channelx: where x can be 0,1,2,3,4,5,6,or 7 to select the DMA Channel.
Input parameter2DMA_InitStruct: pointer to a DMA_InitTypeDef structure which contains the configuration information for the specified DMA_Channelx.
Refer to section “DMA_InitTypeDef: on page 145” for more details.
Output parameter None
Return parameter None
Required preconditions
...
Called functions None
UM0233 DMA controller (DMA)
145/303
DMA_InitTypeDef:
The DMA_InitTypeDef structure is defined in the 91x_dma.h file:typedef struct{u32 DMA_Channel_SrcAdd;u32 DMA_Channel_DesAdd;u32 DMA_Channel_LLstItm;u8 DMA_Channel_DesWidth;u8 DMA_Channel_SrcWidth;u8 DMA_Channel_DesBstSize;u8 DMA_Channel_SrcBstSize;u16 DMA_Channel_TrsfSize;u8 DMA_Channel_FlowCntrl;u8 DMA_Channel_Src;u8 DMA_Channel_Des;
} DMA_InitTypeDef;
DMA_Channel_SrcAdd
The current source address, (byte-aligned), of the data to be transferred.
DMA_Channel_DesAdd
The current destination address, (byte-aligned), of the data to be transferred.
DMA_Channel_LLstItm
The word- aligned address for the next Linked List Item.
DMA_Channel_DesWidth
Destination transfer width.
This member can be one of the following values:
DMA_Channel_SrcWidth
Source transfer width.
This member can be one of the following values:
DMA_Channel_DesWidth Value Meaning
DMA_DesWidth_Byte 0x00000000 Destination Width is one Byte
DMA_DesWidth_HalfWord 0x00200000 Destination Width is one half word
DMA_DesWidth_Word 0x00400000 Destination Width is one Word
DMA_Channel_SrcWidth Value Meaning
DMA_SrcWidth_Byte 0x00000000 Source width is one Byte
DMA_SrcWidth_HalfWord 0x00040000 Source width is one Half Word
DMA_SrcWidth_Word 0x00080000 Source width is one Word
DMA controller (DMA) UM0233
146/303
DMA_Channel_DesBstSize
The destination burst size, which indicates the number of transfers that make up a destination burst transfer request.
This member can be one of the following values:
DMA_Channel_DesBstSize Value Meaning
DMA_DesBst_1Data 0x00000000Destination Burst transfer request is 1 Data (DATA = destination transfer width)
DMA_DesBst_4Data 0x00008000 Destination Burst transfer request is 1 Data
DMA_Bst_8Data 0x00010000 Destination Burst transfer request is 4 Data
DMA_DesBst_16Data 0x00018000 Destination Burst transfer request is 8 Data
DMA_DesBst_32Data 0x00020000 Destination Burst transfer request is 16 Data
DMA_DesBst_64Data 0x00028000 Destination Burst transfer request is 32 Data
DMA_DesBst_128Data 0x00030000Destination Burst transfer request is 128 Data
DMA_DesBst_256Data 0x00038000Destination Burst transfer request is 256 Data
UM0233 DMA controller (DMA)
147/303
DMA_Channel_SrcBstSize
The source burst size indicates the number of transfers that make up a source burst.
This member can be one of the following values:
DMA_Channel_TrsfSize
Transfer size indicates the size of the transfer when the DMA controller is the flow controller.
DMA_Channel_FlowCntrl
Flow control and transfer type: This value indicates the flow controller and transfer type. The flow controller can be the DMA, the source peripheral, or the destination peripheral. The transfer type can be memory to-memory, memory-to-peripheral, peripheral-to-memory, or peripheral to-peripheral.
This member can be one of the following values:
DMA_Channel_SrcBstSize Value Meaning
DMA_SrcBst_1Data 0x00000000Source Burst transfer request is 1 Data (DATA = Source transfer width)
DMA_SrcBst_4Data 0x00001000 Source Burst transfer request is 4 Data
DMA_SrcBst_8Data 0x00002000 Source Burst transfer request is 8 Data
DMA_SrcBst_16Data 0x00003000 Source Burst transfer request is 16 Data
DMA_SrcBst_32Data 0x00004000 Source Burst transfer request is 32 Data
DMA_SrcBst_64Data 0x00005000 Source Burst transfer request is 64Data
DMA_SrcBst_128Data 0x00006000 Source Burst transfer request is 128 Data
DMA_SrcBst_256Data 0x00007000 Source Burst transfer request is 256 Data
DMA_Channel_FlowCntrl Value Transfer Type The flow controller
Source peripheral. This value selects the DMA source request peripheral.
This field is ignored if the source of the transfer is from memory.
DMA_Channel_Src Value Description
DMA_SRC_USB_RX 0X00
DMA_SRC_USB_TX 0x02
DMA_SRC_TIM0 0x04
DMA_SRC_TIM1 0x06
DMA_SRC_UART0_RX 0x08
DMA_SRC_UART0_TX 0x0A
DMA_SRC_UART1_RX 0x0C
2 out of 3 UARTs have DMA support (UART2 is not
supported by DMA)
DMA_SRC_UART1_TX 0x0E
DMA_SRC_External_Req0 0x10
DMA_SRC_External_Req1 0x12
DMA_SRC_I2C0 0x14
DMA_SRC_I2C1 0x16
DMA_SRC_SSP0_RX 0x18
DMA_SRC_SSP0_TX 0x1A
DMA_SRC_SSP1_RX 0x1C
DMA_SRC_SSP1_TX 0x1E
UM0233 DMA controller (DMA)
149/303
DMA_Channel_Des
Destination peripheral. This value selects the DMA destination request peripheral. This field is ignored if the destination of the transfer is to memory.
Example:
/* Initialize the DMA Channel0 according to the DMA_InitStruct members */DMA_InitTypeDef DMA_InitStruct;...DMA_InitStruct.DMA_Channel_SrcAdd= 0x4000000;DMA_InitStruct. DMA_Channel_DesAdd= 0x4002000;DMA_InitStruct.DMA_Channel_LLstItm =0;DMA_InitStruct.DMA_Channel_DesWidth = DMA_Width_HalfWord ;DMA_InitStruct.DMA_Channel_DestBstSize = DMA_DesBst_4Data ;DMA_InitStruct.DMA_Channel_SrcBstSize= DMA_SrcBst_1Data;DMA_InitStruct.DMA_Channel_TrsfSize = 0x14;DMA_InitStruct.DMA_Channel_FlowCntrl= DMA_FlowCntrl_DMA;...DMA_Init(DMA_Channel0,&DMA_InitStruct);
DMA_Channel_Des Value Description
DMA_DES_USB_RX 0X00
DMA_DES_USB_TX 0x40
DMA_DES_TIM0 0x80
DMA_DES_TIM1 0xC0
DMA_DES_UART0_RX 0x100
DMA_DES_UART0_TX 0x140
DMA_DES_UART1_RX 0x180
2 out of 3 UARTs have DMA support (UART2 is not
supported by DMA)
DMA_DES_UART1_TX 0x1C0
DMA_DES_External_Req0 0x200
DMA_DES_External_Req1 0x240
DMA_DES_I2C0 0x280
DMA_DES_I2C1 0x2C0
DMA_DES_SSP0_RX 0x300
DMA_DES_SSP0_TX 0x340
DMA_DES_SSP1_RX 0x380
DMA_DES_SSP1_TX 0x3C0
DMA controller (DMA) UM0233
150/303
13.2.3 DMA_StructInit
Example:.../* define and Initialize a DMA_InitStruct */DMA_InitTypeDef DMA_InitStruct;DMA_StructInit(&DMA_InitStruct);...
13.2.4 DMA_Cmd
Example:/* Enable DMA */...DMA_Cmd(ENABLE);...
Function name DMA_StructInit
Function prototype void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct)
Behavior description Fills each DMA_InitStruct member with its reset value.
Input parameter DMA_InitStruct: pointer to a DMA_InitTypeDef structure.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name DMA_Cmd
Function prototype void DMA_Cmd(FunctionalState NewState)
Behavior description Enables or disables the DMA peripheral.
Input parameter1NewState: new state of the DMA peripheral.
Example:/* Enable the source incrementation feature for the channel0 */...DMA_ChannelSRCIncConfig (DMA_Channel0, ENABLE);...
13.2.7 DMA_ChannelDESIncConfig
Example:/* Enable the destination incrementation feature for the channel0 */...DMA_ChannelDESIncConfig (DMA_Channel0, ENABLE);...
Function name DMA_ChannelSRCIncConfig
Function prototype void DMA_ChannelSRCIncConfig (DMA_Channel_TypeDef * DMA_Channelx, FunctionalState NewState);
Behavior descriptionEnables or disables the source Address incrementing for the specified DMA channelx.
Input parameter1DMA_Channelx: where x can be 0,1,2,3,4,5,6,or 7 to select the DMA Channel.
Input parameter2NewState: new state of the source incrementing feature.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Function name DMA_ChannelDESIncConfig
Function prototype void DMA_ChannelDESIncConfig (DMA_Channel_TypeDef * DMA_Channelx, FunctionalState NewState);
Behavior descriptionEnables or disables the source Address incrementing for the specified DMA channelx.
Input parameter1DMA_Channelx: where x can be 0,1,2,3,4,5,6,or 7 to select the DMA Channel.
Input parameter2NewState: new state of the destination incrementing feature.This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
UM0233 DMA controller (DMA)
153/303
13.2.8 DMA_GetChannelActiveStatus
Example:/* check the channel0 FIFO */...DMA_GetChannelActiveStatus(DMA_Channel0);...
13.2.9 DMA_ITConfig
Function name DMA_GetChannelActiveStatus
Function prototype FlagStatus DMA_GetChannelActiveStatus(DMA_Channel_TypeDef * DMA_Channelx)
Behavior descriptionChecks the DMA_Channelx FIFO if it is empty or not.
Returns SET while the corresponding channel FIFO is not empty.
Input parameter1DMA_Channelx: where x can be 0,1,2,3,4,5,6,or 7 to select the DMA Channel.
Output parameter None
Return parameter Returned status (SET or RESET).
Required preconditions None
Called functions None
Function name DMA_ITConfig
Function prototype void DMA_ITMaskConfig(DMA_Channel_TypeDef* DMA_Channelx, FunctionalState NewState)
Behavior description Enables or disables the specified DMA_Channelx Terminal count.
Input parameter1DMA_Channelx: where x can be 0,1,2,3,4,5,6,or 7 to select the DMA Channel.
Input parameter2NewState: new state of the specified DMA_Channelx interrupts. This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
DMA controller (DMA) UM0233
154/303
13.2.10 DMA_GetChannelStatus
ChannelIndx
This Parameter is used as index for the channel to be checked (there are eight Channels)
ChannelIndx = Channel0=0
ChannelIndx = Channel1 =1
...
ChannelIndx = Channel7 =7
Function name DMA_GetChannelStatus
Function prototype FlagStatus DMA_GetChannelStatus(u8 ChannelIndx)
Behavior description Check the status of DMA channelx (Enabled or Disabled)
Input parameterChannelIndx: specifies the DMA Channel to be checked.
Refer to section “ChannelIndx on page 154” for more details on the allowed values of this parameter.
Output parameter None
Return parameter Returned status (SET or RESET).
Required preconditions ...
Called functions None
UM0233 DMA controller (DMA)
155/303
13.2.11 DMA_GetITStatus
ChannelIndx
This Parameter is used as index for the channel to be checked (there are eight Channels)
ChannelIndx = Channel0 = 0
ChannelIndx = Channel1 = 1
...
ChannelIndx = Channel7 =7
Function name DMA_GetITStatus
Function prototype ITStatus DMA_GetITStatus(u8 ChannelIndx,u8 DMA_ITReq)
Behavior descriptionChecks the status of Terminal Count and Error interrupts request after and before Masking.
Input parameter1ChannelIndx: specifies the DMA Channel to be checked.Refer to section “ChannelIndx on page 154” for more details on the allowed values of this parameter.
Input parameter2DMA_ITReq: specifies the DMA interrupt request status to be checked.
Refer to Table 65: DMA_ITReq parameter values on page 156 for the allowed values of this parameter.
Output parameter None
Return parameter Returned status (SET or RESET).
Required preconditions ...
Called functions None
DMA controller (DMA) UM0233
156/303
DMA_ITReq:
Specifies the DMA interrupt request status to be checked and is coded as index for the register Status containing this interrupt request status.
To check the interrupt status, use a combination of one or more of the following values:
Example:/*Check the status of interrupts after masking on the channel0*/...DMA_GetITStatus(Channel0,DMA_IS);...
Table 65. DMA_ITReq parameter values
DMA_ITReq Value (code) DMA register status Meaning
DMA_IS 0x01 DMA_ISRThe status of the interrupts after masking.
DMA_TCS 0x02 DMA_TCISRThe status of the terminal count after masking.
DMA_ES 0x03 DMA_EISRThe status of the error request after masking
DMA_TCRS 0x04 DMA_TCRISR
Indicates if the DMA channel is requesting a transfer complete (terminal count Interrupt) prior to masking or Not.
DMA_ERS 0x05 DMA_ERISR
Indicates if the DMA channel is requesting an Error Interrupt prior to masking or Not.
UM0233 DMA controller (DMA)
157/303
13.2.12 DMA_ClearIT
DMA_ITClr:
Specifies the DMA interrupt pending to be cleared and is coded as index for the register containing this interrupt pending bit.
To clear interrupts pending bits, use a combination of one or more of the following values:
Function name DMA_ClearIT
Function prototype void DMA_ClearIT(u8 ChannelIndx,u8 DMA_ITClr)
Behavior descriptionClears The Interrupt pending bits for terminal count or Error interrupts for a specified DMA Channel.
Input parameter1ChannelIndx: specifies the DMA Channel.Refer to section “ChannelIndx on page 155” for more details on the allowed values of this parameter.
Input parameter2DMA_ITClr: DMA interrupt pending. Refer to Table 66: DMA_ITClr parameter values on page 157 for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Table 66. DMA_ITClr parameter values
DMA_ITClr Value (code) DMA register status Meaning
DMA_TCC 0X01 DMA_TCICR
Clear a Terminal Count Interrupt on the
corresponding DMA channel
DMA_EC 0X02 DMA_EICR
Clear an Error Interrupt on the corresponding DMA
channel
DMA controller (DMA) UM0233
158/303
13.2.13 DMA_SyncConfig
Note: You must use synchronization logic when the peripheral generating the DMA request runs on a different clock to the DMA. For peripherals running on the same clock as the DMA, disabling the synchronization logic improves the DMA request.
Function name DMA_SyncConfig
Function prototype void DMA_SyncConfig(u16 DMA_SrcReq, FunctionalState NewState)
Behavior descriptionenable or disable synchronization logic for the corresponding DMA Request Signal.
Input parameter1DMA_SrcReq:specifies the DMA Request Source.Refer to Table 67: DMA_SrcReq parameter values on page 158 for the allowed values of this parameter.
Input parameter2NewState: new state of the DMA peripheral.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Table 67. DMA_SrcReq parameter values
DMA_SrcReq Value (code)
DMA_USB_RX_Mask 0x0001
DMA_USB_TX_Mask 0x0002
DMA_TIM0 _Mask 0x0004
DMA_TIM1_Mask 0x0008
DMA_UART0_RX_Mask 0x0010
DMA_UART0_TX_Mask 0x0020
DMA_UART1_RX_Mask 0x0040
DMA_UART1_TX_Mask 0x0080
DMA_External_Req0_Mask 0x0100
DMA_External_Req1_Mask 0x0200
DMA_I2C0_Mask 0x0400
DMA_I2C1_Mask 0x0800
DMA_SSP0_RX_Mask 0x1000
DMA_SSP0_TX_Mask 0x2000
DMA_SSP1_RX_Mask 0x4000
DMA_SSP1_TX_Mask 0x8000
UM0233 DMA controller (DMA)
159/303
13.2.14 DMA_GetSReq
13.2.15 DMA_GetLSReq
Function name DMA_GetSReq
Function prototype FlagStatus DMA_GetSReq(u16 DMA_SrcReq)
Behavior description Checks for a specific source if it requests a Single transfer or not.
Input parameterDMA_SrcReq: specifies the DMA Request Source.
Refer to Table 67: DMA_SrcReq parameter values on page 158 for the allowed values of this parameter.
Output parameter None
Return parameter Returned status (SET or RESET).
Required preconditions None
Called functions None
Function name DMA_GetLSReq
Function prototype FlagStatus DMA_GetLSReq(u16 DMA_SrcReq)
Behavior description Checks for a specific source if it requests a last Single transfer.
Input parameterDMA_SrcReq: specifies the DMA Request Source.
Refer to Table 67: DMA_SrcReq parameter values on page 158 for the allowed values of this parameter.
Output parameter None
Return parameter Returned status (SET or RESET).
Required preconditions None
Called functions None
DMA controller (DMA) UM0233
160/303
13.2.16 DMA_GetBReq
13.2.17 DMA_GetLBReq
13.2.18 DMA_SetSReq
Function name DMA_GetBReq
Function prototype FlagStatus DMA_GetBReq(u16 DMA_SrcReq)
Behavior description Checks for a specific source if it requests a Burst transfer.
Input parameterDMA_SrcReq:specifies the DMA Request Source.
Refer to Table 67: DMA_SrcReq parameter values on page 158 for the allowed values of this parameter.
Output parameter None
Return parameter Returned status (SET or RESET).
Required preconditions None
Called functions None
Function name DMA_GetLBReq
Function prototype FlagStatus DMA_GetLBReq(u16 DMA_SrcReq)
Behavior description Checks for a specific source if it requests a Last Burst transfer.
Input parameterDMA_SrcReq: specifies the DMA Request Source.
Refer to Table 67: DMA_SrcReq parameter values on page 158 for the allowed values of this parameter.
Output parameter None
Return parameter Returned status (SET or RESET).
Required preconditions None
Called functions None
Function name DMA_SetSReq
Function prototype void DMA_SetSReq(u16 DMA_SrcReq)
Behavior descriptionSets the DMA to generate a Single transfer request for the corresponding DMA Request Source.
Input parameterDMA_SrcReq: specifies the DMA Request Source.
Refer to Table 67: DMA_SrcReq parameter values on page 158 for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
UM0233 DMA controller (DMA)
161/303
13.2.19 DMA_SetLSReq
13.2.20 DMA_SetBReq
Function name DMA_SetLSReq
Function prototype void DMA_SetLSReq(u16 DMA_SrcReq)
Behavior descriptionSets the DMA to generate a Last Single transfer request for the corresponding DMA Request Source.
Input parameterDMA_SrcReq: specifies the DMA Request Source.Refer to Table 67: DMA_SrcReq parameter values on page 158 for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name DMA_SetBReq
Function prototype void DMA_SetBReq(u16 DMA_SrcReq)
Behavior descriptionSets the DMA to generate a Burst transfer request for the corresponding DMA Request Source.
Input parameterDMA_SrcReq: specifies the DMA Request Source.
Refer to Table 67: DMA_SrcReq parameter values on page 158 for the allowed values of this parameter.
Function prototype void DMA_SetLBReq(u16 DMA_SrcReq)
Behavior descriptionSets the DMA to generate a Last Burst transfer request for the corresponding DMA Request Source.
Input parameterDMA_SrcReq: specifies the DMA Request Source.Refer to Table 67: DMA_SrcReq parameter values on page 158 for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name DMA_ChannelCmd
Function prototype void DMA_ChannelCmd (DMA_Channel_TypeDef * DMA_Channelx, FunctionalState NewState)
Behavior description Enables or disables the DMA_Channelx.
Input parameter1DMA_Channelx: where x can be 0,1,2,3,4,5,6,or 7 to select the DMA Channel.
Input parameter2NewState: new state of the DMA peripheral.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
UM0233 DMA controller (DMA)
163/303
13.2.23 DMA_ChannelHalt
Example:/* Enable Halt Mode for DMA_Channel0 (ignore extra source DMA requests)*/DMA_ChannelHalt(DMA_Channel0,ENABLE);
13.2.24 DMA_ChannelBuffering
Example:/* Buffering feature enabled for the DMA_Channel0 */DMA_ChannelBuffering(DMA_Channel0,ENABLE);
Function name DMA_ChannelHalt
Function prototype void DMA_ChannelHalt (DMA_Channel_TypeDef * DMA_Channelx,FunctionalState NewState)
Behavior description Enables or disables HALT Mode for the specified DMA_Channelx.
Input parameter1DMA_Channelx: where x can be 0,1,2,3,4,5,6,or 7 to select the DMA Channel.
Input parameter2NewState: new state of the DMA peripheral.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name DMA_ChannelBuffering
Function prototype void DMA_ChannelBuffering (DMA_Channel_TypeDef * DMA_Channelx,FunctionalState NewState)
Behavior descriptionEnables or disables the Buffering Feature for the specified DMA_Channelx.
Input parameter1DMA_Channelx: where x can be 0,1,2,3,4,5,6,or 7 to select the DMA Channel.
Input parameter2NewState: new state of the DMA peripheral. This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
DMA controller (DMA) UM0233
164/303
13.2.25 DMA_ChannelLockTrsf
Example:/* Enable the locked transfers feature for the DMA_Channel0 */DMA_ChannelLockTrsf(DMA_Channel0,ENABLE);
13.2.26 DMA_ChannelCache
Example:/* Enable the cacheability for the DMA_Channel0 */DMA_ChannelCache(DMA_Channel0,ENABLE);
Function name DMA_ChannelLockTrsf
Function prototype void DMA_ChannelLockTrsf(DMA_Channel_TypeDef * DMA_Channelx,FunctionalState NewState)
Behavior descriptionEnables or disables the Locked Transfers Feature for the specified DMA_Channelx.
Input parameter1DMA_Channelx: where x can be 0,1,2,3,4,5,6,or 7 to select the DMA Channel.
Input parameter2NewState: new state of the DMA peripheral.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name DMA_ChannelCache
Function prototypevoid DMA_ChannelCache(DMA_Channel_TypeDef * DMA_Channelx,FunctionalState NewState)
Behavior descriptionEnables or disables the cache ability Feature for the specified DMA_Channelx.
Input parameter1DMA_Channelx: where x can be 0,1,2,3,4,5,6,or 7 to select the DMA Channel.
Input parameter2NewState: new state of the DMA peripheral.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
UM0233 DMA controller (DMA)
165/303
13.2.27 DMA_ChannelProt0Mode
Prot0Mode:
13.2.28 DMA_LLI_CCR_Init
Function name DMA_ChannelProt0Mode
Function prototype void DMA_ChannelProt0Mode(DMA_Channel_TypeDef * DMA_Channelx,u32 Prot0Mode)
Behavior description Sets User or Privileged mode for the specified DMA_Channelx.
Input parameter1DMA_Channelx: where x can be 0,1,2,3,4,5,6,or 7 to select the DMA Channel.
Input parameter2 Prot0Mode: specifies the Privileged mode Or the User mode
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Prot0Mode Value Meaning
DMA_PrivilegedMode 0X10000000
DMA_UserMode 0XEFFFFFFF
Function name DMA_LLI_CCR_Init
Function prototype u32 DMA_LLI_CCR_Init(LLI_CCR_InitTypeDef * LLI_CCR_InitStruct);
Behavior description
Returns the control word of the linked list according to the specified parameters in the LLI_CCR_InitStruct structure.
Input parameter1LLI_CCR_InitStruct: Pointer to LLI_CCR_InitTypeDef: on page 166(Config structure to be loaded in DMA registers).
Output parameter None
Return parameter Control word
Required preconditions
...
Called functions None
DMA controller (DMA) UM0233
166/303
LLI_CCR_InitTypeDef:
The LLI_CCR_InitTypeDef structure is defined in the 91x_dma.h file:typedef struct{ u32 LLI_TrsfSize; u32 LLI_SrcBstSize; u32 LLI_DesBstSize; u32 LLI_SrcWidth; u32 LLI_DesWidth; u32 LLI_SrcIncrement;u32 LLI_DesIncrement; u32 LLI_PROT0; u32 LLI_PROT1;u32 LLI_PROT2; u32 LLI_TCInterrupt; } LLI_CCR_InitTypeDef;
LLI_DesWidth
Destination transfer width.
This member can be one of the following values:
LLI_SrcWidth
Source transfer width.
This member can be one of the following values:
DMA_Channel_DesWidth Value Meaning
DMA_DesWidth_Byte 0x00000000 Destination Width is one Byte
DMA_DesWidth_HalfWord 0x00200000 Destination Width is one half word
DMA_DesWidth_Word 0x00400000 Destination Width is one Word
DMA_Channel_SrcWidth Value Meaning
DMA_SrcWidth_Byte 0x00000000 Source width is one Byte
DMA_SrcWidth_HalfWord 0x00040000 Source width is one Half Word
DMA_SrcWidth_Word 0x00080000 Source width is one Word
UM0233 DMA controller (DMA)
167/303
LLI_DesBstSize
The destination burst size, which indicates the number of transfers that make up a destination burst transfer request.
This member can be one of the following values:
LLI_SrcBstSize
The source burst size indicates the number of transfers that make up a source burst.
This member can be one of the following values:
LLI_TrsfSize
Transfer size indicates the size of the transfer when the DMA controller is the flow controller.
LLI_SrcIncrement
Indicates that the source is incremented or not.
LLI_DesIncrement
Indicates that the destination is incremented or not.
DMA_Channel_DesBstSize Value Meaning
DMA_DesBst_1Data 0x00000000Destination Burst transfer request is 1 Data (DATA = destination transfer width)
DMA_DesBst_4Data 0x00008000 Destination Burst transfer request is 1 Data
DMA_Bst_8Data 0x00010000 Destination Burst transfer request is 4 Data
DMA_DesBst_16Data 0x00018000 Destination Burst transfer request is 8 Data
DMA_DesBst_32Data 0x00020000 Destination Burst transfer request is 16 Data
DMA_DesBst_64Data 0x00028000 Destination Burst transfer request is 32 Data
DMA_DesBst_128Data 0x00030000Destination Burst transfer request is 128 Data
DMA_DesBst_256Data 0x00038000Destination Burst transfer request is 256 Data
DMA_Channel_SrcBstSize Value Meaning
DMA_SrcBst_1Data 0x00000000Source Burst transfer request is 1 Data (DATA = Source transfer width)
DMA_SrcBst_4Data 0x00001000 Source Burst transfer request is 4 Data
DMA_SrcBst_8Data 0x00002000 Source Burst transfer request is 8 Data
DMA_SrcBst_16Data 0x00003000 Source Burst transfer request is 16 Data
DMA_SrcBst_32Data 0x00004000 Source Burst transfer request is 32 Data
DMA_SrcBst_64Data 0x00005000 Source Burst transfer request is 64Data
DMA_SrcBst_128Data 0x00006000 Source Burst transfer request is 128 Data
DMA_SrcBst_256Data 0x00007000 Source Burst transfer request is 256 Data
DMA controller (DMA) UM0233
168/303
LLI_PROT0
Indicates that the access is cacheable or not.
LLI_PROT1
Indicates that the access is bufferable or not.
LLI_PROT2
Indicates that the mode is privileged or user.
LLI_TCInterrupt
Activate the terminal count interrupt or not.
Example:
/*control word to generate*/u32 control_word=0;
/* Initialize the DMA Channel0 according to the DMA_InitStruct members */LLI_InitTypeDef LLI2_InitStructure;...LLI2_CCR_InitStruct.LLI_TrsfSize=10; LLI2_CCR_InitStruct.LLI_SrcBstSize=DMA_SrcBst_4Data; LLI2_CCR_InitStruct.LLI_DesBstSize=DMA_DesBst_1Data; LLI2_CCR_InitStruct.LLI_SrcWidth=DMA_SrcWidth_HalfWord; LLI2_CCR_InitStruct.LLI_DesWidth=DMA_DesWidth_HalfWord;LLI2_CCR_InitStruct.LLI_SrcIncrement= DMA_SrcIncrement ;LLI2_CCR_InitStruct.LLI_DesIncrement=DMA_DesIncrement;LLI2_CCR_InitStruct.LLI_PROT0=DMA_CacheableAccess;LLI2_CCR_InitStruct.LLI_PROT1=DMA_NonBufferableAccess;LLI2_CCR_InitStruct.LLI_PROT2=DMA_UsermodeAccess;LLI2_CCR_InitStruct.LLI_TCInterrupt=DMA_TCInterrupt;...control_word = DMA_LLI_CCR_Init(&LLI2_CCR_InitStruct);
UM0233 Synchronous serial peripheral (SSP)
169/303
14 Synchronous serial peripheral (SSP)
The SSP is a master or slave interface for synchronous serial communication with peripheral devices that have either Motorola SPI, National Semiconductor or Texas Instruments SSI synchronous serial interfaces.
The first section describes the data structure used in the SSP Firmware library. The second one presents the Firmware library functions.
14.1 SSP register structureThe SSP register structure SSP_TypeDef is defined in the 91x_map.h file as follows:typedef struct{vu16 CR0; /* Control Register 1 */ vu16 EMPTY1; vu16 CR1; /* Control Register 2 */ vu16 EMPTY2; vu16 DR; /* Data Register */ vu16 EMPTY3; vu16 SR; /* Status Register */ vu16 EMPTY4; vu16 PR; /* Clock Prescale Register */ vu16 EMPTY5; vu16 IMSCR; /* Interrupt Mask Set or Clear Register */ vu16 EMPTY6; vu16 RISR; /* Raw Interrupt Status Register */ vu16 EMPTY7; vu16 MISR; /* Masked Interrupt Status Register */ vu16 EMPTY8; vu16 ICR; /* Interrupt Clear Register */ vu16 EMPTY9; vu16 DMACR; /* DMA Control Register */ vu16 EMPTY10;} SSP_TypeDef;
Table 68. SSP registers
Register Description
CR0 SSP Control Logic register 0
CR1 SSP Control Logic register 1
DR SSP Data register
SR SSP Status register
PR SSP Clock Prescaler register
IMSCR SSP Interrupt Mask Set and Clear register
RISR SSP Raw Interrupt Status register
Synchronous serial peripheral (SSP) UM0233
170/303
The two SSP interfaces are declared in the same file:
_SSP, _SSP0 and _SSP1 must be defined, in the 91x_conf.h file, to access the peripheral registers as follows:
#define _SSP#define _SSP0#define _SSP1...
14.2 Firmware library functionsThe following table enumerates the functions of the SSP library.
Table 69. SSP library functions
Function name Description
SSP_DeInitDeinitializes the SSPx peripheral registers to their default reset values.
SSP_InitInitializes the SSPx peripheral according to the specified parameters in the SSP_InitStruct.
SSP_StructInit Fills each SSP_InitStruct member with its default value.
SSP_Cmd Enables or disables the specified SSP peripheral.
SSP_ITConfig Enables or disables the specified SSP interrupts.
SSP_DMACmd Configures the SSP DMA interface.
SSP_SendData Transmits a Data through the SSP peripheral.
SSP_ReceiveData Returns the most recent received data by the SSP peripheral.
SSP_LoopBackConfigEnables or disables Loop back mode for the selected SSP peripheral.
SSP_GetFlagStatus Checks whether the specified SSP flag is set or not.
SSP_ClearFlag Clears the SSPx pending flags.
SSP_GetITStatus Checks whether the specified SSP interrupt has occurred or not.
SSP_ClearITPendingBit Clears the SSPx interrupt pending bits.
Synchronous serial peripheral (SSP) UM0233
172/303
14.2.1 SSP_DeInit
Example:/* Deinitialize the SSP0 peripheral. */ SSP_DeInit(SSP0);
14.2.2 SSP_Init
SSP_InitTypeDef
The SSP_InitTypeDef structure is defined in the 91x_SSP.h file:typedef struct{u16 SSP_FrameFormat ;u16 SSP_Mode ;u16 SSP_CPOL ;u16 SSP_CPHA ; u16 SSP_DataSize ; u16 SSP_SlaveOutput ;u8 SSP_ClockRate ;u8 SSP_ClockPrescaler ;} SSP_InitTypeDef;
Function name SSP_DeInit
Function prototype void SSP_DeInit(SSP_TypeDef* SSPx)
Behavior description Deinitializes the SSPx peripheral registers to their default reset values.
Input parameter SSPx: where x can be 0 or 1 to select the SSP peripheral.
Output parameter None
Return parameter None
Required preconditions None
Called functions SCU_APBPeriphReset()
Function name SSP_Init
Function prototype void SSP_Init(SSP_TypeDef* SSPx, SSP_InitTypeDef* SSP_InitStruct)
Behavior descriptionInitializes the SSPx peripheral according to the specified parameters in the SSP_InitStruct .
Input parameter1 SSPx: where x can be 0 or 1 to select the SSP peripheral.
Input parameter2
SSP_InitStruct: pointer to a SSP_InitTypeDef structure that contains the configuration information for the specified SSP peripheral. Refer to section “SSP_InitTypeDef on page 172” for more details on the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
UM0233 Synchronous serial peripheral (SSP)
173/303
SSP_FrameFormat
Specifies whether the frame format is Motorola SPI or TI synchronous serial or Microwire. This member can be one of the following values:
SSP_Mode
Specifies the SSP operation mode. This member can be one of the following values:
SSP_CPOL
Specifies the steady state value of the serial clock. This member can be one of the following values:
SSP_CPHA
Specifies on which clock transition the bit capture is made. This member can be one of the following values:
SSP_FrameFormat Meaning
SSP_FrameFormat_Motorola Motorola frame format is selected
SSP_FrameFormat_TI TI frame format is selected
SSP_FrameFormat_Microwire Microwire frame format is selected
SSP_Mode Meaning
SSP_Mode_Master SSP is configured as a master
SSP_Mode_Slave SSP is configured as a slave
SSP_CPOL Meaning
SSP_CPOL_Low Clock is active low
SSP_CPOL_High Clock is active high
SSP_CPHA Meaning
SSP_CPHA_2Edge Data is captured on the second edge
SSP_CPHA_1Edge Data is captured on the first edge
Synchronous serial peripheral (SSP) UM0233
174/303
SSP_DataSize
Specifies the word length operation of the receive and transmit FIFO. This member can be one of the following values:
SSP_SlaveOutput
Specifies whether the slave output is enabled or disabled. This is used especially in multiple-slave cases. This member can be one of the following values:
SSP_ClockRate
Specifies the serial clock rate value used to configure the transmit and receive bit rate of SCK. This member must be a value from 2 to 254.
SSP_DataSize Meaning
SSP_DataSize_16b Data Size is 16 bits
SSP_DataSize_15b Data Size is 15 bits
SSP_DataSize_14b Data Size is 14 bits
SSP_DataSize_13b Data Size is 13 bits
SSP_DataSize_12b Data Size is 12 bits
SSP_DataSize_11b Data Size is 11 bits
SSP_DataSize_10b Data Size is 10 bits
SSP_DataSize_9b Data Size is 9 bits
SSP_DataSize_8b Data Size is 8 bits
SSP_DataSize_7b Data Size is 7 bits
SSP_DataSize_6b Data Size is 6 bits
SSP_DataSize_5b Data Size is 5 bits
SSP_DataSize_4b Data Size is 4 bits
SSP_SlaveOutput Meaning
SSP_SlaveOutput_Enable Slave output enabled
SSP_SlaveOutput_Disable Slave output disabled
UM0233 Synchronous serial peripheral (SSP)
175/303
SSP_ClockPrescaler
Specifies the division factor by which the input PCLK must be divided to be used by the SSP. This member must be an even number between 2 and 254. The least significant bit of the programmed number is hardcoded to zero. If an odd number is written the least significant bit is changed to zero by hardware.
(1): the communication clock is derived from the master so no need to set the slave clock
Example:/* Initialize the SSP0 according to the SSP_InitStructure members. */SSP_InitTypeDef SSP_InitStructure;
The UART interface provides hardware management of the CTS and RTS signals and has Full Modem interface (on UART0 only). It also supports IrDA mode that reduces the signal for IrDA by 3/16.
To optimize the data transfer between the processor and the peripheral, the UART has two FIFOs (receive/transmit) of 16 bytes each. The UART can be served by the DMA controller.
The first section describes the data structures used in the UART Firmware library. The second one presents the Firmware library functions.
Example:/* The following example illustrates how to initialize a UART_InitTypeDef structure */UART_InitTypeDef UART_InitStructure;UART_StructInit(&UART_InitStructure);
Function name UART_StructInit
Function prototype void UART_StructInit(UART_InitTypeDef* UART_InitStruct)
Behavior descriptionFills each UART_InitStruct member with its default value, refer to the following table for more details.
Input parameterUART_InitStruct: pointer to a UART_InitTypeDef structure which will be initialized.
Example:/* Get the UART0 Overrun Error interrupt status */ITStatus OverrunITStatus;OverrunITStatus = UART_GetITStatus(UART0, UART_IT_OverrunError);
15.2.20 UART_ClearITPendingBit
Example:/* Clear the Overrun error interrupt pending bit */UART_ClearITPendingBit(UART0,UART_IT_OverrunError);
Function name UART_GetITStatus
Function prototype ITStatus UART_GetITStatus(UART_TypeDef* UARTx, u16 UART_IT)
Behavior description Checks whether the specified UART interrupt has occurred or not.
Input parameter1 UARTx: where x can be 0,1 or 2 to select the UART peripheral.
Input parameter2UART_IT: specifies the interrupt source to check. Refer to section “UART_IT on page 194” for more details on the allowed values of this parameter.
Output parameter None
Return parameter The new state of UART_IT (SET or RESET).
Required preconditions None
Called functions None
Function name UART_ClearITPendingBit
Function prototypevoid UART_ClearITPendingBit(UART_TypeDef* UARTx, u16 UART_IT)
Behavior description Clears the UARTx interrupt pending bits.
Input parameter1 UARTx: where x can be 0,1or 2 to select the UART peripheral.
Input parameter2
UART_IT: specifies the interrupt pending bit to clear. More than one interrupt can be cleared using the “|” operator.
Refer to section “UART_IT on page 194” for more details on the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
UM0233 I2C interface module (I2C)
203/303
16 I2C interface module (I2C)
The I2C Bus interface module serves as interface between the microcontroller and the serial I2C bus. It provides both multi-master and slave functions, and controls all I2C bus-specific sequencing, protocol, arbitration and timing.
16.1 I2C register structure The I2C register structure I2C_TypeDef is defined in the 91x_map.h file as follows:typedef struct{vu8 CR; /* Control Register */u8 EMPTY1[3];vu8 SR1; /* Status Register 1 */u8 EMPTY2[3];vu8 SR2; /* Status Register 2 */u8 EMPTY3[3];vu8 CCR; /* Clock Control Register */u8 EMPTY4[3];vu8 OAR1; /* Own Address Register 1 */u8 EMPTY5[3];vu8 OAR2; /* Own Address Register 2 */u8 EMPTY6[3];vu8 DR; /* Data Register */u8 EMPTY7[3];vu8 ECCR; /* Extended Clock Control Register */u8 EMPTY8[3];} I2C_TypeDef;
Table 83. I2C registers
Register Description
I2C_CR Used to configure I2C mode operation
I2C_SR1 Used to check the I2C bus status
I2C_SR2 Used to check the I2C bus status
I2C_CCR I2C clock control register
I2C_OAR1 Used to define the I2C bus address of the bus
I2C_OAR2Used to define the I2C bus address of the bus (Bit 8 and 9) , and specify
I2C bus setup/hold time
I2C_DR This register contains the byte to be received or transmitted on the bus
I2C_ECCR Specify the upper 5 bits of the 11-bit clock divider
I2C interface module (I2C) UM0233
204/303
The two I2C interfaces are declared in the same file:
_I2C, _I2C0 and _I2C1 must be defined, in 91x_conf.h file, to access the peripheral registers as follows:
#define _I2C#define _I2C0#define _I2C1...
UM0233 I2C interface module (I2C)
205/303
16.2 Firmware library functions
16.2.1 I2C_DeInit
Example:/* Deinitialize the I2C0 peripheral */I2C_DeInit (I2C0);
Table 84. I2C library functions
Function name Description
I2C_DeInit Deinitializes the I2Cx peripheral registers to their default reset values.
I2C_InitInitializes the I2Cx peripheral according to the specified parameters in the I2C_InitStruct.
I2C_StructInit Fills each I2C_InitStruct member with its reset value.
I2C_Cmd Enables or disables the I2C peripheral.
I2C_GenerateSTART Generates I2C communication START condition.
I2C_GenerateSTOP Generates I2C communication STOP condition.
I2C_AcknowledgeConfig Enables or disables I2C acknowledge feature.
I2C_ITConfig Enables or disables I2C interrupt.
I2C_ReadRegister Reads any I2C register and return its value.
I2C_GetFlagStatus Checks whether a I2C flag is set or not. The tested flag is passed as parameter of the function.
I2C_ClearFlag Clears the specified I2C flag passed as parameter.
I2C_Send7bitAddress Transmits the address byte to select the slave device.
I2C_SendData Sends a data byte.
I2C_ReceiveData Reads the received byte.
I2C_GetLastEvent Gets the last I2C event that has occurred.
I2C_CheckEventChecks if the last occured event is equal to the one passed as parameter.
Function name I2C_DeInit
Function prototype void I2C_DeInit(I2C_TypeDef* I2Cx)
Behavior description Resets all I2C registers to their default values.
Input parameter I2Cx: where x can be 0,1, to select the I2C peripheral.
Output parameter None
Return parameter None
Required preconditions None
Called functions SCU_APBPeriphReset()
I2C interface module (I2C) UM0233
206/303
16.2.2 I2C_Init
I2C_InitTypeDef
The I2C_InitTypeDef structure is defined in the 91x_i2c.h file:typedef structtypedef struct{ u32 I2C_CLKSpeed; u16 I2C_OwnAddress; u8 I2C_GeneralCall; u8 I2C_Ack;}I2C_InitTypeDef;
I2C_Ack
Enable/Disable the I2C acknowledgement feature.
I2C_OwnAddress
Select the device own address. It can be a 7-bit or 10-bit address.
I2C_GeneralCall
Enables/disables the General call feature. This member can be one of the following values:
Function name I2C_Init
Function prototype void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct)
Behavior descriptionConfigures the selected I2C according to the choosen mode by writing
the corresponding value to the I2C registers.
Input parameter1 I2Cx: where x can be 0,1 to select the I2C peripheral to configure.
Input parameter2
I2C_InitStruct: pointer to a I2C_InitTypeDef structure that contains the
configuration information for the specified I2C peripheral. Refer to section “I2C_InitTypeDef on page 206” for more details on the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
I2C_Ack Meaning
I2C_Ack_Enable Enable the Acknowledgement featue
I2C_Ack_Disable Disable the Acknowledgement feature
I2C_GeneralCall Meaning
I2C_GeneralCall_Enable Enable the General call feature
I2C_GeneralCall_Disable Disable the General call feature
UM0233 I2C interface module (I2C)
207/303
I2C_ClkSpeed
Select the clock speed frequency, value must be under 400000
Example:/* Initialize the I2C peripheral according to the I2C_InitStructure members */I2C_InitTypeDef I2C_InitStructure;
Example:/* Initialize a I2C_InitTypeDef structure */I2C_InitTypeDef I2C_InitStructure;I2C_StructInit(&I2C_InitStructure);"
Function name I2C_StructInit
Function prototype void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct)
Behavior description Fills each I2C_InitStruct member with its reset value.
Input parameterI2C_InitStruct: pointer to a I2C_InitTypeDef structure which
will be initialized.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Table 85. I2C_InitStruct member default values
Member Default value
I2C_CLKSpeed 5000
I2C_OwnAddress 0
I2C_GeneralCall I2C_GeneralCall_Disable
I2C_Ack I2C_Ack_Disable
I2C interface module (I2C) UM0233
208/303
16.2.4 I2C_Cmd
Example:/* To enable I2C0 */I2C_Cmd (I2C0, ENABLE);/* To disable I2C1 */I2C_Cmd (I2C1, DISABLE);
16.2.5 I2C_GenerateSTART
Example:/*To enable the start generation for the I2C0*/I2C_GenerateSTART (I2C0, ENABLE)/*To disable the start generation for the I2C1*/I2C_GenerateSTART (I2C1, DISABLE)
Function name I2C_Cmd
Function prototype void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState)
Behavior description Enables or disables the I2C peripheral.
Input parameter1 I2Cx: where x can be 0,1, to select the I2C peripheral.
Input parameter2NewState: new state of the I2Cx peripheral. This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name I2C_GenerateSTART
Function prototype void I2C_GenerateStart(I2C_TypeDef* I2Cx, FunctionalState NewState)
Behavior description Enables or disables the I2C start generation.
Input parameter1 I2Cx: where x can be 0,1 to select the PPP peripheral.
Input parameter2NewState: specifies whether the start generation is Enabled or Disbaled.
This parameter can be ENABLE or DISABLE
Output parameter None
Return parameter None
Required preconditions The specified I2C peripheral must be enabled
Called functions None
UM0233 I2C interface module (I2C)
209/303
16.2.6 I2C_GenerateSTOP
Example:/*To enable the STOP condition generation for the I2C0*/I2C_GenerateSTOP (I2C0, ENABLE);/*To disable the STOP condition generation for the I2C1 /I2C_GenerateSTOP (I2C1, DISABLE);
16.2.7 I2C_AcknowledgeConfig
Example:/*To enable the acknowledgement feature for the I2C0*/I2C_AcknowledgeConfig (I2C0, ENABLE);/*To disable the acknowledgement feature for the I2C1*/I2C_AcknowledgeConfig (I2C1, DISABLE);
Function name I2C_GenerateSTOP
Function prototype void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState)
Behavior description Enables or disables the STOP condition generation
Input parameter 1 I2Cx : specifies the I2C to be configured
Input parameter 2NewState: specifies whether the stop generation is Enabled or Disbaled.
This parameter can be ENABLE or DISABLE
Output parameterSTOP bit in the I2C_CR is modified according to the NewState parameter
Return parameter None
Required preconditions The specified I2C peripheral must be enabled
Called functions None
Function name I2C_AcknowledgeConfig
Function prototypevoid I2C_AcknowledgeConfig(I2c_TypeDef *I2Cx, FunctionalState NewState)
Behavior description Enables or disables the I2C acknowlegement
Input parameter 1 I2Cx: specifies the I2C to be configured
Input parameter 2NewState: specifies whether the acknowledgement is enabled or disabled.
This parameter can be ENABLE or DISABLE
Output parameter None
Return parameter None
Required preconditions The specified I2C peripheral must be enabled
Called functions None
I2C interface module (I2C) UM0233
210/303
16.2.8 I2C_ITConfig
Example:/*To enable the interrupt feature for the I2C0*/ I2C_ITConfig (I2C0, Enable);/*To disable the interrupt feature for the I2C1*I2C_ITConfig (I2C1, Enable);
16.2.9 I2C_ReadRegister
Example:/*Read the I2C_CR Register*/u8 RegisterValue;RegisterValue = I2C_RegisterRead (I2C0, I2C_CR);
Function name I2C_ITConfig
Function prototype void I2C_ITConfig(I2C_TypeDef *I2Cx, FunctionalState NewState)
Behavior description Enables or disables I2C interrupt feature
Input parameter1 I2Cx: where x can be 0,1to select the I2C peripheral.
Input parameter2NewState: specifies whether the I2C interrupt is enabled or disabled.This parameter can be ENABLE or DISABLE
Output parameter ITE bit in the I2C_CR is modified according to condition parameter
Return parameter None
Required preconditions The specified I2C peripheral must be enabled
Called functions None
Function name I2C_ReadRegister
Function prototype u8 I2C_ReadRegister(I2C_TypeDef* I2Cx, u8 I2C_Register)
Behavior description Reads any I2C register and returns its value.
Input parameter1 I2Cx: where x can be 0,1to select the I2C peripheral.
Input parameter2I2C_Register: specifies the register to be read.
Refer to Table 86: I2C_Register parameter values on page 211 for the allowed values of this parameter.
Output parameter Access to register to be read
Return parameter None
Required preconditions ...
Called functions None
UM0233 I2C interface module (I2C)
211/303
I
Table 86. I2C_Register parameter values
I2C registers Meaning
I2C_CR I2C_CR selected for read
I2C_SR1 I2C_SR1 selected for read
I2C_SR2 I2C_SR2 selected for read
I2C_CCR I2C_CCR selected for read
I2C_OAR1 I2C_OAR1 selected for read
I2C_OAR2 I2C_OAR2 selected for read
I2C_DR I2C_DR selected for read
I2C_ECCR I2C_ECCR selected for read
I2C interface module (I2C) UM0233
212/303
16.2.10 I2C_GetFlagStatus
Example:/*Get the I2C_FLAG_AF status */FlagStatus Status;Status = I2C_GetFlagStatus (I2C0, I2C_FLAG_AF);
Function name I2C_GetFlagStatus
Function prototype Flagstatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, u16 I2C_FLAG)
Behavior description Checks whether the I2C flag is set or not.
Input parameter 1 I2Cx: where x can be 0,1 to select the I2C peripheral.
Input parameter 2I2C_Flag: specifies the flag to checkRefer to Table 87: I2C_Flag parameter value for the allowed values of this parameter.
Output parameter Access to register containing the flag to be checked.
Return parameter
FlagStatus: the status of the specified I2C_Flag. It can be either:
SET: if the tested flag is set
RESET: if the tested flag is reset
Required preconditions None
Called functions None
Table 87. I2C_Flag parameter value
I2C_FLAG Meaning
I2C_FLAG_SB Start (Master mode) flag
I2C_FLAG_M_SL Master/Slave flag
I2C_FLAG_ADSL Address matched (Slave mode) flag
I2C_FLAG_BTF Byte transfer finished flag
I2C_FLAG_BUSY Bus busy flag
I2C_FLAG_TRA Transmitter/Receiver flag
I2C_FLAG_ADD10 10-bit addressing in master mode flag
I2C_FLAG_EVF Event flag
I2C_FLAG_GCAL General call (slave mode) flag
I2C_FLAG_BERR Bus error flag
I2C_FLAG_ARLO Arbitration lost flag
I2C_FLAG_STOPF Stop detection (slave mode) flag
I2C_FLAG_AF Acknowledge failure flag
I2C_FLAG_ENDAD End of address transmission flag
I2C_FLAG_ACK Acknowledge enabled flag
UM0233 I2C interface module (I2C)
213/303
16.2.11 I2C_ClearFlag
Example:/*Clears I2C_FLAG_STOPF flag */I2C_ClearFlag(I2C0, I2C_FLAG_STOPF);
Function name I2C_ClearFlag
Function prototype void I2C_ClearFlag(I2C_TypeDef* I2Cx, u16 I2C_FLAG, ...)
Behavior description Clears the I2C pending flags.
Input parameter1 I2Cx: where x can be 0,1 to select the I2C peripheral.
Input parameter2I2C_Flag: specifies the flag to be cleared. Refer to Table 87: I2C_Flag parameter value on page 212 for the allowed values of this parameter.
Input parameter3Parameter needed in cases where a write to a register is needed to clear the flag.
Output parameter Some flags may be cleared when the register is read.
Return parameter None
Required preconditions None
Called functions I2C_Cmd
I2C interface module (I2C) UM0233
214/303
16.2.12 I2C_Send7bitAddress
Example:/* Send from I2C0, as transmitter, the Slave device address 0xA8 in 7-bit addressing mode */I2C_Send7bitAddress(I2C0, 0xA8, I2C_MODE_TRANSMITTER);
16.2.13 I2C_SendData
Example:/*Transmits the byte 0xAF through the I2C1*/I2C_SendData (I2C1, 0xAF);
Function name I2C_Send7bitAddress
Function prototype void I2C_Send7bitAddress(I2C_TypeDef* I2Cx, u8 Address, u8 Direction)
Behavior description Transmits the address byte to select the slave device.
Input parameter1 I2Cx: where x can be 0,1 to select the I2C peripheral.
Input parameter2 Address: specifies the slave address which will be transmitted
Input parameter3
Direction: specifies whether the I2C device will be a Transmitter or a Receiver. This parameter could be:
I2C_MODE_TRANSMITTER: Transmitter mode.
I2C_MODE_RECEIVER: Receiver mode.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name I2C_SendData
Function prototype void I2C_SendData(I2C_TypeDef* I2Cx, u8 bData)
Behavior description Transmits a single byte
Input parameter1 I2Cx: where x can be 0,1 to select the I2C peripheral.
Input parameter2 bData: indicates the data to be transmitted (1 byte)
Output parameter I2C_DR register value will be modified
Return parameter None
Required preconditions None
Called functions None
UM0233 I2C interface module (I2C)
215/303
16.2.14 I2C_ReceiveData
Example:/* I2C0 Receives a single byte */u8 bByteReceived;bByteReceived = I2C_ReceiveData(I2C0);
16.2.15 I2C_GetLastEvent
Example:/*Get the I2C0 peripheral status*/u16 LastEvent;LastEvent=I2C_GetLastEvent (I2C0);
Function name I2C_ReceiveData
Function prototype u8 I2C_ReceiveData(I2C_TypeDef* I2Cx)
Behavior description Returns the most recent received byte
Input parameter1 I2Cx: where x can be 0,1 to select the I2C peripheral.
Output parameter None
Return parameter I2C_DR register Value
Required preconditions None
Called functions None
Function name I2C_GetLastEvent
Function prototype u16 I2C_GetLastEvent(I2C_TypeDef* I2Cx)
Behavior description Gets the last occurred I2C event.
Input parameter1 I2Cx: where x can be 0,1 to select the I2C peripheral.
Output parameter None
Return parameter The last occurred event.
Required preconditions None
Called functions None
I2C interface module (I2C) UM0233
216/303
16.2.16 I2C_CheckEvent
Example:/*Checks if the last event is equal to I2C_EVENT_MASTER_BYTE_RECEIVED*/I2C_CheckEvent (I2C0, I2C_EVENT_MASTER_BYTE_RECEIVED)
Function name I2C_CheckEvent
Function prototype ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx, u16 I2C_Event
Behavior description Checks whether the last I2C event is equal to the one passed as parameter
Input parameter1 I2Cx: where x can be 0,1 to select the I2C peripheral
Input parameter2I2C_EVENT: specifies the event to be checked. Refer to Table 88: I2C_EVENT parameter values for the allowed values of this parameter.
Output parameter None
Return parameter
An ErrorStatus enumeration value:
SUCCESS: Last event is equal to the I2C_Event ERROR: Last event is different from the I2C_Event
Required preconditions None
Called functions I2C_GetLastEvent()
Table 88. I2C_EVENT parameter values
Values Meaning
I2C_EVENT_SLAVE_ADDRESS_MATCHED EV1
I2C_EVENT_SLAVE_BYTE_RECEIVED EV2
I2C_EVENT_SLAVE_BYTE_TRANSMITTED EV3
I2C_EVENT_SLAVE_STOP_DETECTED EV4
I2C_EVENT_MASTER_MODE_SELECT EV5
I2C_EVENT_MASTER_MODE_SELECTED EV6
I2C_EVENT_MASTER_BYTE_RECEIVED EV7
I2C_EVENT_MASTER_BYTE_TRANSMITTED EV8
I2C_EVENT_MASTER_MODE_ADDRESS10 EV9
I2C_EV31 EV3-1
I2C_EVENT_SLAVE_ACK_FAILURE
UM0233 3-phase induction motor controller (MC)
217/303
17 3-phase induction motor controller (MC)
The MC controller is designed for variable speed motor control applications. Three PWMoutputs are available for controlling a three-phase motor drive. Rotor speed feedback isprovided by capturing a tachogenerator input signal.
The first section describes the data structures used in the MC Firmware library. The secondone presents the Firmware library functions.
17.1 MC register structure The MC register structure MC_TypeDef is defined in the 91x_map.h file as follows:typedef struct{vu16 TCPT;u16 EMPTY1;vu16 TCMP;u16 EMPTY2;vu16 IPR;u16 EMPTY3;vu16 TPRS;u16 EMPTY4;vu16 CPRS;u16 EMPTY5;vu16 REP;u16 EMPTY6;vu16 CMPW;u16 EMPTY7;vu16 CMPV;u16 EMPTY8;vu16 CPMU;u16 EMPTY9;vu16 CMP0;u16 EMPTY10;vu16 PCR0;u16 EMPTY11;vu16 PCR1;u16 EMPTY12;vu16 PCR2;u16 EMPTY13;vu16 PSR;u16 EMPTY14;vu16 OPR;u16 EMPTY15;vu16 IMR;u16 EMPTY16;vu16 DTG;u16 EMPTY17;vu16 ESC;u16 EMPTY18;vu16 ECR; vu16 EMPTY19;vu16 LOK; vu16 EMPTY20;} MC_TypeDef;
3-phase induction motor controller (MC) UM0233
218/303
The MC is declared in the file below
#ifndef EXT #Define EXT extern#endif...#define AHB_APB_BRDG1_U (0x5C000000) /* AHB/APB Bridge 1 UnBuffered Space */#define AHB_APB_BRDG1_B (0x4C000000) /* AHB/APB Bridge 1 Buffered Space */...#define APB_MC_OFST (0x00003000) /* Offset of MC */...#ifndef Buffered #define AHBAPB1_BASE (AHB_APB_BRDG1_U)...#else /* Buffered */...#define AHBAPB1_BASE (AHB_APB_BRDG1_B)
/* MC Base Address definition*/#define MC_BASE (AHBAPB1_BASE + APB_MC_OFST)
.../* MC peripheral declaration*/
Table 89. MC registers
Register Description
TCPT Tacho capture register
TCMP Tacho compare register
IPR Interrupt pending register
TPRS Tacho prescaler register
CPRS PWM counter prescaler register
REP Repetition counter register
CMPW Compare phase W preload register
CMPV Compare phase V preload register
CMPU Compare phase U preload register
CMP0 Compare 0 preload register
PCR0 Peripheral control register 0
PCR1 Peripheral control register 1
PCR2 Peripheral control register 2
PSR Polarity selection register
OPR Output peripheral register
IMR Interrupt mask register
DTG Dead time generator register
ESC Emergency stop clear register
ECR Enhanced control register
LOK Lock register
UM0233 3-phase induction motor controller (MC)
219/303
#ifndef DEBUG...#define MC ((MC_TypeDef *) MC_BASE)...#else...EXT MC_TypeDef *MC;...
#endif
When debug mode is used, the MC pointer is initialized in the 91x_lib.c file:#ifdef _MC MC = (MC_TypeDef *)MC_BASE#endif /* _MC */
_MC must be defined, in 91x_conf.h file, to access the peripheral registers as follows:#define _MC
3-phase induction motor controller (MC) UM0233
220/303
17.2 Firmware library functions
Table 90. MC library functions
Function name Description
MC_DeInitDeinitializes the MC peripheral registers to their default reset values.
MC_InitInitializes the MC peripheral according to the specified parameters in the MC_InitStruct.
MC_StructInit Fills each MC_InitStruct member with its default value.
MC_Cmd Enables or disables the MC peripheral.
MC_ClearPWMCounter Clears the MC PWM Counter.
MC_ClearTachoCounter Clears the MC Tacho Counter.
MC_CtrlPWMOutputs Enables or disables MC peripheral Main Outputs.
MC_ITConfig Enables or disables the MC interrupts.
MC_SetPrescaler Sets the MC PWM prescaler value.
MC_SetPeriod Sets the MC period value.
MC_SetPulseU Sets the PWM pulse U value.
MC_SetPulseV Sets the PWM pulse V value.
MC_SetPulseW Sets the PWM pulse W value.
MC_SetTachoCompare Sets the MC Tacho compare value.
MC_PWMModeConfig Selects the MC PWM Counter Mode.
MC_SetDeadTime Sets the MC dead time value.
MC_EmergencyCmd Enables or disables the MC emergency feature.
MC_EmergencyClear Clears the MC emergency register.
MC_GetPeriod Gets the MC period value.
MC_GetPulseU Gets the MC pulse U value.
MC_GetPulseV Gets the MC pulse V value.
MC_GetPulseW Gets the MC pulse W value.
MC_GetTachoCapture Gets the MC Tacho capture value.
MC_ClearOnTachoCapture Enables or disables the Clear on Capture of Tacho counter.
MC_ForceDataTransfer Sets the MC outputs default states.
MC_SoftwarePreloadConfig Enables the software data transfer.
MC_SoftwareTachoCapture Enables the software Tacho capture.
MC_GetCountingStatus Checks whether the PWM counter is counting UP or DOWN.
MC_GetFlagStatus Checks whether the specified MC flag is set or not.
MC_ClearFlag Clears the MC pending flags.
MC_GetITStatus Checks whether the specified MC interrupt is occurred or not.
MC_ClearITPendingBit Clears the MC interrupt pending bits.
UM0233 3-phase induction motor controller (MC)
221/303
17.2.1 MC_DeInit
Example:/* Deinitializes the MC registers to their default reset value */MC_DeInit ();
17.2.2 MC_Init
MC_Lock Enables the lock of control register bits.
MC_CounterModeConfigSelects the 10-bits mode for the dead time counter and/or selects the 16-bits mode for the PWM counter.
MC_DoubleUpdateMode Enables or disables the Double Update Mode for the MC.
MC_ADCTrigger Enables or disables the Triggers to the ADC conversion.
MC_EnhancedStop Enables or disables the Enhanced Motor Stop feature.
MC_DebugOutputProtectionAllows the output phases to follow the polarity set by PSR if
enabled or they remain in their last known state if disabled.
MC_EmergencyStopPolarity Enables or disables theEnhanced Stop Polarity feature.
Table 90. MC library functions (continued)
Function name Description
Function name MC_DeInit
Function prototype void MC_DeInit(void)
Behavior description Deinitializes the MC peripheral registers to their default reset values.
Input parameter None
Output parameter None
Return parameter None
Required preconditions None
Called functions SCU_APBPeriphReset()
Function name MC_Init
Function prototype void MC_Init(MC_InitTypeDef* MC_InitStruct)
Behavior descriptionInitializes the MC peripheral according to the specified parameters in the MC_InitStruct.
Input parameter
MC_InitStruct: pointer to a MC_InitTypeDef structure that contains the configuration information for the MC peripheral. Refer to section “: MC_InitTypeDef on page 222” for more details on the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
3-phase induction motor controller (MC) UM0233
222/303
MC_InitTypeDef
The MC_InitTypeDef structure is defined in the 91x_mc.h file:typedef struct{u16 MC_OperatingMode;u16 MC_TachoMode;u16 MC_TachoEventMode;u8 MC_Prescaler;u16 MC_TachoPrescaler;u16 MC_PWMMode;u16 MC_Complementary;u8 MC_ForcedPWMState;u16 MC_Emergency;u16 MC_Period;u8 MC_TachoPeriod;u16 MC_Channel;u16 MC_PulseU;u16 MC_PulseV;u16 MC_PulseW;u16 MC_PolarityUL;u16 MC_PolarityUH;u16 MC_PolarityVL;u16 MC_PolarityVH;u16 MC_PolarityWL;u16 MC_PolarityWH;u16 MC_TachoPolarity;u16 MC_DeadTime;u8 MC_RepetitionCounter;} MC_InitTypeDef;
UM0233 3-phase induction motor controller (MC)
223/303
MC_OperatingMode
Specifies the MC operating mode. This member can be one of the following values:
MC_TachoMode
Specifies the MC Tacho mode. This member can be one of the following values:
MC_TachoEventMode
Specifies the MC Tacho mode. This member can be one of the following values:
MC_Prescaler
Specifies the Prescaler value to divide the MC Input clock. The clock of the PWM Counter is divided by MC_Prescaler + 1.
This member must be a number between 0x00 and 0xFF.
MC_TachoPrescaler
Specifies the Prescaler value to divide the Tacho Input clock. The clock of the Tacho Counter is divided by MC_TachoPrescaler + 1.
This member must be a number between 0x000 and 0xFFF.
MC_PWMMode
Specifies the MC PWM mode. This member can be one of the following values:
Enables or disables the complementary MC feature. This member can be one of the following values:
MC_ForcedPWMState
Specifies the default PWM signal states. This member can be one of the following values:
MC_Emergency
Enables or disables the Emergency MC feature. This member can be one of the following values:
MC_Period
Specifies the period value to be loaded in the active Auto-Reload Register at the next update event. This member must be a number between 0x0000 and 0xFFFF.
MC_TachoPeriod
Specifies the Tacho Compare period. This member must be a number between 0x00 and 0xFF.
MC_Channel
Specifies the MC Channel to be used. This member can be one of the following values:
MC_Complementary Meaning
MC_Complementary_Enable MC Complementary Mode Enable.
MC_Complementary_Disable MC Complementary Mode Disable.
MC_ForcedPWMState Meaning
MC_Polarity_Inverted PWM signal polarity inverted
MC_Polarity_NonInverted PWM signal polarity non-inverted
MC_Emergency Meaning
MC_Emergency_Enable MC Emergency Enable.
MC_Emergency_Disable MC Emergency Disable.
MC_Channel Meaning
MC_Channel_U MC Channel U is used.
MC_Channel_V MC Channel V is used.
MC_Channel_W MC Channel W is used.
MC_Channel_ALL MC Channel U, V and W are used.
UM0233 3-phase induction motor controller (MC)
225/303
MC_PulseU
Specifies the Pulse U value to be loaded in the CMPU Register.
The MC_PulseU presents the DutyCycle value. This member must be a number between 0x000 and 0x7FF.
MC_PulseV
Specifies the Pulse V value to be loaded in the CMPV Register.
The MC_PulseV presents the DutyCycle value. This member must be a number between 0x000 and 0x7FF.
MC_PulseW
Specifies the Pulse W value to be loaded in the CMPW Register.
The MC_PulseW presents the DutyCycle value. This member must be a number between 0x000 and 0x7FF.
MC_PolarityUL
Specifies the Channel UL signal Polarity. This member can be one of the following values:
MC_PolarityUH
Specifies the Channel UH signal Polarity. This member can be one of the following values:
MC_PolarityVL
Specifies the Channel VL signal Polarity. This member can be one of the following values:
MC_PolarityVH
Specifies the Channel VH signal Polarity. This member can be one of the following values:
MC_PolarityUL Meaning
MC_Polarity_Inverted Channel UL signal polarity inverted
MC_Polarity_NonInverted Channel UL signal polarity non-inverted
MC_PolarityUH Meaning
MC_Polarity_Inverted Channel UH signal polarity inverted
MC_Polarity_NonInverted Channel UH signal polarity non-inverted
MC_PolarityVL Meaning
MC_Polarity_Inverted Channel VL signal polarity inverted
MC_Polarity_NonInverted Channel VL signal polarity non-inverted
MC_PolarityVH Meaning
MC_Polarity_Inverted Channel VH signal polarity inverted
MC_Polarity_NonInverted Channel VH signal polarity non-inverted
3-phase induction motor controller (MC) UM0233
226/303
MC_PolarityWL
Specifies the Channel WL signal Polarity. This member can be one of the following values:
MC_PolarityWH
Specifies the Channel WH signal Polarity. This member can be one of the following values:
MC_TachoPolarity
Specifies the Tacho Input signal Polarity. This member can be one of the following values:
MC_DeadTime
Specifies the dead time for managing the time between the switching-off and the switching-on instants of the outputs.
MC_RepetitionCounter
Specifies the repetition counter value. Each time the RER down-counter reaches zero, an update event is generated and it restarts counting from RER value.
Example:/* The following example illustrates how to configure the MC hardware operating complementary Mode */MC_InitStructure.MC_OperatingMode = MC_HardwareOperating_Mode;MC_InitStructure.MC_TachoMode = MC_TachoContinuous_Mode;MC_InitStructure.MC_Prescaler = 0x00;MC_InitStructure.MC_TachoPrescaler = 0x000;MC_InitStructure.MC_PWMMode = MC_PWMZeroCentered_Mode;MC_InitStructure.MC_Complementary = MC_Complementary_Enable;MC_InitStructure.MC_Emergency = MC_Emergency_Enable;MC_InitStructure.MC_Period = 0x3FF;MC_InitStructure.MC_TachoCompare = 0xFF;MC_InitStructure.MC_Channel = MC_Channel_ALL;MC_InitStructure.MC_PulseU = 0x1FF;MC_InitStructure.MC_PulseV = 0xFF;MC_InitStructure.MC_PulseW = 0x7F;MC_InitStructure.MC_PolarityUL = MC_Polarity_Inverted;MC_InitStructure.MC_PolarityUH = MC_Polarity_Inverted;MC_InitStructure.MC_PolarityVL = MC_Polarity_NonInverted;MC_InitStructure.MC_PolarityVH = MC_Polarity_NonInverted;MC_InitStructure.MC_PolarityWL = MC_Polarity_Inverted;
MC_PolarityWL Meaning
MC_Polarity_Inverted Channel WL signal polarity inverted
MC_Polarity_NonInverted Channel WL signal polarity non-inverted
MC_PolarityWH Meaning
MC_Polarity_Inverted Channel WH signal polarity inverted
MC_Polarity_NonInverted Channel WH signal polarity non-inverted
MC_TachoPolarity Meaning
MC_Polarity_Inverted Tacho Input signal polarity inverted
MC_Polarity_NonInverted Tacho Input signal polarity non-inverted
Example:/* The following example illustrates how to initialize a MC_InitTypeDef structure */MC_InitTypeDef MC_InitStructure;MC_StructInit(&MC_InitStructure);
17.2.4 MC_Cmd
Example:/* Enable the MC */MC_Cmd(ENABLE);
Function name MC_StructInit
Function prototype void MC_StructInit(MC_InitTypeDef* MC_InitStruct)
Behavior description Fills each MC_InitStruct member with its default value.
Input parameterMC_InitStruct: pointer to an MC_InitTypeDef structure which
will be initialized.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name MC_Cmd
Function prototype void MC_Cmd(FunctionalState NewState)
Behavior description Enables or disables the MC peripheral.
Input parameterNewState: new state of the MC peripheral.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
3-phase induction motor controller (MC) UM0233
228/303
17.2.5 MC_ClearPWMCounter
Example:/* Clears the PWM Counter*/MC_ClearPWMCounter();
17.2.6 MC_ClearTachoCounter
Example:/* Clears the Tacho Counter*/MC_ClearTachoCounter();
17.2.7 MC_CtrlPWMOutputs
Example:/* Enable the MC Outputs */MC_CtrlPWMOutputs(ENABLE);
Function name MC_ClearPWMCounter
Function prototype void MC_ClearPWMCounter(void)
Behavior description Clears the MC PWM counter.
Input parameter None
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name MC_ClearTachoCounter
Function prototype void MC_ClearTachoCounter(void)
Behavior description Clears the MC Tacho counter.
Input parameter None
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name MC_CtrlPWMOutputs
Function prototype void MC_CtrlPWMOutputs(FunctionalState Newstate)
Behavior description Enables or disables MC peripheral Main Outputs.
Input parameterNewState: new state of the MC peripheral outputs.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
UM0233 3-phase induction motor controller (MC)
229/303
17.2.8 MC_ITConfig
MC_IT
To enable or disable MC interrupts, use a combination of one or more of the following values:
Example:/* Enables the MC Output Compare W Interrupt */MC_ITConfig(MC_IT_CMPW, ENABLE);
Function name MC_ITConfig
Function prototype void MC_ITConfig(u16 MC_IT, FunctionalState NewState)
Behavior description Enables or disables the MC interrupts.
Input parameter1MC_IT: specifies the MC interrupts sources to be enabled or disabled. Refer to Table 91: MC_IT parameter values for the allowed values of this parameter.
Input parameter2NewState: new state of the MC interrupts.
Input parameterMC_FLAG: specifies the flags to clear. Refer to Table 92: MC_FLAG parameter values on page 240 for the allowed values of this parameter
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name MC_GetITStatus
Function prototype ITStatus MC_GetITStatus(u16 MC_IT)
Behavior description Checks whether the specific MC interrupt has occurred or not.
Input parameterMC_IT: specifies the interrupt to check.
Refer to Table 91: MC_IT parameter values on page 229 for the allowed values of this parameter.
Output parameter None
Return parameter The new state of MC_IT (SET or RESET).
Required preconditions None
Called functions None
3-phase induction motor controller (MC) UM0233
242/303
17.2.32 MC_ClearITPendingBit
Example:/* Clear the MC Output Compare W interrupt pending bit */ MC_ClearITPendingBit (MC_IT_CMPW);
17.2.33 MC_Lock
Example:/*Enable the lock for the output peripheral register bit*/MC_Lock(MC_LockLevel3);
Function name MC_ClearITPending Bit
Function prototype void MC_ClearITPendingBit(u16 MC_IT)
Behavior description Clears the MC’s interrupt pending bits.
Input parameterMC_IT: specifies the pending bit to clear. Refer to Table 91: MC_IT parameter values on page 229 for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name MC_Lock
Function prototype void MC_Lock(u16 MC_LockLevel)
Behavior description Enables the lock of certain control register bits.
Input parameterMC_LockLevel: Specifies the level to be locked.
Refer to Table 93: MC_LockLevel parameter values for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Table 93. MC_LockLevel parameter values
Value Meaning
MC_LockLevel4 Lock the dead time generator register
MC_LockLevel3 Lock the output peripheral register
MC_LockLevel2 Lock the phase polarity bits
MC_LockLevel1 Lock the emergency stop disable bit
MC_LockLevel0Lock the dead time counter enable and the output dead time counter Selection bits.
UM0233 3-phase induction motor controller (MC)
243/303
17.2.34 MC_CounterModeConfig
Example:/*Enable the 16 bit-mode for the PWM counter*/MC_CounterModeConfig(MC_PWM_Counter);
17.2.35 MC_DoubleUpdateMode
Example:/*Enable the double update mode*/MC_DoubleUpdateMode(ENABLE);
Function name MC_CounterModeConfig
Function prototype void MC_CounterModeConfig(u16 MC_Counter)
Behavior descriptionEnables the 10 bits mode for the dead time counter or enables or enables the 16 bits mode for the PWM counter.
Input parameterMC_Counter: specifies the counterRefer to Table 94: MC_Counter parameter values for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Table 94. MC_Counter parameter values
MC_Counter Meaning
MC_DT_Counter Dead time counter
MC_PWM_Counter PWM counter
Function name MC_DoubleUpdateMode
Function prototype void MC_DoubleUpdateMode(FunctionalState NewState)
Behavior description Enables or disables the double update mode
Input parameterNewState: new state of the MC counter mode bits.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
3-phase induction motor controller (MC) UM0233
244/303
17.2.36 MC_ADCTrigger
Example:/*Trigger the ADC conversion when the PWM counter reaches zero*/MC_ADC_Trigger(MC_ZPC, ENABLE);
17.2.37 MC_EnhancedStop
Example:/*Enable the Enhanced Motor Stop feature*/MC_EnhancedStop(ENABLE);
Function name MC_ADCTrigger
Function prototype void MC_ADCTrigger(u16 IMC_Event, FunctionalState NewState)
Behavior description Enables or disables the trigger to the ADC conversion
Input parameter
IMC_Event: the IMC event used to trigger the ADC conversion.
Refer to Table 95: IMC_Event parameter values for the allowed values of this parameter.
NewState: new state of the ADC trigger.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Table 95. IMC_Event parameter values
Value Meaning
MC_ZPC When the PWM counter reaches zero
MC_CM0 When the PWM counter reaches its maximum count
MC_ADTWhen the PWM counter equals zero and the repetition down counter equals zero.
Function name MC_EnhancedStop
Function prototype void MC_EnhancedStop(FunctionalState NewState)
Behavior description Enables or disables the enhanced motor stop feature.
Input parameterNewState: new state of the output phases. This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
UM0233 3-phase induction motor controller (MC)
245/303
17.2.38 MC_DebugOutputProtection
Example:/*The output phases follow the polarity set by PSR*/MC_DebugOutputProtection(ENABLE);
17.2.39 MC_EmergencyStopPolarity
Example:/*Enable the Emergency Stop Polarity*/MC_EmergencyStopPolarity(ENABLE);
Function name MC_DebugOutputProtection
Function prototype void MC_DebugOutputProtection(FunctionalState NewState)
Behavior descriptionAllows the output phases to follow the polarity set by PSR if enabled or they remain in their last known state if disabled.
Input parameterNewState: new state of the output phases. This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name MC_EmergencyStopPolarity
Function prototype void MC_EmergencyStopPolarity(FunctionalState NewState)
Behavior description Enables or disables an Emergency Stop Polarity.
Input parameterNewState: new state of the output phases.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Controller area network (CAN) UM0233
246/303
18 Controller area network (CAN)
This peripheral performs communication according to the CAN protocol version 2.0 part Aand B. The bitrate can be programmed to values up to 1Mbit/s. Another main feature of thiscell is that 32 message objects are implemented which can be fully configured with 2interfaces.
The first section describes the data structures used in the CAN Firmware library. Thesecond one presents the Firmware library functions.
Note: Before using any CAN function, the I/O ports linked to the CAN RX and CAN TX pins must be set up as follows: GPIO 1.5 (CAN RX pin) must be input Tri-state CMOS, and GPIO 1.6 (CAN TX pin) must be output alternate push-pull.
18.1 CAN register structureThe structures of the CAN_TypeDef and CAN_MsgObj_TypeDef registers are defined in the 91x_map.h file as follows:typedef volatile struct{ vu16 CRR; u16 EMPTY1; vu16 CMR; u16 EMPTY2; vu16 M1R; u16 EMPTY3; vu16 M2R; u16 EMPTY4; vu16 A1R; u16 EMPTY5; vu16 A2R; u16 EMPTY6; vu16 MCR; u16 EMPTY7; vu16 DA1R; u16 EMPTY8; vu16 DA2R; u16 EMPTY9; vu16 DB1R; u16 EMPTY10; vu16 DB2R; u16 EMPTY11[27];} CAN_MsgObj_TypeDef;
The CAN is declared in the file below#ifndef EXT #Define EXT extern#endif...#define AHB_APB_BRDG1_U (0x5C000000) /* AHB/APB Bridge 1 UnBuffered Space */#define AHB_APB_BRDG1_B (0x4C000000) /* AHB/APB Bridge 1 Buffered Space */...#define APB_CAN_OFST (0x00009000) /* Offset of CAN */...#ifndef Buffered #define AHBAPB1_BASE (AHB_APB_BRDG1_U)...#else /* Buffered */...#define AHBAPB1_BASE (AHB_APB_BRDG1_B)
/* CAN Base Address definition*/#define CAN_BASE (AHBAPB1_BASE + APB_CAN_OFST)
.../* CAN peripheral declaration*/
#ifndef DEBUG...#define CAN ((CAN_TypeDef *) CAN_BASE)...#else...EXT CAN_TypeDef *CAN;...
A1R CAN IF2 Message Arbitration 1 Register
A2R CAN IF2 Message Arbitration 2 Register
MCR CAN IF2 Message Control Register
DA1R CAN IF2 DATA A 1 Register
DA2R CAN IF2 DATA A 2 Register
DB1R CAN IF2 DATA B 1 Register
DB2R CAN IF2 DATA B 2 Register
TXR1R CAN Transmission Request 1 Register
TXR2R CAN Transmission Request 2 Register
ND1R CAN New Data 1 Register
ND2R CAN New Data 2 Register
IP1R CAN Interrupt Pending 1 Register
IP2R CAN Interrupt Pending 2 Register
MV1R CAN Message Valid 1 Register
MV2R CAN Message Valid 2 Register
Table 96. CAN registers (continued)
Register Description
UM0233 Controller area network (CAN)
249/303
#endif
When debug mode is used, CAN pointer is initialized in 91x_lib.c file:
#ifdef _CAN
CAN = (CAN_TypeDef *)CAN_BASE
#endif /* _CAN */
_CAN must be defined, in 91x_conf.h file, to access the peripheral registers as follows:#define _CAN...
18.2 Firmware library functions
Table 97. CAN library functions
Function name Description
CAN_DeInitDeinitializes the CAN peripheral registers to their default reset values.
CAN_Init Initializes the CAN cell and sets the bitrate.
CAN_StructInit Fills each CAN_InitStruct member with its default value.
CAN_EnterInitMode Switches the CAN to initialization mode.
CAN_LeaveInitMode Leaves initialization mode (switches to normal mode).
CAN_EnterTestMode Switches the CAN to test mode.
CAN_LeaveTestMode Leaves the current test mode (switches to normal mode).
CAN_SetBitrate Sets up a standard CAN bitrate.
CAN_SetTiming Sets up the CAN timing with specific parameters.
CAN_SetUnusedMsgObj Configures the message object as unused.
CAN_SetTxMsgObj Configures the message object as TX.
CAN_SetRxMsgObj Configures the message object as RX.
CAN_SetUnusedAllMsgObj Configures all the message objects as unused.
CAN_ReleaseMessage Releases the message object.
CAN_ReleaseTxMessage Releases the transmit message object.
CAN_ReleaseRxMessage Releases the receive message object.
CAN_UpdateMsgObj Updates the message object
CAN_TransmitRequestRequests the transmission of a message object. A data or remote frame is sent.
CAN_SendMessage Starts transmission of a message.
CAN_ReceiveMessage Gets the message, if received.
CAN_WaitEndOfTx Waits until current transmission is finished.
CAN_BasicSendMessage Starts transmission of a message in BASIC mode.
Controller area network (CAN) UM0233
250/303
18.2.1 CAN_DeInit
Example:
This example illustrates how to initialize the CAN registers.{/* Initialize CAN registers*/ CAN_DeInit ();}
CAN_BasicReceiveMessage Gets the message in BASIC mode, if received.
CAN_GetMsgReceiveStatus Tests the waiting status of a received message.
CAN_GetMsgTransmitRequestStatus
Tests the request status of a transmitted message.
CAN_GetMsgInterruptStatus Tests the interrupt status of a message object.
CAN_GetMsgValidStatus Tests the validity of a message object (ready to use).
CAN_GetFlagStatusReturns the state of the CAN flags: TxOK, RxOK, EPASS, EWARN and BOFF
CAN_GetTransmitErrorCounter Gets the CAN transmit Error counter
CAN_GetReceiveErrorCounter Gets the CAN receive Error counter
Table 97. CAN library functions (continued)
Function name Description
Function name CAN_DeInit
Function prototype void CAN_DeInit(void)
Behavior description Deinitializes the CAN peripheral registers to their default reset values.
Input parameter None
Output parameter None
Return parameter None
Required preconditions None
Called functions SCU_APBPeriphReset()
UM0233 Controller area network (CAN)
251/303
18.2.2 CAN_Init
CAN_InitTypeDef
The CAN_InitTypeDef structure is defined in the 91x_can.h file:typedef struct{
u8 CAN_ConfigParameters;u32 CAN_Bitrate;
}CAN_InitTypeDef;
CAN_ConfigParameters
Specifies the CAN configuration parameters. This member can be any combination of the following values:
Function name CAN_Init
Function prototype void CAN_Init(CAN_InitTypeDef* CAN_InitStruct)
Behavior descriptionInitializes the CAN peripheral according to the specified parameters in the CAN_InitStruct.
Input parameter
CAN_InitStruct: pointer to a CAN_InitTypeDef structure that contains the configuration information for the CAN peripheral.
Refer to section “CAN_InitTypeDef on page 251” for more details on the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions
CAN_EnterInitMode()
CAN_SetBitrate()
CAN_LeaveInitMode()
CAN_LeaveTestMode()
CAN_ConfigParameters Meaning
CAN_CR_TEST Test mode enable
CAN_CR_CCE Configuration change enable
CAN_CR_DAR Disable automatic retransmission
CAN_CR_EIE Error interrupt enable
CAN_CR_SIE Status change interrupt enable
CAN_CR_IE Module interrupt enable
CAN_CR_INIT Initialization
Controller area network (CAN) UM0233
252/303
CAN_Bitrate
Specifies the CAN bit rate. This member can be one of the following values:
Example:
This example illustrates how to initialize the CAN at 100 kbit/s and enable the interrupts.{ /* Init Structure declarations for CAN*/ CAN_InitTypeDef CAN_InitStructure;
/*Configure CAN registers*/ CAN_InitStructure.CAN_ConfigParameters = CAN_CR_IE; CAN_InitStructure.CAN_Bitrate = CAN_BITRATE_100K; CAN_Init(&CAN_InitStructure);}
18.2.3 CAN_StructInit
Example:
This example illustrates how to initialize CAN init structure.{ /* Init Structures declarations for CAN */ CAN_InitTypeDef CAN_InitStructure;
/*Initialize CAN structure*/ CAN_StructInit (&CAN_InitStructure);}
CAN_Bitrate Meaning
CAN_BITRATE_100K 100 kbit/s bit rate
CAN_BITRATE_125K 125 kbit/s bit rate
CAN_BITRATE_250K 250 kbit/s bit rate
CAN_BITRATE_500K 500 kbit/s bit rate
CAN_BITRATE_1M 1 Mbit/s bit rate
Function name CAN_StructInit
Function prototype void CAN_StructInit(CAN_InitTypeDef* CAN_InitStruct)
Behavior description Fills each CAN_InitStruct member with its default value.
Input parameterCAN_InitStruct: pointer to a CAN_InitTypeDef structure which
will be initialized.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
UM0233 Controller area network (CAN)
253/303
18.2.4 CAN_EnterInitMode
Note: This function sets the INIT bit in the Control register, ORed with the mask and resets the Status register.
InitMask
Specifies the CAN configuration which will be set after the initialisation in normal mode. This member can be any combination of the following values:
Example:
This example illustrates how to initialize the CAN enable interrupts.{ CAN_EnterInitMode(CAN_CR_IE);}
Function name CAN_EnterInitMode
Prototype void CAN_EnterInitMode(u8 InitMask)
Behavior descriptionSwitches the CAN into initialization mode. This function must be used in conjunction with CAN_LeaveInitMode().
Input parameter InitMask: specifies the CAN configuration in normal mode.Refer to Table 98: InitMask parameter values” for the allowed values of this parameter.
Output parameter None
Return Value None
Required preconditions None
Called functions None
Table 98. InitMask parameter values
Value Meaning
CAN_CR_CCE Configuration change enable
CAN_CR_DAR Disable automatic retransmission
CAN_CR_EIE Error interrupt enable
CAN_CR_SIE Status change interrupt enable
CAN_CR_IE Module interrupt enable
Controller area network (CAN) UM0233
254/303
18.2.5 CAN_LeaveInitMode
Note: This function clears the INIT and CCE bits in the Control register.
Example:
This example illustrates how to leave CAN init mode.{ CAN_LeaveInitMode();}
Function name CAN_LeaveInitMode
Prototype void CAN_LeaveInitMode()
Behavior descriptionLeaves initialization mode (switch into normal mode).
This function must be used in conjunction with CAN_EnterInitMode().
Input parameter None
Output parameter None
Return Value None
Required preconditions None
Called functions None
UM0233 Controller area network (CAN)
255/303
18.2.6 CAN_EnterTestMode
Note: This function sets the TEST bit in the Control register to enable test mode and updates the Test register by ORing its value with the mask.
TestMask
Specifies the CAN configuration in test modes. This member can be any combination of the following values:
Example:
This example illustrates how to switch the CAN into Loopback mode, i.e. RX is disconnected from the bus, and TX is internally linked to RX.{ CAN_EnterTestMode(CAN_TESTR_LBACK);}
Function name CAN_EnterTestMode
Prototype void CAN_EnterTestMode(u8 TestMask);
Behavior descriptionSwitches the CAN into test mode.
This function must be used in conjunction with CAN_LeaveTestMode().
Input parameterTestMask: specifies the configuration in test modes.
Refer to Table 99: TestMask parameter values” for the allowed values of this parameter.
Output parameter None
Return Value None
Required preconditions None
Called functions None
Table 99. TestMask parameter values
TestMask Meaning
CAN_TESTR_LBACK Loopback mode enabled
CAN_TESTR_SILENT Silent mode enabled
CAN_TESTR_BASIC Basic mode enabled
Controller area network (CAN) UM0233
256/303
18.2.7 CAN_LeaveTestMode
Note: This function sets the TEST bit in the Control register to enable write access to the Test register, clears the LBACK, SILENT and BASIC bits in the Test register and clears the TEST bit in the Control register to disable write access to the Test register.
Example:{ CAN_LeaveTestMode();}
Function name CAN_LeaveTestMode
Prototype void CAN_LeaveTestMode()
Behavior descriptionLeaves the current test mode (switches into normal mode).
This function must be used in conjunction with CAN_EnterTestMode().
Input parameter None
Output parameter None
Return Value None
Required preconditions None
Called functions None
UM0233 Controller area network (CAN)
257/303
18.2.8 CAN_SetBitrate
Note: This function writes the predefined timing value in the Bit Timing register and clears the BRPR register.
Example:
This example illustrates how to enable the configuration change bit, to be able to set the bitrate{ CAN_EnterInitMode(CAN_CR_CCE);CAN_SetBitrate(CAN_BITRATE_100K);CAN_LeaveInitMode();}
Function name CAN_SetBitrate
Prototype void CAN_SetBitrate(u32 bitrate);
Behavior description Sets up a standard CAN bitrate.
Input parameterBitRate: specifies the bit rate.
Refer to Table 100: BitRate parameter values” for the allowed values of this parameter.
Output parameter None
Return Value None
Required preconditionsCAN_EnterInitMode() must have been called before.
The APB clock must be 8 MHz
Called functions None
Table 100. BitRate parameter values
BitRate Meaning
CAN_BITRATE_100K 100 kbit/s
CAN_BITRATE_125K 125 kbit/s
CAN_BITRATE_250K 250 kbit/s
CAN_BITRATE_500K 500 kbit/s
CAN_BITRATE_1M 1 Mbit/s
Controller area network (CAN) UM0233
258/303
18.2.9 CAN_SetTiming
Note: This function writes the timing value in the Bit Timing register, from the tseg1, tseg2, sjw parameters and bits 5..0 of brp parameter and writes the BRPR register with bits 9..0 of brp parameter; and all written values are the real values decremented by one unit.
Example:
This example illustrates how to enable the configuration change bit, to be able to set the specific timing parameters: TSEG1=11, TSEG2=4, SJW=4, BRP=5{ CAN_EnterInitMode(CAN_CR_CCE);CAN_SetTiming(11, 4, 4, 5);CAN_LeaveInitMode();}
Behavior description Sets up the CAN timing with specific parameters.
Input parameter 1tseg1: Time Segment before the sample point position.
It can take values from 1 to 16.
Input parameter 2tseg2: Time Segment after the sample point position.
It can take values from 1 to 8.
Input parameter 3sjw: Synchronization Jump Width.
It can take values from 1 to 4.
Input parameter 4brp: Baud Rate Prescaler.
It can take values from 1 to 1024.
Output parameter None
Return Value None
Required preconditions CAN_EnterInitMode() must have been called before.
Called functions None
UM0233 Controller area network (CAN)
259/303
18.2.10 CAN_SetUnusedMsgObj
Note: This function searches for a free message interface from IF0 and IF1, sets the WR/RD, Mask, Arb, Control, DataA and DataB bits in the Command Mask register, clears the Mask1 and Mask2 registers, clears the Arb1 and Arb2 register, clears the Message Control register, clears the DataA1, DataA2, DataB1, DataB2 registers and writes the value 1+msgobj in the Command Request register.
Example:
This example illustrates how to invalidate the message objects from 16 to 31: these objects will not be used by the hardware{ for (i=16; i<=31; i++) CAN_SetUnusedMsgObj(i);}
Behavior description Configure the message object as unused.
Input parametermsgobj
The message object number, from 0 to 31.
Output parameter None
Return Value None
Required preconditions
An ErrorStatus enumeration value:
- SUCCESS: Found Interface to treat the message- ERROR: No interface found to treat the message
Called functions CAN_GetFreeIF()
Controller area network (CAN) UM0233
260/303
18.2.11 CAN_SetTxMsgObj
Note: 1 This function: Search for a free message interface from IF0 and IF1. Set the WR/RD, Mask, Arb, Control, DataA and DataB bits in the Command Mask register. Clear the Mask1 and Arb1 registers. Set the MDir bit in the Mask2 register, also the MXtd bit if extended ID is used. Set the MsgVal and Dir bits in the Arb2 register, also the Xtd bit if extended ID is used. Set the TxIE and EoB bits in the Message Control register. Clear the DataA1, DataA2, DataB1, DataB2 registers. Write the value 1+msgobj to the Command Request register to copy the registers into the message RAM.
2 When defining which message object number to use for TX or RX, you must take into account the priority levels when processing the objects. The lower number (0) has the highest priority and the higher number (31) has the lowest priority, whatever their type. Also, for optimum performance, it is not recommended to have “holes” in the object list.
Example:
This example illustrates how to define transmit message object 0 with standard identifiers and disable remote functionality.{ CAN_SetTxMsgObj(0, CAN_STD_ID, DISABLE);}
Input parameter 3RemoteEN: This parameter can be: ENABLE or DISABLE.Remote functionality is enabled if ENABLE,else it’s disabled.
Output parameter None
Return Value
An ErrorStatus enumeration value:
- SUCCESS: Interface to treat the message
- ERROR: No interface to treat the message
Required preconditions None
Called functions CAN_GetFreeIF()
UM0233 Controller area network (CAN)
261/303
18.2.12 CAN_SetRxMsgObj
Note: 1 This function: Search for a free message interface from IF0 and IF1. Set the WR/RD, Mask, Arb, Control, DataA and DataB bits in the Command Mask register. Write the ID mask value formed from idLow and idHigh in the Mask1 and Mask2 registers, and also set the MXtd bit in the Mask2 register if extended ID is used. Write the ID arbitration value formed from idLow and idHigh in the Arb1 and Arb2 registers, set the MsgVal bit, and also Xtd bit in the Arb2 register if extended ID is used. Set the RxIE and UMask bits in the Message Control register, and also the EoB bit if the parameter singleOrFifoLast is TRUE. Clear the DataA1, DataA2, DataB1, DataB2 registers. Write the value 1+msgobj to the Command Request register to copy the selected registers into the message RAM.
2 Care must be taken when defining an ID range: all combinations of idLow and idHigh will not always produce the expected result, because of the way identifiers are filtered by the hardware. The criteria applied to keep a received frame is as follows: (received ID) AND (ID mask) = (ID arbitration), where AND is a bitwise operator. Consequently, for idLow, it is generally better to choose a value with some LSBs cleared, and for idHigh a value that
Input parameter 3idLow: The low part of the identifier range used for acceptance filtering.It can take values from 0 to 0x7FF for standard ID, and values from 0 to 0x1FFFFFFF for extended ID.
Input parameter 4
idHigh: The high part of the identifier range used for acceptance filtering.It can take values from 0 to 0x7FF for standard ID, and values from 0 to 0x1FFFFFFF for extended ID.idHigh must be above idLow.
For convenience, use one of the following values to set the maximum ID: CAN_LAST_STD_ID or CAN_LAST_EXT_ID
Input parameter 5
singleOrFifoLast: End-of-buffer indicator, it can take the following values:
-TRUE for a single receive object or a FIFO receive object that is the last one in the FIFO
-FALSE for a FIFO receive object that is not the last one
Output parameter None
Return Value
An ErrorStatus enumeration value:
- SUCCESS: Interface to treat the message
- ERROR: No interface to treat the message
Required preconditions None
Called functions CAN_GetFreeIF()
Controller area network (CAN) UM0233
262/303
“logically contains” idLow and with the same LSBs set. Example: the range 0x100-0x3FF will work, but the range 0x100-0x2FF will not because 0x100 is not logically contained in 0x2FF (i.e. 0x100 & 0x2FF = 0).
Example:
This example illustrates how to define FIFOs and acceptance filtering{ /*Define a receive FIFO of depth 2 (objects 0 and 1) for standard identifiers, in which IDs are filtered in the range 0x400-0x5FF*/CAN_SetRxMsgObj(0, CAN_STD_ID, 0x400, 0x5FF, FALSE);CAN_SetRxMsgObj(1, CAN_STD_ID, 0x400, 0x5FF, TRUE);/*Define a single receive object for extended identifiers, in which all IDs are filtered in*/CAN_SetRxMsgObj(2, CAN_EXT_ID, 0, CAN_LAST_EXT_ID, TRUE);}
18.2.13 CAN_SetUnusedAllMsgObj
Example:{CAN_SetUnusedAllMsgObj();}
Function name CAN_SetUnusedAllMsgObj
Prototype ErrorStatus CAN_SetUnusedAllMsgObj();
Behavior description Configures all the message objects as unused.
Input parameter None
Output parameter None
Return Value
An ErrorStatus enumeration value:
- SUCCESS: Interface to treat all messages
- ERROR: No interface to treat one message
Required preconditions None
Called functions CAN_SetUnusedMsgObj()
UM0233 Controller area network (CAN)
263/303
18.2.14 CAN_ReleaseMessage
Note: This function:
Search for a free message interface from IF0 and IF1.
Set the bits ClrIntPnd and TxRqst/NewDat in the Command Mask register.
Write the value 1+msgobj to the Command Request register to copy the selected registers into the message RAM.
Example:
This example illustrates how to release the message object 0.{ CAN_ReleaseMessage(0);}
Function name CAN_ReleaseMessage
Prototype void CAN_ReleaseMessage(u32 msgobj);
Behavior description Releases the message object.
Input parametermsgobj
The message object number, from 0 to 31.
Output parameter None
Return Value None
Required preconditions None
Called functions CAN_GetFreeIF()
Controller area network (CAN) UM0233
264/303
18.2.15 CAN_ReleaseTxMessage
Note: This function:
Sets the ClrIntPnd and TxRqst/NewDat bits in the Command Mask register of message interface 0.
Writes the value 1+msgobj to the Command Request register to copy the selected registers into the message RAM.
Example:
This example illustrates how to release transmit message object 0.{ /*It is assumed that message interface 0 is always used for transmission*//*Release the transmit message object 0*/CAN_ReleaseTxMessage(0);}
Function name CAN_ReleaseTxMessage
Prototype void CAN_ReleaseTxMessage(u32 msgobj);
Behavior description Releases the transmit message object.
Input parameter msgobj: The message object number, from 0 to 31.
Output parameter None
Return Value None
Required preconditions The message interface 0 must not be busy.
Called functions None
UM0233 Controller area network (CAN)
265/303
18.2.16 CAN_ReleaseRxMessage
Note: This function:
Sets the bits ClrIntPnd and TxRqst/NewDat in the Command Mask register of message interface 1.
Writes the value 1+msgobj to the Command Request register to copy the selected registers into the message RAM.
Example:
This example illustrates how to release the receive message object 0.{ /*It is assumed that message interface 1 is always used for reception*//*Release the receive message object 0*/CAN_ReleaseRxMessage(0);}
Function name CAN_ReleaseRxMessage
Prototype void CAN_ReleaseRxMessage(u32 msgobj);
Behavior description Releases the receive message object.
Input parameter msgobj: The message object number, from 0 to 31.
Output parameter None
Return Value None
Required preconditions The message interface 1 must not be busy.
Called functions None
Controller area network (CAN) UM0233
266/303
18.2.17 CAN_UpdateMsgObj
Example :
The following example illustrates how to update a message object already configured to transmit.
Starts the transmission of a messsage object. A data frame is transmitted if the message object is configured in transmission mode. A remote frame is transmitted if the message object is configured in reception mode.
Input parameter msgobj: The message object number, from 0 to 31.
Output parameter None
Return Value
An ErrorStatus enumeration value:
- SUCCESS: IF found to treat the message - ERROR: No IF found to treat the message
Required preconditions The message object must have been set up properly.
Controller area network (CAN) UM0233
268/303
18.2.19 CAN_SendMessage
Note: This function:
Waits for message interface 0 to be free.
Read the Arbitration and Message Control registers.
Waits for message interface 0 to be free.
Updates the Arbitration, Message Control, DataA and DataB registers with the message contents.
Writes the value 1+msgobj to the Command Request register to copy the selected registers into the message RAM and to start the transmission.
Example:
This example illustrates how to send a standard ID data frame containing 4 data value.{ canmsg CanMsg = { CAN_STD_ID, 0x111, 4, {0x10, 0x20, 0x40, 0x80} };/*Send a standard ID data frame containing 4 data values*/CAN_SendMessage(0, &CanMsg);}
Behavior description Starts transmission of a message.
Input parameter 1 msgobj: The message object number, from 0 to 31.
Input parameter 2pCanMsg: Pointer to the canmsg structure that contains the data to transmit: ID type, ID value, data length, data values.
Output parameter None
Return Value An ErrorStatus enumeration value:- SUCCESS: Transmission OK
- ERROR: No transmission
Required preconditions The message object must have been set up properly.
Called functionsCAN_UpdateMsgObj
CAN_TransmitRequest
UM0233 Controller area network (CAN)
269/303
18.2.20 CAN_ReceiveMessage
Note: This function:
Test the bit corresponding to the message object number in the NewData registers.
Clear the bit RxOk in the Status register.
Copy the message contents from the message RAM to the registers and to the structure, and release the message object if asked.
Example:
This example illustrates how to receive a message.{ canmsg CanMsg;/*Receive a message in the object 0 and ask for release*/ if (CAN_ReceiveMessage(CAN0, 0, TRUE, &CanMsg)) { /*Check or copy the message contents*/ } else { /* Error handling*/ }}
Behavior description Gets the message, if received.
Input parameter 1 msgobj: The message object number, from 0 to 31.
Input parameter 2
Release: The message release indicator, it can take the following values:
-TRUE: the message object is released at the same time as it is copied from message RAM, then it is free for next reception
-FALSE: the message object is not released, it is to the caller to do it
Input parameter 3pCanMsg: Pointer to the canmsg structure where the received message is copied.
Output parameter None
Return Value
An ErrorStatus enumeration value:
- SUCCESS: Transmission OK
- ERROR: No transmission
Required preconditions The message object must have been set up properly.
Called functions CAN_GetMsgReceiveStatus()
Controller area network (CAN) UM0233
270/303
18.2.21 CAN_WaitEndOfTx
Example:
This example illustrates how to send frames.{ /*Send consecutive data frames using message object 0*/for (i = 0; i < 10; i++){ CAN_SendMessage(0, CanMsgTable[i]); CAN_WaitEndOfTx();}}
18.2.22 CAN_BasicSendMessage
Note: This function:
Clears the bit NewDat in message interface 1.
Writes the Arbitration, Message Control, DataA and DataB registers of message interface 0, with the message contents.
Writes the value 1+msgobj to the Command Request register to start the transmission.
Function name CAN_WaitEndOfTx
Prototype ErrorStatus CAN_WaitEndOfTx(void);
BehaviorTests the TxOk bit in the Status register, and loops until it is set.
Clears this bit to prepare the next transmission.
Input parameter None
Output parameter None
Return Value An ErrorStatus enumeration value:- SUCCESS: Transmission ended
- ERROR: Transmission did not occur yet
Required preconditions A message must have been sent before.
Behavior descriptionStarts transmission of a message in BASIC mode.
This mode does not use the message RAM.
Input parameterpCanMsg: Pointer to the canmsg structure that contains the data to transmit: ID type, ID value, data length, data values.
Output parameter None
Return Value
An ErrorStatus enumeration value:
- SUCCESS: Transmission OK
- ERROR: No transmission
Required preconditions The CAN must have been switched into BASIC mode.
Called functions None
UM0233 Controller area network (CAN)
271/303
Example:
This example illustrates how to send frames.{ /*Send consecutive data frames using message object 0*/for (i = 0; i < 10; i++){ CAN_SendMessage(0, CanMsgTable[i]); CAN_WaitEndOfTx();}}
18.2.23 CAN_BasicReceiveMessage
Note: This function:
Tests the bit NewDat in the Message Control register of message interface 1.
Clears the bit RxOk in the Status register.
Copies the message contents from the message interface 1 registers to the structure.
Example:
This example illustrates how to receive frame in basic mode.{ canmsg CanMsg;/*Receive a message in BASIC mode*/if (CAN_BasicReceiveMessage(&CanMsg)){ /* Check or copy the message contents*/}else{ /* Error handling*/}}
Behavior descriptionGets the message in BASIC mode, if received.This mode does not use the message RAM.
Input parameterpCanMsg: Pointer to the canmsg structure where the received message is copied.
Output parameter None
Return Value
An ErrorStatus enumeration value:
- SUCCESS: Reception OK- ERROR: No message pending
Required preconditions The CAN must have been switched into BASIC mode.
Called functions None
Controller area network (CAN) UM0233
272/303
18.2.24 CAN_GetMsgReceiveStatus
Note: This function:
Tests the corresponding bit in the NewData 1 or 2 registers.
Example:
This example illustrates how to test the new data registers for the message object 0.{ /*Test if a message is pending in the receive message object 0*/if (CAN_GetMsgReceiveStatus(0)){ /* Receive the message from this message object (i.e. get its data from message RAM)*/}}
Function name CAN_GetMsgReceiveStatus
Function prototype FlagStatus CAN_GetMsgReceiveStatus(u32 msgobj);
Behavior description Tests the waiting status of a received message.
Input parameter msgobj : message object number, from 0 to 31.
Output parameter None
Return ValueSET if the corresponding message object has received a message waiting to be copied, else RESET.
Required preconditions The corresponding message object must have been set as RX.
Called functions None
UM0233 Controller area network (CAN)
273/303
18.2.25 CAN_GetMsgTransmitRequestStatus
Note: This function:
Tests the corresponding bit in the Transmission Request 1 or 2 registers.
Example:
This example illustrates how to test the transmit request.{ /*Send a message using object 0*/CAN_SendMessage(0, &CanMsg);/*Wait for the end of transmit request*/while (CAN_GetMsgTransmitRequestStatus(0));/*Now, the message is being processed by the priority handler of the CAN cell, and ready to be emitted on the bus*/}
Behavior description Tests the request status of a transmitted message.
Input parameter msgobj: The message object number, from 0 to 31.
Output parameter None
Return Value SET if the corresponding message is requested to transmit, else RESET.
Required preconditions A message must have been sent before.
Called functions None
Controller area network (CAN) UM0233
274/303
18.2.26 CAN_GetMsgInterruptStatus
This function Tests the corresponding bit in the Interrupt Pending 1 or 2 registers.
Example:
This example illustrates how to test interrupt pending.{ /*Send a message using object 0*/CAN_SendMessage(0, &CanMsg)/* Wait for the TX interrupt*/while (!CAN_GetMsgInterruptStatus(0));}
Behavior description Returns the transmit error counter content
Input parameter None
Output parameter None
Return Value Transmit Error Counter value
Required preconditions None
Called functions None
Function name CAN_GetReceiveErrorCounter
Prototype u32 CAN_GetReceiveErrorCounter( void );
Behavior description Returns the receive error counter content
Input parameter None
Output parameter None
Return Value Receive Error Counter value
Called functions None
Analog-to-digital converter (ADC) UM0233
278/303
19 Analog-to-digital converter (ADC)
The 10-bit ADC is a simple successive approximation based ADC that has 8 analog inputs. The analog inputs are just a simple analog switch (mux). Only one channel can be active at a time.
When debug mode is used, ADC pointer is initialized in 91x_lib.c file:#ifdef _ADC ADC = (ADC_TypeDef *)ADC_BASE#endif /* _ADC */
_ADC must be defined, in the 91x_conf.h file, to access the peripheral registers as follows:#define _ADC...
19.2 Firmware library functions
Table 102. ADC library functions
Function name Description
ADC_DeInit Reset all the ADC registers to their default values.
ADC_StructInit Reset all the Init struct parameters to their default values.
ADC_InitConfigure the ADC according to the input passed parameters.
ADC_PrescalerConfig Configure the ADC prescaler value.
ADC_GetPrescalerValue Get the ADC prescaler value.
ADC_GetFlagStatus Check whether the specified ADC flag is set or not.
ADC_ClearFlag Clear the ADC pending flags.
ADC_GetConversionValueRead the result of conversion from the appropriate data register.
ADC_GetAnalogWatchdogResultReturn the result of the comparison on the selected Analog Watchdog.
ADC_ClearAnalogWatchdogResultClear result of the comparison on the selected Analog Watchdog.
ADC_GetWatchdogThresholdGet the Higher or the Lower thresholds values of the watchdog.
ADC_ITConfig Enable /Disable the specified ADC interrupts.
ADC_StandbyModeConfig Enable/disable the standby mode.
ADC_Cmd Power on or put in the Reset mode the ADC peripheral.
ADC_ConversionCmd Start or stop the ADC conversion in the selected mode.
ADC_ExternalTrigConfig Source and edge selection of external trigger.
ADC_ExternalTrigCmd Enable or disable the external trigger feature.
ADC_DMACmd Enable or disable the DMA request for ADC.
ADC_AutomaticClockGatedCmdEnables or disables the Automatic clock gated mode( Only in Rev H).
UM0233 Analog-to-digital converter (ADC)
281/303
19.2.1 ADC_DeInit
Example:/* To initialize the ADC registers to their default values */ADC_DeInit();
19.2.2 ADC_StructInit
Example:/* Initialize the ADC structure */ADC_StructInit(&ADC_InitStruct);
Function name ADC_DeInit
Function prototype void ADC_DeInit(void)
Behavior description Deinitializes the ADC peripheral registers to their default reset values.
Input parameter None
Output parameter None
Return parameter None
Required preconditions ...
Called functions SCU_APBPeriphReset()
Function name ADC_StructInit
Function prototype void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct)
Behavior description Fills each ADC_InitStruct member with its reset value.
Input parameterADC_InitStruct: pointer to a ADC_InitTypeDef structure which will be initialized.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Analog-to-digital converter (ADC) UM0233
282/303
19.2.3 ADC_Init
ADC_InitTypeDef
The ADC_InitTypeDef structure is defined in the 91x_ADC.h file:typedef struct{ u16 ADC_WDG_High_Threshold; u16 ADC_WDG_Low_Threshold; u16 ADC_Channel_0_Mode; u16 ADC_Channel_1_Mode; u16 ADC_Channel_2_Mode; u16 ADC_Channel_3_Mode; u16 ADC_Channel_4_Mode; u16 ADC_Channel_5_Mode; u16 ADC_Channel_6_Mode; u16 ADC_Channel_7_Mode; u16 ADC_Select_Channel; FunctionalState ADC_Scan_Mode; u16 ADC_Conversion_Mode;}ADC_InitTypeDef;
ADC_WDG_High_Threshold
The high threshold value of the watchdog. It can be a value between 0 and 0x3FF.
ADC_WDG_Low_Threshold
The low threshold value of the watchdog. It can be a value between 0 and ADC_WDG_High_Threshold.
ADC_Channel_i_Mode
The channel i conversion mode. It can take one of the following values.
Function name ADC_Init
Function prototype void ADC_Init(ADC_InitTypeDef* ADC_InitStruct)
Behavior descriptionInitializes the ADC peripheral according to the specified parameters in the ADC_InitStruct.
Input parameter
ADC_InitStruct: pointer to a ADC_InitTypeDef structure that contains the configuration information for the specified ADC peripheral. Refer to section “ADC_InitTypeDef on page 282” for more details on the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
ADC_Channel_i_Mode Meaning
ADC_NoThreshold_Conversion Channel i is converted without watchdog
ADC_HighThreshold_Conversion Channel i is converted with watchdog on the higher threshold
ADC_LowThreshold_Conversion Channel i is converted with watchdog on the lower threshold
ADC_NoConversion Channel i is never converted
UM0233 Analog-to-digital converter (ADC)
283/303
ADC_Select_Channel
The channel to be converted when scan mode is disabled. It can be one of the following values.
ADC_Scan_Mode
The scan mode status. It can be one of the following values.
ADC_Conversion_Mode
The type of the conversion. It can be one of the following values.
Example:/* Configure the ADC to convert the channel 2 on the high threshold (0xFF) and in continuous mode */ADC_InitStruct ADC_Init_Structure;ADC_StructInit(&ADC_Init_Structure);ADC_Init_Structure->ADC_WDG_High_Threshold = 0xFF;ADC_Init_Structure->ADC_Channel_2_Mode = ADC_HighThreshold_Conversion;ADC_Init_Structure->ADC_Conversion_Mode = ADC_Continuous_Mode;ADC_Init(&ADC_Init_Structure);
ADC_Select_Channel Meaning
ADC_Channel_0 ADC Channel 0
ADC_Channel_1 ADC Channel 1
ADC_Channel_2 ADC Channel 2
ADC_Channel_3 ADC Channel 3
ADC_Channel_4 ADC Channel 4
ADC_Channel_5 ADC Channel 5
ADC_Channel_6 ADC Channel 6
ADC_Channel_7 ADC Channel 7
ADC_Scan_Mode Meaning
ENABLE Scan mode is enabled, all the ADC inputs are converted.
DISABLE Scan mode is disabled, only the selected channel is converted.
ADC_Conversion_Mode Meaning
ADC_Continuous_Mode The conversion is restarted continuously
ADC_Single_Mode One single conversion
Analog-to-digital converter (ADC) UM0233
284/303
19.2.4 ADC_PrescalerConfig
Example:/* Configure the ADC prescaler to 0xF */ADC_PrescalerConfig(0xF);
19.2.5 ADC_GetPrescalerValue
Example:u8 ADC_Prescaler;/* Get the ADC prescaler value */ADC_Prescaler = ADC_GetPrescalerValue();
Function name ADC_PrescalerConfig
Function prototype void ADC_PrescalerConfig(u8 ADC_Prescaler);
Behavior description Configures the ADC prescaler value.
Input parameterADC_Prescaler: specifies the prescaler value.
This parameter can be a value from 0x0 to 0xFF.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Function name ADC_GetPrescalerValue
Function prototype u8 ADC_GetPrescalerValue(void);
Behavior description Gets the ADC prescaler value.
Input parameter None
Output parameter None
Return parameter The prescaler value.
Required preconditions ...
Called functions None
UM0233 Analog-to-digital converter (ADC)
285/303
19.2.6 ADC_GetFlagStatus
Example:/* To get the end of conversion flag */FlagStatus ADC_ECV_Status;ADC_ECV_Status = ADC_GetFlagStatus(ADC_FLAG_ECV);
Function name ADC_GetFlagStatus
Function prototype FlagStatus ADC_GetFlagStatus(u16 ADC_Flag)
Behavior description Checks whether the specified ADC flag is set or not.
Input parameterADC_Flag: specifies the flag to check.
Refer to Table 103: ADC_Flag parameter values” for the allowed values of this parameter.
Output parameter None
Return parameter The new state of ADC_FLAG (SET or RESET).
Required preconditions ...
Called functions None
Table 103. ADC_Flag parameter values
Value Meaning
ADC_FLAG_OV_CH_0 Conversion overflow status for channel 0
ADC_FLAG_OV_CH_1 Conversion overflow status for channel 1
ADC_FLAG_OV_CH_2 Conversion overflow status for channel 2
ADC_FLAG_OV_CH_3 Conversion overflow status for channel 3
ADC_FLAG_OV_CH_4 Conversion overflow status for channel 4
ADC_FLAG_OV_CH_5 Conversion overflow status for channel 5
ADC_FLAG_OV_CH_6 Conversion overflow status for channel 6
ADC_FLAG_OV_CH_7 Conversion overflow status for channel 7
ADC_FLAG_ECV End of conversion status
ADC_FLAG_AWD Analog watchdog status
Analog-to-digital converter (ADC) UM0233
286/303
19.2.7 ADC_ClearFlag
ADC_Flag
To clear ADC flags, use a combination of one or more of the following values:
Example:/* To clear the end of conversion flag */ADC_ClearFlag(ADC_FLAG_ECV);
Function name ADC_ClearFlag
Function prototype void ADC_ClearFlag(16 ADC_Flag)
Behavior description Clears the ADC pending flags.
Input parameterADC_Flag: specifies the flag to clear.
Refer to Table 104: ADC_Flag parameter values” for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Table 104. ADC_Flag parameter values
Value Meaning
ADC_FLAG_ECV End of conversion status
ADC_FLAG_AWD Analog watchdog status
ADC_FLAG_ORD DMA overrun status
UM0233 Analog-to-digital converter (ADC)
287/303
19.2.8 ADC_GetConversionValue
Example:/* To get the conversion value of channel 1 */u16 ADC_Conversion_Value;ADC_Conversion_Value = ADC_GetConversionValue(ADC_Channel_1);
Function name ADC_GetConversionValue
Function prototype u16 ADC_GetConversionValue(u16 ADC_Channel)
Behavior description Reads the result of conversion from the appropriate data register.
Input parameterADC_Channel: the corresponding channel of the ADC peripheral.
Refer to Table 105: ADC channel parameter values” for the allowed values of this parameter.
Output parameter None
Return parameter Returns the result of the conversion for the specific channel.
Required preconditions ...
Called functions None
Table 105. ADC channel parameter values
Value Meaning
ADC_Channel_0 ADC Channel 0
ADC_Channel_1 ADC Channel 1
ADC_Channel_2 ADC Channel 2
ADC_Channel_3 ADC Channel 3
ADC_Channel_4 ADC Channel 4
ADC_Channel_5 ADC Channel 5
ADC_Channel_6 ADC Channel 6
ADC_Channel_7 ADC Channel 7
Analog-to-digital converter (ADC) UM0233
288/303
19.2.9 ADC_GetAnalogWatchdogResult
Example:/* To get the watchdog result of channel 1 */FlagStatus ADC_Analog_WDG_Status;ADC_Analog_WDG_Status = ADC_GetAnalogWatchdogResult(ADC_Channel_1);
Function name ADC_GetAnalogWatchdogReslt
Function prototype FlagStatus ADC_GetAnalogWatchdogResult(u16 ADC_Channel)
Behavior description Returns the result of the comparison on the selected Analog Watchdog
Input parameterADC_Channel: the corresponding channel of the ADC peripheral.
Refer to Table 105: ADC channel parameter values on page 287” for the allowed values of this parameter.
Output parameter None
Return parameter The state of the comparison (SET or RESET)
Required preconditions ...
Called functions None
UM0233 Analog-to-digital converter (ADC)
289/303
19.2.10 ADC_ClearAnalogWatchdogResult
Example:/* To clear the watchdog result of the channel 2 */ADC_ClearAnalogWatchdogResult(ADC_Channel_2);
Function name ADC_ClearAnalogWatchdogResult
Function prototype void ADC_ClearAnalogWatchdogResult(u16 ADC_Channel)
Behavior description Clear the result of the comparison on the selected Analog Watchdog
Input parameterADC_Channel: the corresponding channel of the ADC peripheral.
Refer to Table 105: ADC channel parameter values on page 287” for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Analog-to-digital converter (ADC) UM0233
290/303
19.2.11 ADC_GetWatchdogThreshold
Example:/* To get the high threshold of the watchdog*/u16 ADC_High_Threshold;ADC_High_Threshold = ADC_GetWatchdogThreshold(ADC_HighTreshold);
19.2.12 ADC_ITConfig
Function name ADC_GetWatchdogThreshold
Function prototype u16 ADC_GetWatchdogThreshold(ADC_ThresholdType ADC_Threshold)
Behavior description Gets the higher or the lower threshold values of the watchdog.
Input parameterADC_Threshold: The lower or the higher threshold.
Refer to Table 106: ADC_ThresholdType parameter values” for the allowed values of this parameter.
Output parameter None
Return parameter The selected threshold.
Required preconditions ...
Called functions None
Table 106. ADC_ThresholdType parameter values
Value Meaning
ADC_HighThreshold The high threshold of the watchdog
ADC_LowThreshold The low threshold of the watchdog
Function name ADC_ITConfig
Function prototype void ADC_ITConfig(u16 ADC_IT, FunctionalState ADC_NewState)
Behavior description Enables or disables the specified ADC interrupts.
Input parameter1ADC_IT: specifies the ADC interrupt sources to be enabled or disabled.
Refer to Table 107: ADC_IT parameter values” for the allowed values of this parameter.
Input parameter2ADC_NewState: new state of the specified ADC interrupts.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
UM0233 Analog-to-digital converter (ADC)
291/303
ADC_IT
To enable or disable ADC interrupts, use a combination of one or more of the following values:
Example:/* To enable the end of conversion interrupt */ADC_ITConfig(ADC_IT_ECV,ENABLE);
19.2.13 ADC_StandbyModeCmd
Example:/* To enable the standby mode */ADC_StandbyModeCmd(ENABLE);
19.2.14 ADC_Cmd
Example:/* To power on the ADC */ADC_Cmd(ENABLE);
Table 107. ADC_IT parameter values
Value Meaning
ADC_IT_ECV End of conversion interrupt
ADC_IT_AWD Analog watchdog interrupt
ADC_IT_ORD Overun DMA Interrupt
Function name ADC_StandbyModeCmd
Function prototype void ADC_StandbyModeCmd(FunctionalState ADC_NewState)
Behavior description Enables or disables ADC standby mode.
Input parameterADC_NewState: new state of the ADC standby mode.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Function name ADC_Cmd
Function prototype void ADC_Cmd(FunctionalState ADC_NewState)
Behavior description Powers on or puts the ADC peripheral in reset mode.
Input parameterADC_NewState: new state of the ADC peripheral.
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Analog-to-digital converter (ADC) UM0233
292/303
19.2.15 ADC_ConversionCmd
Example:/* To start the conversion */ADC_ConversionCmd(ADC_Conversion_Start);
Function name ADC_ConversionCmd
Function prototype void ADC_ConversionCmd(u16 ADC_Conversion)
Behavior description Start or stop the ADC conversion in the selected mode.
Input parameterADC_Conversion: the conversion command of the ADC peripheral.
Refer to Table 108: ADC_Conversion parameter values” for the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Table 108. ADC_Conversion parameter values
Value Meaning
ADC_Conversion_Start Start the conversion
ADC_Conversion_Stop Stop the conversion
UM0233 Analog-to-digital converter (ADC)
293/303
19.2.16 ADC_ExternalTrigConfig
ADC_ExtTrig_Edge
The ADC external trigger edges that can be selected are listed in the following table:
Example:/*External Pin trigger with rising edge*/ADC_ExternalTrigConfig(ADC_PIN_Trig , Rising_ETE);
Function name ADC_ExternalTrigConfig
Function prototype void ADC_ExternalTrigConfig(u16 ADC_ExtTrig_Src , u16 ADC_ExtTrig_Edge)
Behavior description Source and edge selection of external trigger
Input parameter1ADC_ExtTrig_Src: The ADC external trigger source
Refer to Table 109: ADC_ExtTrig_Src parameter values” for the allowed values of this parameter.
Input parameter2ADC_ExtTrig_Edge:The ADC external trigger edgeRefer to Table 110: ADC_ExtTrig_Edge parameter values” for the allowed values of this parameter.
Function prototype void ADC_ExternalTrigCmd(FunctionalState ADC_NewState)
Behavior description Enable or disable the external trigger feature.
Input parameterADC_NewState: new state of the ADC external trigger .
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
Function name ADC_DMACmd
Function prototype void ADC_DMACmd(FunctionalState ADC_NewState);
Behavior description Enables or disables the DMA request for ADC
Input parameterADC_NewState: new state of the ADC DMA .
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
UM0233 Analog-to-digital converter (ADC)
295/303
19.2.19 ADC_AutomaticClockGatedCmd
Example:/*Fast Trigger mode enable(in Rev H devices)*/ADC_AutomaticClockGatedCmd(ENABLE);
Function name ADC_AutomaticClockGatedCmd
Function prototype void ADC_AutomaticClockGatedCmd(FunctionalStateADC_NewState)
Behavior description Enables or disables the Automatic clock gated mode( Only in Rev H)
Input parameterADC_NewState: new state of the ADC DMA .
This parameter can be: ENABLE or DISABLE.
Output parameter None
Return parameter None
Required preconditions ...
Called functions None
AHB/APB Bridges (AHBAPB) UM0233
296/303
20 AHB/APB Bridges (AHBAPB)
The AHB/APB bridge provides a completely asynchronous connection between the AHB with the APB buses. The AHB/APB clock ratio could be typically around 1/10. As a consequence, an APB read access will need more than 20 AHB cycle to be done.
The first section below describes the data structures used in the AHBAPB Firmware library. The second one presents the Firmware library functions.
20.1 AHBAPB register structure The AHBAPB register structure AHBAPB_TypeDef is defined in the 91x_map.h file as follows:typedef struct{vu32 BSR; /* Bridge Status Register */vu32 BCR; /* Bridge Configuration Register */vu32 PAER; /* Peripheral Address Error register */} AHBAPB_TypeDef;
The following table presents the AHBAPB registers:
The 2 AHBAPB interfaces are declared in the same file:...#define AHB_APB_BRDG0_B (0x48000000) #define AHB_APB_BRDG1_B (0x4C000000)...#define AHB_APB_BRDG0_U (0x58000000)#define AHB_APB_BRDG1_U (0x5C000000)...#ifndef Buffered...#define AHBAPB0_BASE (AHB_APB_BRDG0_U)#define AHBAPB1_BASE (AHB_APB_BRDG1_U)...#else /* Buffered */...#define AHBAPB0_BASE (AHB_APB_BRDG0_B)#define AHBAPB1_BASE (AHB_APB_BRDG1_B)...#endif...#ifndef DEBUG...#define AHBAPB0 ((AHBAPB_TypeDef *)AHBAPB0_BASE)#define AHBAPB1 ((AHBAPB_TypeDef *)AHBAPB1_BASE)
When debug mode is used, the AHBAPB pointer is initialized in the 91x_lib.c file:#ifdef _AHBAPB0AHBAPB0 = (AHBAPB_TypeDef *)AHBAPB0_BASE;#endif /*_AHBAPB0 */#ifdef _AHBAPB1AHBAPB1 = (AHBAPB_TypeDef *)AHBAPB1_BASE;#endif /*_AHBAPB1 */
_AHBAPB, _AHBAPB0, _AHBAPB1 must be defined, in the 91x_conf.h file, to access the peripheral registers as follows:#define _AHBAPB#define _AHBAPB0#define _AHBAPB1
20.2 Firmware library functions
Table 112. AHBAPB library functions
Function name Description
AHBAPB_DeInitDeinitializes the AHBAPBx peripheral registers to their default reset values.
AHBAPB_InitInitializes the AHBAPBx peripheral according to the specified pa-rameters in the AHBAPB_InitStruct.
AHBAPB_StructInit Fills each AHBAPB_InitStruct member with its reset value.
AHBAPB_GetFlagStatus Checks whether the specified AHBAPB flag is set or not.
AHBAPB_ClearFlag Clears the AHBAPBx’s pending flags.
AHBAPB_GetPeriphAddrError Gets the AHBAPB error address peripherals.
AHB/APB Bridges (AHBAPB) UM0233
298/303
20.2.1 AHBAPB_DeInit
Example:/*Deinitializes the AHPABP0 peripheral registers to their default reset values*/AHBAPB_DeInit(AHBAPB0);
20.2.2 AHBAPB_Init
AHBAPB_InitTypeDef
The AHBAPB_InitTypeDef structure is defined in the 91x_AHBAPB.h file:typedef struct{u32 AHBAPB_Error; u32 AHBAPB_SetTimeOut;u32 AHBAPB_Split; u8 AHBAPB_SplitCounter;} AHBAPB_InitTypeDef;
AHBAPB_SetTimeOut
Sets the Time-out, in terms of APB clock periods, that the bridge can wait for a target completion, before asserting the time-out error, allowed values are from 0 to 31. When the time-out counter = 0, is disabled.
Function name AHBAPB_DeInit
Function prototype void AHBAPB_DeInit(AHBAPB_TypeDef* AHBAPBx)
Behavior descriptionDeinitializes the AHBAPBx peripheral registers to their default reset values.
Input parameter AHBAPBx: where x can be 0 or1 to select the AHBAPB peripheral.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Function name AHBAPB_Init
Function prototype void AHBAPB_Init(AHBAPB_TypeDef* AHBAPBx, AHBAPB_InitTypeDef* AHBAPB_InitStruct)
Behavior descriptionInitializes the AHBAPBx peripheral according to the specified parameters in the AHBAPB_InitStruct.
Input parameter1 AHBAPBx: where x can be 0 or1 to select the AHBAPB peripheral.
Input parameter2
AHBAPB_InitStruct: pointer to an AHBAPB_InitTypeDef structure that contains the configuration information for the specified AHBAPB peripheral. Refer to section “AHBAPB_InitTypeDef on page 298” for more details on the allowed values of this parameter.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
UM0233 AHB/APB Bridges (AHBAPB)
299/303
AHBAPB_Error
Enables or disables error generation.
This member can be one of the following values:
Note: If AHBAPB_Error_Disable is used, AHBAPB_SetTimeOut struct member has no effect.
AHBAPB_Split
Enables or disables accesses to be split after the number of AHB cycles.
This member can be one of the following values:
Note: If AHBAPB_Split_Disable is used, AHBAPB_SplitCounter struct member has no effect.
AHBAPB_SplitCounter
Sets the number of AHB cycle to be performed before returning a split to the arbiter.
Function prototype void AHBAPB_ClearFlag(AHBAPB_TypeDef* AHBAPBx, u8 AHBAPB_FLAG)
Behavior description Clears the AHBAPBx’s pending flags.
Input parameter1 AHBAPBx: where x can be 0,1 to select the AHBAPB peripheral.
Input parameter2AHBAPB_FLAG: specifies the flag to clear. To clear AHBAPB flags, use a combination of one or more of the values in Table 114: AHBAPB_FLAG parameter values.
Output parameter None
Return parameter None
Required preconditions None
Called functions None
Table 114. AHBAPB_FLAG parameter values
AHBAPB_FLAG Meaning
AHBAPB_FLAG_ERROR A previous access has been aborted because it generates an error.
AHBAPB_FLAG_OUTM An access out of memory has been attempted.
AHBAPB_FLAG_APBT A peripheral did not answer before the time out.
Function name AHBAPB_GetPeriphAddrError
Function prototype u32 AHBAPB_GetPeriphAddr(AHBAPB_TypeDef* AHBAPBx)
Behavior description Gets the AHBAPB peripheral address error.
Input parameter AHBAPBx: where x can be 0,1 to select the AHBAPB peripheral.
Modified Figure 1: Firmware library directory structure on page 18Updated Section 6.1.1: SCU register structure on page 50
Modified Section 8.2.9: VIC_GetISRVectAdd on page 90
Removed function WDG Deinit in Section 11: Watchdog timer (WDG)
UM0233
303/303
Please Read Carefully:
Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve theright to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at anytime, without notice.
All ST products are sold pursuant to ST’s terms and conditions of sale.
Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes noliability whatsoever relating to the choice, selection or use of the ST products and services described herein.
No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of thisdocument refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party productsor services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of suchthird party products or services or any intellectual property contained therein.
UNLESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIEDWARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIEDWARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWSOF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.
UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZE REPRESENTATIVE OF ST, ST PRODUCTS ARE NOT DESIGNED,AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING APPLICATIONS,NOR IN PRODUCTS OR SYSTEMS, WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY, DEATH, ORSEVERE PROPERTY OR ENVIRONMENTAL DAMAGE.
Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately voidany warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, anyliability of ST.
ST and the ST logo are trademarks or registered trademarks of ST in various countries.
Information in this document supersedes and replaces all information previously supplied.
The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners.
Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan - Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America