cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with USB CDC implementation on STM32F401CB

tpoms9
Associate II
Posted on September 23, 2014 at 18:59

Hello!

I'm using the USB driver that is provided by STM32CubeMX 4.3.0. I want to use the CDC implemantation for virtual COM port communication between STM32F401CB and a PC.

But I'm facing mainly two problems:

1.) It is not possible to send less than 64 bytes via the CDC driver. In this case only one transmission is successfull. Why is this not possible? How to adopt the code to enable one byte transmissions as well?

2.) How to know if the transmission has been completed? I'm calling CDC_Transmit_FS(...) for sending data, but can't find any callback / interrupt that will be called when the PC has received the data. So in this case I don't know when I can start the next transmission cycle.

Thanks for any help!

Regards,

Thomas
3 REPLIES 3
Posted on September 26, 2014 at 13:36

Hi Thomas,

Could you provide a little more information about the issue you’re experiencing?  Can you provide the usbd_cdc_interface.c, usbd_conf.c and main.c source files? What environment are you using?  That would help more easily figure out where a problem could be.

Regards,

Heisenberg.

tpoms9
Associate II
Posted on September 29, 2014 at 11:08

Hello!

Attached you find the relevant files. The main.c has been adopted and only shows the relevant parts.

The transmission using CDC_Transmit_FS(...) only works once, if I send just a few bytes via USB. TxState is never reset to 0 again, so USBD_CDC_TransmitPacket(...) always returns busy for subsequent calls of CDC_Transmit_FS(...). If I use larger packets to transmit there is no problem.

If I set hcdc->TxState = 0; in usbd_cdc.c line 850 it works, but in this case there must be a delay between subsequent calls of CDC_Transmit_FS(...). So this is just an ugly workaround...

Thanks for your help!

Regards,

Thomas

________________

Attachments :

main.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I13r&d=%2Fa%2F0X0000000bhb%2FtNnm52IUu7HeJUYxg3qE4.fxxWWniLJp88OvL1bhKMw&asPdf=false

usbd_cdc.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I13h&d=%2Fa%2F0X0000000bhc%2FWDoiHsZbK1N0Pq8cx13f57lqmrYccga2r1my30gPIpY&asPdf=false

usbd_cdc_if.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I13Z&d=%2Fa%2F0X0000000bhZ%2FFvgYi9mfAtpch9XwV5mfSkv7Yuyy0FkNmmZtWghibfk&asPdf=false

usbd_conf.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0xR&d=%2Fa%2F0X0000000bhX%2FgIti23adJvNF6kj7iPb_c45ovsano9vDOwzgGHT3f1A&asPdf=false
Posted on October 15, 2014 at 13:10

Dear Thomas,

Regarding your implementation:
  • You shouldn’t modify the CDC class in “Middlewares\ST\STM32_USB_Device_Library\Class\CDC�? unless you have to implement a specific featurelike(//hcdc->TxState = 1; in USBD_CDC_TransmitPacket)
  • In your main loop (code below), you are not sure that the com port is open at the moment of calling CDC_Transmit_FS().

    while(1)

    { CDC_Transmit_FS(buf, strlen(hello));

    delay(500);

    }

I suggest that you refer to the CDC application provided within STM324xG-EVAL as an implementation example. It is located in this path “Projects\STM324xG_EVAL\Applications\USB_Device\CDC_Standalone�?. As a first trial, you can send your string when a get character from host machine. When you get at this stage we can provide a solution for notifying that the com port is open. Regards, Heisenberg.