Skip to content

Commit c7dffcd

Browse files
authored
Merge pull request stm32duino#456 from makarenya/receive_double_buffering_for_f1
Receive double buffering for STM32F1xx
2 parents 0378630 + 2bdb516 commit c7dffcd

File tree

11 files changed

+341
-196
lines changed

11 files changed

+341
-196
lines changed

Diff for: cores/arduino/stm32/usb/cdc/usbd_cdc.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,9 @@ static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
651651
USBD_CDC_ItfTypeDef *ctrl = (USBD_CDC_ItfTypeDef *)pdev->pUserData;
652652

653653
if (pdev->pClassData != NULL) {
654-
if ((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U)) {
654+
if ((hcdc->TxLastLength > 0U) && ((hcdc->TxLastLength % hpcd->IN_ep[epnum].maxpacket) == 0U)) {
655655
/* Update the packet total length */
656-
pdev->ep_in[epnum].total_length = 0U;
656+
hcdc->TxLastLength = 0U;
657657

658658
/* Send ZLP */
659659
USBD_LL_Transmit(pdev, epnum, NULL, 0U);
@@ -835,7 +835,7 @@ uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
835835
hcdc->TxState = 1U;
836836

837837
/* Update the packet total length */
838-
pdev->ep_in[CDC_IN_EP & 0xFU].total_length = hcdc->TxLength;
838+
hcdc->TxLastLength = hcdc->TxLength;
839839

840840
/* Transmit next packet */
841841
USBD_LL_Transmit(pdev, CDC_IN_EP, hcdc->TxBuffer,

Diff for: cores/arduino/stm32/usb/cdc/usbd_cdc.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ extern "C" {
4141
/** @defgroup usbd_cdc_Exported_Defines
4242
* @{
4343
*/
44-
#define CDC_IN_EP 0x81U /* EP1 for data IN */
44+
#define CDC_IN_EP 0x82U /* EP1 for data IN */
4545
#define CDC_OUT_EP 0x01U /* EP1 for data OUT */
46-
#define CDC_CMD_EP 0x82U /* EP2 for CDC commands */
46+
#define CDC_CMD_EP 0x83U /* EP2 for CDC commands */
4747

4848
#ifndef CDC_HS_BINTERVAL
4949
#define CDC_HS_BINTERVAL 0x10U
@@ -115,6 +115,7 @@ typedef struct {
115115
uint8_t *TxBuffer;
116116
uint32_t RxLength;
117117
uint32_t TxLength;
118+
uint32_t TxLastLength;
118119

119120
__IO uint32_t TxState;
120121
__IO uint32_t RxState;

Diff for: cores/arduino/stm32/usb/usbd_conf.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
/* Private typedef -----------------------------------------------------------*/
2929
/* Private define ------------------------------------------------------------*/
3030
/* Size in words, byte size divided by 2 */
31-
#define PMA_EP0_OUT_ADDR (8 * 3)
31+
#define PMA_EP0_OUT_ADDR (8 * 4)
3232
#define PMA_EP0_IN_ADDR (PMA_EP0_OUT_ADDR + USB_MAX_EP0_SIZE)
33-
#define PMA_CDC_OUT_ADDR (PMA_EP0_IN_ADDR + USB_MAX_EP0_SIZE)
34-
#define PMA_CDC_IN_ADDR (PMA_CDC_OUT_ADDR + USB_FS_MAX_PACKET_SIZE)
33+
#define PMA_CDC_OUT_BASE (PMA_EP0_IN_ADDR + USB_MAX_EP0_SIZE)
34+
#define PMA_CDC_OUT_ADDR ((PMA_CDC_OUT_BASE + USB_FS_MAX_PACKET_SIZE) | \
35+
(PMA_CDC_OUT_BASE << 16U))
36+
#define PMA_CDC_IN_ADDR (PMA_CDC_OUT_BASE + USB_FS_MAX_PACKET_SIZE * 2)
3537
#define PMA_CDC_CMD_ADDR (PMA_CDC_IN_ADDR + USB_FS_MAX_PACKET_SIZE)
3638
/* Private macro -------------------------------------------------------------*/
3739
/* Private variables ---------------------------------------------------------*/
@@ -520,9 +522,9 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
520522
#else
521523
HAL_PCDEx_PMAConfig(&g_hpcd, 0x00, PCD_SNG_BUF, PMA_EP0_OUT_ADDR);
522524
HAL_PCDEx_PMAConfig(&g_hpcd, 0x80, PCD_SNG_BUF, PMA_EP0_IN_ADDR);
523-
HAL_PCDEx_PMAConfig(&g_hpcd, 0x01, PCD_SNG_BUF, PMA_CDC_OUT_ADDR);
524-
HAL_PCDEx_PMAConfig(&g_hpcd, 0x81, PCD_SNG_BUF, PMA_CDC_IN_ADDR);
525-
HAL_PCDEx_PMAConfig(&g_hpcd, 0x82, PCD_SNG_BUF, PMA_CDC_CMD_ADDR);
525+
HAL_PCDEx_PMAConfig(&g_hpcd, 0x01, PCD_DBL_BUF, PMA_CDC_OUT_ADDR);
526+
HAL_PCDEx_PMAConfig(&g_hpcd, 0x82, PCD_SNG_BUF, PMA_CDC_IN_ADDR);
527+
HAL_PCDEx_PMAConfig(&g_hpcd, 0x83, PCD_SNG_BUF, PMA_CDC_CMD_ADDR);
526528
#endif
527529
#endif /* USE_USB_HS */
528530
return USBD_OK;

Diff for: 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)