C语言 如何仅使用软件在STM32微控制器中重新初始化USB枚举?

uelo1irk  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(99)

我正在做一个USB Msc项目,需要不同的USB棒才能连接到stm32f429。我正在使用HAL库。
某些USB记忆棒需要重新启动或重新枚举文件读写操作。
我想重新启动USB过程,就像断开和连接USB棒一样,但只使用软件。
我已经尝试使用下面的函数重置USB端口,但它没有导致USB枚举。

static uint8_t  USBMNG_ResetUsbPort(void)
    {
      uint32_t curState = ((USBx_HPRT0 ) & 0x01UL);
      
      if(curState != 0)
      {
        USBx_HPRT0 &= ~(1UL << 12);
      }
      else
      {
        USBx_HPRT0 &= ~(1UL << 12);
        USBx_HPRT0 |= (1UL << 12);
      }
      return 1;
    }

    uint8_t  USBMNG_USBDevDisconnect(void)
    {
      
      /* In case phy is stopped, ensure to ungate and restore the phy CLK */
      USBx_PCGCCTL &= ~(USB_OTG_PCGCCTL_STOPCLK | USB_OTG_PCGCCTL_GATECLK);

      USBx_DEVICE->DCTL |= USB_OTG_DCTL_SDIS;
      return 1;
    }

    uint8_t  USBMNG_USBDevConnect(void)
    {
      /* In case phy is stopped, ensure to ungate and restore the phy CLK */
      USBx_PCGCCTL &= ~(USB_OTG_PCGCCTL_STOPCLK | USB_OTG_PCGCCTL_GATECLK);

      USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_SDIS;
      return 1;
    }

字符串

rpppsulh

rpppsulh1#

我发现了如何重新枚举USB。
usbh_core. c中的USBH_ReEnumerate函数执行以下操作:

相关问题