ESP32-S2开发之坑(4)--USB挖坑
<div class='showpostmsg'><p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;">tinyusb获取 按以下readme说明进行获取</span></span></p><p style="margin-left:28px; text-indent:0cm; text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"><a href="https://github.com/hathach/tinyusb" style="color:blue; text-decoration:underline">https://github.com/hathach/tinyusb</a></span></span></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">esp32s2</span></span><span style="background:#fcfcfc"><span style="color:#404040">移植</span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040"> tinyusb</span></span><span style="background:#fcfcfc"><span style="color:#404040">已经支持</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">esp32s2</span></span><span style="background:#fcfcfc"><span style="color:#404040">,主要有设备端</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">hid.msc,cdc</span></span><span style="background:#fcfcfc"><span style="color:#404040">。主机端目前并未做支持。</span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"><span style="background:#fcfcfc"><span style="color:#404040"> 了解一个开源库,绝多数库都会有</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">debug log</span></span><span style="background:#fcfcfc"><span style="color:#404040">打印,我们需要对齐</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">debug</span></span><span style="background:#fcfcfc"><span style="color:#404040">打印,了解下</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">tinyusb</span></span><span style="background:#fcfcfc"><span style="color:#404040">的运行情况</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">.</span></span></span></span></p>
<p style="text-indent:21.0pt; text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"><span style="background:#fcfcfc"><span style="color:#404040">实际调试中,建议配合源码,</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">tinyusb</span></span><span style="background:#fcfcfc"><span style="color:#404040">作为小型</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">USB</span></span><span style="background:#fcfcfc"><span style="color:#404040">协议栈,我觉得还是可以学习下。</span></span></span></span></p>
<p style="text-indent:21.0pt; text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"><span style="background:#fcfcfc"><span style="color:#404040">可以看到</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">tusb_common.h</span></span><span style="background:#fcfcfc"><span style="color:#404040">中,有对</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">log</span></span><span style="background:#fcfcfc"><span style="color:#404040">打印的宏定义,这里</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">0</span></span><span style="background:#fcfcfc"><span style="color:#404040">代表不需要打印,</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">1</span></span><span style="background:#fcfcfc"><span style="color:#404040">代表出错时候打印,</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">2</span></span><span style="background:#fcfcfc"><span style="color:#404040">代表打印</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">debug</span></span><span style="background:#fcfcfc"><span style="color:#404040">日志。</span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:Calibri,sans-serif"><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040"> 而打印输出函数,可以自定义也可以直接使用</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">C</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">库的</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">Printf,</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">但是前提你需要重定向,这里</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">esp32s2</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">都是</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">printf</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">重定向了串口</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">0,</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">我们这里就不需要自定义了。而官方默认的是</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">1</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">,则是出错的时候才打印,我们这里改为</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">2</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">,全部打印日志。然后进行编译烧写</span></span></span></span></span></p>
<p style="text-align:justify"></p>
<p style="text-indent:21.0pt; text-align:justify"><span style="font-size:20px;"><span style="font-family:Calibri,sans-serif"><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">这样打印的时候就会有出现相关初始化,以及相关枚举过程,对于要深入了解</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">tinyusb</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">库,是有必要开启这个</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">debug</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">来进行跟踪。</span></span></span></span></span></p>
<p style="text-align:justify"></p>
</div><script> var loginstr = '<div class="locked">查看精华帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
}
</script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p style="text-indent:21.0pt; text-align:justify"><span style="font-size:20px;"><span style="font-family:Calibri,sans-serif"><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">目前</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">tingusb</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">基本移植好了</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">cdc,msc,hid</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">三个设备到</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">esp32s2</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">上,这里使用的例子是</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">cdc_msc_freertos</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">例子,如下已经宏使能了</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">cdc</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">和</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">msc</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">。</span></span></span></span></span></p>
<p style="text-align:justify"></p>
<p style="text-indent:21.0pt; text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"> <span style="background:#fcfcfc"><span style="color:#404040">在</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">main</span></span><span style="background:#fcfcfc"><span style="color:#404040">函数里面首先需要适配初始化板子,这里</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">tinyusb</span></span><span style="background:#fcfcfc"><span style="color:#404040">初始化了乐鑫的</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">esp32s2_saola</span></span><span style="background:#fcfcfc"><span style="color:#404040">板,而楼主的板子相关外设与乐鑫不同,比如</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">LED</span></span><span style="background:#fcfcfc"><span style="color:#404040">所用不同</span></span></span></span></p>
<p style="text-align:justify"></p>
<p style="text-indent:21.0pt; text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"><span style="background:#fcfcfc"><span style="color:#404040">需要自己在</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">bsp</span></span><span style="background:#fcfcfc"><span style="color:#404040">上新建一个</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">port</span></span><span style="background:#fcfcfc"><span style="color:#404040">,以便适配调用相关接口。主要是</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">board_init</span></span><span style="background:#fcfcfc"><span style="color:#404040">以及</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">board_led_write</span></span><span style="background:#fcfcfc"><span style="color:#404040">,</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">board_button_read</span></span><span style="background:#fcfcfc"><span style="color:#404040">。其中</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">board_init</span></span><span style="background:#fcfcfc"><span style="color:#404040">里面也初始化了</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">USB</span></span><span style="background:#fcfcfc"><span style="color:#404040">,这里乐鑫对于</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">usb</span></span><span style="background:#fcfcfc"><span style="color:#404040">外设上的并没有相关文档说明,这里先不细说。</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">Tinyusb</span></span><span style="background:#fcfcfc"><span style="color:#404040">也是基于</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">stm32</span></span><span style="background:#fcfcfc"><span style="color:#404040">的</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">USB</span></span><span style="background:#fcfcfc"><span style="color:#404040">外设来猜测</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">esp32s2</span></span><span style="background:#fcfcfc"><span style="color:#404040">,具体说明可以参考</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">tinyusb</span></span><span style="background:#fcfcfc"><span style="color:#404040">的</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">pull </span></span><span style="background:#fcfcfc"><span style="color:#404040">。</span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"><a href="https://github.com/hathach/tinyusb/pull/319" style="color:blue; text-decoration:underline">https://github.com/hathach/tinyusb/pull/319</a></span></span></p>
<p style="text-align:justify"></p>
<p style="text-indent:21.0pt; text-align:justify"><span style="font-size:20px;"><span style="font-family:Calibri,sans-serif"><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">例子在</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">linux</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">和</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">window</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">下可用,不过需要注意的点有以下</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">:</span></span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:Calibri,sans-serif"> <span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">在判断是否串口连接与断开的时候,是以判断</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">DTR</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">的状态作为判断,所以不管是利用别人的串口助手,还是自己做的上位机,在打开串口的时候,需要开启</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">DTR,tinyusb</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">才能以此判断是否连接,关闭的时候可以关闭</span></span></span><span lang="EN-US" style="background:#fcfcfc"><span style="font-family:"Arial","sans-serif""><span style="color:#404040">DTR</span></span></span><span style="background:#fcfcfc"><span style="font-family:宋体"><span style="color:#404040">。</span></span></span></span></span></p>
<p style="text-align:justify"></p>
<p style="text-indent:21.0pt; text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">Cdc</span></span><span style="background:#fcfcfc"><span style="color:#404040">可以自适应波特率相关属性,在这里如果需要自己固定死波特率,可以通过以下进行改变。</span></span></span></span></p>
<p style="text-align:justify"></p>
<p style="text-align:justify"><span style="font-size:20px;"><span style="font-family:宋体;"> <span style="background:#fcfcfc"><span style="color:#404040">在</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">MSC</span></span><span style="background:#fcfcfc"><span style="color:#404040">上,也可以在</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">disk</span></span><span style="background:#fcfcfc"><span style="color:#404040">文件上改变磁盘名字,以及写入相关文件。但是由于映射的是内部</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">flash</span></span><span style="background:#fcfcfc"><span style="color:#404040">,尚未对外部</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">flash</span></span><span style="background:#fcfcfc"><span style="color:#404040">进行映射,对于</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">msc</span></span><span style="background:#fcfcfc"><span style="color:#404040">这块尚不清楚,楼主需要进一步搜索。</span></span></span></span></p>
<p style="text-align:justify"></p>
<p style="text-align:justify"></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri,sans-serif"> <span style="font-size:20px;"><span style="font-family:宋体;"> <span style="background:#fcfcfc"><span style="color:#404040">在这里楼主验证</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">cdc</span></span><span style="background:#fcfcfc"><span style="color:#404040">,在收发一个多小时</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">100ms</span></span><span style="background:#fcfcfc"><span style="color:#404040">定时没出现问题,目前来说,对于</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">esp32</span></span><span style="background:#fcfcfc"><span style="color:#404040">只有两个串口,并且还要有一个串口当</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">debug</span></span><span style="background:#fcfcfc"><span style="color:#404040">,如此紧张的串口资源,有</span></span><span lang="EN-US" style="background:#fcfcfc"><span style="color:#404040">cdc</span></span><span style="background:#fcfcfc"><span style="color:#404040">进行补充,也是一件好事。</span></span></span></span></span></span></p>
<p style="text-align:justify"></p>
<p><span style="font-size:20px;"><span style="font-family:宋体;">CDC收发效果:</span></span></p>
<p></p>
<p>不错不错,感谢楼主分享!</p>
<p>这个要是做成uvc,用处就大了。</p>
RCSN 发表于 2020-5-17 22:26
例子在linux和window下可用,不过需要注意的点有以下:
在判断是 ...
<p>楼主,MSC映射外部flash的有头绪了没</p>
<p>我弄了一两个星期没搞出来,楼主可以求一份源码学习一下吗?1412134399@qq.com,感激不尽</p>
<p>感谢楼主,很不错的分享,正好不会,闲暇时来学习一下。</p>
<p>感谢分享,很不错的分享,正想学习,闲暇的时候来看看,学习一下!</p>
<p>这个要是做成uvc,用处就大了。</p>
路过学习一下路过学习一下路过学习一下路过学习一下 <p>IDF用的什么版本,是不是只有4.4可以用tinyusb</p><br/>
页:
[1]