打印

stm32_usb-fs-device_lib中的又一个“BUG”?

[复制链接]
2504|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 Simon21ic 于 2012-7-19 15:25 编辑

今天又为了USB困扰了半天了,诶,还是因为自己对于自己的方案太过于执着。
另外,对于绝大部分用户,应该是碰不到这个问题的。对于一些了解特殊优化手段的用户,可能是需要注意一下的。

下面进入正题,这次发现的问题是USB的CNTR寄存器。
CNTR寄存器的FRES置位后,USB复位,然后清除FRES位,但这时需要清掉RESET标志(由于之前置位FRES引起的),那很简单,ISTR寄存器直接清零,代码如下:
SetCNTR(CNTR_FRES);
SetCNTR(0);
SetISTR(0);

ST的Library中的代码类似:
  /*** CNTR_PWDN = 0 ***/
  wRegVal = CNTR_FRES;
  _SetCNTR(wRegVal);

  /*** CNTR_FRES = 0 ***/
  wInterrupt_Mask = 0;
  _SetCNTR(wInterrupt_Mask);
  /*** Clear pending interrupts ***/
  _SetISTR(0);

时序貌似没有问题,但是,在超高代码优化的情况下,RESET标志是无法清零的,汇编如下:

测试发现,单步调试正常,连续运行不正常,RESET标志没有清零。
第一想到的就是延时,继续测试发现,增加7个nop后解决,少于7个都会出问题,汇编如下:


请问,是否有明确的参数,清FRES后,要过多少个clock才能清RESET标志?貌似是8个?
沙发
香水城| | 2012-7-19 15:27 | 只看该作者
参考手册上是这么说的:

After that, the analog part of the device related to the USB transceiver must be switched on
using the PDWN bit in CNTR register, which requires a special handling. This bit is intended
to switch on the internal voltage references that supply the port transceiver. This circuit has
a defined startup time (tSTARTUP specified in the datasheet) during which the behavior of the
USB transceiver is not defined. It is thus necessary to wait this time, after setting the PDWN
bit in the CNTR register, before removing the reset condition on the USB part (by clearing
the FRES bit in the CNTR register). Clearing the ISTR register then removes any spurious
pending interrupt before any other macrocell operation is enabled.


不过这个不算LIB里的BUG吧

LZ是高手,要的是非普通应用,ST提供的是在普通情况下可以使用的参考演示例程

使用特权

评论回复
板凳
Simon21ic|  楼主 | 2012-7-19 16:45 | 只看该作者
本帖最后由 Simon21ic 于 2012-7-19 16:50 编辑

呵呵,所以BUG打引号了,LIB里的代码的写法,一般不会优化到这种程度,而且也说明了,一般用户不会碰到这个问题。
不过既然确实是有这个delay,LIB最好还是考虑一下,最好做到代码逻辑上,在任何情况都没有问题,而不是在编译器没有巨大优化下没有问题。当然,这个只是建议而已。

话说,我现在在新塘,还真不应该给ST太多建议:)

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:www.versaloon.com --- under construction

266

主题

2597

帖子

104

粉丝