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

问题描述 投票:0回答:1

我正在开发一个 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;
    }
c embedded stm32
1个回答
0
投票

我找到了如何重新枚举 USB。

usbh_core.c 中的 USBH_ReEnumerate 函数完成这项工作:

© www.soinside.com 2019 - 2024. All rights reserved.