USB VBUS检测

重新设计了USB硬件,兼容所有F4系列64Pin封装芯片
但下载USB程序,PC检测不到USB设备

看了下ST提供的代码,主要是以下几个问题

  1. 晶振问题
    库使用的是25MHz晶振,我焊接的是8MHz晶振
    代码修改如下
    1. #define PLL_M 8
    2. #define HSE_VALUE ((uint32_t)8000000) /!< Value of the External oscillator in Hz /
  2. VBUS检测问题
    默认情况下,STM32用PA9来检测VBUS电压,并设置对应的上拉模式
    所以可以在OTG_FS_GCCFG寄存器中,置位NOVBUSSENS,关闭VBUS检测功能,强制使用上拉模式
    这样,外部DP,DM就不需要使用1.5K上拉电阻

手册摘录如下:

Bit 21 NOVBUSSENS: VBUS sensing disable option
When this bit is set, VBUS is considered internally to be always at VBUS valid level (5 V). This option removes the need for a dedicated VBUS pad, and leave this pad free to be used for other purposes such as a shared functionality. VBUS connection can be remapped on another general purpose input pad and monitored by software.
This option is only suitable for host-only or device-only applications.
0: VBUS sensing available by hardware
1: VBUS sensing not available by hardware.

参考资料

  1. STM32 OTG_FS/HS 模块