2021-07-14 02:10 PM
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.
2021-07-14 03:52 PM
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.
2021-07-14 04:12 PM
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.
2021-07-14 04:15 PM
Well, certainly if the SPI callback prevents USB callbacks from happening, it's going to be a problem.
2021-07-15 07:24 AM
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.
2021-07-23 07:01 AM
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.