Skip to content

Commit

Permalink
Double buffering fix for reception. In the case of double buffering,
Browse files Browse the repository at this point in the history
it is impossible to determine exactly how large the allocated buffer should be.
To achieve double-buffering acceleration, the PCD_FreeUserBuffer call must
occur before the HAL_PCD_DataOutStageCallback call. But the real data buffer
can be allocated only in this callback. It turns out that the approach itself
needs to be changed - always allocate maximum allowable endpoint buffer size
(it's already happends in USB_ActivateEndpoint). At the same time we need to
check the size of the data received. This check be done at the time of data
receipt. During reception confirmation, it may be that there is no allocated
buffer at all. In this case, we will have to leave the filled PMA intact and
not complete its release. In this case, this operation will be repeated in
HAL_PCD_EP_ReceiveData.
  • Loading branch information
makarenya committed Mar 7, 2019
1 parent e5b25f8 commit 07c4ee4
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 90 deletions.
13 changes: 10 additions & 3 deletions system/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ typedef struct
uint32_t xfer_len; /*!< Current transfer length */

uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */

uint16_t pending0; /*!, Fact, that double buffering transfer have pended data */
uint16_t pending1; /*!, Fact, that double buffering transfer have pended data */
}USB_OTG_EPTypeDef;

typedef struct
Expand Down Expand Up @@ -269,20 +272,24 @@ typedef struct

uint8_t doublebuffer; /*!< Double buffer enable
This parameter can be 0 or 1 */
uint16_t tx_fifo_num; /*!< This parameter is not required by USB Device FS peripheral, it is used

uint16_t tx_fifo_num; /*!< This parameter is not required by USB Device FS peripheral, it is used
only by USB OTG FS peripheral
This parameter is added to ensure compatibility across USB peripherals */

uint32_t maxpacket; /*!< Endpoint Max packet size
This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */

uint8_t *xfer_buff; /*!< Pointer to transfer buffer */



uint32_t xfer_len; /*!< Current transfer length */

uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */

uint16_t pending0; /*!, Fact, that double buffering transfer have pended data */
uint16_t pending1; /*!, Fact, that double buffering transfer have pended data */

} USB_EPTypeDef;
#endif /* USB */
/**
Expand Down

0 comments on commit 07c4ee4

Please sign in to comment.