2024-08-27 07:33 AM
CubeMX generated a example for USB CDC, and with HAL_PCD_IRQHandler.
Now I want use polling method to initial USB,and communicate with host without USB interrupt.
So how can I modify it?
I had tried to do something ,but it not work.Please help me.
1. disable USB interrupt at HAL_PCD_Start().
HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd)
{
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
__HAL_LOCK(hpcd);
if (((USBx->GUSBCFG & USB_OTG_GUSBCFG_PHYSEL) != 0U) &&
(hpcd->Init.battery_charging_enable == 1U))
{
/* Enable USB Transceiver */
USBx->GCCFG |= USB_OTG_GCCFG_PWRDWN;
}
// __HAL_PCD_ENABLE(hpcd);
(void)USB_DevConnect(hpcd->Instance);
__HAL_UNLOCK(hpcd);
return HAL_OK;
}
2. moved out HAL_PCD_IRQHandler function to main loop.
but it dose not work.
when host send get descriptor,device dose not response.
Solved! Go to Solution.
2024-08-27 08:28 AM
Don't use/disable the timer thing for now, leave only the USB in the loop. Maybe, remove the battery charging thing too. Will it work? Will it at least pass thru reset, assignment of address and at least one descriptor request?
2024-08-27 08:13 AM
You could poll for USB IRQ flags and call the handler when they're active, but that seems silly. What's the purpose of removing interrupts?
2024-08-27 08:17 AM
We have a Timer interrupt and priority is very high, the interrupt time is 100us.we do not want usb interrupt disturb it.
I had tried the method like you said.But when the host send get descriptor command, device wasn't response.
2024-08-27 08:22 AM
> We have a Timer interrupt and priority is very high, the interrupt time is 100us.we do not want usb interrupt disturb it.
Set the USB interrupt to be lower priority (numerically higher) than your timer priority.
2024-08-27 08:28 AM
Don't use/disable the timer thing for now, leave only the USB in the loop. Maybe, remove the battery charging thing too. Will it work? Will it at least pass thru reset, assignment of address and at least one descriptor request?
2024-08-27 08:30 AM
I will try what you said.
USB reset status can be received.but descriptor is not.
2024-08-27 08:35 AM
Then the USB data lines may be in problem. Get a physical USB bus analyzer or scope.