Skip to main content
Visitor II
July 14, 2021
Question

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

  • July 14, 2021
  • 4 replies
  • 1537 views

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.

    4 replies

    Super User
    July 14, 2021

    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.

    NBaro.1Author
    Visitor II
    July 14, 2021

    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.

    Super User
    July 14, 2021

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

    NBaro.1Author
    Visitor II
    July 15, 2021

    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.1Author
    Visitor II
    July 23, 2021

    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.