当前位置:首页 > 单片机 > 单片机
[导读]一、最近在玩stm32,用库(V3.5.0)开发,被 stm32的变量定义搞的晕头转向,决心将其弄清楚。在 stdint.h 文件里,我们可以清楚的看到:typedef signed char int8_t;typedef signed short int int16_t;typedef signe

一、最近在玩stm32,用库(V3.5.0)开发,被 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的作用: 作为指令关键字,确保本条指令不会因编译器的优化而省略,且要求每次直接读值.

而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数据类型对比

固件库类型

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位数据

表格摘自http://forum.eepw.com.cn/thread/215752/1

变量声明宏定义及重命名基本都在此了!


本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭