Cortex Microcontroller Software Interface Standard
UART Device
This file describes the UART Device Driver for Cortex Microcontroller Software Interface Standard (CMSIS).
Version: 1.10 - 24. February 2009
Information in this file, the accompany manuals, and software is
Copyright © ARM Ltd.
All rights reserved.
Revision History
- Revision 0.01 - January 2009: Concept
- Revision 1.10 - February 2009: First Release
Contents
- About
- CMSIS Uart Device Files
- CMSIS Uart Device Definitions
- CMSIS Uart Device I/O Block
- CMSIS Uart Device Functions
- Flowcharts
About
The CMSIS Uart Device provides a standard interface to a Universal synchronous asynchronous receiver transmitter (USART) that is part of a Cortex-M3 system. This interface is an hardware abstraction layer for the USART. It consists of a general Uart Device Driver (files UartDev.h) and a device specific Uart Device Driver (files UartDev_STM32.[h,c]). The device specific Uart Device Driver provides an I/O Block to pass parameter and to access the Device Driver. Each Uart Device needs a device specific Uart Device Driver which provides it's own I/O block.
To ease use and design of the Uart Device Driver only one USART can be used and also no flowcontrol is supported. This will cover most of the use cases for an USART.
CMSIS Uart Device Files
The sample driver is implemented for a ST Microlectronics STM32F103 device and uses the following files:
Name | Description |
---|---|
UartDev.h | Global defines and structure definitions for general Uart Device interface. |
UartDev_STM32.h | Device dependent definitions of the device specific Uart Device Driver. |
UartDev_STM32.c | Device specific Uart Device Driver. |
File UartDev.h
Description | File UartDev.h contains function prototypes and type definitions for configuration values. Also global defines are part of this file. File UartDev.h must be included in the application. This file contains the type definition for I/O Block. The I/O block contains configuration values and function pointer to access the device specific Uart Device Driver . |
File UartDev_STM32.h
Description | File UartDev_STM32.h contains STM32F103 device specific defines like registers and register values. It is only included from file UartDev_STM32.c. |
File UartDev_STM32.c
Description | File UartDev_STM32.c contains static functions of this specific Uart Device Driver and provides the Device Driver specific I/O block. It must be linked to the application. The compiler switches _USART_, _USART_REMAP_are used to select the USART and the USART pins. The compiler switch _BUF_SIZE_ is used specify the size of the receive and transmit buffer. |
Compiler switches |
_USART_
_USART_REMAP_
_BUF_SIZE_
|
CMSIS Uart Device Definitions
Uart Device Driver uses following definitions for configuartion and function parameter values:
Name | Description |
---|---|
Global Defines | Global defined values. |
Uart Configuration | Uart Configuration parameters. |
Global Defines
Summary |
#define UartDev_DATABITS_8 8 #define UartDev_DATABITS_9 9 #define UartDev_STOPBITS_0_5 3 #define UartDev_STOPBITS_1 1 #define UartDev_STOPBITS_1_5 4 #define UartDev_STOPBITS_2 2 #define UartDev_PARITY_NONE 0 #define UartDev_PARITY_ODD 1 #define UartDev_PARITY_EVEN 2 #define UartDev_FLAG_BLOCKING 0 #define UartDev_FLAG_NONBLOCKING 1 |
Description |
These defines are used from the Uart Device Driver. |
Define |
UartDev_DATABITS_8 UartDev_DATABITS_9 UartDev_STOPBITS_0_5 UartDev_STOPBITS_1 UartDev_STOPBITS_1_5 UartDev_STOPBITS_2 UartDev_PARITY_NONE UartDev_PARITY_ODD UartDev_PARITY_EVEN UartDev_FLAG_BLOCKING UartDev_FLAG_NONBLOCKING |
Uart Configuration
Summary |
typedef struct { int BaudRate:20; int DataBits:4; int StopBits:3; int Parity:2; int Reserved:3; } UartDev_CFG; |
Description |
Uart Configuration attributes and explanation. |
Attributes |
BaudRate DataBis
StopBits
Parity
Reserved |
CMSIS Uart Device I/O Block
Uart Device Driver defines the following structure to pass initialization data and to access device specific functions:
Name | Description |
---|---|
UartDev_IOB | Structure for configuration values and functions pointers to the Uart Device Driver. |
Structure UartDev_IOB
Summary |
typedef struct { UartDev_CFG Cfg; int (*Init) (void); int (*UnInit) (void); int (*BufTx) (void *pData, int* pSize, unsigned int flags); int (*BufRx) (void *pData, int* pSize, unsigned int flags); int (*BufFlush)(void); } UartDev_IOB; |
Description |
This structure is used to hold configuration values and function pointers to access the device specific Uart Device Driver. The configuration values are preset with default values. |
Attributes |
Cfg int (*Init) (void); int (*UnInit) (void); int (*BufTx) (void *pData, int* pSize, unsigned int flags); int (*BufRx) (void *pData, int* pSize, unsigned int flags); int (*BufFlush) (void); |
CMSIS Uart Device Functions
Uart Device Driver contains the following static functions:
Name | Description |
---|---|
UartDev_Init | Initialize and start the Uart Device Driver. |
UartDev_UnInit | Uninitialize and stop the Uart Device Driver. |
UartDev_BufTx | Pass data to the Uart Device Driver to transmit. |
UartDev_BufRx | Receive data from the Uart Device Driver. |
UartDev_BufFlush | Flush receive and transmit buffer from the Uart Device Driver. |
Function UartDev_Init
Summary |
static int UartDev_Init (void); |
Description | This function initializes the Uart Device Driver according the UartDev_IOB structure and starts it. |
Parameter | none |
Return Code |
|
Function UartDev_UnInit
Summary |
static int UartDev_UnInit (void); |
Description | This function uninitializes the Uart Device Driver and stops it. |
Parameter | none |
Return Code |
|
Function UartDev_BufTx
Summary |
static int UartDev_BufTx (void *pData, int* pSize, unsigned int flags); |
Description | This function passes data to the specific Uart Device Driver to transmit. If blocking tansmission is selected than this function blocks until the comlete data is sent. If nonblocking transmission is selected than this function sends as much data as fits in the transmit buffer. |
Parameter |
pData pSize flags
|
Return Code |
|
Function UartDev_BufRx
Summary |
static int UartDev_BufRx (void *pData, int* pSize, unsigned int flags); |
Description | This function reads data from the specific Uart Device Driver. If blocking tansmission is selected than this function blocks until the comlete data is received. If nonblocking transmission is selected than this function receives tye current data stored in the transmit buffer. This might be less than specified with pSize. |
Parameter |
pData pSize flags
|
Return Code |
|
Function UartDev_BufFlush
Summary |
static int UartDev_BufFlush(void); |
Description | This function flushs the receive and transmit buffer from the specific Uart Device Driver. |
Parameter | none |
Return Code |
|
Flowcharts
The following Flowchart shows a typical Uart Device flow.