Skip to content

Commit 45c3ab7

Browse files
committed
Double buffering fix for reception. In the case of double buffering,
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.
1 parent d01044b commit 45c3ab7

File tree

5 files changed

+276
-90
lines changed

5 files changed

+276
-90
lines changed

system/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usb.h

+10-3
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ typedef struct
160160
uint32_t xfer_len; /*!< Current transfer length */
161161

162162
uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */
163+
164+
uint16_t pending0; /*!, Fact, that double buffering transfer have pended data */
165+
uint16_t pending1; /*!, Fact, that double buffering transfer have pended data */
163166
}USB_OTG_EPTypeDef;
164167

165168
typedef struct
@@ -269,20 +272,24 @@ typedef struct
269272

270273
uint8_t doublebuffer; /*!< Double buffer enable
271274
This parameter can be 0 or 1 */
272-
273-
uint16_t tx_fifo_num; /*!< This parameter is not required by USB Device FS peripheral, it is used
275+
276+
uint16_t tx_fifo_num; /*!< This parameter is not required by USB Device FS peripheral, it is used
274277
only by USB OTG FS peripheral
275278
This parameter is added to ensure compatibility across USB peripherals */
276279

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

280283
uint8_t *xfer_buff; /*!< Pointer to transfer buffer */
281-
284+
285+
282286
uint32_t xfer_len; /*!< Current transfer length */
283287

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

290+
uint16_t pending0; /*!, Fact, that double buffering transfer have pended data */
291+
uint16_t pending1; /*!, Fact, that double buffering transfer have pended data */
292+
286293
} USB_EPTypeDef;
287294
#endif /* USB */
288295
/**

0 commit comments

Comments
 (0)