cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L552 USB CDC Library CDC_Receive_FS Interrupt Control and Speed Optimization

DBark.2
Associate III

I'm looking to control the CDC_Receive_FS interrupt in a manner that I'm hoping is supported by the lower level hardware, but I'm having difficulty locating registers and functionality to support this behavior.

To give a hint to the architecture I'm working with. When the CDC_Receive_FS callback is triggered by interrupt, I take the data and put it into a FIFO queue. I'd like to:

  1. Be able to "disable" the interrupt when the FIFO is full such that all messages that are attempted to be sent by the host are NAK'd until I've handled the FIFO and am ready to accept new messages.
  2. For handling large file transfer, I'd like to be able to make sure the UserRxBufferFS is completely filled with data BEFORE I receive the interrupt/callback. The idea here is that I can receive a full buffer, transfer it via MEM_TO_MEM DMA_IT, and then receive a new completely filled buffer afterwards. I don't want to receive a bunch of partially filled buffers of a few bytes at a time.

I'm trying to get a grasp of how the USB works internally, and how I should customize it for my use case. I know the USB MSC uses Bulk Transfer and DMA. Does the USBD CDC device class automatically support bulk transfer and DMA? I've seen information that points me in both directions. If it does, how do I activate the DMA/Bulk Transfer. There aren't any options in the .ioc or in the STM Source Code Comments. (Usually peripheral code [like spi.c] contain documentation on how to activate available features).

The MSC_Standalone usbd_storage_if.c interface gives examples of features and capacities I'd like to use, but that would require re-initializing my USB device in order to Register Storage in a different capacity specifically for the transfer, and then switching back again. Can the MSC features be used from the USBD CDC Storage class?

Thank you for the assistance!

1 REPLY 1
DBark.2
Associate III

I've just realized the "USBD_CDC_ReceivePacket" function from within CDC_Receive_FS() controls when new packets are able to arrive. So I can use that to control buffer overflow, and I can adjust the new buffer position with "USBD_CDC_SetRxBuffer" to the next increment in the buffer, to allow a filled buffer, then handle it at the end. Because the max byte size is 64, it's pretty easy to just do the math.

It looks like USB DMA has to be manually activated through a defined macro: USB_OTG_HS_INTERNAL_DMA_ENABLED. But it's recommended against. Are there any runtime instead of compile-time bulk-transfer tools that can be used?