{"id":43159,"date":"2025-06-11T08:55:52","date_gmt":"2025-06-11T00:55:52","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/43159.html"},"modified":"2025-06-11T08:55:52","modified_gmt":"2025-06-11T00:55:52","slug":"stm32-usb%e8%99%9a%e6%8b%9f%e4%b8%b2%e5%8f%a3%e9%80%9a%e4%bf%a1","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/43159.html","title":{"rendered":"STM32 -- USB\u865a\u62df\u4e32\u53e3\u901a\u4fe1"},"content":{"rendered":"<p>\u672c\u7bc7\u64cd\u4f5c:<\/p>\n<ul>\n<li>\u901a\u8fc7CubeMX &#043; Keil&#xff0c;\u914d\u7f6eSTM32\u4f5c\u4e3aUSB\u8bbe\u5907\u7aef&#xff0c;\u4e0e\u7535\u8111\u4e0a\u4f4d\u673a\u8fdb\u884c\u901a\u4fe1&#xff08;CDC&#xff09;&#xff1b;<\/li>\n<li>\u901a\u7528\u5e26USB\u529f\u80fd\u7684 STM32 \u82af\u7247 &#xff08;\u5982F1\u3001F4\u7b49&#xff0c;\u7cfb\u7edf\u65f6\u949f\u914d\u7f6e\u4e0d\u540c&#xff0c;\u4ee3\u7801\u901a\u7528&#xff09;\u3002<\/li>\n<\/ul>\n<hr \/>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E4%B8%80%E3%80%81%C2%A0STM32%E5%86%85%E7%BD%AEUSB%E3%80%81%E8%99%9A%E6%8B%9F%E4%B8%B2%E5%8F%A3%E4%BB%8B%E7%BB%8D-toc\" style=\"margin-left:0px\">\u4e00\u3001\u00a0STM32\u5185\u7f6eUSB\u3001\u865a\u62df\u4e32\u53e3\u7b80\u8ff0<\/p>\n<p id=\"%E4%BA%8C%E3%80%81CubeMX%20%E6%96%B0%E5%BB%BA%20%E8%99%9A%E6%8B%9F%E4%B8%B2%E5%8F%A3%E5%B7%A5%E7%A8%8B-toc\" style=\"margin-left:0px\">\u4e8c\u3001CubeMX \u65b0\u5efa\u5de5\u7a0b<\/p>\n<p id=\"%E4%B8%89%E3%80%81Keil%E5%B7%A5%E7%A8%8B%E7%9A%84%E9%85%8D%E7%BD%AE-toc\" style=\"margin-left:0px\">\u4e09\u3001Keil \u5de5\u7a0b\u914d\u7f6e<\/p>\n<p id=\"%E5%9B%9B%E3%80%81%E5%A2%9E%E5%8A%A0%E9%9C%80%E8%A6%81%E7%9A%84%E4%BB%A3%E7%A0%81-toc\" style=\"margin-left:0px\">\u56db\u3001\u5b9e\u73b0USB\u6a21\u62df\u63d2\u62d4<\/p>\n<p id=\"%E4%BA%94%E3%80%81%E5%8F%91%E9%80%81%E7%9A%84%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:0px\">\u4e94\u3001\u53d1\u9001<\/p>\n<p id=\"%E5%85%AD%E3%80%81%E5%8F%91%E9%80%81%C2%A0%E4%BC%98%E5%8C%96-toc\" style=\"margin-left:0px\">\u516d\u3001\u53d1\u9001\u4f18\u5316&#xff08;\u8fde\u7eed\u53d1\u9001&#xff09;<\/p>\n<p id=\"%E5%85%AD%E3%80%81%E6%8E%A5%E6%94%B6-toc\" style=\"margin-left:0px\">\u4e03\u3001\u63a5\u6536<\/p>\n<p id=\"%E5%85%AB%E3%80%81%C2%A0%E6%8E%A5%E6%94%B6%C2%A0%E4%BC%98%E5%8C%96-toc\" style=\"margin-left:0px\">\u516b\u3001\u63a5\u6536\u4f18\u5316&#xff08;\u5728\u5916\u90e8\u5904\u7406\u6570\u636e&#xff09;<\/p>\n<p id=\"%E5%85%AD%E3%80%81%E6%8E%A5%E6%94%B6-toc\" style=\"margin-left:0px\">\n<hr \/>\n<h2><\/h2>\n<h2><\/h2>\n<h2 id=\"%E4%B8%80%E3%80%81%C2%A0STM32%E5%86%85%E7%BD%AEUSB%E3%80%81%E8%99%9A%E6%8B%9F%E4%B8%B2%E5%8F%A3%E4%BB%8B%E7%BB%8D\"><span style=\"color:#fe2c24\">\u4e00\u3001\u00a0STM32\u5185\u7f6eUSB\u3001\u865a\u62df\u4e32\u53e3\u7b80\u8ff0<\/span><\/h2>\n<p>STM32 \u82af\u7247&#xff0c;\u7edd\u5927\u90e8\u5206\u578b\u53f7\u90fd\u5e26\u5185\u7f6eUSB&#xff0c;\u5982\u5e38\u7528\u7684 F1\u3001F4\u3001H7\u3001G4 \u7b49\u7cfb\u5217&#xff0c;\u80fd\u591f\u901a\u8fc7USB\u63a5\u53e3\u4e0e\u8ba1\u7b97\u673a\u6216\u5176\u4ed6USB\u8bbe\u5907\u8fdb\u884c\u901a\u4fe1\u3002<\/p>\n<p>STM32\u5185\u7f6e\u7684USB&#xff0c;\u5747\u53ef\u652f\u6301USB 2.0\u6807\u51c6&#xff0c;\u53ef\u4ee5\u652f\u6301\u4e09\u79cd\u4f20\u8f93\u901f\u7387&#xff1a;<\/p>\n<li>\u9ad8\u901f\u6a21\u5f0f&#xff1a;\u6700\u9ad8\u53ef\u8fbe480 Mbps\u00a0 &#xff08;\u90e8\u5206\u578b\u53f7\u652f\u6301&#xff0c;\u4e14\u9700\u642d\u914d\u5916\u90e8\u82af\u7247&#xff0c;\u4e0d\u5e38\u7528 )<\/li>\n<li>\u5168\u901f\u6a21\u5f0f&#xff1a;\u6700\u9ad8\u53ef\u8fbe12 Mbps\u00a0 \u00a0 \u00a0 (\u6700\u5e38\u7528&#xff09;<\/li>\n<li>\u4f4e\u901f\u6a21\u5f0f&#xff1a;\u6700\u9ad8\u53ef\u8fbe1.5 Mbps\u00a0 \u00a0 \u00a0<\/li>\n<p>\u9ad8\u901f\u6a21\u5f0f&#xff0c;\u9700\u8981\u642d\u914d\u5916\u56f4USB PHY\u82af\u7247&#xff0c;\u5982USB3300&#xff0c;\u786c\u4ef6\u6210\u672c\u504f\u9ad8 \u3002 \u5168\u901f\u6a21\u5f0f&#xff0c;\u7535\u8def\u5f88\u7b80\u5355\u3002\u4ece\u673a\u5728PCB\u5e03\u7ebf\u65f6&#xff0c;\u4ec5\u9700\u628aSTM32\u7684\u5f15\u811aPA11\u3001PA12,\u00a0 \u8fde\u63a5\u81f3USB\u5ea7\u7684DP\u3001DM&#xff0c;\u7136\u540e&#xff0c;PA12(DP\u7ebf)\u75281.5K\u7535\u963b\u4e0a\u62c9\u81f33.3V\u3002\u5177\u4f53\u5982\u4e0b\u56fe&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"304\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005546-6848d412b1be7.png\" width=\"453\" \/><\/p>\n<p>\u4e0a\u62c9\u8bf4\u660e<\/p>\n<p>\u63d2\u62d4\u68c0\u6d4b&#xff1a;\u8bbe\u5907\u672a\u63d2\u5165\u65f6&#xff0c;\u4e3b\u673a\u7aefDP\u3001DM\u4e3a\u4f4e\u7535\u5e73&#xff0c;\u5f53\u53d1\u73b0\u88ab\u7f6e\u9ad8&#xff0c;\u5373\u4e3a\u6709\u8bbe\u5907\u63d2\u5165&#xff1b;<\/p>\n<p>\u533a\u5206\u901f\u7387&#xff1a;DM\u7ebf\u4e0a\u62c9\u662f\u4f4e\u901f\u6a21\u5f0f&#xff0c;DP\u7ebf\u4e0a\u62c9\u662f\u5168\u901f\\\\\u9ad8\u901f\u6a21\u5f0f&#xff1b;<\/p>\n<p>\u4e0a\u62c9\u7535\u538b&#xff1a;3.3V\u3002USB\u901a\u4fe1\u7535\u5e73\u662f3.3V&#xff0c;\u800c\u4e0d\u662f\u603b\u7ebf\u4f9b\u7535\u76845V\u3002<\/p>\n<\/p>\n<p>USB\u865a\u62df\u4e32\u53e3&#xff0c;\u7b80\u79f0VPC&#xff0c;Virtual Port Com \u7684\u7b80\u5199\u3002\u4f46\u66f4\u4e60\u60ef\u4e8e\u628a\u865a\u62df\u4e32\u53e3\u53eb\u4f5c: CDC&#xff0c;\u56e0\u4e3a\u5b83\u662f\u5229\u7528 USB \u7684 CDC\u7c7b \u5b9e\u73b0\u7684\u4e00\u79cd\u901a\u4fe1\u63a5\u53e3\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5229\u7528STM32\u81ea\u5e26\u7684USB\u529f\u80fd&#xff0c;\u901a\u8fc7CubeMX\u7684\u914d\u7f6e&#xff0c;\u5f88\u65b9\u4fbf\u5730\u5b9e\u73b0\u4e00\u4e2aUSB\u865a\u62df\u4e32\u53e3&#xff0c;\u4ece\u800c\u901a\u8fc7USB\u7ebf&#xff0c;\u5b9e\u73b0\u7535\u8111\u4e0eSTM32\u7684\u6570\u636e\u4e92\u4f20\u3002<\/p>\n<p>\u54ea\u4e9bwin\u7cfb\u7edf\u652f\u6301\u865a\u62df\u4e32\u53e3&#xff1f;<\/p>\n<p>Win10\u3001Win11 \u5df2\u5e26\u865a\u62df\u4e32\u53e3\u9a71\u52a8&#xff1b;\u65e0\u9700\u5b89\u88c5\u4efb\u4f55\u9a71\u52a8;\u00a0<\/p>\n<p>Win7 \u8981\u63d0\u524d\u624b\u52a8\u5b89\u88c5\u9a71\u52a8&#xff0c;\u5426\u5219\u65e0\u6cd5\u8bc6\u522b &#xff1a;\u865a\u62df\u4e32\u53e3\u9a71\u52a8 \u4e0b\u8f7d<\/p>\n<hr \/>\n<h2><\/h2>\n<h2 id=\"%E4%BA%8C%E3%80%81CubeMX%20%E6%96%B0%E5%BB%BA%20%E8%99%9A%E6%8B%9F%E4%B8%B2%E5%8F%A3%E5%B7%A5%E7%A8%8B\"><span style=\"color:#fe2c24\">\u4e8c\u3001CubeMX \u65b0\u5efa\u5de5\u7a0b<\/span><\/h2>\n<p>\u672c\u7bc7\u4e3a\u4e86\u5de5\u7a0b\u7684\u6e05\u6670&#xff0c;\u5c06\u4ece0\u5f00\u59cb&#xff0c; \u65b0\u5efa\u4e00\u4e2a\u865a\u62df\u4e32\u53e3\u901a\u4fe1\u7684\u5de5\u7a0b\u3002<\/p>\n<p>\u65e5\u5e38\u505a\u9879\u76ee&#xff0c;\u4e0d\u5efa\u8bae\u65b0\u5efa&#xff0c;\u800c\u662f\u590d\u5236\u5df2\u6709\u7684\u65e7\u5de5\u7a0b&#xff0c;\u901a\u8fc7CubeMX\u589e\u5220\u9700\u8981\u7684\u529f\u80fd\u3002<\/p>\n<p>\u8fd9\u6837\u80fd\u51cf\u5c11\u4e00\u4e9b\u5e38\u7528\u529f\u80fd\u7684\u518d\u6b21\u914d\u7f6e&#xff0c;\u5982\u6309\u952e\u3001UART\u7b49&#xff1b;<\/p>\n<p>\u590d\u7528\u65e7\u5de5\u7a0b\u91cc\u5df2\u9a8c\u8bc1\u8fc7\u7684\u529f\u80fd&#xff0c;\u80fd\u6709\u6548\u5730\u51cf\u5c11\u5e38\u7528\u529f\u80fd\u7684\u8c03\u8bd5\u65f6\u95f4\u3002<\/p>\n<\/p>\n<p>1\u3001\u4ee5\u82af\u7247\u578b\u53f7\u65b0\u5efa<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"535\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005546-6848d412cc397.png\" width=\"1124\" \/><\/p>\n<\/p>\n<p>2\u3001\u641c\u7d22\u82af\u7247\u578b\u53f7<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"628\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005547-6848d413162d2.png\" width=\"1200\" \/><\/p>\n<\/p>\n<p>3\u3001\u8bbe\u7f6e\u8c03\u8bd5\u6a21\u5f0f<\/p>\n<p>\u8fdb\u5165\u914d\u7f6e\u9875\u9762\u540e&#xff0c;\u517b\u6210\u4e60\u60ef&#xff0c;\u4f18\u5148\u8bbe\u7f6e\u8c03\u8bd5\u6a21\u5f0f&#xff1a;Serial Wire\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"555\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005547-6848d4137641b.png\" width=\"1072\" \/><\/p>\n<\/p>\n<p>4\u3001\u9009\u62e9\u6676\u632f\u6e90<\/p>\n<p>\u5916\u90e8\u9ad8\u901f\u6676\u632f\u6e90(HSE)&#xff1a;Crystal\/Ceramic Resonator<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"632\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005547-6848d413d4e98.png\" width=\"1127\" \/><\/p>\n<\/p>\n<p>5\u3001USB\u5de5\u4f5c\u6a21\u5f0f<\/p>\n<p>USB_OTG_FS&#xff1a;\u9009\u62e9 Device_Only;\u00a0 \u8bbe\u5907\u6a21\u5f0f(\u4ece\u673a\u6a21\u5f0f);\u00a0 \u00a0\u5176\u5b83\u53c2\u6570&#xff0c;\u9ed8\u8ba4\u3002<\/p>\n<p>\u6709\u4e9b\u82af\u7247\u578b\u53f7&#xff0c;\u5982F103\u7cfb\u5217&#xff0c;CubeMX\u4e0a\u7684\u663e\u793a\u662f&#xff1a;USB_FS&#xff0c;\u914d\u7f6e\u6b65\u9aa4\u662f\u4e00\u6837\u7684\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"630\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005548-6848d41447866.png\" width=\"1139\" \/><\/p>\n<\/p>\n<p>6\u3001\u4e2d\u95f4\u4ef6\u7ec4\u4ef6<\/p>\n<p>USB_DEVICE&#xff1a;\u9009\u62e9 CDC (VPC)&#xff1b;\u00a0 \u5176\u5b83\u53c2\u6570&#xff0c;\u9ed8\u8ba4;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"615\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005548-6848d4149906a.png\" width=\"996\" \/><\/p>\n<\/p>\n<p>6\u3001\u914d\u7f6e\u7cfb\u7edf\u65f6\u949f<\/p>\n<p>\u2460\u00a0\u5f53\u542f\u7528USB\u529f\u80fd\u540e&#xff0c;\u8fdb\u5165\u65f6\u949f\u914d\u7f6e\u9875\u9762\u65f6&#xff0c;\u5f39\u7a97&#xff1a;\u00a0\u662f\u5426\u81ea\u52a8\u914d\u7f6e\u7cfb\u7edf\u65f6\u949f?\u00a0 \u9009\u62e9&#xff1a;No \u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"568\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005548-6848d414c6f9d.png\" width=\"1138\" \/><\/p>\n<\/p>\n<p>\u2461\u00a0\u5148\u786e\u8ba4\u677f\u4e0a\u7684\u6676\u632f\u503c<\/p>\n<ul>\n<li>\u914d\u7f6e\u65f6\u949f\u524d&#xff0c;\u5f88\u91cd\u8981\u7684\u4e00\u4e2a\u4e8b&#xff1a;\u5148\u6838\u5bf9\u5f00\u53d1\u677f\u4e0a\u7684\u6676\u632f\u9891\u7387&#xff08;\u5728\u6676\u632f\u4e0a\u7684\u6570\u5b57&#xff09;&#xff01;<\/li>\n<li>\u6676\u632f\u9891\u7387\u914d\u7f6e\u9519\u8bef\u65f6&#xff0c;\u7f16\u8bd1\u4e0d\u4f1a\u62a5\u9519&#xff0c;\u4f46\u7cfb\u7edf\u53ef\u80fd\u4e0d\u8fd0\u884c\u3001\u901a\u4fe1\u9519\u4e71\u7b49&#xff0c;\u540e\u671f\u6392\u67e5\u5f88\u8d39\u65f6\u95f4&#xff01;<\/li>\n<li>\u76ee\u524dSTM32\u7684\u677f\u5b50&#xff0c;\u5e38\u7528\u7684\u5916\u90e8\u9ad8\u901f\u6676\u632f\u6709\u4e09\u79cd&#xff1a;8M\u300112M\u300125M\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"203\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005549-6848d4151d222.png\" width=\"235\" \/><\/p>\n<\/p>\n<p>\u2462\u00a0STM32F103 \u65f6\u949f\u914d\u7f6e&#xff1a;<\/p>\n<table align=\"center\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:600px\">\n<tr>\u6676\u632f\u503c\u8f93\u5165\u5206\u9891\u8f93\u51fa\u500d\u9891USB\u5206\u9891APB1\u5206\u9891APB2\u5206\u9891\u7cfb\u7edf\u00a0\u65f6\u949f<\/tr>\n<tbody>\n<tr>\n<td style=\"text-align:center\">8<\/td>\n<td style=\"text-align:center\">1<\/td>\n<td style=\"text-align:center\">9<\/td>\n<td style=\"text-align:center\">1.5<\/td>\n<td style=\"text-align:center\">2<\/td>\n<td style=\"text-align:center\">1<\/td>\n<td style=\"text-align:center\">72MHz<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"605\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005549-6848d4153bc81.png\" width=\"1105\" \/><\/p>\n<\/p>\n<p>\u2463\u00a0STM32F4xx \u65f6\u949f\u914d\u7f6e&#xff1a;<\/p>\n<p>\u6ce8\u610f&#xff1a;F4\u7cfb\u5217&#xff0c;\u5404\u677f\u5546\u7565\u6709\u4e0d\u540c&#xff0c;\u5927\u90e8\u5206\u662f25M,\u00a0\u5c11\u90e8\u5206\u662f8M&#xff0c;\u4f7f\u7528\u6548\u679c\u4e00\u6837\u3002<\/p>\n<table align=\"center\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:680px\">\n<tr>\u6676\u632f\u503c\u8f93\u5165\u5206\u9891\u8f93\u51fa\u500d\u9891\u8f93\u51fa\u5206\u9891USB\u5206\u9891APB1\u5206\u9891APB2\u5206\u9891\u7cfb\u7edf\u65f6\u949f<\/tr>\n<tbody>\n<tr>\n<td style=\"text-align:center\">25<\/td>\n<td style=\"text-align:center\">25<\/td>\n<td style=\"text-align:center\">336<\/td>\n<td style=\"text-align:center\">2<\/td>\n<td style=\"text-align:center\">7<\/td>\n<td style=\"text-align:center\">4<\/td>\n<td style=\"text-align:center\">2<\/td>\n<td style=\"text-align:center\">168MHz<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"471\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005549-6848d415a4216.png\" width=\"1103\" \/><\/p>\n<\/p>\n<p>7\u3001\u5de5\u7a0b\u914d\u7f6e<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"393\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005550-6848d41604fd9.png\" width=\"1200\" \/><\/p>\n<ul>\n<li>\u5de5\u7a0b\u540d\u79f0\u3001\u8def\u5f84&#xff0c;\u8fd9\u4e24\u9879&#xff0c;\u5fc5\u987b\u82f1\u6587\u3002\u5426\u5219&#xff0c;\u751f\u6210\u7684\u5de5\u7a0b\u5c06\u4f1a\u7f3a\u5c11\u542f\u52a8\u6587\u4ef6<\/li>\n<li>\u5f00\u53d1\u5de5\u5177&#xff1a;MDK-ARM,\u00a0 \u5373\u751f\u6210Keil\u5de5\u7a0b\u00a0<\/li>\n<li>\u5806\u5927\u5c0f&#xff0c;\u5efa\u8bae&#xff1a;0x400<\/li>\n<li>\u6808\u5927\u5c0f&#xff0c;\u5efa\u8bae&#xff1a;0x1000<\/li>\n<\/ul>\n<\/p>\n<p>8\u3001\u6587\u4ef6\u548c\u4ee3\u7801\u7684\u914d\u7f6e<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"381\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005550-6848d4164775e.png\" width=\"1143\" \/><\/p>\n<\/p>\n<p>9\u3001\u751f\u6210<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"551\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005550-6848d4167a635.png\" width=\"1200\" \/><\/p>\n<\/p>\n<p>\u7a0d\u7b49\u00a0\u7247\u523b&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"247\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005550-6848d416b9a91.png\" width=\"499\" \/><\/p>\n<\/p>\n<p>\u751f\u6210\u7684\u5de5\u7a0b\u6587\u4ef6\u5939&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"190\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005550-6848d416c887d.png\" width=\"542\" \/><\/p>\n<p>Keil\u5de5\u7a0b\u7684\u5165\u53e3\u6587\u4ef6&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"231\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005550-6848d416d587b.png\" width=\"609\" \/><\/p>\n<\/p>\n<hr \/>\n<h2><\/h2>\n<h2><\/h2>\n<h2 id=\"%E4%B8%89%E3%80%81Keil%E5%B7%A5%E7%A8%8B%E7%9A%84%E9%85%8D%E7%BD%AE\"><span style=\"color:#fe2c24\">\u4e09\u3001Keil \u5de5\u7a0b\u914d\u7f6e<\/span><\/h2>\n<\/p>\n<p>\u6309\u4e0a\u8ff0&#xff0c;\u53cc\u51fb\u6253\u5f00Keil\u5de5\u7a0b\u3002<\/p>\n<p>1\u3001\u65b0\u5efa\u7684\u5de5\u7a0b&#xff0c;\u9700\u8981\u8bbe\u7f6e\u4e00\u6b21\u4eff\u771f\u5668\u53c2\u6570 \u3002&#xff08;\u70b9\u51fb OK \u4fdd\u5b58&#xff0c;\u5426\u5219\u65e0\u6548&#xff09;\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"673\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005550-6848d416e7b21.png\" width=\"1200\" \/><\/p>\n<\/p>\n<p>2\u3001\u914d\u7f6e\u5e38\u7528\u7684\u8c03\u8bd5\u9009\u9879<\/p>\n<p>\u4e0b\u9762\u8fd9\u4e24\u9879\u662f\u975e\u5fc5\u8981\u7684&#xff0c;\u5efa\u8bae\u6253\u52fe\u4f7f\u7528&#xff1b;\u7f16\u8bd1\u540e\u751f\u6548; \u6253\u52fe\u4f1a\u4ee4\u7f16\u8bd1\u901f\u5ea6\u53d8\u6162&#xff1b;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"333\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005551-6848d41742685.png\" width=\"443\" \/><\/p>\n<ul>\n<li>Debug Infomation: \u751f\u6210\u8c03\u8bd5\u4fe1\u606f\u3002debug\u6a21\u5f0f\u4e2d\u65e0\u6cd5\u8bbe\u7f6e\u65ad\u70b9&#xff0c;\u5c31\u662f\u8fd9\u4e2a\u9009\u9879\u6ca1\u6253\u52fe\u3002<\/li>\n<li>Bowse Infomation: \u751f\u6210\u8ffd\u8e2a\u4fe1\u606f\u3002\u5982&#xff0c;\u53f3\u51fb\u51fd\u6570\u3001\u53d8\u91cf&#xff0c;\u70b9\u51fb\u5f39\u51fa\u83dc\u5355&#xff1a;Go To Definition&#8230;<\/li>\n<\/ul>\n<p>\u00a03\u3001\u7f16\u8bd1 \u9a8c\u8bc1<\/p>\n<ul>\n<li>0\u00a0Error&#xff0c;\u6b63\u7a0b\u6b63\u5e38\u3002<\/li>\n<li>\u6709 Error&#xff0c;\u5931\u8d25&#xff1b;\u5e94\u8be5\u662f (2-7) \u90a3\u4e00\u6b65\u5de5\u7a0b\u540d\u79f0\u3001\u8def\u5f84\u6709\u4e2d\u6587\u3002\u4fee\u6539\u540e\u91cd\u65b0\u751f\u6210\u5373\u53ef\u3002<\/li>\n<li>\u5148\u522b\u70e7\u5f55&#xff0c;\u522b\u70e7\u5f55&#xff0c;\u522b\u70e7\u5f55\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"363\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005551-6848d41759dd1.png\" width=\"817\" \/><\/p>\n<\/p>\n<hr \/>\n<h2 id=\"%E5%9B%9B%E3%80%81%E5%A2%9E%E5%8A%A0%E9%9C%80%E8%A6%81%E7%9A%84%E4%BB%A3%E7%A0%81\"><span style=\"color:#fe2c24\">\u56db\u3001\u5b9e\u73b0USB\u6a21\u62df\u63d2\u62d4<\/span><\/h2>\n<\/p>\n<p>\u901a\u8fc7 CubeMX\u00a0\u914d\u7f6e\u540e\u751f\u6210\u7684\u5de5\u7a0b&#xff0c;\u5b83\u5df2\u5e26\u9700\u8981\u7684\u521d\u59cb\u5316\u4ee3\u7801\u3001\u914d\u7f6e\u4ee3\u7801\u3001\u57fa\u7840\u51fd\u6570\u7b49\u3002<\/p>\n<p>\u6211\u4eec\u53ea\u9700\u5728\u5de5\u7a0b\u91cc&#xff0c;\u6309\u9700\u8fdb\u884c\u7b80\u5355\u7684\u914d\u7f6e\u3001\u4fee\u6539\u4ee3\u7801&#xff0c;\u5373\u53ef\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p>\u00a01\u3001\u5305\u542b USB\u63a5\u53e3\u00a0\u7684\u5934\u6587\u4ef6<\/p>\n<ul>\n<li>\u6253\u5f00 main.c\u6587\u4ef6&#xff0c;\u5927\u7ea6\u7b2c26\u884c&#xff0c;\u914d\u5bf9\u7684\u00a0<span style=\"color:#1c7331\">\/*\u00a0USER CODE &#8230;&#8230;\u00a0Includes *\/\u00a0<\/span>\u6ce8\u91ca\u4e4b\u95f4,<\/li>\n<li>\u6dfb\u52a0&#xff1a;#include\u00a0 &#034;usbd_cdc_if.h&#034;<\/li>\n<\/ul>\n<p>\u5b8c\u6210\u540e&#xff0c;\u662f\u8fd9\u4e2a\u6837\u5b50\u7684&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"344\" src=\"2025-06-11j0gcpzhusym.png\" width=\"716\" \/><\/p>\n<\/p>\n<p>2\u3001\u589e\u52a0 USB\u6a21\u62df\u63d2\u62d4 <\/p>\n<p>\u6211\u4eec\u5728\u8c03\u8bd5STM32\u7a0b\u5e8f\u671f\u95f4&#xff0c;\u9700\u8981\u53cd\u590d\u5730\u00a0\u4fee\u6539\u7a0b\u5e8f\u3001\u7f16\u8bd1\u3001\u70e7\u5f55;\u00a0 \u8fd9\u662f\u5e38\u89c4\u64cd\u4f5c&#xff0c;\u7528\u4e8e\u8c03\u8bd5\u5176\u5b83\u901a\u4fe1\u6a21\u5757&#xff0c;\u5982DHT11\u3001ESP8266\u7b49&#xff0c;\u662f\u6ca1\u6709\u95ee\u9898\u7684&#xff0c;\u4f46\u7528\u4e8e\u8c03\u8bd5USB\u7684\u901a\u4fe1&#xff0c;\u5c31\u4f1a\u7ffb\u8f66\u3002<\/p>\n<p>\u5f53\u865a\u62df\u4e32\u53e3\u6240\u7528\u7684USB\u7ebf\u4e00\u76f4\u63d2\u5728USB\u53e3\u4e0a&#xff0c;\u7a0b\u5e8f\u91cd\u65b0\u70e7\u5f55\u540e&#xff0c;\u7a0b\u5e8f\u7684\u91cd\u65b0\u8fd0\u884c&#xff0c;\u5c06\u5bfc\u81f4\u901a\u4fe1\u9519\u8bef\u3001USB\u7aef\u53e3&#034;\u5047\u6b7b&#034;\u7b49\u73b0\u8c61;\u00a0<\/p>\n<p>\u4e0a\u6587\u4e2d\u5df2\u4ecb\u7ecd&#xff0c;\u7535\u8111\u7aefUSB\u53e3\u6ca1\u6709\u63d2\u5165\u8bbe\u5907\u65f6&#xff0c;DP\u548cDM\u7ebf&#xff0c;\u662f\u4f4e\u7535\u5e73\u72b6\u6001&#xff0c;\u800c\u8bbe\u5907\u7aef\u7684DP\u7ebf&#xff0c;\u67091.5K\u7535\u963b\u4e0a\u62c9\u52303.3V&#xff0c;\u5f53\u8bbe\u5907\u63d2\u5165\u5230\u7535\u8111USB\u53e3&#xff0c;USB\u53e3\u7684DP\u7ebf\u5c31\u4f1a\u88ab\u7f6e\u9ad8\u7535\u5e73&#xff0c;\u4e3b\u673a\u662f\u4f9d\u9760\u8fd9\u4e2a\u673a\u5236\u5224\u65ad\u8bbe\u5907\u662f\u5426\u63d2\u5165\u3001\u62d4\u51fa&#xff0c;\u7ee7\u800c\u89e6\u53d1\u4e0d\u540c\u7684\u52a8\u4f5c&#xff0c;\u5982\u679a\u4e3e\u3001\u91ca\u653e\u7aef\u53e3\u7b49\u3002<\/p>\n<p>\u5f53\u865a\u62df\u4e32\u53e3\u6240\u7528\u7684USB\u7ebf\u4e00\u76f4\u63d2\u5728USB\u53e3\u4e0a&#xff0c;\u5728STM32\u70e7\u5f55\u7a0b\u5e8f\u91cd\u65b0\u8fd0\u884c\u540e&#xff0c;\u7a0b\u5e8f\u91cc\u7684USB\u4ee3\u7801\u7b49\u5f85\u7740\u4e3b\u673a\u65b9\u53d1\u8d77\u679a\u4e3e\u8fc7\u7a0b&#xff1b;\u800c\u8fd9\u4e2a\u671f\u95f4\u865a\u62df\u4e32\u53e3\u7684USB\u7ebf\u6ca1\u6709\u65ad\u5f00&#xff0c;\u4e3b\u673a\u65b9\u8ba4\u4e3a\u8bbe\u5907\u65b9\u4e00\u76f4\u5728\u7ebf&#xff0c;\u65e9\u5df2\u679a\u4e3e\u6210\u529f&#xff0c;\u4e00\u76f4\u5bf9\u5176\u8f6e\u8be2\u6570\u636e\u6536\u53d1\u3002\u53cc\u65b9\u201c\u5357\u8f95\u5317\u8f99&#xff0c;\u80e1\u8a00\u4e71\u8bed\u201d&#xff0c;\u6ce8\u5b9a\u7ffb\u8f66\u3002<\/p>\n<p>\u6b63\u5e38\u64cd\u4f5c\u662f&#xff1a;\u6bcf\u6b21\u70e7\u5f55\u524d&#xff0c;\u5148\u628a\u865a\u62df\u4e32\u53e3\u7684USB\u7ebf\u62d4\u4e0b\u6765&#xff0c;\u70e7\u5f55\u597d\u4e86&#xff0c;\u518d\u63d2\u4e0a&#xff0c;&#8230;&#8230;\u3002<\/p>\n<p>\u4e3a\u4e86\u907f\u514d\u8c03\u8bd5\u671f\u95f4\u9891\u7e41\u5730\u624b\u52a8\u64cd\u4f5c&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5728\u7a0b\u5e8f\u5f00\u8dd1\u540e\u3001USB\u521d\u59cb\u5316\u524d&#xff0c;\u7528\u4ee3\u7801\u628aPA12\u7f6e\u4f4e&#xff0c;\u4f7fD&#043;\u7ebf\u4e3a\u4f4e\u7535\u5e73&#xff0c;\u6301\u7eed\u4e00\u6bb5\u65f6\u95f4&#xff0c;\u6a21\u62dfUSB\u62d4\u51fa\u52a8\u4f5c&#xff0c;\u4ee4\u4e3b\u673a\u8ba4\u4e3a\u8bbe\u5907\u5df2\u65ad\u5f00\u8fde\u63a5&#xff0c;\u91ca\u653e\u7aef\u53e3; \u7136\u540e&#xff0c;\u5f53\u7a0b\u5e8f\u8fd0\u884c\u5230\u540e\u9762\u7684USB\u521d\u59cb\u5316\u51fd\u6570\u65f6&#xff0c;PA12\u4f1a\u88ab\u6b63\u5e38\u914d\u7f6e&#xff08;DP\u7ebf\u7535\u5e73\u88ab\u7f6e\u9ad8)&#xff0c;USB\u4e3b\u673a\u5c31\u4f1a&#034;\u53d1\u73b0&#034;\u6709\u8bbe\u5907\u63d2\u5165&#xff0c;\u5f00\u59cb\u5c1d\u8bd5\u679a\u4e3e\u3001\u914d\u7f6e;<\/p>\n<p>\u5177\u4f53\u64cd\u4f5c&#xff1a;<\/p>\n<ul>\n<li>\u6253\u5f00\u00a0usbd_conf.c\u00a0\u6587\u4ef6&#xff0c;\u5927\u7ea6\u7b2c70\u884c\u9644\u8fd1&#xff0c;\u627e\u5230HAL_PCD_MspInit ( )\u51fd\u6570;<\/li>\n<li>\u5728\u4e24\u5bf9 \/* USER &#8230; 0 *\/\u00a0\u6ce8\u91ca\u4e4b\u95f4&#xff0c;\u7ea675\u884c&#xff0c;\u6dfb\u52a0PA12\u5f15\u811a\u7f6e\u4f4e\u7535\u5e73\u64cd\u4f5c,\u00a0 \u5982\u4e0b&#xff08;\u53ef\u590d\u5236&#xff09;:<\/li>\n<\/ul>\n<p>    __HAL_RCC_GPIOA_CLK_ENABLE();                   \/\/ \u4f7f\u80fdGPIOA\u7aef\u53e3<br \/>\n    GPIO_InitTypeDef GPIO_InitStruct &#061; {0};         \/\/ \u58f0\u660e\u7ed3\u6784\u4f53; \u5982\u679c\u4e0e\u6587\u4e2d\u4f4d\u7f6e\u76f8\u540c&#xff0c;\u8fd9\u884c\u53ef\u4e0d\u5199<br \/>\n    GPIO_InitStruct.Pin &#061; GPIO_PIN_12;              \/\/ \u5f15\u811aPA12, \u5373D&#043;<br \/>\n    GPIO_InitStruct.Mode &#061; GPIO_MODE_OUTPUT_PP;     \/\/ \u5f15\u811a\u5de5\u4f5c\u6a21\u5f0f<br \/>\n    GPIO_InitStruct.Pull &#061; GPIO_PULLDOWN;           \/\/ \u4e0b\u62c9<br \/>\n    GPIO_InitStruct.Speed &#061; GPIO_SPEED_FREQ_LOW;    \/\/ \u5f15\u811a\u53cd\u8f6c\u901f\u5ea6<br \/>\n    HAL_GPIO_Init(GPIOA, &amp;GPIO_InitStruct);         \/\/ \u521d\u59cb\u5316<br \/>\n    HAL_Delay(5);                                   \/\/ \u6301\u7eed\u7247\u523b <\/p>\n<p>\u6ce8\u610f&#xff0c;\u6700\u540e\u4e00\u884c\u7684\u5ef6\u65f6&#xff0c;\u662f\u5fc5\u987b\u7684&#xff0c;\u5efa\u8bae\u57285ms\u5de6\u53f3;<\/p>\n<p>\u5b8c\u6210\u540e&#xff0c;\u662f\u8fd9\u4e2a\u6837\u5b50\u7684&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"585\" src=\"2025-06-11pkc4v3kde0s.png\" width=\"1170\" \/><\/p>\n<p>\u589e\u52a0\u8fd9\u6bb5\u4ee3\u7801\u540e&#xff0c;\u518d\u65e0\u9700\u624b\u52a8\u63d2\u62d4\u00a0\u865a\u62df\u4e32\u53e3\u7684USB\u00a0\u7ebf\u4e86&#xff0c;\u7a0b\u5e8f\u5c06\u6a21\u62df \u201c\u00a0\u65ad\u5f00\u3001\u63d2\u5165\u201d;<\/p>\n<p>\u518d\u6b21\u7f16\u8bd1&#xff0c;\u786e\u4fdd\u4e0a\u8ff0\u64cd\u4f5c\u6b63\u5e38 &#xff08;\u5148\u522b\u70e7\u5f55&#xff09;\u3002<\/p>\n<\/p>\n<hr \/>\n<h2><\/h2>\n<h2><\/h2>\n<h2 id=\"%E4%BA%94%E3%80%81%E5%8F%91%E9%80%81%E7%9A%84%E5%AE%9E%E7%8E%B0\"><span style=\"color:#fe2c24\">\u4e94\u3001\u53d1\u9001<\/span><\/h2>\n<\/p>\n<p>\u53d1\u9001\u6570\u636e\u7684\u51fd\u6570<\/p>\n<p>uint8_t  CDC_Transmit_FS ( uint8_t* Buf,  uint16_t Len ); <\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u51fd\u6570\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570&#xff1a;\u6570\u636e\u7f13\u51b2\u533a\u7684\u5730\u5740\u3001\u5b57\u8282\u6570\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5982\u679cUSB\u8bbe\u5907\u6b63\u5fd9&#xff0c;\u5b83\u4f1a\u8fd4\u56deUSBD_BUSY\u72b6\u6001\u3002<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8fd9\u4e2a\u51fd\u6570\u7684\u4f5c\u7528\u662f\u8bbe\u7f6e\u4f20\u8f93\u6570\u636e\u7684\u7f13\u51b2\u533a&#xff0c;\u5e76\u6807\u8bb0\u6570\u636e\u5305\u4e3a\u5f85\u53d1\u9001\u3002\u6570\u636e\u5e76\u975e\u7acb\u523b\u53d1\u51fa&#xff0c;\u800c\u662f\u88ab\u5b58\u50a8\u5728USB\u5916\u8bbe\u7684\u7f13\u51b2\u533a\u4e2d&#xff0c;\u7b49\u5f85\u4e3b\u673a\u8f6e\u8be2\u8bf7\u6c42\u4f20\u8f93\u3002<\/p>\n<\/p>\n<p>\u53d1\u9001\u793a\u8303\u64cd\u4f5c<\/p>\n<ul>\n<li>\u5728main.c\u00a0\u7684 while\u00a0\u5faa\u73af\u4e2d&#xff0c;\u6dfb\u52a0\u4e09\u884c\u6d4b\u8bd5\u4ee3\u7801&#xff1a;1\u884c\u5ef6\u65f6\u3001\u4e24\u884c\u53d1\u9001\u6570\u636e;<\/li>\n<\/ul>\n<p>\u6ce8\u610f&#xff1a;\u662f\u5171\u4e09\u884c&#xff0c;1\u884c\u5ef6\u65f6&#xff0c;2\u884c\u53d1\u9001\u3002<\/p>\n<p>\u8bf7\u4e25\u683c\u6309\u7167\u8fd9\u4e09\u884c\u6765\u5199&#xff0c;\u56e0\u4e3a\u6211\u4eec\u8981\u987a\u5e26\u5b9e\u73b0\u4e00\u4e2abug,\u00a0 \u7136\u540e\u4e0b\u9762\u65b9\u4fbf\u89e3\u91ca\u5177\u4f53\u539f\u56e0&#xff01;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"410\" src=\"2025-06-113mzkiksur3o.png\" width=\"647\" \/><\/p>\n<p>\u65b0\u624b&#xff0c;\u60f3\u7701\u65f6\u95f4&#xff0c;\u5c31\u8bf7\u6309\u6b65\u9aa4\u64cd\u4f5c\u00a0&#xff1a;<\/p>\n<ul>\n<li>\u5148\u522b\u63d2\u865a\u62df\u4e32\u53e3\u6240\u7528\u7684USB\u7ebf<\/li>\n<li>\u7f16\u8bd1\u3001\u70e7\u5f55\u4ee3\u7801<\/li>\n<li>\u6253\u5f00\u4e32\u53e3\u52a9\u624b, &#xff08;\u8fd9\u65f6\u662f\u6ca1\u6709\u63d2\u865a\u62df\u4e32\u53e3USB\u7ebf\u7684&#xff09;&#xff0c;\u67e5\u770b\u76ee\u524d\u6709\u54ea\u4e9b\u7aef\u53e3\u53f7<\/li>\n<li>\u63d2\u5165\u865a\u62df\u4e32\u53e3\u7684USB\u7ebf&#xff0c;\u5230\u5f00\u53d1\u677f\u7684 USB-Slave\u63a5\u53e3\u00a0<\/li>\n<li>( \u524d\u63d0&#xff1a;win10\u300111\u7cfb\u7edf\u5df2\u5e26\u865a\u62df\u4e32\u53e3\u9a71\u52a8; win7\u8981\u624b\u52a8\u5b89\u88c5\u9a71\u52a8&#xff1a;\u865a\u62df\u4e32\u53e3\u4e0b\u8f7d)<\/li>\n<li>( \u7535\u8111\u4f1a\u81ea\u52a8\u8bc6\u522b\u5230\u8bbe\u5907&#xff1b;\u5982\u679c\u662f\u7b2c\u4e00\u6b21\u4f7f\u7528\u865a\u62df\u4e32\u53e3&#xff0c;\u7535\u8111\u5c06\u81ea\u52a8\u5b89\u88c5\u9a71\u52a8\u7a0b\u5e8f)<\/li>\n<li>\u68c0\u67e5\u4e32\u53e3\u52a9\u624b&#xff0c;\u53d1\u73b0\u591a\u4e86\u4e00\u4e2a\u7aef\u53e3\u53f7&#xff0c; \u9009\u62e9\u5b83&#xff0c;\u6ce2\u7279\u7387\u7b49\u53c2\u6570\u4e0d\u7528\u4fee\u6539&#xff0c;\u6253\u5f00\u7aef\u53e3;<\/li>\n<\/ul>\n<p>\u63a5\u7ebf&#xff0c;\u5982\u4e0b\u56fe&#xff08;\u793a\u4f8b\u6240\u7528\u7684\u5f00\u53d1\u677f&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u5de6\u4fa7\u4e3a\u7528\u6237USB\u63a5\u53e3&#xff0c;\u5df2\u8fde\u63a5PA11\u3001PA12&#xff0c;\u6211\u4eec\u5c31\u662f\u7528\u8fd9\u4e2aU\u53e3\u5b9e\u73b0\u865a\u62df\u4e32\u53e3\u901a\u4fe1\u3002<\/li>\n<li>\u53f3\u4fa7\u662f\u677f\u8f7d\u4eff\u771f\u5668CMSIS DAP\u7684\u63a5\u53e3&#xff0c;\u5b83\u81ea\u5e26\u4e86USB\u8f6cTTL\u529f\u80fd\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"785\" src=\"2025-06-11kygpd5qvaly.png\" width=\"1122\" \/><\/p>\n<p>\u6ce8\u610f\u7aef\u53e3\u7684\u9009\u62e9&#xff1a;<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u5f53\u4f7f\u7528\u7684\u5f00\u53d1\u677f&#xff0c;\u5df2\u5e26USB\u8f6cTTL\u529f\u80fd&#xff0c;\u5982\u4e0a\u9762\u8fd9\u4e2a\u3002\u5728\u70e7\u5f55\u865a\u62df\u4e32\u53e3\u7684\u7a0b\u5e8f\u540e&#xff0c;\u4e32\u53e3\u52a9\u624b\u4f1a\u6709\u81f3\u5c11\u4e24\u4e2a\u7aef\u53e3\u53f7&#xff1a;\u677f\u5b50\u81ea\u5e26\u7684USB\u8f6cTTL&#xff08;\u53f3\u4fa7&#xff09;\u3001\u7a0b\u5e8f\u5b9e\u73b0\u7684\u865a\u62df\u4e32\u53e3&#xff08;\u5de6\u4fa7&#xff09;&#xff0c;\u6ce8\u610f\u4e0d\u8981\u9009\u62e9\u9519\u4e86\u3002<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u5982\u679c\u4e0d\u77e5\u9053\u54ea\u6839\u7ebf\u5bf9\u5e94\u54ea\u4e2a\u7aef\u53e3&#xff1a;\u5728\u70e7\u5f55\u540e&#xff0c;\u62d4\u4e00\u4e0bUSB\u7ebf&#xff0c;\u770b\u770b\u54ea\u4e2a\u7aef\u53e3\u6d88\u5931\u4e86\u3002<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u53e6\u4e00\u65b9\u6cd5&#xff0c;\u6709\u4e9b\u4e32\u53e3\u52a9\u624b\u7684\u7aef\u53e3\u5217\u8868&#xff0c;\u80fd\u663e\u793a\u8bbe\u5907\u4fe1\u606f&#xff0c;\u627e\u5230\u5e26\u201cSTM&#8230;\u201d\u63cf\u8ff0\u7684\u90a3\u4e2a\u3002<\/p>\n<\/p>\n<p>\u73b0\u5728\u80fd\u770b\u5230&#xff0c;\u4e32\u53e3\u52a9\u624b\u80fd\u63a5\u6536\u5230\u7a0b\u5e8f\u6301\u7eed\u53d1\u51fa\u7684\u6570\u636e\u4e86&#xff01;<\/p>\n<p>\u6548\u679c\u5982\u4e0b\u56fe&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"550\" src=\"2025-06-11safnr4z5r5h.png\" width=\"785\" \/><\/p>\n<hr \/>\n<\/p>\n<h2 id=\"%E5%85%AD%E3%80%81%E5%8F%91%E9%80%81%C2%A0%E4%BC%98%E5%8C%96\"><span style=\"color:#fe2c24\">\u516d\u3001\u53d1\u9001\u4f18\u5316&#xff08;\u8fde\u7eed\u53d1\u9001&#xff09;<\/span><\/h2>\n<\/p>\n<p>\u4e0a\u8282\u7684\u53d1\u9001&#xff0c;\u5b9e\u73b0\u65f6&#xff0c;\u53ea\u80fd\u6536\u5230\u7b2c\u4e00\u884c&#034;Hello&#034;&#xff0c;\u800c\u7b2c\u4e8c\u884c\u53d1\u51fa\u7684\u6570\u636e:&#034;\u501f\u70b9\u94b1 &#034;\u5374\u6ca1\u6536\u5230&#xff01;&#xff01;<\/p>\n<p>\u4e0d\u662f\u6ca1\u6536\u5230\u3002\u5176\u5b9e&#xff0c;\u4eceSTM32\u7a0b\u5e8f\u7684\u89d2\u5ea6&#xff0c;\u662f\u6ca1\u6709\u53d1\u51fa\u6570\u636e&#xff01;<\/p>\n<p>\u5148\u8bf4\u8bf4&#xff0c;USB\u865a\u62df\u4e32\u53e3\u901a\u4fe1\u7684\u51e0\u4e2a\u91cd\u70b9 (\u7279\u6307&#xff1a;USB2.0\u3001\u5168\u901f\u6a21\u5f0f\u3001\u4e2d\u65ad\u4f20\u8f93&#xff09;&#xff1a;<\/p>\n<ul>\n<li>USB\u662f\u8f6e\u8be2\u673a\u5236&#xff0c;\u4e3b\u673a\u5bf9\u8bbe\u5907\u4e0d\u65ad\u8f6e\u8be2&#xff0c;\u95f4\u9694\u6700\u5c0f1ms&#xff1b;\u4e0d\u662f\u56fa\u5b9a\u76841ms,\u00a0 \u662f\u6700\u5c0f\u95f4\u9694\u65f6\u95f4;<\/li>\n<li>USB\u7684\u6570\u636e&#xff0c;\u662f\u6309\u5305\u4f20\u8f93\u7684;\u00a0<\/li>\n<li>\u6bcf\u4e2a\u8bbe\u5907&#xff0c;\u6bcf1ms&#xff0c;\u6700\u591a\u4f20\u8f931\u5305\u6570\u636e;<\/li>\n<li>\u6bcf\u5305\u6700\u591a64\u5b57\u8282&#xff08;\u6709\u6548\u8d1f\u8f7d&#xff09;;<\/li>\n<\/ul>\n<p>\u518d\u8bf4\u8bf4&#xff0c;CDC_Transmit_FS ( )\u00a0\u51fd\u6570&#xff1a;<\/p>\n<ul>\n<li>\u5b83\u7684\u7b2c2\u4e2a\u53c2\u6570&#xff0c;&#034;\u5b57\u8282\u6570&#034;&#xff0c;\u8303\u56f4&#xff1a;0~2048;\u00a0\u8fd9\u4e2a2048\u53ef\u4ee5\u5728CubeMX\u91cc\u8fdb\u884c\u8bbe\u7f6e\u5927\u5c0f;\u00a0<\/li>\n<li>\u5b57\u8282\u6570 &lt;&#061; 64&#xff0c;\u7b971\u5305\u3002\u5982&#xff1a;\u53d13\u4e2a\u5b57\u8282&#xff0c;\u4e5f\u7b971\u5305\u3002<\/li>\n<li>\u5b57\u8282\u6570 &#061;&#061; 0&#xff0c;\u4e5f\u7b971\u5305\u3002\u4fd7\u79f0&#xff1a;\u7a7a\u5305; \u5982\u679c\u4e0a\u4e00\u5e27\u521a\u597d\u53d1\u900164\u5b57\u8282&#xff0c;\u518d\u53d1\u4e00\u4e2a\u7a7a\u5305\u4f5c\u4e3a\u7ed3\u675f\u5305;<\/li>\n<li>\u5b57\u8282\u6570 &gt;\u00a064&#xff0c;\u00a0CDC_Transmit_FS ( )\u00a0\u80cc\u540e\u6709\u7f13\u5b58&#xff0c;\u5b83\u81ea\u52a8\u5206\u5305&#xff0c;1ms\u5de6\u53f3\u53d11\u5305&#xff0c;\u76f4\u81f3\u53d1\u5b8c;<\/li>\n<li>\u5982\u679c\u4e0a\u4e00\u5305\u8fd8\u6ca1\u53d1\u5b8c&#xff0c;\u518d\u6b21\u8c03\u7528CDC_Transmit_FS ( ) &#xff0c;\u5c06\u653e\u5f03\u672c\u6b21\u8c03\u7528\u3002<\/li>\n<\/ul>\n<p>\u4e0a\u9762while\u5faa\u73af\u4e2d&#xff0c;\u8fde\u7eed\u3001\u4e24\u6b21\u8c03\u7528CDC_Transmit_FS ( ) .<\/p>\n<ul>\n<li>\u7b2c1\u6b21\u8c03\u7528&#xff0c;\u5c06\u6b63\u5e38\u53d1\u51fa\u4e00\u5305\u6570\u636e;<\/li>\n<li>\u7b2c2\u6b21\u8c03\u7528&#xff0c;\u518d\u53d1\u9001\u4e00\u5305\u3002\u4f46\u662f&#xff0c;\u4e24\u5305\u6ca1\u6709\u95f4\u96941ms\u4ee5\u4e0a&#xff0c;\u5bfc\u81f4\u4e86\u7b2c2\u6b21\u7684\u53d1\u9001&#xff0c;\u88ab\u820d\u5f03\u4e86\u3002<\/li>\n<\/ul>\n<p>\u6211\u4eec\u5148\u6253\u5f00\u00a0CDC_Transmit_FS ( )\u00a0\u51fd\u6570&#xff0c;\u770b\u770b\u51fd\u6570\u539f\u578b\u3002<\/p>\n<p>\u5728\u4ee3\u7801\u4e2d&#xff0c;\u53f3\u51fbCDC_Transmit_FS ( ) &#xff0c;\u5f39\u51fa\u83dc\u5355&#xff0c;\u9009\u62e9Go To Definition&#8230;&#xff0c;\u5c06\u8df3\u8f6c\u5230\u51fd\u6570\u4f4d\u7f6e;<\/p>\n<p>\u6216\u8005&#xff0c;\u5728\u5de6\u4fa7\u6587\u4ef6\u6811\u4e2d&#xff0c;\u53cc\u51fb\u6253\u5f00usbd_cdc_if.c\u00a0\u6587\u4ef6 &#xff0c;CDC_Transmit_FS ( ) \u4f4d\u4e8e\u5927\u7ea6280\u884c\u00a0;<\/p>\n<p><span style=\"color:#fe2c24\">\u7279\u522b\u6ce8\u610f&#xff1a;<\/span><\/p>\n<p>usbd_cdc_if.c\u00a0\u662f\u5e94\u7528\u5c42\u6587\u4ef6&#xff0c;\u6211\u4eec\u5bf9\u6536\u3001\u53d1\u6709\u5565\u7279\u6b8a\u9700\u6c42&#xff0c;\u901a\u8fc7\u4fee\u6539\u6587\u4ef6\u91cc\u7684\u53d1\u9001\u51fd\u6570\u3001\u63a5\u6536\u56de\u8c03\u51fd\u6570\u3001\u7c7b\u8bf7\u6c42\u51fd\u6570&#xff0c;\u57fa\u672c\u90fd\u80fd\u5b9e\u73b0\u3002<\/p>\n<p>\u4e0b\u56fe&#xff0c;\u662f\u00a0CDC_Transmit_FS ( )\u00a0\u51fd\u6570\u622a\u56fe\u3002<\/p>\n<p>\u7ea2\u6846\u7684\u4ee3\u7801\u4f5c\u7528\u662f&#xff1a;\u5f53\u8bbe\u5907\u5fd9\u65f6&#xff0c;\u76f4\u63a5\u653e\u5f03\u53d1\u9001,&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"348\" src=\"2025-06-11jxr0cwv3plt.png\" width=\"816\" \/><\/p>\n<\/p>\n<p>\u4fee\u6539&#xff1a;<\/p>\n<ul>\n<li>\u6ce8\u91ca\u6389\u521a\u624d if\u00a0\u4f53\u76843\u884c\u4ee3\u7801;<\/li>\n<li>\u589e\u52a0\u7b49\u5f85\u53d1\u9001\u7a7a\u95f2\u3001\u5224\u65ad\u8d85\u65f6&#xff0c;\u5982\u4e0b6\u884c;<\/li>\n<li>\u6574\u4e2aCDC_Transmit_FS ( ) \u51fd\u6570&#xff0c;\u5982\u4e0b:&#xff08;\u53ef\u590d\u5236&#xff09;<\/li>\n<\/ul>\n<p>uint8_t CDC_Transmit_FS(uint8_t *Buf, uint16_t Len)<br \/>\n{<br \/>\n    uint8_t result &#061; USBD_OK;<br \/>\n    \/* USER CODE BEGIN 7 *\/<\/p>\n<p>    USBD_CDC_HandleTypeDef *hcdc &#061; (USBD_CDC_HandleTypeDef *)hUsbDeviceFS.pClassData; \/\/ \u83b7\u5f97\u8bbe\u5907\u7684\u72b6\u6001\u4fe1\u606f\u7ed3\u6784\u4f53<br \/>\n    \/\/ if (hcdc-&gt;TxState !&#061; 0){<br \/>\n    \/\/ return USBD_BUSY;<br \/>\n    \/\/ }<br \/>\n    uint32_t timeStart &#061; HAL_GetTick();<br \/>\n    while (hcdc-&gt;TxState)<br \/>\n    {<br \/>\n        if (HAL_GetTick() &#8211; timeStart &gt; 20)<br \/>\n            return USBD_BUSY;<br \/>\n    }<\/p>\n<p>    USBD_CDC_SetTxBuffer(&amp;hUsbDeviceFS, Buf, Len);<br \/>\n    result &#061; USBD_CDC_TransmitPacket(&amp;hUsbDeviceFS);<\/p>\n<p>    \/* USER CODE END 7 *\/<br \/>\n    return result;<br \/>\n} <\/p>\n<p>\u5b8c\u6210\u540e&#xff0c;\u662f\u8fd9\u4e2a\u6837\u5b50&#xff1a;<img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"448\" src=\"2025-06-11wskj2ab31oc.png\" width=\"1200\" \/><\/p>\n<\/p>\n<p>\u518d\u6b21\u7f16\u8bd1\u3001\u70e7\u5f55\u7a0b\u5e8f\u3002<\/p>\n<p>\u4e32\u53e3\u52a9\u624b&#xff0c;\u73b0\u5728\u662f\u8fd9\u4e2a\u6837\u5b50\u7684&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"550\" src=\"2025-06-11dz5w0t5fvi5.png\" width=\"785\" \/><\/p>\n<p>\u8fde\u7eed\u53d1\u9001\u5df2\u5b9e\u73b0\u4e86\u3002<\/p>\n<p>\u4e0a\u8ff0\u65b9\u6cd5\u80fd\u591f\u89e3\u51b3\u8fde\u7eed\u53d1\u9001\u5931\u8d25\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4f46\u5b83\u5b58\u5728\u4e00\u4e2a\u663e\u8457\u7f3a\u70b9&#xff1a;\u7531\u4e8e\u5176\u963b\u585e\u6027\u8d28&#xff0c;\u9891\u5bc6\u8fde\u7eed\u53d1\u9001\u65f6&#xff0c;\u5c06\u5bfc\u81f4\u8fd0\u884c\u201c\u6b7b\u7b49\u201d&#xff0c;\u5f71\u54cd\u7a0b\u5e8f\u6548\u7387\u3002<\/p>\n<p>&#xff08;\u5bf9\u4e8e\u5927\u90e8\u5206\u573a\u666f&#xff0c;\u4e0a\u8ff0\u65b9\u6cd5\u5df2\u8db3\u591f\u3002\u672c\u8282\u5185\u5bb9&#xff0c;\u53ea\u662f\u4e3a\u4f60\u9884\u57cb\u4e00\u79cd\u5907\u7528\u601d\u8def&#xff0c;\u65e0\u9700\u6b7b\u78d5\u3002&#xff09;<\/p>\n<p>\u5982\u679c\u9879\u76ee\u5bf9\u5b9e\u65f6\u6027\u6709\u8f83\u9ad8\u7684\u8981\u6c42&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u7ed3\u5408\u4f7f\u7528\u53d1\u9001\u6570\u636e\u51fd\u6570 CDC_Transmit_FS() \u548c\u53d1\u9001\u5b8c\u6210\u56de\u8c03\u51fd\u6570 CDC_TransmitCplt_FS() \u6765\u63d0\u9ad8\u4f20\u8f93\u6548\u7387\u3002CDC_TransmitCplt_FS() \u4f1a\u5728 CDC_Transmit_FS() \u51fd\u6570\u53d1\u9001\u6570\u636e\u5b8c\u6bd5\u540e\u81ea\u52a8\u88ab\u8c03\u7528\u3002<\/p>\n<p>\u6839\u636e\u8fd9\u4e24\u4e2a\u51fd\u6570\u7684\u7279\u70b9&#xff0c;\u53ef\u4ee5\u8bbe\u8ba1\u4e00\u5957\u9ad8\u6548\u7684\u53d1\u9001\u7f13\u5b58\u673a\u5236\u3002\u4f8b\u5982&#xff0c;\u53ef\u4ee5\u7ef4\u62a4\u4e00\u4e2a\u53d1\u9001\u961f\u5217&#xff0c;\u5f53 CDC_Transmit_FS() \u5b8c\u6210\u53d1\u9001\u540e&#xff0c;CDC_TransmitCplt_FS() \u88ab\u8c03\u7528\u65f6&#xff0c;\u4ece\u961f\u5217\u4e2d\u53d6\u51fa\u4e0b\u4e00\u4e2a\u6570\u636e\u9879\u8fdb\u884c\u53d1\u9001&#xff0c;\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u6570\u636e\u4f20\u8f93\u7684\u8fde\u7eed\u6027\u3002<\/p>\n<p>\u8fd9\u4e2a\u53d1\u9001\u5b8c\u6210\u56de\u8c03\u51fd\u6570 CDC_TransmitCplt_FS() &#xff0c;\u4f4d\u4e8e\u53d1\u9001\u51fd\u6570 CDC_Transmit_FS() \u7684\u6b63\u4e0b\u65b9\u3002<\/p>\n<p>\u81f3\u4e8e\u5177\u4f53\u7684\u4ee3\u7801\u5b9e\u73b0&#xff0c;\u4e0d\u540c\u9879\u76ee\u9700\u6c42\u5404\u5f02&#xff0c;\u65e0\u6cd5\u63d0\u4f9b\u4e00\u4e2a\u901a\u7528\u7684\u89e3\u51b3\u65b9\u6848\u3002\u56e0\u6b64&#xff0c;\u9700\u8981\u6839\u636e\u5177\u4f53\u7684\u9879\u76ee\u9700\u6c42&#xff0c;\u8fdb\u884c\u9488\u5bf9\u6027\u7684\u8bbe\u8ba1\u548c\u4f18\u5316&#xff0c;\u4e0d\u80fd\u4e00\u836f\u6cbb\u767e\u75c5\u3002<\/p>\n<hr \/>\n<h2><\/h2>\n<h2><\/h2>\n<h2 id=\"%E5%85%AD%E3%80%81%E6%8E%A5%E6%94%B6\"><span style=\"color:#fe2c24\">\u4e03\u3001\u63a5\u6536<\/span><\/h2>\n<\/p>\n<p>1\u3001\u63a5\u6536\u65b9\u5f0f\u7684\u7b80\u8ff0<\/p>\n<p>\u5f53USB CDC\u63a5\u6536\u5230\u6765\u81eaUSB\u4e3b\u673a\u7684\u6570\u636e\u65f6&#xff0c;\u89e6\u53d1\u4e2d\u65ad\u8fdb\u5165\u4e2d\u65ad\u51fd\u6570&#xff0c;\u7ee7\u800c\u81ea\u52a8\u8c03\u7528\u63a5\u6536\u56de\u8c03\u51fd\u6570:<\/p>\n<p>int8_t\u00a0 CDC_Receive_FS\u00a0(uint8_t* Buf, uint32_t *Len);\u00a0\u00a0 <\/p>\n<ul>\n<li>uint8_t* Buf:\u00a0 \u00a0\u6307\u5411\u63a5\u6536\u7f13\u51b2\u533a\u7684\u6307\u9488&#xff0c;\u5373\u6570\u636e\u7f13\u5b58\u7684\u5730\u5740\u3002<\/li>\n<li>uint16_t* Len: \u5f53\u524d\u6570\u636e\u5305\u7684\u5b57\u8282\u6570\u3002<\/li>\n<\/ul>\n<p>\u6211\u4eec\u5c31\u5728\u8fd9\u4e2a\u56de\u8c03\u51fd\u6570\u91cc&#xff0c;\u5904\u7406\u63a5\u6536\u5230\u7684\u6570\u636e&#xff01;<\/p>\n<p>\u5b83\u5728\u00a0usbd_cdc_if.c \u6587\u4ef6&#xff0c;\u4f4d\u4e8e\u53d1\u9001\u51fd\u6570\u7684\u6b63\u4e0a\u65b9&#xff1b;<\/p>\n<p>\u51fd\u6570\u5185\u90e8&#xff0c;\u751f\u6210\u7684\u4ee3\u7801\u91cc&#xff0c;\u53ea\u67092\u884c\u6267\u884c\u4ee3\u7801&#xff0c;\u6307\u5b9a\u4e0b\u6b21\u63a5\u6536\u7684\u5b58\u653e\u4f4d\u7f6e;\u00a0 \u5982\u4e0b\u56fe\u6240\u793a&#xff1a;<\/p>\n<p>\u800c\u672c\u6b21\u6240\u63a5\u6536\u5230\u7684\u6570\u636e&#xff0c;\u8be5\u5982\u4f55\u5904\u7406&#xff0c;\u9700\u8981\u6211\u4eec\u81ea\u884c\u6dfb\u52a0\u4ee3\u7801\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"725\" src=\"2025-06-11op5tenqbgv0.png\" width=\"844\" \/><\/p>\n<\/p>\n<p>\u63a5\u6536\u673a\u5236\u6ce8\u610f\u4e8b\u9879&#xff1a;<\/p>\n<ul>\n<li>\u6bcf\u5f53\u63a5\u6536\u5230\u4e00\u5305\u6570\u636e&#xff0c;\u786c\u4ef6\u81ea\u52a8\u89e6\u53d1\u4e2d\u65ad\u51fd\u6570&#xff0c;\u00a0\u7ee7\u800c\u8c03\u7528\u6b64\u63a5\u6536\u56de\u8c03\u51fd\u6570&#xff0c;\u65e0\u9700\u4eba\u5de5\u8c03\u7528\u3002<\/li>\n<li>\u4e0e\u53d1\u9001\u673a\u5236\u76f8\u4f3c&#xff0c;\u6bcf\u95f4\u96941ms&#xff0c;\u6700\u591a\u63a5\u65361\u5305\u6570\u636e&#xff0c;\u6bcf\u5305\u6700\u592764\u5b57\u8282\u3002\u3002<\/li>\n<li>\u5982\u679c\u9700\u8981\u63a5\u6536\u8d85\u8fc764\u5b57\u8282\u7684\u6570\u636e\u5e27&#xff0c;\u6ce8\u610f&#xff0c;\u6307\u4e0a\u4f4d\u673a\u53d1\u9001\u76841\u4e2a\u5b8c\u6574\u6570\u636e\u5e27&#xff0c;\u800c\u975eUSB\u7684\u5355\u5305\u6570\u636e&#xff0c;\u5982&#xff0c;\u4e0a\u4f4d\u673a\u53d1\u6765\u4e00\u5f20\u56fe\u7247\u6570\u636e&#xff0c;8350\u4e2a\u5b57\u8282&#xff0c;\u5219\u9700\u8981\u5728\u6b64\u56de\u8c03\u51fd\u6570\u4e2d\u6dfb\u52a0\u989d\u5916\u7684\u4ee3\u7801\u6765\u5224\u65ad\u5e27\u6570\u636e\u4f20\u8f93\u5b8c\u6574\u7ed3\u675f \u3001\u624b\u52a8\u5c06\u591a\u4e2a\u6570\u636e\u5305\u62fc\u63a5\u6210\u5b8c\u6574\u7684\u6570\u636e\u5e27\u3002<\/li>\n<li>\u63a5\u6536\u5230\u6570\u636e\u65f6&#xff0c;\u7f13\u5b58\u4e0d\u4f1a\u63d0\u524d\u81ea\u52a8\u6e05\u96f6&#xff0c;\u65b0\u6570\u636e\u4eceBuf\u7684\u8d77\u59cb\u4f4d\u7f6e\u5f00\u59cb&#xff0c;\u8986\u76d6\u5b58\u653e\u3002<\/li>\n<li>\u7531\u4e8e\u8be5\u56de\u8c03\u51fd\u6570\u662f\u88ab\u4e2d\u65ad\u51fd\u6570\u8c03\u7528\u7684&#xff0c;\u56e0\u6b64\u5efa\u8bae\u51fd\u6570\u5185\u90e8\u7684\u5904\u7406\u5c3d\u53ef\u80fd\u5730\u7b80\u77ed&#xff0c;\u4ee5\u907f\u514d\u5f71\u54cd\u7cfb\u7edf\u7684\u5b9e\u65f6\u6027&#xff08;\u4e2d\u65ad\u51fd\u6570\u8fd0\u884c\u671f\u95f4&#xff0c;\u4f1a\u4ee4\u7a0b\u5e8f\u6301\u7eed\u6302\u8d77&#xff09;\u3002<\/li>\n<\/ul>\n<p>2\u3001\u63a5\u6536\u793a\u8303<\/p>\n<p>\u672c\u8282\u5c06\u793a\u8303&#xff1a;<\/p>\n<ul>\n<li>\u901a\u8fc7\u4e32\u53e3\u52a9\u624b&#xff0c;\u53d1\u9001\u5b57\u7b26\u4e32\u00a0<\/li>\n<li>STM32&#xff08;\u8bbe\u5907\u7aef&#xff09;\u6536\u5230\u6570\u636e\u540e&#xff0c;\u628a\u6536\u5230\u7684\u5b57\u8282\u6570\u3001\u5b57\u7b26\u4e32&#xff0c;\u53d1\u56de\u4e32\u53e3\u52a9\u624b\u663e\u793a&#xff08;\u4e3b\u673a\u7aef&#xff09;<\/li>\n<\/ul>\n<p>\u5728\u51fd\u6570\u5185\u7684\u6ce8\u91ca\u884c\u00a0 \/* USER CODE BEGIN *\/\u00a0 \u4e0b\u65b9&#xff0c;\u6dfb\u52a04\u884c\u81ea\u5b9a\u4e49\u4ee3\u7801&#xff08;\u53ef\u590d\u5236&#xff09;\u3002<\/p>\n<p>    char myStr[64] &#061; {0};                                                     \/\/ \u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4&#xff0c;\u7528\u4e8e\u5b58\u653e\u8981\u8f93\u51fa\u7684\u5b57\u7b26\u4e32<br \/>\n    sprintf(myStr, &#034;\\\\r\\\\r\u6536\u5230 %d \u4e2a\u5b57\u8282&#xff1b;\\\\r\u5185\u5bb9\u662f&#xff1a;%s\\\\r\\\\r&#034;, *Len, (char *)Buf); \/\/ \u683c\u5f0f\u5316\u5b57\u7b26\u4e32<br \/>\n    CDC_Transmit_FS((uint8_t *)myStr, strlen(myStr));                         \/\/ \u53d1\u9001<br \/>\n    memset(Buf, 0, 64);                                                       \/\/ \u5904\u7406\u5b8c\u6570\u636e&#xff0c;\u6e050\u63a5\u6536\u7f13\u5b58;<\/p>\n<p>\u6ce8\u610f&#xff1a;<\/p>\n<ul>\n<li>\u7528char\u00a0\u58f0\u660emyStr[ ],\u00a0\u662f\u56e0\u4e3a\u6b64\u5904\u60f3\u628a\u5b83\u4f5c\u4e3a\u4e00\u6bb5\u5b57\u7b26\u4e32\u7a7a\u95f4;<\/li>\n<li>sprintf\u662fC\u8bed\u8a00\u6807\u51c6\u8f93\u5165\u8f93\u51fa\u5e93\u7684\u51fd\u6570&#xff0c;\u5982\u679c\u62a5\u9519\u6ca1\u6709\u8fd9\u4e2a\u51fd\u6570&#xff0c;\u5c31&#xff1a;#include &lt;stdio.h&gt;<\/li>\n<li>\u83b7\u53d6\u5b57\u8282\u6570&#xff0c;\u662f*Len&#xff0c;\u800c\u4e0d\u662fLen;\u00a0 \u56e0\u4e3a\u5b83\u5728\u51fd\u6570\u53c2\u6570\u91cc\u7684\u58f0\u660e&#xff0c;\u662f\u4e00\u4e2a\u6307\u9488;<\/li>\n<li>\u4e3a\u4e86\u683c\u5f0f\u5316\u6210\u5b57\u7b26\u4e32&#xff0c;Buf\u7528\u4e86(char*)\u8fdb\u884c\u5f3a\u5236\u8f6c\u6362\u6210\u5b57\u7b26\u7c7b\u578b;\u00a0<\/li>\n<li>CDC_Transmit_FS( )\u91cc&#xff0c;\u7528\u4e86strlen\u83b7\u53d6\u5b57\u7b26\u4e32\u7684\u5b57\u8282\u6570&#xff0c;\u5b83\u53ea\u5bf9\u5b57\u7b26\u4e32\u6709\u6548&#xff0c;\u5bf9\u5176\u5b83\u6570\u636e\u7c7b\u578b\u65e0\u6548;\u00a0 \u5982\u679c\u62a5\u9519\u6ca1\u6709\u8fd9\u4e2a\u51fd\u6570&#xff0c;\u5c31&#xff1a;#include\u00a0 &lt;string.h&gt;<\/li>\n<li>\u5982\u679c\u4f20\u8f93\u7684\u662f16\u8fdb\u5236\u6570&#xff0c;\u7528uint8_t\u00a0\u58f0\u660e\u4e0a\u9762\u6570\u7ec4&#xff0c;\u7136\u540e\u4fee\u6539sprintf\u7684\u683c\u5f0f\u5316\u65b9\u5f0f\u3002<\/li>\n<\/ul>\n<p>\u6dfb\u52a0\u5b8c\u6210\u540e&#xff0c;\u6587\u4ef6\u662f\u8fd9\u6837\u5b50\u7684&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"393\" src=\"2025-06-11iay4rrrmb1a.png\" width=\"1200\" \/><\/p>\n<\/p>\n<p>\u518d\u6b21\u7f16\u8bd1\u3001\u70e7\u5f55\u7a0b\u5e8f\u3002<\/p>\n<p>\u4e32\u53e3\u52a9\u624b&#xff0c;\u6253\u5f00\u5bf9\u5e94\u7684\u7aef\u53e3\u53f7&#xff08;\u6ce2\u7279\u7387\u7b49\u53c2\u6570\u4e0d\u7528\u4fee\u6539&#xff09;&#xff0c;<\/p>\n<p>\u5728\u53d1\u9001\u533a&#xff0c;\u4ee5ASCII\u65b9\u5f0f&#xff0c;\u53d1\u9001\u5b57\u7b26\u4e32&#xff08;\u56e0\u4e3a\u6dfb\u52a0\u7684\u4ee3\u7801\u91cc\u7528%s\u683c\u5f0f\u5316&#xff0c;\u5904\u7406\u7684\u662f\u5b57\u7b26\u4e32)&#xff0c;<\/p>\n<p>\u7136\u540e&#xff0c;\u4e32\u53e3\u52a9\u624b\u7684\u63a5\u6536\u533a&#xff0c;\u9a6c\u4e0a\u80fd\u63a5\u6536\u5230\u521a\u624d\u53d1\u51fa\u7684\u6570\u636e&#xff01;<\/p>\n<p>\u81f3\u6b64&#xff0c;\u5df2\u5b9e\u73b0\u63a5\u6536\u7684\u5904\u7406\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"550\" src=\"2025-06-11zogxkm0imvb.png\" width=\"785\" \/><\/p>\n<hr \/>\n<\/p>\n<h2 id=\"%E5%85%AB%E3%80%81%C2%A0%E6%8E%A5%E6%94%B6%C2%A0%E4%BC%98%E5%8C%96\"><span style=\"color:#fe2c24\">\u516b\u3001\u63a5\u6536\u4f18\u5316&#xff08;\u5728\u5916\u90e8\u5904\u7406\u6570\u636e&#xff09;<\/span><\/h2>\n<\/p>\n<p>\u4e0a\u9762&#xff0c;\u6211\u4eec\u5df2\u5b9e\u73b0&#xff1a;\u83b7\u53d6\u3001\u4f7f\u7528\u63a5\u6536\u5230\u7684\u6570\u636e\u3002<\/p>\n<p>\u5728\u63a5\u6536\u56de\u8c03\u51fd\u6570\u4e2d&#xff0c;\u76f4\u63a5\u64cd\u4f5c\u6570\u636e\u7684\u53d1\u9001&#xff0c;\u901a\u5e38\u662f\u5b89\u5168\u7684&#xff0c;\u56e0\u4e3a\u8fd9\u79cd\u64cd\u4f5c\u8017\u65f6\u975e\u5e38\u77ed&#xff0c;\u6700\u591a\u7b49\u5f851\u6b21\u4e3b\u673a\u8f6e\u8be2\u5468\u671f&#xff08;1ms&#xff09;\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b&#xff0c;\u4e0d\u4f1a\u5bf9\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u548c\u6570\u636e\u63a5\u6536\u9020\u6210\u663e\u8457\u5f71\u54cd\u3002<\/p>\n<p>\u4f46\u662f&#xff0c;\u5982\u679c\u5728\u63a5\u6536\u56de\u8c03\u51fd\u6570\u4e2d\u6267\u884c\u8017\u65f6\u8f83\u957f\u7684\u64cd\u4f5c&#xff0c;\u5982\u663e\u793a\u5230LCD\u6216\u5b58\u50a8\u5230Flash\u7b49&#xff0c;\u8fd9\u4e9b\u64cd\u4f5c\u53ef\u80fd\u9700\u8981\u6570\u6beb\u79d2\u5230\u6570\u5341\u6beb\u79d2\u624d\u80fd\u5b8c\u6210\u3002\u8017\u65f6\u8f83\u957f\u7684\u64cd\u4f5c&#xff0c;\u53ef\u80fd\u4f1a\u5bfc\u81f4\u63a5\u6536\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u6f0f\u5305\u73b0\u8c61\u3002<\/p>\n<p>\u56e0\u4e3a\u63a5\u6536\u56de\u8c03\u51fd\u6570\u662f\u7531USB\u4e2d\u65ad\u670d\u52a1\u7a0b\u5e8f\u8c03\u7528\u7684&#xff0c;\u5c5e\u4e8e\u4e2d\u65ad\u5904\u7406\u7684\u4e00\u90e8\u5206&#xff0c;\u5728\u56de\u8c03\u51fd\u6570\u6267\u884c\u671f\u95f4&#xff0c;\u4e3b\u7a0b\u5e8f\u8fd8\u5904\u4e8e\u4e2d\u65ad\u6302\u8d77\u72b6\u6001&#xff0c;\u5176\u4ed6\u4ee3\u7801\u548c\u4e2d\u65ad\u4e5f\u4f1a\u88ab\u6682\u505c\u6267\u884c&#xff0c;\u5f62\u8c61\u5730\u63cf\u8ff0&#xff1a;\u201c\u5361\u6b7b\u201d\u3002<\/p>\n<p>\u5982\u679c\u4e2d\u65ad\u670d\u52a1\u7a0b\u5e8f\u7684\u6267\u884c\u64cd\u4f5c\u8f83\u8017\u65f6&#xff0c;\u4f1a\u5bfc\u81f4\u4e0b\u4e00\u5305\u6570\u636e\u65e0\u6cd5\u53ca\u65f6\u8fdb\u5165\u4e2d\u65ad&#xff0c;\u4ece\u800c\u9020\u6210\u6570\u636e\u4e22\u5931\u3002<\/p>\n<p>\u4e3e\u4f8b\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>A (\u7535\u8111USB\u4e3b\u673a)\u6bcf\u96941ms\u6254\u51fa1\u679a\u9e21\u86cb&#xff0c;B(STM32\u4e2d\u65ad\u670d\u52a1\u51fd\u6570&#xff09;\u8d1f\u8d23\u63a5\u9e21\u86cb\u3002<\/li>\n<li>\u5f53B\u63a5\u9e21\u86cb\u5904\u7406\u5f97\u6bd4A\u5feb&#xff0c;\u5373\u6bd4A\u6254\u51fa\u7684\u95f4\u9694\u66f4\u77ed&#xff0c;\u59820.5ms&#xff0c;\u90a3&#xff0c;\u6ca1\u95ee\u9898\u3002<\/li>\n<li>\u4f46\u662f&#xff0c;\u5f53B\u63a5\u9e21\u86cb\u7684\u5904\u7406\u65f6\u95f4\u8f83\u957f&#xff0c;\u5982&#xff0c;\u63a5\u4e86\u9e21\u86cb\u8fd8\u8981\u5199\u4e0a\u4ef7\u683c&#xff0c;\u518d\u653e\u7f6e\u5230\u8d27\u67b6&#xff0c;\u517120ms&#xff0c;\u00a0\u90a3\u80af\u5b9a\u5c31\u63a5\u4e0d\u4f4fA\u6301\u7eed\u6254\u8fc7\u6765\u7684\u9e21\u86cb\u4e86&#xff0c;\u6bcf\u63a51\u4e2a&#xff0c;\u5c31\u4f1a\u4e22\u5931\u540e\u9762\u768419\u4e2a&#xff0c;\u518d\u63a51\u4e2a&#xff0c;\u518d\u4e22\u593119\u4e2a&#8230;&#8230;.;\u00a0\u6ce8\u610f&#xff0c;A\u662f\u4e0d\u7ba1B\u662f\u5426\u6570\u636e\u4e22\u5305\u7684&#xff0c;\u5b83\u53ea\u8d1f\u8d23\u6bcf1ms\u6254(\u53d1\u9001)\u4e00\u6b21\u3002<\/li>\n<\/ul>\n<p>\u6211\u4eec\u9700\u8981\u91c7\u53d6\u4e00\u79cd\u7b56\u7565&#xff0c;\u4f7f\u5f97\u7a0b\u5e8f\u7684\u4e2d\u65ad\u54cd\u5e94\u3001\u201c\u5361\u6b7b\u201d\u5360\u65f6&#xff0c;\u5c3d\u53ef\u80fd\u5730\u77ed&#xff1a;<\/p>\n<ul>\n<li>\u63a5\u6536\u6570\u636e&#xff1a;\u5728\u4e2d\u65ad\u56de\u8c03\u51fd\u6570\u4e2d&#xff0c;\u6211\u4eec\u4ec5\u6267\u884c\u5fc5\u8981\u7684\u6570\u636e\u590d\u5236\u64cd\u4f5c&#xff0c;\u5373\u628a\u63a5\u6536\u5230\u7684\u6570\u636e\u8fc5\u901f\u590d\u5236\u5230\u5916\u90e8\u7f13\u5b58\u4e2d\u3002\u8fd9\u4e00\u64cd\u4f5c\u7684\u8017\u65f6\u901a\u5e38\u5728us\u7ea7\u522b;<\/li>\n<li>\u5904\u7406\u6570\u636e&#xff1a;\u5728\u4e3b\u7a0b\u5e8f\u7684while\u5faa\u73af\u4e2d&#xff0c;\u6211\u4eec\u518d\u5bf9\u6570\u636e\u8fdb\u884c\u8fdb\u4e00\u6b65\u7684\u5904\u7406\u3002\u7531\u4e8e\u8fd9\u4e00\u5904\u7406\u8fc7\u7a0b\u4e0d\u5360\u7528\u4e2d\u65ad\u8d44\u6e90&#xff0c;\u56e0\u6b64\u4e0d\u4f1a\u5f71\u54cd\u7a0b\u5e8f\u5bf9\u65b0\u6570\u636e\u7684\u63a5\u6536;<\/li>\n<\/ul>\n<p>\u8fd9\u79cd\u7b56\u7565\u901a\u8fc7\u5206\u79bb\u6570\u636e\u63a5\u6536\u548c\u6570\u636e\u5904\u7406\u4e24\u4e2a\u6b65\u9aa4&#xff0c;\u786e\u4fdd\u4e86\u7a0b\u5e8f\u80fd\u591f\u5feb\u901f\u54cd\u5e94\u8fde\u7eed\u7684\u6570\u636e\u6d41&#xff0c;\u540c\u65f6\u907f\u514d\u4e86\u56e0\u5904\u7406\u65f6\u95f4\u8fc7\u957f\u800c\u5bfc\u81f4\u7684\u6570\u636e\u4e22\u5931\u3002<\/p>\n<\/p>\n<p>\u64cd\u4f5c\u51714\u4e2a\u6b65\u9aa4&#xff0c;\u5177\u4f53\u5982\u4e0b&#xff1a;<\/p>\n<p>1\u3001\u589e\u52a0\u5168\u5c40\u53d8\u91cf<\/p>\n<p>\u5728usbd_cdc_if.c\u6587\u4ef6\u5927\u7ea697\u884c&#xff0c;\u914d\u5bf9\u7684\u6ce8\u91ca\u5185&#xff0c;\u5b9a\u4e49\u4e24\u4e2a\u53d8\u91cf&#xff1a;<\/p>\n<p>\/* USER CODE BEGIN PRIVATE_VARIABLES *\/<br \/>\nuint8_t  myUsbRxData[64] &#061; { 0 };   \/\/ \u63a5\u6536\u5230\u7684\u6570\u636e<br \/>\nuint16_t myUsbRxNum &#061; 0;            \/\/ \u63a5\u6536\u5230\u7684\u5b57\u8282\u6570<\/p>\n<p>\/* USER CODE END PRIVATE_VARIABLES *\/ <\/p>\n<p>\u73b0\u5728&#xff0c;\u5b83\u4fe9\u53ea\u662f\u672c\u5730\u53d8\u91cf&#xff0c;\u7b49\u4f1a\u8981\u5728main\u4e2d\u7528extern\u518d\u58f0\u660e\u4e00\u6b21&#xff0c;\u624d\u80fd\u88ab\u5916\u90e8\u8c03\u7528\u3002<\/p>\n<p>\u5b8c\u6210\u540e&#xff0c;\u662f\u8fd9\u4e2a\u6837\u5b50\u7684&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"389\" src=\"2025-06-11exiobdeetns.png\" width=\"963\" \/><\/p>\n<\/p>\n<p>2\u3001\u4fee\u6539\u63a5\u6536\u56de\u8c03\u51fd\u6570<\/p>\n<p>\u5728CDC_Receive_FS()\u00a0\u91cc&#xff0c;\u5220\u9664\u6211\u4eec\u4e0a\u8282\u589e\u52a0\u7684\u6d4b\u8bd5\u4ee3\u7801;<\/p>\n<p>\u628aBuf\u548c*Len\u7684\u6570\u636e&#xff0c;\u590d\u5236\u5230\u6211\u4eec\u521a\u624d\u7684\u4e24\u4e2a\u53d8\u91cf\u91cc\u3002\u51fd\u6570\u4fee\u6539\u6210&#xff1a;<\/p>\n<p>static int8_t CDC_Receive_FS(uint8_t *Buf, uint32_t *Len)<br \/>\n{<br \/>\n    \/* USER CODE BEGIN 6 *\/<br \/>\n    \/\/ \u628aBuf\u91cc\u9762\u7684\u6570\u636e&#xff0c;\u590d\u5236\u5230\u5916\u90e8\u7f13\u5b58<br \/>\n    memset(myUsbRxData, 0, 64);                     \/\/ \u6e050\u7f13\u5b58\u533a<br \/>\n    memcpy(myUsbRxData, Buf, *Len);                 \/\/ \u628a\u63a5\u6536\u5230\u7684\u6570\u636e&#xff0c;\u590d\u5236\u5230\u81ea\u5df1\u7684\u7f13\u5b58\u533a\u4e2d<br \/>\n    myUsbRxNum &#061; *Len;                              \/\/ \u590d\u5236\u5b57\u8282\u6570<br \/>\n    memset(Buf, 0, 64);                             \/\/ \u5904\u7406\u5b8c\u6570\u636e&#xff0c;\u6e050\u63a5\u6536\u7f13\u5b58;                       <\/p>\n<p>    \/\/ CubeMX\u751f\u6210\u7684\u4ee3\u7801&#xff0c;\u4fdd\u7559<br \/>\n    USBD_CDC_SetRxBuffer(&amp;hUsbDeviceFS, &amp;Buf[0]);   \/\/ \u8bbe\u7f6e\u4e0b-\u4e2a\u63a5\u6536\u7f13\u51b2\u533a<br \/>\n    USBD_CDC_ReceivePacket(&amp;hUsbDeviceFS);          \/\/ \u542f\u52a8\u4e0b\u4e00\u4e2a\u6570\u636e\u5305\u7684\u63a5\u6536<br \/>\n    return (USBD_OK);<br \/>\n    \/* USER CODE END 6 *\/<br \/>\n} <\/p>\n<p>\u5b8c\u6210\u540e&#xff0c;\u662f\u8fd9\u4e2a\u6837\u5b50\u7684&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"439\" src=\"2025-06-11c1fy3z2xri4.png\" width=\"1162\" \/><\/p>\n<p>\u73b0\u5728&#xff0c;\u6570\u636e\u63a5\u6536\u90e8\u5206&#xff0c;\u5df2\u5904\u7406\u597d\u4e86\u3002<\/p>\n<p>\u4ee5\u540e\u56de\u8c03\u51fd\u6570\u8fd0\u884c\u65f6&#xff0c;\u53ea\u590d\u5236\u6570\u636e\u81f3\u5916\u90e8\u7f13\u5b58&#xff08;\u5907\u7528&#xff09;&#xff0c;\u4e2d\u65ad\u65f6\u95f4\u5360\u7528\u6781\u77ed&#xff0c;\u4e0d\u4f1a\u5f71\u54cd\u4e0b\u5305\u63a5\u6536\u3002<\/p>\n<\/p>\n<p>3\u3001 \u5728\u5916\u90e8\u7528extern\u58f0\u660e\u53d8\u91cf&#xff0c;\u4ee4\u5916\u90e8\u53ef\u8c03\u7528\u6570\u636e<\/p>\n<p>\u5916\u90e8&#xff0c;\u54ea\u4e2a\u6587\u4ef6\u91cc\u8981\u4f7f\u7528CDC\u63a5\u6536\u7684\u6570\u636e&#xff0c;\u5c31\u5728\u8fd9\u4e2a\u6587\u4ef6\u91cc&#xff0c;\u7528extern\u58f0\u660e\u90a3\u4fe9\u53d8\u91cf\u3002<\/p>\n<p>\u5982&#xff0c;\u53ef\u4ee5\u5728LCD\u6587\u4ef6&#xff0c;\u4e5f\u53ef\u4ee5\u5728SD\u5361\u7684\u6587\u4ef6\u4e2d&#xff0c;\u90fd\u884c\u3002<\/p>\n<p>\u5efa\u8bae\u5728main.h\u6587\u4ef6\u4e2d\u58f0\u660e&#xff0c;\u5176\u5b83\u6587\u4ef6\u518d#include &#034;main.h&#034;&#xff0c;\u8fd9\u6837&#xff0c;\u53ef\u4ee5\u4ee4\u53d8\u91cf\u5168\u5c40\u53ef\u7528\u3002<\/p>\n<ul>\n<li>\u6253\u5f00 main.c&#xff0c;\u53f3\u51fb\u7a7a\u767d&#xff0c;\u70b9\u51fb&#034;Toggle\u00a0Header\/Code File&#034;&#xff0c;\u53ef\u4ee5\u8df3\u8f6c\u5230\u5934\u6587\u4ef6&#xff1a;main.h\u00a0\u00a0<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"574\" src=\"2025-06-11tzbet4jrwx4.png\" width=\"900\" \/><\/p>\n<\/p>\n<p>\u5728main.h\u4e2d&#xff0c;\u5927\u7ea638\u884c&#xff0c;\u627e\u5230\u00a0\u914d\u5bf9\u7684\u6ce8\u91ca\u884c\u00a0\/* USER CODE BEGIN ET *\/<\/p>\n<p>\u7528 extern\u00a0\u518d\u6b21\u58f0\u660e\u521a\u624d\u4e24\u4e2a\u53d8\u91cf\u3002\u5982\u4e0b&#xff08;\u53ef\u590d\u5236&#xff09;&#xff1a;<\/p>\n<p>\u6ce8\u610f&#xff0c;\u662f\u53ea\u58f0\u660e&#xff0c;\u4e0d\u8981\u8d4b\u503c&#xff0c;\u5426\u5219\u7f16\u8bd1\u9519\u8bef\u3002<\/p>\n<p>\/* USER CODE BEGIN ET *\/<br \/>\nextern uint8_t myUsbRxData[ ] ;<br \/>\nextern uint16_t myUsbRxNum ;<\/p>\n<p>\/* USER CODE END ET *\/ <\/p>\n<p>\u5b8c\u6210\u540e&#xff0c;\u662f\u8fd9\u4e2a\u6837\u5b50\u7684&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"409\" src=\"2025-06-11ufgmhylgjv4.png\" width=\"862\" \/><\/p>\n<p><span style=\"color:#fe2c24\">\u4ee3\u7801\u89c4\u8303&#xff1a;<\/span> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u8fd9\u91cc\u7684\u793a\u8303&#xff0c;\u4f7f\u7528\u5168\u5c40\u53d8\u91cf&#xff0c;\u53ea\u662f\u4e3a\u4e86\u66f4\u6e05\u6670\u5730\u6f14\u793a\u64cd\u4f5c\u601d\u8def\u3002<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u9879\u76ee\u4e2d&#xff0c;\u5c3d\u91cf\u907f\u514d\u4f7f\u7528\u5168\u5c40\u53d8\u91cf&#xff1b;\u4e0d\u540c\u6587\u4ef6\u95f4\u7684\u6570\u636e\u83b7\u53d6&#xff0c;\u53ef\u4ee5\u5c01\u88c5\u6210\u51fd\u6570&#xff0c;\u5982 CDC_GetRxData()\u3001CDC_GetRxNum()&#xff0c;\u8fd4\u56de\u6570\u636e\u5730\u5740\u3001\u63a5\u6536\u7684\u5b57\u8282\u6570\u3002\u00a0\u00a0\u00a0\u00a0<\/p>\n<\/p>\n<p>4\u3001\u4f7f\u7528\u63a5\u6536\u5230\u6570\u636e<\/p>\n<p>\u5728main.c\u7684while\u5faa\u73af\u4e2d&#xff0c;\u901a\u8fc7\u5224\u65admyUsbRxNum\u7684\u503c&#xff0c;\u53ea\u8981\u5927\u4e8e0&#xff0c;\u5c31\u8868\u793a\u6536\u5230\u6570\u636e\u4e86<\/p>\n<p>\u8bb0\u5f97\u6bcf\u6b21\u5904\u7406\u5b8c\u6570\u636e&#xff0c;\u628amyUsbRxNum\u7f6e0&#xff0c;\u4ee5\u4fbf\u4e8e\u4e0b\u4e00\u8f6e\u7684\u5224\u65ad\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"631\" src=\"2025-06-11bi2ulgxalow.png\" width=\"1200\" \/><\/p>\n<p>\u518d\u6b21\u70e7\u5f55&#xff0c;\u70e7\u5f55\u7a0b\u5e8f\u3002<\/p>\n<p>\u6253\u5f00\u4e32\u53e3\u52a9\u624b&#xff0c;\u53d1\u9001\u6d4b\u8bd5\u6587\u672c&#xff0c;\u53ef\u4ee5\u53d1\u73b0&#xff0c;\u80fd\u6210\u529f\u6536\u5230STM32\u53d1\u8fc7\u6765\u7684\u56de\u4f20\u6570\u636e\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"550\" src=\"2025-06-110noax3xzjeg.png\" width=\"785\" \/><\/p>\n<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u5982\u679c&#xff0c;\u5916\u90e8\u5904\u7406\u6570\u636e\u7684\u901f\u5ea6\u8ddf\u4e0d\u4e0a&#xff0c;\u5982&#xff0c;\u5728while\u91cc\u6bcf\u6b21\u6536\u5230\u6570\u636e\u90fd\u8981\u663e\u793a\u5230LCD&#xff0c;LCD\u7684\u901f\u5ea6\u8fdc\u6162\u4e8eUSB\u7684\u4f20\u8f93&#xff0c;\u90a3&#xff0c;\u8fd8\u4e0d\u662f\u53d8\u76f8\u4e22\u4e86\u6570\u636e&#xff1f;&#xff01;\u662f\u7684&#xff0c;\u4f1a\u6709\u8fd9\u79cd\u60c5\u51b5&#xff01;<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u4f46&#xff0c;\u90a3\u5df2\u7ecf\u662f\u7a0b\u5e8f\u903b\u8f91\u548c\u65f6\u95f4\u7247\u673a\u5236\u7684\u95ee\u9898\u4e86&#xff0c;3\u59293\u591c\u4e5f\u55d1\u4e0d\u5b8c&#xff01;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u672c\u8282\u53ea\u8ba8\u8bba&#xff1a;\u786e\u4fdd\u6bcf\u4e00\u5305\u6570\u636e&#xff0c;\u90fd\u80fd\u88ab\u6b63\u5e38\u63a5\u6536\u5230\u3002\u5916\u90e8\u80fd\u5426\u53ca\u65f6\u5904\u7406&#xff0c;\u4e0d\u8ff0\u3002<\/p>\n<\/p>\n<p>\u81f3\u6b64&#xff0c;\u672c\u7bc7\u5b8c\u7ed3\u3002<\/p>\n<p>\u5982\u6709\u9519\u6f0f&#xff0c;\u671b\u7559\u8a00\u6307\u6b63&#xff0c;\u53ca\u65f6\u66f4\u65b0&#xff01;&#xff01;<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.4w\u6b21\uff0c\u70b9\u8d5e164\u6b21\uff0c\u6536\u85cf499\u6b21\u3002\u901a\u8fc7CubeMX + Keil\uff0c\u914d\u7f6eSTM32\u4f5c\u4e3aUSB\u8bbe\u5907\u7aef\uff0c\u4e0e\u7535\u8111\u8fdb\u884c\u901a\u4fe1\uff08CDC\uff09\uff1b\u901a\u7528\u5e26USB\u529f\u80fd\u7684 STM32 \u82af\u7247 \uff08\u5982F1\u3001F4\u7b49\uff0c\u7cfb\u7edf\u65f6\u949f\u914d\u7f6e\u4e0d\u540c\uff0c\u4ee3\u7801\u901a\u7528\uff09\u3002_stm32 usb<\/p>\n","protected":false},"author":2,"featured_media":43139,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[4006,4008,217,4010,4009,4007],"topic":[],"class_list":["post-43159","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-hal-stm32-cubemx-","tag-cdc","tag-stm32","tag-stm32f407","tag-usb","tag-4007"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>STM32 - USB\u865a\u62df\u4e32\u53e3\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/43159.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"STM32 - USB\u865a\u62df\u4e32\u53e3\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.4w\u6b21\uff0c\u70b9\u8d5e164\u6b21\uff0c\u6536\u85cf499\u6b21\u3002\u901a\u8fc7CubeMX + Keil\uff0c\u914d\u7f6eSTM32\u4f5c\u4e3aUSB\u8bbe\u5907\u7aef\uff0c\u4e0e\u7535\u8111\u8fdb\u884c\u901a\u4fe1\uff08CDC\uff09\uff1b\u901a\u7528\u5e26USB\u529f\u80fd\u7684 STM32 \u82af\u7247 \uff08\u5982F1\u3001F4\u7b49\uff0c\u7cfb\u7edf\u65f6\u949f\u914d\u7f6e\u4e0d\u540c\uff0c\u4ee3\u7801\u901a\u7528\uff09\u3002_stm32 usb\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/43159.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-06-11T00:55:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005546-6848d412b1be7.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/43159.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/43159.html\",\"name\":\"STM32 - USB\u865a\u62df\u4e32\u53e3\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-06-11T00:55:52+00:00\",\"dateModified\":\"2025-06-11T00:55:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/43159.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/43159.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/43159.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"STM32 -- USB\u865a\u62df\u4e32\u53e3\u901a\u4fe1\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"STM32 - USB\u865a\u62df\u4e32\u53e3\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/43159.html","og_locale":"zh_CN","og_type":"article","og_title":"STM32 - USB\u865a\u62df\u4e32\u53e3\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb2.4w\u6b21\uff0c\u70b9\u8d5e164\u6b21\uff0c\u6536\u85cf499\u6b21\u3002\u901a\u8fc7CubeMX + Keil\uff0c\u914d\u7f6eSTM32\u4f5c\u4e3aUSB\u8bbe\u5907\u7aef\uff0c\u4e0e\u7535\u8111\u8fdb\u884c\u901a\u4fe1\uff08CDC\uff09\uff1b\u901a\u7528\u5e26USB\u529f\u80fd\u7684 STM32 \u82af\u7247 \uff08\u5982F1\u3001F4\u7b49\uff0c\u7cfb\u7edf\u65f6\u949f\u914d\u7f6e\u4e0d\u540c\uff0c\u4ee3\u7801\u901a\u7528\uff09\u3002_stm32 usb","og_url":"https:\/\/www.wsisp.com\/helps\/43159.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-06-11T00:55:52+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250611005546-6848d412b1be7.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"9 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/43159.html","url":"https:\/\/www.wsisp.com\/helps\/43159.html","name":"STM32 - USB\u865a\u62df\u4e32\u53e3\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-06-11T00:55:52+00:00","dateModified":"2025-06-11T00:55:52+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/43159.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/43159.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/43159.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"STM32 -- USB\u865a\u62df\u4e32\u53e3\u901a\u4fe1"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/43159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=43159"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/43159\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/43139"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=43159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=43159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=43159"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=43159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}