【头文件】STM32F1系列单片机USB外设相关寄存器的定义(USB_TypeDef)
2017-08-27 12:03
891 查看
Keil MDK网站上下载的Keil.STM32F1xx_DFP.2.2.0.pack包中的stm32f10x.h头文件里面没有USB_TypeDef的定义,只有寄存器位的定义,是不完整的头文件。没有USB的数据结构就会给访问USB寄存器带来一定的困难。虽然可以参照STM32参考手册中的USB register map自己编写出USB_TypeDef结构体,但是这样比较麻烦。
不过,STM32CubeMX工具生成的STM32F103工程中的头文件stm32f103xe.h中就有完整的USB数据结构,该头文件的版本是V4.2.0,日期为31-March-2017,作者仍然是Keil里面的MCD Application Team,这比Keil中的V3.5.0(11-March-2011)版本新得多,里面还额外增加了各寄存器位的具体位置的定义:***_Pos。
有了Pos定义,我们就可以直接指定多位选项的值。例如:
我们可以把其中常用的USB有关的内容复制出来,单独存放为一个stm32f10x_usb.h文件,或者索性直接就使用较新版本的头文件。
【stm32f10x_usb.h】
不过,STM32CubeMX工具生成的STM32F103工程中的头文件stm32f103xe.h中就有完整的USB数据结构,该头文件的版本是V4.2.0,日期为31-March-2017,作者仍然是Keil里面的MCD Application Team,这比Keil中的V3.5.0(11-March-2011)版本新得多,里面还额外增加了各寄存器位的具体位置的定义:***_Pos。
有了Pos定义,我们就可以直接指定多位选项的值。例如:
SDIO->CLKCR = SDIO_CLKCR_CLKEN | (70 << SDIO_CLKCR_CLKDIV_Pos); // 72MHz/(70+2)=1MHz SDIO->CMD = SDIO_CMD_CPSMEN | (15 << SDIO_CMD_CMDINDEX_Pos); // 发送15号命令 ADC1->SQR1 = (3 << ADC_SQR1_L_Pos); // L=3, 3+1 conversions ADC1->SQR3 = (4 << ADC_SQR3_SQ1_Pos) | (9 << ADC_SQR3_SQ2_Pos) | (0 << ADC_SQR3_SQ3_Pos) | (11 << ADC_SQR3_SQ4_Pos);而不用一位一位的或起来,这样可读性比较差:
ADC1->SQR1 = ADC_SQR1_L_1 | ADC_SQR1_L_0; // L=3, 3+1 conversions
我们可以把其中常用的USB有关的内容复制出来,单独存放为一个stm32f10x_usb.h文件,或者索性直接就使用较新版本的头文件。
【stm32f10x_usb.h】
#define USB_BASE (APB1PERIPH_BASE + 0x00005C00U) /*!< USB_IP Peripheral Registers base address */ #define USB_PMAADDR (APB1PERIPH_BASE + 0x00006000U) /*!< USB_IP Packet Memory Area base address */ #define USB ((USB_TypeDef *)USB_BASE) /** * @brief Universal Serial Bus Full Speed Device */ typedef struct { __IO uint16_t EP0R; /*!< USB Endpoint 0 register, Address offset: 0x00 */ __IO uint16_t RESERVED0; /*!< Reserved */ __IO uint16_t EP1R; /*!< USB Endpoint 1 register, Address offset: 0x04 */ __IO uint16_t RESERVED1; /*!< Reserved */ __IO uint16_t EP2R; /*!< USB Endpoint 2 register, Address offset: 0x08 */ __IO uint16_t RESERVED2; /*!< Reserved */ __IO uint16_t EP3R; /*!< USB Endpoint 3 register, Address offset: 0x0C */ __IO uint16_t RESERVED3; /*!< Reserved */ __IO uint16_t EP4R; /*!< USB Endpoint 4 register, Address offset: 0x10 */ __IO uint16_t RESERVED4; /*!< Reserved */ __IO uint16_t EP5R; /*!< USB Endpoint 5 register, Address offset: 0x14 */ __IO uint16_t RESERVED5; /*!< Reserved */ __IO uint16_t EP6R; /*!< USB Endpoint 6 register, Address offset: 0x18 */ __IO uint16_t RESERVED6; /*!< Reserved */ __IO uint16_t EP7R; /*!< USB Endpoint 7 register, Address offset: 0x1C */ __IO uint16_t RESERVED7[17]; /*!< Reserved */ __IO uint16_t CNTR; /*!< Control register, Address offset: 0x40 */ __IO uint16_t RESERVED8; /*!< Reserved */ __IO uint16_t ISTR; /*!< Interrupt status register, Address offset: 0x44 */ __IO uint16_t RESERVED9; /*!< Reserved */ __IO uint16_t FNR; /*!< Frame number register, Address offset: 0x48 */ __IO uint16_t RESERVEDA; /*!< Reserved */ __IO uint16_t DADDR; /*!< Device address register, Address offset: 0x4C */ __IO uint16_t RESERVEDB; /*!< Reserved */ __IO uint16_t BTABLE; /*!< Buffer Table address register, Address offset: 0x50 */ __IO uint16_t RESERVEDC; /*!< Reserved */ } USB_TypeDef;
相关文章推荐
- [编译相关]系列3:makefile或者config文件当中的空格或者注释导致编译出错
- stm32f407系列单片机usb高速模式下的速度测试
- SharePoint【Ribbon系列】-- 09.如何让用户定义的Ribbon引用外部Javascript文件
- STC12系列单片机的AUXR辅助寄存器
- Linux系列教程(十四)——Linux用户和用户组管理之相关配置文件
- linux下C++开发系列(六)——文件IO相关的系统调用
- .NET相关操作其他文件的小程序(系列文章)
- PHP相关系列 - PHP 文件上传类
- 几种单片机相关的编译器预定义宏
- opensslBIO系列之2---BIO结构和BIO相关文件介绍
- C8051F系列单片机相关
- C语言系列(七)文件的相关操作
- Android中USB相关的文件
- Android/Linux USB HID驱动(即USB鼠标USB键盘等驱动)相关文件
- C8051F系列单片机相关
- STM32F1系列之常用外设说明
- STM32 usb_prop.c文件分析与usb_core.h一些数据定义分析
- [opencv相关]系列1:opencv支持的图像文件类型及cvLoadImage函数读取/载入图像文件出错原因分析
- S3C6410 按键驱动(一) --- 相关头文件的定义
- openssl之BIO系列之2---BIO结构和BIO相关文件介绍