CMSIS-Driver
Version 2.05
Peripheral Interface for Middleware and Application Code
|
This section gives an overview of the general operation of CMSIS-Drivers. It explains the Common Driver Functions that are common in all CMSIS-Drivers along with the Function Call Sequence. The topic Data Transfer Functions describes how data read/write operations to the peripheral are implemented.
Each CMSIS-Driver defines an Access Struct for calling the various driver functions and each peripheral (that is accessed via a CMSIS-Driver) has one Driver Instance.
Each CMSIS-Driver contains these functions:
ARM_POWER_FULL:
Peripheral is turned on and fully operational. The driver initializes the peripheral registers, interrupts, and (optionally) DMA.ARM_POWER_LOW:
(optional) Peripheral is in low power mode and partially operational; usually, it can detect external events and wake-up.ARM_POWER_OFF:
Peripheral is turned off and not operational (pending operations are terminated). This is the state after device reset.The section Function Call Sequence contains more information on the operation of each function. Additional functions are specific to each driver interface and are described in the individual sections of each driver.
The CMSIS-Driver functions access peripherals and interrupts and are designed to execute in Privileged mode. When calling CMSIS-Driver functions from RTOS threads, it should be ensure that these threads execute in Privileged mode.
For normal operation of the driver, the API functions GetVersion, GetCapabilities, Initialize, PowerControl, Uninitialize are called in the following order:
The functions GetVersion and GetCapabilities can be called any time to obtain the required information from the driver. These functions return always the same information.
To start working with a peripheral the functions Initialize and PowerControl need to be called in this order:
ARM_POWER_FULL
) sets the peripheral registers including interrupt (NVIC) and optionally DMA. The function can be called multiple times; if the registers are already set it performs no operation and just returns with ARM_DRIVER_OK.To stop working with a peripheral the functions PowerControl and Uninitialize need to be called in this order:
The functions PowerControl and Uninitialize always execute and can be used to put the peripheral into a Safe State, for example after any data transmission errors. To restart the peripheral in a error condition, you should first execute the Stop Sequence and then the Start Sequence.
ARM_POWER_OFF
) terminates any pending data transfers with the peripheral, disables the peripheral and leaves it in a defined mode (typically the reset state).All CMSIS-Driver provide a Start Sequence and Stop Sequence. Therefore two different drivers can share the same I/O pins, for example UART1 and SPI1 can have overlapping I/O pins. In this case the communication channels can be used as shown below:
A CMSIS-Driver implements non-blocking functions to transfer data to a peripheral. This means that the driver configures the read or write access to the peripheral and instantly returns to the calling application. The function names for data transfer end with:
During a data transfer, the application can query the number of transferred data items using functions named GetxxxCount. On completion of a data transfer, the driver calls a callback function with a specific event code.
During the data exchange with the peripheral, the application can decide to:
The following diagram shows the basic communication flow when using the _Send function in an application.
A CMSIS-Driver publishes an Access Struct with the data type name ARM_DRIVER_xxxx that gives to access the driver functions.
Code Example: Function Access of the SPI driver
A device may offer several peripherals of the same type. For such devices, the CMSIS-Driver publishes multiple instances of the Access Struct. The name of each driver instance reflects the names of the peripheral available in the device.
Code Example: Access Struct for three SPIs in a microcontroller device.
The access functions can be passed to middleware to specify the driver instance that the middleware should use for communication.
Example:
For a device family, the drivers may be configurable. The Reference Implementation stores configuration options in a central file with the name RTE_Device.h. However, the configuration of the drivers itself is not part of the CMSIS-Driver specification.
The following example code shows the usage of the SPI interface.