Skip to main content
Visitor II
August 27, 2024
Solved

STM32H7 USB Device configurate without USB interrupter

  • August 27, 2024
  • 2 replies
  • 1677 views

 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.

 

    This topic has been closed for replies.
    Best answer by Pavel A.

    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?

     

    2 replies

    Super User
    August 27, 2024

    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?

    SDFSDFDSFAuthor
    Visitor II
    August 27, 2024

    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.

    Super User
    August 27, 2024

    > 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.

    Pavel A.Answer
    Super User
    August 27, 2024

    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?

     

    SDFSDFDSFAuthor
    Visitor II
    August 27, 2024

    I will try what you said.

    USB reset status can be received.but descriptor is not.

    Super User
    August 27, 2024

    Then the USB data lines may be in problem. Get a physical USB bus analyzer or scope.