2017-10-18 02:10 PM
So I am trying to write firmware for an STM32F0303, and I am trying to use
USBD_LL_Transmit from the STM32Cube USB device library to send data to the usb host. The only documentation on this function that I can find just says that it
'Transmits data over an endpoint'. The arguments are pretty straightforward and I can write demo code to call this and get the data that I want on the host end. But this one sentence leaves me with a lot of questions about how to actually use this function in the firmware that I want to write:
Does this function block until the write to the host is complete?
If not, how can the firmware that I am writing tell when it is safe to call this function again? And how can it tell when it can overwrite the contents of
pbuf without corrupting the transfer?Is there some documentation that I am missing that goes into more detail about how to use this function?
#stm32-usb #stm32 #usb #stm32_usb_device_library #stm32-f32017-10-19 02:16 AM
The STM32 USB Device Library together with the PCD HAL use an event-driven device management, where after initializing and starting the USB device everything is managed in the context of the USB interrupt handler.
The endpoints have a context record kept in the handles, which tracks how much data has been received/transmitted so far, and how much more buffer space/data is remaining. The device transfers no more bytes than the endpoint's max packet size at a time, and updates the context record. When an endpoint transfer is complete, the driver checks the record. If there is still data to be transferred, it continues it, if there isn't, an endpoint callback is triggered.
So to answer your questions, the call is non-blocking, and the DataIn callback of your USBD class is called with the endpoint number (excluding 0x80 bit, as I have pointed out
) when the entire buffer has been transmitted over the endpoint. You can also observe the HAL PCD code to see how the context record is updated so you know how to check how much of the data has been transmitted at any given time.