一、最近在玩stm32,用庫(V3.5.0)開發(fā),被 stm32的變量定義搞的暈頭轉向,決心將其弄清楚。
在 stdint.h 文件里,我們可以清楚的看到:
typedef signed char int8_t;
typedef signed short int int16_t;
typedef signed int int32_t;
typedef signed __int64 int64_t;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned __int64 uint64_t;
typedef signed char int_least8_t;
typedef signed short int int_least16_t;
typedef signed int int_least32_t;
typedef signed __int64 int_least64_t;
typedef unsigned char uint_least8_t;
typedef unsigned short 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
讀和寫訪問
表格摘自http://forum.eepw.com.cn/thread/215752/1
其中,volatile的作用: 作為指令關鍵字,確保本條指令不會因編譯器的優(yōu)化而省略,且要求每次直接讀值.
而const是一個C語言的關鍵字,它限定一個變量不允許被改變。
三、在 stm32f10x.h 文件里,有如下定義:
typedef int32_t s32;
typedef int16_t s16;
typedef int8_t s8;
typedef const int32_t sc32;
typedef const int16_t sc16;
typedef const int8_t sc8;
typedef __IO int32_t vs32;
typedef __IO int16_t vs16;
typedef __IO int8_t vs8;
typedef __I int32_t vsc32;
typedef __I int16_t vsc16;
typedef __I int8_t vsc8;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
typedef const uint32_t uc32;
typedef const uint16_t uc16;
typedef const uint8_t uc8;
typedef __IO uint32_t vu32;
typedef __IO uint16_t vu16;
typedef __IO uint8_t vu8;
typedef __I uint32_t vuc32;
typedef __I uint16_t vuc16;
typedef __I uint8_t vuc8;
固件庫與CMSIS數(shù)據(jù)類型對比
固件庫類型
CMSIS類型
描述
s32
int32_t
易揮發(fā)只讀有符號32位數(shù)據(jù)
s16
int16_t
易揮發(fā)只讀有符號16位數(shù)據(jù)
s8
int8_t
易揮發(fā)只讀有符號8位數(shù)據(jù)
sc32
const int32_t
只讀有符號32位數(shù)據(jù)
sc16
const int16_t
只讀有符號16位數(shù)據(jù)
sc8
const int8_t
只讀有符號8位數(shù)據(jù)
vs32
_IO int32_t
易揮發(fā)讀寫訪問有符號32位數(shù)據(jù)
vs16
_IO int16_t
易揮發(fā)讀寫訪問有符號16位數(shù)據(jù)
vs8
_IO int8_t
易揮發(fā)讀寫訪問有符號8位數(shù)據(jù)
vsc32
_I int32_t
易揮發(fā)只讀有符號32位數(shù)據(jù)
vsc16
_I int16_t
易揮發(fā)只讀有符號16位數(shù)據(jù)
vsc8
_I int8_t
易揮發(fā)只讀有符號8位數(shù)據(jù)
u32
uint32_t
無符號32位數(shù)據(jù)
u16
uint16_t
無符號16位數(shù)據(jù)
u8
uint8_t
無符號8位數(shù)據(jù)
uc32
const uint32_t
只讀無符號32位數(shù)據(jù)
uc16
const uint16_t
只讀無符號16位數(shù)據(jù)
uc8
const uint8_t
只讀無符號8位數(shù)據(jù)
vu32
_IO uint32_t
易揮發(fā)讀寫訪問無符號32位數(shù)據(jù)
vu16
_IO uint16_t
易揮發(fā)讀寫訪問無符號16位數(shù)據(jù)
vu8
_IO uint8_t
易揮發(fā)讀寫訪問無符號8位數(shù)據(jù)
vuc32
_I uint32_t
易揮發(fā)只讀無符號32位數(shù)據(jù)
vuc16
_I uint16_t
易揮發(fā)只讀無符號16位數(shù)據(jù)
vuc8
_I uint8_t
易揮發(fā)只讀無符號8位數(shù)據(jù)
表格摘自http://forum.eepw.com.cn/thread/215752/1
變量聲明宏定義及重命名基本都在此了!