STM32 USB学习条记2

2018-09-14来源: eefocus 要害字:STM32   USB学习

主机情况:Windows 7 SP1

开发情况:MDK5.14

目标板:STM32F103C8T6

开发库:STM32F1Cube库和STM32_USB_Device_Library


STM32Cube库中提供了一些有关USB的例程,在其工程目录下的Applications目录中,这里打开STM3210E_EVAL目录,可以看到如下例程:


这里选取一个简朴的例子CDC_Standalone,为一个USB通信例程,具体实现是一个USB转串口的功效,相当于USB串口线。把示例里面的inc和src目录下的文件拷贝到新建工程中,这里是把跟usb通信相关的文件放到了vcp目录下。文件目录结构如下:


其中BSP目录很简朴,由于所购置的单板只用到了USB,UART模块以及一个LED灯,原理图如下:


其中PA15引脚连接了一个LED灯,如下:


因此在stm32f103_demo文件中只添加了led的操作,源文件如下:


/**

  ******************************************************************************

  * @file    stm32f103_demo.c

  * @author  MCD Application Team

  * @version V6.0.0

  * @date    13-October-2015

  * @brief   This file provides a set of firmware functions to manage Leds, 

  *          for STM32F103_DEMO

  ******************************************************************************

  * @attention

  *

  *

© COPYRIGHT(c) 2014 STMicroelectronics

  *

  * Redistribution and use in source and binary forms, with or without modification,

  * are permitted provided that the following conditions are met:

  *   1. Redistributions of source code must retain the above copyright notice,

  *      this list of conditions and the following disclaimer.

  *   2. Redistributions in binary form must reproduce the above copyright notice,

  *      this list of conditions and the following disclaimer in the documentation

  *      and/or other materials provided with the distribution.

  *   3. Neither the name of STMicroelectronics nor the names of its contributors

  *      may be used to endorse or promote products derived from this software

  *      without specific prior written permission.

  *

  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"

  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE

  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL

  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR

  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER

  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,

  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE

  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

  *

  ******************************************************************************

  */

  

/* Includes ------------------------------------------------------------------*/

#include "STM32f103_demo.h"

 

/** @addtogroup BSP

  * @{

  */ 

 

/** @defgroup STM32F103_DEMO STM32F103-DEMO

  * @{

  */ 

 

/** @defgroup STM32F103_DEMO_Common STM32F103-DEMO Common

  * @{

  */ 

 

/** @defgroup STM32F103_DEMO_Private_TypesDefinitions Private Types Definitions

  * @{

  */ 

 

/**

  * @}

  */ 

 

/** @defgroup STM32F103_DEMO_Private_Defines Private Defines

  * @{

  */ 

 

/**

 * @brief STM32103 EVAL BSP Driver version number V6.0.0

   */

#define __STM32F103_DEMO_BSP_VERSION_MAIN       (0x06) /*!< [31:24] main version */

#define __STM32F103_DEMO_BSP_VERSION_SUB1       (0x00) /*!< [23:16] sub1 version */

#define __STM32F103_DEMO_BSP_VERSION_SUB2       (0x00) /*!< [15:8]  sub2 version */

#define __STM32F103_DEMO_BSP_VERSION_RC         (0x00) /*!< [7:0]  release candidate */

#define __STM32F103_DEMO_BSP_VERSION            ((__STM32F103_DEMO_BSP_VERSION_MAIN << 24)\

                                               "(__STM32F103_DEMO_BSP_VERSION_SUB1 << 16)\

                                               |(__STM32F103_DEMO_BSP_VERSION_SUB2 << 8 )\

                                               |(__STM32F103_DEMO_BSP_VERSION_RC))

 

/**

  * @}

  */

 

 

/** @defgroup STM32F103_DEMO_Private_Variables Private Variables

  * @{

  */ 

/**

 * @brief LED variables

 */

GPIO_TypeDef* LED_PORT[LEDn] = {LED_GPIO_PORT};

 

const uint16_t LED_PINS[LEDn] = {LED_PIN};

 

/**

  * @brief  This method returns the STM32103 EVAL BSP Driver revision

  * @retval version : 0xXYZR (8bits for each decimal, R for RC)

  */

uint32_t BSP_GetVersion(void)

{

  return __STM32F103_DEMO_BSP_VERSION;

}

 

/**

  * @brief  Configures LED GPIO.

  * @param  Led: Specifies the Led to be configured. 

  *   This parameter can be one of following parameters:

  *     @arg LED

  * @retval None

  */

void BSP_LED_Init(Led_TypeDef Led)

{

GPIO_InitTypeDef  gpioinitstruct = {0};

 

/* Enable the GPIO_LED clock */

LED_GPIO_CLK_ENABLE();

__HAL_RCC_AFIO_CLK_ENABLE();

__HAL_AFIO_REMAP_SWJ_DISABLE();

 

/* Configure the GPIO_LED pin */

gpioinitstruct.Pin    = LED_PINS[Led];

gpioinitstruct.Mode   = GPIO_MODE_OUTPUT_PP;

gpioinitstruct.Pull   = GPIO_NOPULL;

gpioinitstruct.Speed  = GPIO_SPEED_HIGH;

 

HAL_GPIO_Init(LED_PORT[Led], &gpioinitstruct);

 

HAL_GPIO_WritePin(LED_PORT[Led], LED_PINS[Led], GPIO_PIN_RESET);

}

 

/**

  * @brief  Turns selected LED On.

  * @param  Led: Specifies the Led to be set on. 

  *   This parameter can be one of following parameters:

  *     @arg LED

  * @retval None

  */

void BSP_LED_On(Led_TypeDef Led)

{

  HAL_GPIO_WritePin(LED_PORT[Led], LED_PINS[Led], GPIO_PIN_RESET);

}

 

/**

  * @brief  Turns selected LED Off.

  * @param  Led: Specifies the Led to be set off. 

  *   This parameter can be one of following parameters:

  *     @arg LED

  * @retval None

  */

void BSP_LED_Off(Led_TypeDef Led)

{

  HAL_GPIO_WritePin(LED_PORT[Led], LED_PINS[Led], GPIO_PIN_SET);

}

 

/**

  * @brief  Toggles the selected LED.

  * @param  Led: Specifies the Led to be toggled. 

  *   This parameter can be one of following parameters:

  *     @arg LED

  * @retval None

  */

void BSP_LED_Toggle(Led_TypeDef Led)

{

  HAL_GPIO_TogglePin(LED_PORT[Led], LED_PINS[Led]);

}

 

/**

  * @}

  */    

  

/**

  * @}

  */    

  

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

 


头文件如下:


/**

  ******************************************************************************

  * @file    stm32f103_demo.h

  * @author  MCD Application Team

  * @version V6.0.0

  * @date    13-October-2015

  * @brief   This file contains definitions for STM32F103_DEMO's LEDs, 

  *          hardware resources.

  ******************************************************************************

  * @attention

  *

  *

© COPYRIGHT(c) 2014 STMicroelectronics

  *

  * Redistribution and use in source and binary forms, with or without modification,

  * are permitted provided that the following conditions are met:

  *   1. Redistributions of source code must retain the above copyright notice,

  *      this list of conditions and the following disclaimer.

  *   2. Redistributions in binary form must reproduce the above copyright notice,

  *      this list of conditions and the following disclaimer in the documentation

  *      and/or other materials provided with the distribution.

  *   3. Neither the name of STMicroelectronics nor the names of its contributors

  *      may be used to endorse or promote products derived from this software

  *      without specific prior written permission.

  *

  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"

  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE

  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE

  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL

  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR

  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER

  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,

* OR TORT (INCLUDING NEGLIGENCE OR OTHE

[1] [2] [3]

要害字:STM32   USB学习

编辑:什么鱼 引用地址:/mcu/2018/ic-news091441327.html
本网站转载的所有的文章、图片、音频视频文件等资料的版权归版权所有人所有,本站接纳的非本站原创文章及图片等内容无法一一联系确认版权者。如果本网所选内容的文章作者及编辑认为其作品不宜果真自由流传,或不应无偿使用,请实时通过电子邮件或电话通知我们,以迅速接纳适当措施,制止给双方造成不须要的经济损失。

上一篇:STM32 USB学习条记8
下一篇:最后一页

关注亿博娱乐注册民众号 快捷获取更多信息
关注亿博娱乐注册民众号
快捷获取更多信息
关注亿博娱乐注册服务号 享受更多官方福利
关注亿博娱乐注册服务号
享受更多官方福利

推荐阅读

STM32F10X的USB固件库说明

。3)、usb_sil.c,本文件包罗精简接口的初始化或向端点读写的操作函数。上层1)、usb_pwr.c,该文件中包罗处置惩罚上电、掉电、挂起和恢复事件的函数。2)、usb_istr.c,该文件中只有一个函数,即USB中断的USB_Istr函数,该函数对种种引起USB中断的事件做轮询处置惩罚。3)、usb_desc.c,该文件包罗一些与USB相关的设备描述符、配置描述符等,以数组形式存储,在USB主机请求的时候这些信息将发送给主机。5)、usb_prop.c,该文件用于实现相关设备的USB协议,如初始化、SETUP包、IN包、OUT包等。6)、usb_endp.c,本文件包罗端点收、发送的处置惩罚函数,由用户凭据差异的USB设备进行差异的界说。 
发表于 2018-09-14

STM32 USB OTG官方库移植

口。确认硬件完毕后,需要确认所需使用的晶振,外部内部均可。STM32F2为例,HSI为16M。则可以直接用HSI来配置 配置出48M的晶振供应USB。此配置可接纳ST官方的配置工具来完成,操作轻便 ,将配置生成的system_stm32f2xx.c与工程中的替换即可。时钟确认完毕,接下来需要对USB库进行配置。USB库中有许多例程,此处我是做USB升级方案,则有两种,一种是DFU升级模式,需要配合官方给的DFU Demo上位机软件来使用,第二种是MSC模式,读取U盘。库做的很完善,FATFS已经写进例程。配置主要看是USB_HOST照旧USB_DEV抑或是OTG双向模式。目前没有用到双向模式。模式配置需要在usb_conf.h中修改
发表于 2018-09-14

STM8学习条记---串口uart1

使用uart1串口,需要用到stm8s_uart1.c和stm8s_uart1.h两个文件1、建设工程目录结构如下:2、编写uart.h文件如下:#ifndef __UART_H#define __UART_H#include "stm8s.h"#include "stm8s_clk.h"void USART_Configuration(void);   //串口配置函数void UART_send_string(uint8_t *Buffer);//发送一个字符串函数#endif /* __UART_H */3、编写uart.c文件如下:#include "
发表于 2018-09-13

STM32 GPIO——流水灯例程 学习总结

通过控制LED灯,熟悉STM32的存储器结构、地址映射、时钟树、库文件、利用库的要领及开发工程的步骤,建设STM32的开发思想。这是我建设的第一个工程,由于涉及面较广,知识点疏散,在此做一个总结。1)为控制LED灯,知道要使用GPIO外设。GPIO(General-Purpose I/O):I/O引脚可以被软件设置成种种差异的功效,如输入或输出。控制LED灯,即控制STM32芯片的I/O引脚电平的崎岖来实现。2)了解GPIO外设有什么功效,要如何使用。GPIO引脚又被分为GPIOA、GPIOB、...、GPIOG差异的组,每组端口分为0~15共16个差异的引脚,对于差异型号的芯片,端口的组和引脚的数量差异。功效检察参考手册3)获知
发表于 2018-09-13

STM32F103C8T6-LED点亮法式

#include <stm32f10x.h> //----------------------------------------------------------------------------- void mydelay_ms(int ms){    volatile int  i;    int k = ms * 2333 ;    for ( i=0; i<k; i++ ) {        ;   
发表于 2018-09-13

STM32F0在IAR新建工程

1、到官网下载固件库,类似"STM32F0xx_StdPeriph_Lib_V1.5.0",解压获得文件"_htmresc"  "Libraries"  "Projects"   "Utilities".     ①“Libraries\STM32F0xx_StdPeriph_Driver”下的inc与src是底层驱动。     ②“Libraries\CMSIS\Device\ST\STM32F0xx\Source\Templates\iar
发表于 2018-09-13
热门资源推荐
更多
  •  pdf文件圈圈教你玩USB
  •  rar文件usb学习例子
  •  rar文件基于STM32的源法式uCOSII2.91+lwip-1.3.2 (DM9000A),硬件资源是STM32,DM9
  •  rar文件基于2148的usb例程
  •  51单片机C语言法式设计教程
  •  LaTeX入门
  •  嵌入式实时操作系统uCOS-II
  •  [漫画傅里叶解析].(日)

小广播

热门运动
换一批
更多

下载有好礼!未来已来,你准备好了吗?益莱储5G白皮书!
TI 电机驱动应用闯关答题赛
造个车,一起驶向诗和远方!学习 TI 汽车参考设计,加入技术小测试赢好礼!
有奖直播:基于GaN 的高频(1.2MHz)高效率 1.6kW 高密度临界模式 (CrM) 图腾柱功率因数校正 (PFC)转换器的应用介绍
TI E2E中文社区年终回馈,15 块 CC3200-LAUNCHXL 开发板免费申请中……测评赢好礼喽!

最新视频课程更多

SimpleLink CC26x2CC13x2 可支持多重协议的无线微控制器
SimpleLink CC26x2CC13x2 可支持多重协议的无线微控制器
 SimpleLink 系列产物的宁静性介绍
SimpleLink 系列产物的宁静性介绍
基于 TI MSP430 Scan Interface?技术的流量表解决方案
基于 TI MSP430 Scan Interface?技术的流量表解决方案
2018 TI SimpleLink? MCU 平台研讨会 - 回看
2018 TI SimpleLink? MCU 平台研讨会 - 回看
Simplelink 无线连接平台介绍
Simplelink 无线连接平台介绍

何立民专栏

单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广事情。

更多相关热搜器件

  •  SiT9001AC-44-33E6-4800000X
  •  MC78M08ABT
  •  SiT8033AC-24-25A-1600000
  •  CP3BT26Y98AWJX-NOPB
  •  LM5116HJD
  •  LTC3769IFE#TRPBF
  •  LTC3834IDHC-1#TRPBF
  •  CV500-BSC61
  •  ASGTX-D-212.500MHz-2
  •  LM20143MH/NOPB
亿博娱乐平台版权所有 京ICP证060456号 京ICP备10001474号 电信业务审批[2006]字第258号函 京公海网安备110108001534 Copyright ? 2005-2018 EEWORLD.com.cn, Inc. All rights reserved