cancel
Showing results for 
Search instead for 
Did you mean: 

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

NBaro.1
Associate II

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.

5 REPLIES 5
TDK
Guru

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
Associate II

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
Guru

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".

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
Associate II

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.