找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 6444|回复: 3
打印 上一主题 下一主题
收起左侧

STM32实现USB串口源码,可与电脑通信

[复制链接]
跳转到指定楼层
楼主
采用STM32的USB接口实现串口功能,可方便STM32的调试通信等功能。

3,例程KEIL MDK版本? V4.22A
4,例程软件库版本? 未使用
5,例程驱动库版本? V3.5.0
6,例程是用多大尺寸的液晶屏测试的?  未使用                     
7,例程是用多少G的SD卡测试?           未使用
8,程序设置下载是否复位运行?  是



STM32单片机源程序如下:
  1. /****************************Copyright(c)*****************************
  2. **--------------File Info---------------------------------------------------------------------------------
  3. ** File name:           main.c
  4. ** Last modified Date:  2014-03-14
  5. ** Last Version:        V1.00
  6. ** Descriptions:        
  7. **
  8. **----------------------------------------------------------------------------------------------------
  9. ** Created by:          hzq
  10. ** Created date:        2014-03-14
  11. ** Version:             V1.00
  12. ** Descriptions:        下载程序,3.2寸屏显示对应的信息,等待USB枚举完成,安装驱动之后,可以识别出虚拟串口。
  13. **                                                                                        USB口接在USB2上。
  14. **
  15. **----------------------------------------------------------------------------------------------------
  16. ** Modified by:         
  17. ** Modified date:        
  18. ** Version:            
  19. ** Descriptions:      
  20. **                                                                                                                                                 
  21. *****************************************************************/

  22. /* Includes ------------------------------------------------------------------*/

  23. #include "usbd_cdc_core.h"
  24. #include "usbd_usr.h"
  25. #include "usb_conf.h"
  26. #include "usbd_desc.h"

  27. /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
  28.   * @{
  29.   */
  30.   
  31. #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
  32.   #if defined ( __ICCARM__ ) /*!< IAR Compiler */
  33.     #pragma data_alignment=4   
  34.   #endif
  35. #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
  36.    
  37. __ALIGN_BEGIN USB_OTG_CORE_HANDLE    USB_OTG_dev __ALIGN_END ;

  38. /**
  39.   * @}
  40.   */


  41. /** @defgroup APP_VCP_Private_FunctionPrototypes
  42.   * @{
  43.   */
  44. /**
  45.   * @}
  46.   */


  47. /** @defgroup APP_VCP_Private_Functions
  48.   * @{
  49.   */

  50. /**
  51.   * @brief  Program entry point
  52.   * @param  None
  53.   * @retval None
  54.   */
  55. int main(void)
  56. {
  57.   __IO uint32_t i = 0;  

  58.   /*!< At this stage the microcontroller clock setting is already configured,
  59.   this is done through SystemInit() function which is called from startup
  60.   file (startup_stm32fxxx_xx.s) before to branch to application main.
  61.   To reconfigure the default setting of SystemInit() function, refer to
  62.   system_stm32fxxx.c file
  63.   */  

  64.   USBD_Init(&USB_OTG_dev,
  65. #ifdef USE_USB_OTG_HS
  66.             USB_OTG_HS_CORE_ID,
  67. #else            
  68.             USB_OTG_FS_CORE_ID,
  69. #endif  
  70.             &USR_desc,
  71.             &USBD_CDC_cb,
  72.             &USR_cb);
  73.   
  74.   /* Main loop */
  75.   while (1)
  76.   {
  77.     if (i++ == 0x100000)
  78.     {
  79.       STM_EVAL_LEDToggle(LED1);
  80.       STM_EVAL_LEDToggle(LED2);
  81.       STM_EVAL_LEDToggle(LED3);
  82.       STM_EVAL_LEDToggle(LED4);
  83.       i = 0;
  84.     }
  85.   }
  86. }

  87. #ifdef USE_FULL_ASSERT
  88. /**
  89. * @brief  assert_failed
  90. *         Reports the name of the source file and the source line number
  91. *         where the assert_param error has occurred.
  92. * @param  File: pointer to the source file name
  93. * @param  Line: assert_param error line source number
  94. * @retval None
  95. */
  96. void assert_failed(uint8_t* file, uint32_t line)
  97. {
  98.   /* User can add his own implementation to report the file name and line number,
  99.   ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  100.   
  101.   /* Infinite loop */
  102.   while (1)
  103.   {}
  104. }
  105. #endif

  106. /**
  107.   * @}
  108.   */


  109. /**
  110.   * @}
  111.   */


  112. /**
  113.   * @}
  114.   */

  115. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
复制代码

所有资料51hei提供下载:
107_DEVICE_VCP .rar (632.18 KB, 下载次数: 60)



评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:268087 发表于 2019-5-5 10:35 | 只看该作者
好多开发板都有这样的例程。
回复

使用道具 举报

板凳
ID:582809 发表于 2019-7-12 10:34 | 只看该作者
很好,不错的例子
回复

使用道具 举报

地板
ID:156302 发表于 2020-2-3 11:24 | 只看该作者
看看咋样,谢谢分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表