Skip to main content
Visitor II
November 30, 2023
Question

STM32H563ZI : USB CDC issue

  • November 30, 2023
  • 3 replies
  • 2412 views

Hello , 

As per reference document added USB driver in firmware , but gives error at function 

USBD_SetClassConfig(pdev, cfgidx);

added screenshot of error

stm32_error.png

 

If ignore this error , USB Serial device port detected but failed to set transmission buffer

static int8_t CDC_Itf_Init(void)

{

// Set Application Buffers

USBD_CDC_SetTxBuffer(&USBD_Device,UserTXBuf,0); //USBD FAIL error received

USBD_CDC_SetRxBuffer(&USBD_Device,UserRXBuf);

// Initialize buffer pointers

UserRXBufCur = 0;

UserRXBufLen = 0;

return (USBD_OK);

}

please suggest answer

    This topic has been closed for replies.

    3 replies

    Super User
    December 3, 2023

    Go into USBD_SetClassConfig and figure out why it's failing. Set a breakpoint, step through.

     

    poojaAuthor
    Visitor II
    December 4, 2023

    Hello ,

    USBD_EMEM error received in USBD_SetClassConfig

    STM32_USB_Set_config_error.png

    Super User
    December 4, 2023

    Keep following it. Go into the Init function and find where that failed...

    poojaAuthor
    Visitor II
    December 5, 2023

    it will fail in CDC_INIT function 

    pdev->pClassDataCmsit[pdev->classId] always return a NULL value 

    classId_STM32_NULL.png

    Super User
    December 5, 2023

    Step through USBD_malloc and understand why it's failing. On newer HAL USB versions, this is a static allocation which can never fail. On older ones it called malloc, which should work, but may not if you have insufficient heap space.

    USBD_EMEM indicates a memory error.