Skip to main content
NBaro.1
Associate II
Jul 14, 2021 9:10 PM UTC
Question

How to send large amounts of data through USB FS asynchronously.

Context: I'm porting code from an old STM32F4 to a ST32H7 for USB FS.

In the old code, Handle_USBAsynchXfer is used to transfer large amounts of data 64 bytes at a time.

Now that I am using STM32CubeIDE, I don't see HandleUSBAsynchXfer, but I do see CDC_Transmit_FS. However I don't see how to use it asynchronously.

I am aware that the old code uses usbd_cdc_SOF, but that doesn't seem to be hitting in the new software. Please note that the hardware implementation is the same, so I'm sure this has to do with how to use the new API.

To be more specific through an example:

Imagine I have an array of 2000 bytes. When I get a USB command, I have to start streaming that data to the PC. I'm not sure how to do that.

This topic has been closed for replies.

5 replies

TDK
Jul 14, 2021 10:52 PM UTC

CDC_Transmit_FS is asynchronous. You call it and it does its thing in the background. You can call it with 2000 bytes of data.

"If you feel a post has answered your question, please click ""Accept as Solution""."
NBaro.1
NBaro.1Author
Associate II
Jul 14, 2021 11:12 PM UTC

Oh, that's what I saw, but for some reason it isn't working for me.

I am calling it from an SPI complete callback. Not sure if interrupt priority has anything to do with this.

TDK
Jul 14, 2021 11:15 PM UTC

Well, certainly if the SPI callback prevents USB callbacks from happening, it's going to be a problem.

"If you feel a post has answered your question, please click ""Accept as Solution""."
NBaro.1
NBaro.1Author
Associate II
Jul 15, 2021 2:24 PM UTC

So, I tried using CDC_Transmit_FS in main and I'm not getting anything either. It goes through and says HAL_OK, but I'm using a USB sniffer and there's nothing on the line.

I saw that the old firmware uses USBD_CDC_SOF, and so I added that function to this firmware, but it never gets called. I'm not sure how to trigger it.

NBaro.1
NBaro.1Author
Associate II
Jul 23, 2021 2:01 PM UTC

I finally realized that you need to add  HAL_PCDEx_SetTxFiFo in the USBD_LL_Init in usbd_conf.c file for the corresponding endpoint.