Skip to main content
Visitor II
April 26, 2021
Solved

Unable to recognize USB port as a device(virtual com port) when connected to PC.

  • April 26, 2021
  • 1 reply
  • 998 views

@Hi,

I'm using STM32F469 MCU for my application where I'm using USB in DEVICE mode in FS.

Here I'm unable to go to the "OTG_FS_IRQHandler" interrupt handler and also the virtual comport is not recognized by the PC.

It is working fine with the Host mode, where the board is successfully detecting the pen drive and writing data to it.

The same library if I'm using with STM32F217, IT IS WORKING.

System Clock configured for 168MHz.

Here are the functions I have used

#define USB_OTG_HS_BASE_ADDR         0x40040000

#define USB_OTG_FS_BASE_ADDR         0x50000000

void usbDevInit()

{

  USB_OTG_BSP_disableVBUS();

 USBH_Disconnect(&USB_OTG_Core);

 delay_ms(10);

 usbStatus = USB_DEV;

USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb); // USB Device init

 delay_ms(20);

}

void USBD_Init(USB_OTG_CORE_HANDLE *pdev,

        USB_OTG_CORE_ID_TypeDef coreID,

        USBD_DEVICE *pDevice,          

        USBD_Class_cb_TypeDef *class_cb)

{

 /* Hardware Init */

 USB_OTG_BSP_Init(pdev);

  

 USBD_DeInit(pdev);  

 /*Register class and user callbacks */

 pdev->dev.class_cb = class_cb;

 pdev->dev.usr_device = pDevice;   

  

 /* set USB OTG core params */

 DCD_Init(pdev , coreID);  

 /* Enable Interrupts */

 USB_OTG_BSP_EnableInterrupt(pdev);

}

void USB_OTG_BSP_Init(USB_OTG_CORE_HANDLE *pdev)

{

GPIO_InitTypeDef GPIO_InitStructure;  

RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA , ENABLE);   

/* Configure SOF VBUS ID DM DP Pins */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 |GPIO_Pin_11 |GPIO_Pin_12;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;

GPIO_Init(GPIOA, &GPIO_InitStructure);  

  

GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_OTG1_FS) ; 

GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_OTG1_FS) ; 

GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_OTG1_FS) ;

  

/* this for ID line debug */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_OTG_FS, ENABLE) ; 

if(usbStatus == USB_HOST)

 /* Intialize Timer for delay function */

 USB_OTG_BSP_TimeInit();

}

USBD_Status USBD_DeInit(USB_OTG_CORE_HANDLE *pdev)

{

 /* Software Init */

USBD_Suspend(pdev);

USB_OTG_BSP_DisableInterrupt(pdev);

  

 return USBD_OK;

}

void DCD_Init(USB_OTG_CORE_HANDLE *pdev , 

       USB_OTG_CORE_ID_TypeDef coreID)

{

 uint32_t i;

 USB_OTG_EP *ep;

  

 USB_OTG_SelectCore (pdev , coreID);

  

 pdev->dev.device_status = USB_OTG_DEFAULT;

 pdev->dev.device_address = 0;

  

 /* Init ep structure */

 for (i = 0; i < pdev->cfg.dev_endpoints ; i++)

 {

  ep = &pdev->dev.in_ep[i];

  /* Init ep structure */

  ep->is_in = 1;

  ep->num = i;

  ep->tx_fifo_num = i;

  /* Control until ep is actvated */

  ep->type = EP_TYPE_CTRL;

  ep->maxpacket = USB_OTG_MAX_EP0_SIZE;

  ep->xfer_buff = 0;

  ep->xfer_len = 0;

 }

  

 for (i = 0; i < pdev->cfg.dev_endpoints; i++)

 {

  ep = &pdev->dev.out_ep[i];

  /* Init ep structure */

  ep->is_in = 0;

  ep->num = i;

  ep->tx_fifo_num = i;

  /* Control until ep is activated */

  ep->type = EP_TYPE_CTRL;

  ep->maxpacket = USB_OTG_MAX_EP0_SIZE;

  ep->xfer_buff = 0;

  ep->xfer_len = 0;

 }

  

 USB_OTG_DisableGlobalInt(pdev);

  

 /*Init the Core (common init.) */

 USB_OTG_CoreInit(pdev);

 /* Force Device Mode*/

 USB_OTG_SetCurrentMode(pdev, DEVICE_MODE);

  

 /* Init Device */

 USB_OTG_CoreInitDev(pdev);

  

  

 /* Enable USB Global interrupt */

 USB_OTG_EnableGlobalInt(pdev);

}

void USB_OTG_BSP_EnableInterrupt(USB_OTG_CORE_HANDLE *pdev)

{

NVIC_InitTypeDef NVIC_InitStructure; 

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

NVIC_InitStructure.NVIC_IRQChannel = OTG_FS_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);  

}

Kindly help me in solving the issue.

    This topic has been closed for replies.
    Best answer by Walid ZRELLI

    Hello @SNULU​,

    Take a look at the example provided by ST under Firmware\Projects\STM32469I_EVAL\Applications\USB_Device\CDC_Standalone it might help you.

    Moreover, make sure that you have properly configured the interrupt and enabled the NVIC.

    I hope this help you.

    BeST Regards,

    Walid

    1 reply

    Visitor II
    May 28, 2021

    Hello @SNULU​,

    Take a look at the example provided by ST under Firmware\Projects\STM32469I_EVAL\Applications\USB_Device\CDC_Standalone it might help you.

    Moreover, make sure that you have properly configured the interrupt and enabled the NVIC.

    I hope this help you.

    BeST Regards,

    Walid

    SNULUAuthor
    Visitor II
    June 1, 2021

    hi,

    thank you for the reply.

    I have tried the same and it worked fine.

    I have one more doubt regarding USB as mass storage, can you please help me in that.

    that was mentioned in my recent question