cancel
Showing results for 
Search instead for 
Did you mean: 

CDC_Transmit_FS() is giving me a headache (USB CDC Device mode)

Javier1
Principal

Hello everyone and i hope youre having a great embedded morning.

CDC_Transmit_FS() bricks itself when i check status of the ongoing transmission

is there any mechanism to know when a CDC_Transmit_FS transaction is finished?

When i try to CDC_Transmit_FS before the previous CDC_Transmit_FS is done retval=USBD_BUSY which is to be expected, well after that CDC_Transmit_FS doesnt work anymore always returning USBD_BUSY.

This code bricks the usb peripheral and can only be used again after system reset:

do {
//HAL_Delay(100);
retval=CDC_Transmit_FS(&buffer, receivedbytes);
} while (retval!=USBD_OK);//
 
retval=CDC_Transmit_FS("finished transmission", sizeof("finished transmission"));//this will return HAL_OK but no transaction will be done

If i place a dirty delay big enough for the first transaction to be done everything works.

retval=CDC_Transmit_FS(&buffer, receivedbytes);
HAL_Delay(1000);
retval=CDC_Transmit_FS("finished transmission", sizeof("finished transmission"));

im using STM32f205ret6

CubeMX Version 6.1.1

0693W000008zjjjQAA.png 

we dont need to firmware by ourselves, lets talk
12 REPLIES 12

So i didnt find a solution after 2 weeks struggle...

What ive done is just transmitt data in smaller chunks of 4kB data and place small hal_delay(300); in between.

uint8_t aux=receivedbytesUSB/0x800;//how many full 4kb pages we want to transmitt	
for(uint8_t i=0;i<aux;++i){			//transmitt full 4kb pages
CDC_Transmit_FS(&txBufferUSB68K[i*0x800], 0x800);			
HAL_Delay(300);
}
//transmitt the last less than 4kb page
CDC_Transmit_FS(&rxBufferUSB68K[aux*0x800], receivedbytesUSB%(aux*0x800));
HAL_Delay(300);

This is not ideal but it works

we dont need to firmware by ourselves, lets talk

Hello, I find myself in similar situation, my communication is blocked and stalls the whole microcontroller trying to transmit an irregular amount of data.

In your workaround, what value do you give to "receivedbytesUSB"?

Thank you

@LHUAN.1​  received bytes is a variable ammount of data,

what my app does is:

  1. RX from the pc an ammount of receivedbytesUSB
  2. store it in a ram buffer
  3. TX back the same buffer (with size=receivedbytesUSB) to the pc

I also realised very glitchy behaviours when trying to send buffers bigger than 4kB, thats why i send the txBufferUSB68K[] in 4kB chunks

we dont need to firmware by ourselves, lets talk