一、最近在玩stm32,用庫(V3.5.0)開發,被 stm32的變量定義搞的暈頭轉向,決心將其弄清楚。
在 stdint.h 文件裏,我們可以清楚的看到:
typedef signed char int8_t;
typedef signedshort int int16_t;
typedef signed int int32_t;
typedef signed __int64 int64_t;
typedef unsigned char uint8_t;
typedef unsignedshort int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned __int64 uint64_t;
typedef signed char int_least8_t;
typedef signedshort int int_least16_t;
typedef signed int int_least32_t;
typedef signed __int64 int_least64_t;
typedef unsigned char uint_least8_t;
typedef unsignedshort int uint_least16_t;
typedef unsigned int uint_least32_t;
typedef unsigned __int64 uint_least64_t;
typedef signed int int_fast8_t;
typedef signed int int_fast16_t;
typedef signed int int_fast32_t;
typedef signed __int64 int_fast64_t;
typedef unsigned int uint_fast8_t;
typedef unsigned int uint_fast16_t;
typedef unsigned int uint_fast32_t;
typedef unsigned __int64 uint_fast64_t;
typedef signed int intptr_t;
typedef unsigned int uintptr_t;
typedef signed __int64 intmax_t;
typedef unsigned __int64 uintmax_t;
在百度百科中,我們可以看到 stdint.h 的作用:
二、在 core_cm3.h 文件裏,有如下定義:
#ifdef__cplusplus
#define __I volatile
#else
#define __I volatile const
#endif
#define __O volatile
#define __IO volatile
CMSIS IO類型限定詞
IO類限定詞
#define
描述
_I
volatile const
只讀訪問
_O
volatile
只寫訪問
_IO
volatile
讀和寫訪問
stm32變量的定義
其中,volatile 的作用: 作為指令關鍵字,確保本條指令不會因編譯器的優化而省略,且要求每次直接讀值.
而 const 是一個C語言的關鍵字,它限定一個變量不允許被改變。
三、在 stm32f10x.h 文件裏,有如下定義:
typedef int32_t s32;
typedef int16_ts16;
typedef int8_t s8;
typedef constint32_t sc32;
typedef constint16_t sc16;
typedef constint8_t sc8;
typedef __IOint32_t vs32;
typedef __IOint16_t vs16;
typedef __IOint8_t vs8;
typedef __Iint32_t vsc32;
typedef __Iint16_t vsc16;
typedef __I int8_tvsc8;
typedef uint32_t u32;
typedef uint16_tu16;
typedef uint8_t u8;
typedef constuint32_t uc32;
typedef constuint16_t uc16;
typedef constuint8_t uc8;
typedef __IOuint32_t vu32;
typedef __IOuint16_t vu16;
typedef __IOuint8_t vu8;
typedef __Iuint32_t vuc32;
typedef __Iuint16_t vuc16;
typedef __I uint8_tvuc8;
固件庫與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位數據 |
變量聲明宏定義及重命名基本都在此了!