這段程序完成了DMA1通道的配置,首先定義了DMA_InitType DMA_InitStructure,接著配置DMA_InitType的各種參數,各參數的命名方式也均使用約定的命名方式,從命名就能夠很容易的看出各參數所指代的具體功能。功能參數配置完成后,使用DMA_Init(DMA1_Channel1, &DMA_InitStructure);完成相應外設的初始化,最后使用DMA_Cmd(DMA1_Channel1, ENABLE) 使能相應外設。從這個例子就能夠很容易的看出標準外設庫這種規范化的命名規則給編寫和閱讀程序帶來的好處。
3. 變量定義在早期的版本中有24個變量定義,在Keil的安裝根目錄下,可以找到對應的定義,路徑為:Keil\ARM\INC\ST\STM32F10x\stm32f10x_type.h
/* Includes ------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef signed long s32;
typedef signed short s16;
typedef signed char s8;
typedef signed long const sc32; /* Read Only */
typedef signed short const sc16; /* Read Only */
typedef signed char const sc8; /* Read Only */
typedef volatile signed long vs32;
typedef volatile signed short vs16;
typedef volatile signed char vs8;
typedef volatile signed long const vsc32; /* Read Only */
typedef volatile signed short const vsc16; /* Read Only */
typedef volatile signed char const vsc8; /* Read Only */
typedef unsigned long u32;
typedef unsigned short u16;
typedef unsigned char u8;
typedef unsigned long const uc32; /* Read Only */
typedef unsigned short const uc16; /* Read Only */
typedef unsigned char const uc8; /* Read Only */
typedef volatile unsigned long vu32;
typedef volatile unsigned short vu16;
typedef volatile unsigned char vu8;
typedef volatile unsigned long const vuc32; /* Read Only */
typedef volatile unsigned short const vuc16; /* Read Only */
typedef volatile unsigned char const vuc8; /* Read Only */
3.0以后的版本中使用了CMSIS數據類型,變量的定義有所不同,但是出于兼容舊版本的目的,以上的數據類型仍然兼容。CMSIS的IO類型限定詞如表 5?7所示,CMSIS和STM32固件庫的數據類型對比如表 5?8所示。這些數據類型可以在STM32F10x_StdPeriph_Lib_V3.4.0\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\stm32f10x.h中找到具體的定義,此部分定義如下。
/*!< STM32F10x Standard Peripheral Library old types (maintained for legacy purpose) */
typedef int32_t s32;
typedef int16_t s16;
typedef int8_t s8;
typedef const int32_t sc32; /*!< Read Only */
typedef const int16_t sc16; /*!< Read Only */
typedef const int8_t sc8; /*!< Read Only */
typedef __IO int32_t vs32;
typedef __IO int16_t vs16;
typedef __IO int8_t vs8;
typedef __I int32_t vsc32; /*!< Read Only */
typedef __I int16_t vsc16; /*!< Read Only */
typedef __I int8_t vsc8; /*!< Read Only */
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
typedef const uint32_t uc32; /*!< Read Only */
typedef const uint16_t uc16; /*!< Read Only */
typedef const uint8_t uc8; /*!< Read Only */
typedef __IO uint32_t vu32;
typedef __IO uint16_t vu16;
typedef __IO uint8_t vu8;
typedef __I uint32_t vuc32; /*!< Read Only */
typedef __I uint16_t vuc16; /*!< Read Only */
typedef __I uint8_t vuc8; /*!< Read Only */
表 5?7 CMSIS IO類型限定詞
IO類限定詞
#define
描述
_I
volatile const
只讀訪問
_O
volatile
只寫訪問
_IO
volatile
讀和寫訪問
表 5?8 固件庫與CMSIS數據類型對比
固件庫類型
CMSIS類型
描述
s32
int32_t
易揮發只讀有符號32位數據
s16
int16_t
易揮發只讀有符號16位數據
s8
int8_t
易揮發只讀有符號8位數據
sc32
const int32_t
只讀有符號32位數據
sc16
const int16_t
只讀有符號16位數據
sc8
const int8_t
只讀有符號8位數據
vs32
_IO int32_t
易揮發讀寫訪問有符號32位數據
vs16
_IO int16_t
易揮發讀寫訪問有符號16位數據
vs8
_IO int8_t
易揮發讀寫訪問有符號8位數據
vsc32
_I int32_t
易揮發只讀有符號32位數據
vsc16
_I int16_t
易揮發只讀有符號16位數據
vsc8
_I int8_t
易揮發只讀有符號8位數據
u32
uint32_t
無符號32位數據
u16
uint16_t
無符號16位數據
u8
uint8_t
無符號8位數據
uc32
const uint32_t
只讀無符號32位數據
uc16
const uint16_t
只讀無符號16位數據
uc8
const uint8_t
只讀無符號8位數據
vu32
_IO uint32_t
易揮發讀寫訪問無符號32位數據
vu16
_IO uint16_t
易揮發讀寫訪問無符號16位數據
vu8
_IO uint8_t
易揮發讀寫訪問無符號8位數據
vuc32
_I uint32_t
易揮發只讀無符號32位數據
vuc16
_I uint16_t
易揮發只讀無符號16位數據
vuc8
_I uint8_t
易揮發只讀無符號8位數據
stm32f10x.h文件中還包含了常用的布爾形變量定義,如:
typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus;
typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
#define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus;
電子發燒友App















評論