主机环境: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的操作,源文件如下:
<pre name="code" class="cpp">/**
******************************************************************************
* @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
*
* <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
*
* 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 CONTRIBU