Skip to main content
Javier1
Principal
April 9, 2021
Solved

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

  • April 9, 2021
  • 12 replies
  • 9179 views

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 

This topic has been closed for replies.
Best answer by Javier1

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

12 replies

Javier1
Javier1Author
Principal
April 9, 2021

@leogarberoglio​ had the same issue, the answer provided by @Amel NASRI​ didnt helped me.

https://community.st.com/s/question/0D50X00009XkfqgSAB/how-to-wait-until-cdctransmitfs-finish

hit me up in https://www.linkedin.com/in/javiermuñoz/
Ons KOOLI
Associate
April 16, 2021

Hi Javier,

Did you have a look at the STM32CubeF2 Firmware ? Under directory Projects/$board_name$/Applications/USB_Device/CDC_Standalone

Best Regards,

Ons.

Javier1
Javier1Author
Principal
April 19, 2021

Hi @Ons KOOLI​ , thanks for your reply.

Yes i looked in those examples but i could only find examples for USB cdc host mode

C:\Users\myuser\STM32Cube\Repository\STM32Cube_FW_F2_V1.9.2\Projects\STM322xG_EVAL\Applications\USB_Host\CDC_Standalone\

Im using usb cdc device mode and the issue is my CDC_Transmit_FS blocks the preipheral/process when you check the status of the ongoing transaction.

All other examples and youtube videos ive seen everyone is just sending very small bursts of data, not minding if the previous transmission is over yet.

I trying to send 64kB bursts of data , so the time it takes to finish the tx is very important to me.

hit me up in https://www.linkedin.com/in/javiermuñoz/