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


Contents

  1. About
  2. CMSIS Uart Device Files
  3. CMSIS Uart Device Definitions
  4. CMSIS Uart Device I/O Block
  5. CMSIS Uart Device Functions
  6. 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_
Valid values are:

  • 1..3

_USART_REMAP_
Valid values are:

  • 0 USART pins are not remapped (default)
  • 1 USART1 pins are remapped
  • 2 USART2 pins are remapped
  • 3 USART3 pins are partial remapped
  • 4 USART3 pins are full remapped

_BUF_SIZE_
Valid values are:

  • 2..n n must be a power of 2

 

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
8 databits are used.

UartDev_DATABITS_9
9 databits are used.

UartDev_STOPBITS_0_5
0.5 stopbits are used.

UartDev_STOPBITS_1
1 stopbit is used.

UartDev_STOPBITS_1_5
1.5 stopbits are used.

UartDev_STOPBITS_2
2 stopbits are used.

UartDev_PARITY_NONE
No parity is used.

UartDev_PARITY_ODD
Odd parity is used.

UartDev_PARITY_EVEN
Even parity is used.

UartDev_FLAG_BLOCKING
Blocking data transmission is used.

UartDev_FLAG_NONBLOCKING
Nonblocking data transmission is used.

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
Baudrate to use (e.g. 9600, ..., 115200, ...)

DataBis
Valid values are:

  • UartDev_DATABITS_8
  • UartDev_DATABITS_9

StopBits
Valid values are:

  • UartDev_STOPBITS_0_5
  • UartDev_STOPBITS_1
  • UartDev_STOPBITS_1_5
  • UartDev_STOPBITS_2

Parity
Valid values are:

  • UartDev_PARITY_NONE
  • UartDev_PARITY_ODD
  • UartDev_PARITY_EVEN

Reserved
Reserved for future use.

 

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
A UartDev_CFG structure holding the configuration parameter.

int (*Init) (void);
Function pointer to Init function.

int (*UnInit) (void);
Function pointer to UnInit function.

int (*BufTx) (void *pData, int* pSize, unsigned int flags);
Function pointer to data transmit function.

int (*BufRx) (void *pData, int* pSize, unsigned int flags);
Function pointer to data receive function.

int (*BufFlush) (void);
Function pointer to Flush buffer function.

 

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
  • Success (0)
  • Failed (-1)

Function UartDev_UnInit

Summary
static int  UartDev_UnInit (void);
Description This function uninitializes the Uart Device Driver and stops it.
Parameter none
Return Code
  • Success (0)
  • Failed (-1)

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
Pointer to the data to send.

pSize
Number of bytes to send. If nonblocking transmission is used number of bytes actualy sent.

flags
Selects transmission to use. Valid values are:

  • UartDev_FLAG_BLOCKING
  • UartDev_FLAG_NONBLOCKING

Return Code
  • Success (0)
  • Failed (-1)

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
Pointer to a buffer to store the data.

pSize
Number of bytes to receive. If nonblocking transmission is used number of bytes actualy received.

flags
Selects transmission to use. Valid values are:

  • UartDev_FLAG_BLOCKING
  • UartDev_FLAG_NONBLOCKING

Return Code
  • Success (0)
  • Failed (-1)

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
  • Success (0)
  • Failed (-1)

 

Flowcharts

The following Flowchart shows a typical Uart Device flow.

CMSIS_UartDev_Interrupt