0

I have a STM32 Nucleo-64 development board with STM32L476RG MCU on it.. I have made a small PCB that, among other things, brings the USB interface to a connector.

I have followed the steps shown here: https://www.youtube.com/watch?v=rLnQ3W8gmjY

When I run the code in debug mode (in STM32CubeIDE v1.10.1) the USB never appears on my computer. I have also probed the USB data +/- signals and see no activity.

When I step through the code, I can see that something is failing immediately in:

MX_USB_DEVICE_Init() USBD_Init()

The code the that fails is:

USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev,
                             USBD_DescriptorsTypeDef *pdesc, uint8_t id)
{
  USBD_StatusTypeDef ret;

  /* Check whether the USB Host handle is valid */
  if (pdev == NULL)
  {
#if (USBD_DEBUG_LEVEL > 1U)
    USBD_ErrLog("Invalid Device handle");
#endif
    return USBD_FAIL;
  }

The exact line above that fails is if (pdev == NULL)

One thing to note is that the CubeMX tool did NOT add a handler declaration:

USBD_HandleTypeDef hUsbDeviceFS;

...despite me configuring up the USB interface... I added my own line in main.c:

extern USBD_HandleTypeDef hUsbDeviceFS;

..thinking it may be declared elsewhere??

Can someone please help me figure out whats going on?

Thanks!

Followed a video example online, but its not working as expected. I was expecting to see the dev board appear as a USB device on my computer and spit out some text.

Steve
  • 1
  • If `pdev == NULL` then it is NULL at the point of invokation of `USBD_Init`, see the calling code. It is always good to look at the working example, USB examples are located under Applictions folder (`STM32Cube\Repository\[Your librart]\Projects\[Your board]\Applications`). If there is no USB example for your board, try looking under other boards, EVALs are usualy therichest – Flexz Nov 11 '22 at 05:01

0 Answers0