一、最近在玩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位数据 |
变量声明宏定义及重命名基本都在此了!