cancel
Showing results for 
Search instead for 
Did you mean: 

USB CDC not working without modification in Middlewares\ST\STM32_USB_Device_Library\Class\CDC\Src/usbd_cdc.c !!!!

HAlzo
Senior

Hello I am using MxCube V5.6.0 FW V. 1.7.0 tto generate my code for usb cdc class.

the problem is that the usb device is not recognized without modifying the usbd_cdc.c file

the work around is mentioned here

https://community.st.com/s/question/0D50X00009Xkfnj/problem-solved-with-usb-cdc

I keep following the updates in the FW and MxCube , but the solution was not implemented in any update, which puts me in doubt if the work around is correct or not?

3 REPLIES 3
Bob S
Principal

Yes, you need to implement code in CDC_SET_LINE_CODING and CDC_GET_LINE_CODING. It mostly worked in Win7 and earlier without that, but not always. Win10 is more picky. But more importantly, it is the right thing to do. You don't mention which CPU (or HAL library) you are using. It may not have been implemented in that version of whichever HAL lib you are using.

HAlzo
Senior

I am using STM32H743VIT6 MCU with STM32CubeH7 Firmware Package V1.7.0 / 14-February-2020

Regarding CDC_SET_LINE_CODING & CDC_GET_LINE_CODING , I just found #define for values in usbd_cdc.h, what code should I implement here?

what I did exactly is

in file usbd)cdc.c in function USBD_CDC_Init() after allocating memory

pdev->pClassData = USBD_malloc(sizeof (USBD_CDC_HandleTypeDef));

I added one line to clear the memory

memset(pdev->pClassData,0,sizeof(USBD_CDC_HandleTypeDef));

Is this the right way to overcome the problem? and why it's not implemented in all new versions of the FW library ?

That shouldn't hurt, and may help in general, but not for the set/get line coding issue. Search these forums for CDC_SET_LINE_CODING and you will find examples of how to do this. Hint - the change is in CDC_Control_FS(), or perhaps I'm guessing CDC_Control_HS() if you are running a high-speed USB interface (I have no experience with the H7 family).