一、介绍CMISIS
什么是CMSIS(cortex microcontrol software interface standard一种软件标准接口),官网地址:https://arm-software.github.io/CMSIS_6/latest/General/index.html
包含的core、driver、RTOS、dsp、nn等部分,这些源码文件的编写有的是ARM官方编写,有的是半导体厂商编写,标准是ARM联合这些半导体厂商联合制定的。
二、CMSIS-core部分介绍
一般工程都需要包含CMSIS-core部分文件,包括启动文件,系统初始化文件还有头文件等
启动文件:
系统初始化和一些头文件:
c
system_stm32f10x.c
至于其作用,解释几个头文件,stm32f10x.h是stm32f10x系列单片机寄存器定义的头文件,core_cm3.h 是ARM对cortex-M3系列单片机做出的统一标准等,至此就是对CMSIS-core部分的大致介绍。
三、CMSIS RTE框架的介绍
一些重要或者有必要了解的头文件:
c
RTE_Device.h 管理外设驱动
RTE_Components.h 组件管理
驱动源文件,有的需要配合标准库或者HAL库来使用
里面的函数整合在ARM的CMSIS框架中
以spi为例子Driver_SPI.h中提供的框架
c
/**
\brief Access structure of the SPI Driver.
*/
typedef struct _ARM_DRIVER_SPI {
ARM_DRIVER_VERSION (*GetVersion) (void); ///< Pointer to \ref ARM_SPI_GetVersion : Get driver version.
ARM_SPI_CAPABILITIES (*GetCapabilities) (void); ///< Pointer to \ref ARM_SPI_GetCapabilities : Get driver capabilities.
int32_t (*Initialize) (ARM_SPI_SignalEvent_t cb_event); ///< Pointer to \ref ARM_SPI_Initialize : Initialize SPI Interface.
int32_t (*Uninitialize) (void); ///< Pointer to \ref ARM_SPI_Uninitialize : De-initialize SPI Interface.
int32_t (*PowerControl) (ARM_POWER_STATE state); ///< Pointer to \ref ARM_SPI_PowerControl : Control SPI Interface Power.
int32_t (*Send) (const void *data, uint32_t num); ///< Pointer to \ref ARM_SPI_Send : Start sending data to SPI Interface.
int32_t (*Receive) ( void *data, uint32_t num); ///< Pointer to \ref ARM_SPI_Receive : Start receiving data from SPI Interface.
int32_t (*Transfer) (const void *data_out,
void *data_in,
uint32_t num); ///< Pointer to \ref ARM_SPI_Transfer : Start sending/receiving data to/from SPI.
uint32_t (*GetDataCount) (void); ///< Pointer to \ref ARM_SPI_GetDataCount : Get transferred data count.
int32_t (*Control) (uint32_t control, uint32_t arg); ///< Pointer to \ref ARM_SPI_Control : Control SPI Interface.
ARM_SPI_STATUS (*GetStatus) (void); ///< Pointer to \ref ARM_SPI_GetStatus : Get SPI status.
} const ARM_DRIVER_SPI;
在SPI_STM32F10x.c中的使用
c
// SPI1
#ifdef MX_SPI1
static int32_t SPI1_Initialize (ARM_SPI_SignalEvent_t pSignalEvent) { return SPI_Initialize (pSignalEvent, &SPI1_Resources); }
static int32_t SPI1_Uninitialize (void) { return SPI_Uninitialize (&SPI1_Resources); }
static int32_t SPI1_PowerControl (ARM_POWER_STATE state) { return SPI_PowerControl (state, &SPI1_Resources); }
static int32_t SPI1_Send (const void *data, uint32_t num) { return SPI_Send (data, num, &SPI1_Resources); }
static int32_t SPI1_Receive (void *data, uint32_t num) { return SPI_Receive (data, num, &SPI1_Resources); }
static int32_t SPI1_Transfer (const void *data_out, void *data_in, uint32_t num) { return SPI_Transfer (data_out, data_in, num, &SPI1_Resources); }
static uint32_t SPI1_GetDataCount (void) { return SPI_GetDataCount (&SPI1_Resources); }
static int32_t SPI1_Control (uint32_t control, uint32_t arg) { return SPI_Control (control, arg, &SPI1_Resources); }
static ARM_SPI_STATUS SPI1_GetStatus (void) { return SPI_GetStatus (&SPI1_Resources); }
void SPI1_IRQHandler (void) { SPI_IRQHandler (&SPI1_Resources); }
#ifdef MX_SPI1_TX_DMA_Instance
void SPI1_TX_DMA_Handler (uint32_t events) { SPI_TX_DMA_Complete (events, &SPI1_Resources); }
#endif
#ifdef MX_SPI1_RX_DMA_Instance
void SPI1_RX_DMA_Handler (uint32_t events) { SPI_RX_DMA_Complete (events, &SPI1_Resources); }
#endif
ARM_DRIVER_SPI Driver_SPI1 = {
SPIX_GetVersion,
SPIX_GetCapabilities,
SPI1_Initialize,
SPI1_Uninitialize,
SPI1_PowerControl,
SPI1_Send,
SPI1_Receive,
SPI1_Transfer,
SPI1_GetDataCount,
SPI1_Control,
SPI1_GetStatus
};
#endif
先记录到这里,这里要注意一个分层次的关系,后续还会引入RTOS依次会设计的层次是软件层->RTOS层->设备层->驱动层->寄存器层。