/* Be aware that enabling DMA mode will result in data being sent only by
multiple of 4 packet sizes. This is due to the fact that USB DMA does
not allow sending data from non word-aligned addresses.
For this specific application, it is advised to not enable this option
unless required. */
hpcd.Init.dma_enable = 0;
hpcd.Init.low_power_enable = 0;
//use inter phy!! 使用内部PHY
hpcd.Init.phy_itface = PCD_PHY_EMBEDDED;
hpcd.Init.Sof_enable = 0;
hpcd.Init.speed = PCD_SPEED_FULL;
hpcd.Init.vbus_sensing_enable = 0;
/* Link The driver to the stack */
hpcd.pData = pdev;
pdev->pData = &hpcd;
/* Initialize LL Driver */
HAL_PCD_Init(&hpcd);
if(hpcd->Init.low_power_enable == 1)
{
/* Enable EXTI Line 20 for USB wakeup*/
__HAL_USB_OTG_HS_WAKEUP_EXTI_CLEAR_FLAG();
__HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_RISING_EDGE();
__HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_IT();
/* Set EXTI Wakeup Interrupt priority*/
HAL_NVIC_SetPriority(OTG_HS_WKUP_IRQn, 0, 0);
如果工作在HS模式就必须外加PHY, FS模式就可以用内置的PHY.
使用demo修改的,在USB 的D+上加了一个上拉, 使用官方的HID demo修改,FS USB 接口可以识别,为啥HS接口无法识别,调试发现USB会发生复位中断,后面就没有任何中断了!代码如下:
hpcd.Instance = USB_OTG_HS;
hpcd.Init.dev_endpoints = 4;
hpcd.Init.use_dedicated_ep1 = 0;
hpcd.Init.ep0_mps = 0x40;
/* Be aware that enabling DMA mode will result in data being sent only by
multiple of 4 packet sizes. This is due to the fact that USB DMA does
not allow sending data from non word-aligned addresses.
For this specific application, it is advised to not enable this option
unless required. */
hpcd.Init.dma_enable = 0;
hpcd.Init.low_power_enable = 0;
//use inter phy!! 使用内部PHY
hpcd.Init.phy_itface = PCD_PHY_EMBEDDED;
hpcd.Init.Sof_enable = 0;
hpcd.Init.speed = PCD_SPEED_FULL;
hpcd.Init.vbus_sensing_enable = 0;
/* Link The driver to the stack */
hpcd.pData = pdev;
pdev->pData = &hpcd;
/* Initialize LL Driver */
HAL_PCD_Init(&hpcd);
HAL_PCDEx_SetRxFiFo(&hpcd, 0x80);
HAL_PCDEx_SetTxFiFo(&hpcd, 0, 0x40);
HAL_PCDEx_SetTxFiFo(&hpcd, 1, 0x80);
IO设置:
{
/* Configure USB H GPIOs */
__HAL_RCC_GPIOB_CLK_ENABLE();
/* Configure DM DP Pins */
GPIO_InitStruct.Pin = (GPIO_PIN_14 | GPIO_PIN_15);
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* Enable USB HS Clocks */
__HAL_RCC_USB_OTG_HS_CLK_ENABLE();
//__HAL_RCC_USB_OTG_HS_ULPI_CLK_ENABLE();
/* Set USBHS Interrupt priority */
HAL_NVIC_SetPriority(OTG_HS_IRQn, 5, 0);
/* Enable USBHS Interrupt */
HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
if(hpcd->Init.low_power_enable == 1)
{
/* Enable EXTI Line 20 for USB wakeup*/
__HAL_USB_OTG_HS_WAKEUP_EXTI_CLEAR_FLAG();
__HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_RISING_EDGE();
__HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_IT();
/* Set EXTI Wakeup Interrupt priority*/
HAL_NVIC_SetPriority(OTG_HS_WKUP_IRQn, 0, 0);
/* Enable EXTI Interrupt */
HAL_NVIC_EnableIRQ(OTG_HS_WKUP_IRQn);
}
}
其他的配置和FS一样的了。难道HS配置还有什么特别要注意的地方?
一周热门 更多>