stm32 數(shù)據(jù)類型的定義
在Keil MDK 開(kāi)發(fā)環(huán)境里,比如一個(gè) 無(wú)符號(hào)32位整形數(shù)據(jù)會(huì)有很多種表示方法:1,unsigned int 32 (C語(yǔ)言標(biāo)準(zhǔn)表達(dá)方法) 2,uint32_t ;3 ,u32;這三種方式都是在表達(dá)同一個(gè)意思,可為什么ST的開(kāi)發(fā)人員要搞的這么亂呢? 還有其他好多你可能看起來(lái)很陌生 ,很不好理解的表達(dá)方式,如:_IOint32_t他等同于vs32(這個(gè)你同樣很陌生),不過(guò)他還等同于 volatile int32_t,還等同于 volatilesigned int 32;最后這種表達(dá)方式才是C語(yǔ)言的標(biāo)準(zhǔn)表達(dá)方式,夠亂吧,能把初學(xué)者弄的暈頭轉(zhuǎn)向。
其實(shí)ST 搞這么多花樣,無(wú)非是想開(kāi)發(fā)人員在寫代碼時(shí)定義數(shù)據(jù)類型能少寫幾個(gè)符號(hào),然后又因?yàn)榍昂蟀姹旧?jí),為了兼容舊版本(主要是V2.0)才會(huì)出現(xiàn)這么多表示方法。不管他怎么換,都是基于標(biāo)準(zhǔn)C來(lái)的,看清楚以下幾個(gè)文件你就OK了:core_cm3.h;stm32f10x.h;stdint.h;其中每個(gè)文件大概作用如下:
stdint.h 這里放著C語(yǔ)言的標(biāo)準(zhǔn)表達(dá)方式
//第36行開(kāi)始
typedefsignedchar int8_t;//標(biāo)準(zhǔn)表達(dá)方式 signed char 被等同于 int8_t;
typedefsigned shortint int16_t;
typedefsignedint int32_t;//在32位環(huán)境里,int代表4個(gè)字節(jié)32位??!
typedefsigned__int64 int64_t;
typedef unsignedchar uint8_t;
typedef unsigned shortint uint16_t;
typedef unsignedint uint32_t;
typedef unsigned__int64 uint64_t;
typedefsignedchar int_least8_t;
typedefsigned shortint int_least16_t;
typedefsignedint int_least32_t;
typedefsigned__int64 int_least64_t;
typedef unsignedchar uint_least8_t;
typedef unsigned shortint uint_least16_t;
typedef unsignedint uint_least32_t;
typedef unsigned__int64 uint_least64_t;
typedefsignedint int_fast8_t;
typedefsignedint int_fast16_t;
typedefsignedint int_fast32_t;
typedefsigned__int64 int_fast64_t;
typedef unsignedint uint_fast8_t;
typedef unsignedint uint_fast16_t;
typedef unsignedint uint_fast32_t;
typedef unsigned__int64 uint_fast64_t;
typedefsignedint intptr_t;
typedef unsignedint uintptr_t;
typedefsigned__int64 intmax_t;
typedef unsigned__int64 uintmax_t;
core_cm3.h 文件主要針對(duì)動(dòng)態(tài) 靜態(tài) 變量修飾符做出類型擴(kuò)展
#ifdef __cplusplus
#define__Ivolatile
#else
#define__Ivolatile const
#endif
#define__Ovolatile
#define__IOvolatile
stm32f10x.h 這個(gè)文件主要是為了兼容舊版本吧
typedef int32_ts32;
typedef int16_t s16;
typedef int8_ts8;
typedef const int32_t sc32;
typedef const int16_t sc16;
typedef const int8_t sc8;
typedef __IO int32_tvs32;
typedef __IO int16_tvs16;
typedef __IO int8_tvs8;
typedef __I int32_t vsc32;
typedef __I int16_t vsc16;
typedef __I int8_t vsc8;
typedef uint32_tu32;
typedef uint16_t u16;
typedef uint8_tu8;
typedef const uint32_t uc32;
typedef const uint16_t uc16;
typedef const uint8_t uc8;
typedef __IO uint32_tvu32;
typedef __IO uint16_t vu16;
typedef __IO uint8_tvu8;
typedef __I uint32_t vuc32;
typedef __I uint16_t vuc16;
typedef __I uint8_t vuc8;