Skip to content

Commit 9d71bad

Browse files
committed
Variables total_length and rem_length moved into device specific context
1 parent f337aa5 commit 9d71bad

File tree

5 files changed

+19
-26
lines changed

5 files changed

+19
-26
lines changed

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,

cores/arduino/stm32/usb/cdc/usbd_cdc.h

+1
Original file line numberDiff line numberDiff line change
@@ -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;

system/Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ typedef struct {
223223
typedef struct {
224224
uint32_t status;
225225
uint32_t is_used;
226-
uint32_t total_length;
227-
uint32_t rem_length;
228226
} USBD_EndpointTypeDef;
229227

230228
/* USB Device handle structure */
@@ -238,6 +236,8 @@ typedef struct _USBD_HandleTypeDef {
238236
USBD_EndpointTypeDef ep_out[15];
239237
uint32_t ep0_state;
240238
uint32_t ep0_data_len;
239+
uint32_t ep0_rem_len;
240+
uint32_t ep0_total_len;
241241
uint8_t dev_state;
242242
uint8_t dev_old_state;
243243
uint8_t dev_address;

system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c

+9-17
Original file line numberDiff line numberDiff line change
@@ -289,18 +289,14 @@ USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup)
289289
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev,
290290
uint8_t epnum, uint8_t *pdata)
291291
{
292-
USBD_EndpointTypeDef *pep;
293-
294292
if (epnum == 0U) {
295-
pep = &pdev->ep_out[0];
296-
297293
if (pdev->ep0_state == USBD_EP0_DATA_OUT) {
298-
if (pep->rem_length > USB_MAX_EP0_SIZE) {
299-
pep->rem_length -= USB_MAX_EP0_SIZE;
294+
if (pdev->ep0_rem_len > USB_MAX_EP0_SIZE) {
295+
pdev->ep0_rem_len -= USB_MAX_EP0_SIZE;
300296

301297
USBD_CtlContinueRx(pdev,
302298
pdata,
303-
(uint16_t)MIN(pep->rem_length, USB_MAX_EP0_SIZE));
299+
(uint16_t)MIN(pdev->ep0_rem_len, USB_MAX_EP0_SIZE));
304300
} else {
305301
if ((pdev->pClass->EP0_RxReady != NULL) &&
306302
(pdev->dev_state == USBD_STATE_CONFIGURED)) {
@@ -338,24 +334,20 @@ USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev,
338334
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum,
339335
uint8_t *pdata)
340336
{
341-
USBD_EndpointTypeDef *pep;
342-
343337
if (epnum == 0U) {
344-
pep = &pdev->ep_in[0];
345-
346338
if (pdev->ep0_state == USBD_EP0_DATA_IN) {
347-
if (pep->rem_length > USB_MAX_EP0_SIZE) {
348-
pep->rem_length -= USB_MAX_EP0_SIZE;
339+
if (pdev->ep0_rem_len > USB_MAX_EP0_SIZE) {
340+
pdev->ep0_rem_len -= USB_MAX_EP0_SIZE;
349341

350-
USBD_CtlContinueSendData(pdev, pdata, (uint16_t)pep->rem_length);
342+
USBD_CtlContinueSendData(pdev, pdata, (uint16_t)pdev->ep0_rem_len);
351343

352344
/* Prepare endpoint for premature end of transfer */
353345
USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
354346
} else {
355347
/* last packet is MPS multiple, so send ZLP packet */
356-
if ((pep->total_length % USB_MAX_EP0_SIZE == 0U) &&
357-
(pep->total_length >= USB_MAX_EP0_SIZE) &&
358-
(pep->total_length < pdev->ep0_data_len)) {
348+
if ((pdev->ep0_total_len % USB_MAX_EP0_SIZE == 0U) &&
349+
(pdev->ep0_total_len >= USB_MAX_EP0_SIZE) &&
350+
(pdev->ep0_total_len < pdev->ep0_data_len)) {
359351
USBD_CtlContinueSendData(pdev, NULL, 0U);
360352
pdev->ep0_data_len = 0U;
361353

system/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev, uint8_t *pbuf,
8989
{
9090
/* Set EP0 State */
9191
pdev->ep0_state = USBD_EP0_DATA_IN;
92-
pdev->ep_in[0].total_length = len;
93-
pdev->ep_in[0].rem_length = len;
92+
pdev->ep0_total_len = len;
93+
pdev->ep0_rem_len = len;
9494

9595
/* Start the transfer */
9696
USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
@@ -128,8 +128,8 @@ USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev, uint8_t *pbuf,
128128
{
129129
/* Set EP0 State */
130130
pdev->ep0_state = USBD_EP0_DATA_OUT;
131-
pdev->ep_out[0].total_length = len;
132-
pdev->ep_out[0].rem_length = len;
131+
pdev->ep0_total_len = len;
132+
pdev->ep0_rem_len = len;
133133

134134
/* Start the transfer */
135135
USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);

0 commit comments

Comments
 (0)