2016-05-12 03:44 AM
Hello friends!
I'm working on implementing USBTMC class USB Device Library. The question was how to implement the transfer of bulk-out. According USBTMC specification: ''... If the last data payloadis wMaxPacketSize, the Host should not send a zero-length packet. ''How can I correctly receive a packet of arbitrary length multiple wMaxPacketSize? How do you know that the data transfer from the host is completed? #usb #usb #hal #device #usbtmc #device #usb #usbtmc #usbtmc2016-05-13 02:35 AM
Each USBTMC message has TransferSize field in the header.
Reading out the first Bulk-OUT transaction, your device knows this TransferSize. And then, it determines how many bytes expected in latter transactions of this transfer. Tsuneo2016-05-13 03:22 AM
Thanks for your reply. I am interested in the question of whether to do this act which at the class level possible for STM USB Device Library Library (from STM32CubeMX). Using the call function HAL_PCD_EP_Receive (PCD_HandleTypeDef * hpcd, uint8_t ep_addr, uint8_t * pBuf, uint32_t len), EP I prepare to receive data less than or equal len. In this case, if the packet length will multiple wMaxPacketSize, HAL_PCD_DataOutStageCallback function (PCD_HandleTypeDef * hpcd, uint8_t epnum) is not called, as the transfer is not considered finished. If I understand you correctly, the only right way for me is to write low-level code to work with usb?
2016-05-13 08:05 AM
Your device may do this job with HAL_PCD_EP_Receive(), as it is.
Just after HAL_PCD_EP_Open() of the Bulk-OUT EP (in SetConfig request handling), 1) prime the Bulk-OUT endpoint using HAL_PCD_EP_Receive() for wMaxPacketSize of the Bulk-OUT EP. When host sends a USBTMC message, 2) At the completion of the first transaction, HAL_PCD_DataOutStageCallback() is called by the stack. 3) In this callback, read out TransferSize field on the received packet, calculate the remaining size of the transfer. Call another HAL_PCD_EP_Receive() for the remaining transfer, if required. 5) At the completion of the second transfer, concatenate the first packet with the rest, to recover full message. 6) process the USBTMC message. 7) back to 1) Tsuneo2016-05-14 10:52 AM
Thank you
.
It really works
.