Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c7dffcd

Browse files
authoredMar 8, 2019
Merge pull request #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
 

‎cores/arduino/stm32/usb/cdc/usbd_cdc.c

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 2 deletions
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;

‎cores/arduino/stm32/usb/usbd_conf.c

Lines changed: 8 additions & 6 deletions
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;

‎system/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_ll_usb.h

Lines changed: 10 additions & 3 deletions
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
/**

‎system/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd.c

Lines changed: 239 additions & 89 deletions
Large diffs are not rendered by default.

‎system/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_ll_usb.c

Lines changed: 43 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,54 +1725,51 @@ HAL_StatusTypeDef USB_ActivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
17251725

17261726
if (ep->doublebuffer == 0)
17271727
{
1728-
if (ep->is_in)
1728+
if (ep->is_in == 1)
17291729
{
1730-
/*Set the endpoint Transmit buffer address */
1730+
/* Set the endpoint Transmit buffer address */
17311731
PCD_SET_EP_TX_ADDRESS(USBx, ep->num, ep->pmaadress);
17321732
PCD_CLEAR_TX_DTOG(USBx, ep->num);
1733-
/* Configure NAK status for the Endpoint*/
1734-
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_NAK);
1733+
/* Configure NAK status for the Endpoint */
1734+
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_NAK);
17351735
}
17361736
else
17371737
{
1738-
/*Set the endpoint Receive buffer address */
1738+
/* Set the endpoint Receive buffer address */
17391739
PCD_SET_EP_RX_ADDRESS(USBx, ep->num, ep->pmaadress);
1740-
/*Set the endpoint Receive buffer counter*/
1740+
/* Set the endpoint Receive buffer counter */
17411741
PCD_SET_EP_RX_CNT(USBx, ep->num, ep->maxpacket);
17421742
PCD_CLEAR_RX_DTOG(USBx, ep->num);
1743-
/* Configure VALID status for the Endpoint*/
1744-
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
1743+
/* All ep must NAK to every host request before PrepareReceive */
1744+
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_NAK);
17451745
}
17461746
}
1747-
/*Double Buffer*/
1747+
/* Double Buffer */
17481748
else
17491749
{
1750-
/*Set the endpoint as double buffered*/
1750+
/* Set the endpoint as double buffered */
17511751
PCD_SET_EP_DBUF(USBx, ep->num);
1752-
/*Set buffer address for double buffered mode*/
1752+
/* Set buffer address for double buffered mode */
17531753
PCD_SET_EP_DBUF_ADDR(USBx, ep->num,ep->pmaaddr0, ep->pmaaddr1);
17541754

1755-
if (ep->is_in==0)
1755+
if (ep->is_in == 1)
17561756
{
1757-
/* Clear the data toggle bits for the endpoint IN/OUT*/
1757+
/* Clear the data toggle bits for the endpoint IN/OUT */
17581758
PCD_CLEAR_RX_DTOG(USBx, ep->num);
17591759
PCD_CLEAR_TX_DTOG(USBx, ep->num);
1760-
1761-
/* Reset value of the data toggle bits for the endpoint out*/
1762-
PCD_TX_DTOG(USBx, ep->num);
1763-
1764-
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
1765-
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
1760+
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_VALID);
1761+
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
17661762
}
17671763
else
17681764
{
1769-
/* Clear the data toggle bits for the endpoint IN/OUT*/
1765+
PCD_SET_EP_DBUF_CNT(USBx, ep->num, ep->is_in, ep->maxpacket);
1766+
/* Clear the data toggle bits for the endpoint IN/OUT */
17701767
PCD_CLEAR_RX_DTOG(USBx, ep->num);
17711768
PCD_CLEAR_TX_DTOG(USBx, ep->num);
1772-
PCD_RX_DTOG(USBx, ep->num);
1773-
/* Configure DISABLE status for the Endpoint*/
1769+
/* All ep must NAK to every host request before PrepareReceive */
1770+
/* Reset value of the data toggle bits for the endpoint out */
1771+
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
17741772
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
1775-
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
17761773
}
17771774
}
17781775

@@ -1789,11 +1786,11 @@ HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
17891786
{
17901787
if (ep->doublebuffer == 0)
17911788
{
1792-
if (ep->is_in)
1789+
if (ep->is_in == 1)
17931790
{
17941791
PCD_CLEAR_TX_DTOG(USBx, ep->num);
17951792
/* Configure DISABLE status for the Endpoint*/
1796-
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
1793+
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
17971794
}
17981795
else
17991796
{
@@ -1805,27 +1802,25 @@ HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
18051802
/*Double Buffer*/
18061803
else
18071804
{
1808-
if (ep->is_in==0)
1805+
if (ep->is_in == 1)
18091806
{
18101807
/* Clear the data toggle bits for the endpoint IN/OUT*/
18111808
PCD_CLEAR_RX_DTOG(USBx, ep->num);
18121809
PCD_CLEAR_TX_DTOG(USBx, ep->num);
1813-
1814-
/* Reset value of the data toggle bits for the endpoint out*/
1815-
PCD_TX_DTOG(USBx, ep->num);
1816-
1817-
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
1810+
PCD_RX_DTOG(USBx, ep->num);
1811+
/* Configure DISABLE status for the Endpoint*/
18181812
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
1813+
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
18191814
}
18201815
else
18211816
{
18221817
/* Clear the data toggle bits for the endpoint IN/OUT*/
18231818
PCD_CLEAR_RX_DTOG(USBx, ep->num);
18241819
PCD_CLEAR_TX_DTOG(USBx, ep->num);
1825-
PCD_RX_DTOG(USBx, ep->num);
1826-
/* Configure DISABLE status for the Endpoint*/
1827-
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
1820+
/* Reset value of the data toggle bits for the endpoint out*/
1821+
PCD_TX_DTOG(USBx, ep->num);
18281822
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
1823+
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
18291824
}
18301825
}
18311826

@@ -1840,13 +1835,13 @@ HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep)
18401835
*/
18411836
HAL_StatusTypeDef USB_EPStartXfer(USB_TypeDef *USBx , USB_EPTypeDef *ep)
18421837
{
1843-
uint16_t pmabuffer = 0;
1844-
uint32_t len = ep->xfer_len;
1838+
uint16_t pmabuffer;
1839+
uint32_t len;
18451840

18461841
/* IN endpoint */
18471842
if (ep->is_in == 1)
18481843
{
1849-
/*Multi packet transfer*/
1844+
/* Multi packet transfer */
18501845
if (ep->xfer_len > ep->maxpacket)
18511846
{
18521847
len=ep->maxpacket;
@@ -1861,8 +1856,8 @@ HAL_StatusTypeDef USB_EPStartXfer(USB_TypeDef *USBx , USB_EPTypeDef *ep)
18611856
/* configure and validate Tx endpoint */
18621857
if (ep->doublebuffer == 0)
18631858
{
1864-
USB_WritePMA(USBx, ep->xfer_buff, ep->pmaadress, len);
18651859
PCD_SET_EP_TX_CNT(USBx, ep->num, len);
1860+
pmabuffer = ep->pmaadress;
18661861
}
18671862
else
18681863
{
@@ -1879,41 +1874,24 @@ HAL_StatusTypeDef USB_EPStartXfer(USB_TypeDef *USBx , USB_EPTypeDef *ep)
18791874
PCD_SET_EP_DBUF0_CNT(USBx, ep->num, ep->is_in, len);
18801875
pmabuffer = ep->pmaaddr0;
18811876
}
1882-
USB_WritePMA(USBx, ep->xfer_buff, pmabuffer, len);
1883-
PCD_FreeUserBuffer(USBx, ep->num, ep->is_in);
18841877
}
1885-
1886-
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_VALID);
1887-
}
1888-
else /* OUT endpoint */
1889-
{
1890-
/* Multi packet transfer*/
1891-
if (ep->xfer_len > ep->maxpacket)
1892-
{
1893-
len=ep->maxpacket;
1894-
ep->xfer_len-=len;
1895-
}
1896-
else
1897-
{
1898-
len=ep->xfer_len;
1899-
ep->xfer_len =0;
1900-
}
1901-
1902-
/* configure and validate Rx endpoint */
1903-
if (ep->doublebuffer == 0)
1878+
1879+
USB_WritePMA(USBx, ep->xfer_buff, pmabuffer, (uint16_t) len);
1880+
1881+
if (ep->doublebuffer == 0)
19041882
{
1905-
/*Set RX buffer count*/
1906-
PCD_SET_EP_RX_CNT(USBx, ep->num, len);
1883+
PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_VALID);
19071884
}
19081885
else
19091886
{
1910-
/*Set the Double buffer counter*/
1911-
PCD_SET_EP_DBUF_CNT(USBx, ep->num, ep->is_in, len);
1887+
PCD_FreeUserBuffer(USBx, ep->num, ep->is_in);
19121888
}
1913-
1889+
}
1890+
else
1891+
{
19141892
PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
19151893
}
1916-
1894+
19171895
return HAL_OK;
19181896
}
19191897

‎system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev,
154154
uint8_t *pbuff);
155155

156156
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev);
157+
uint8_t USBD_CDC_ClearBuffer(USBD_HandleTypeDef *pdev);
157158

158159
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev);
159160
/**

‎system/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,25 @@ uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
877877
return USBD_FAIL;
878878
}
879879
}
880+
881+
uint8_t USBD_CDC_ClearBuffer(USBD_HandleTypeDef *pdev)
882+
{
883+
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
884+
885+
/* Suspend or Resume USB Out process */
886+
if (pdev->pClassData != NULL) {
887+
if (pdev->dev_speed == USBD_SPEED_HIGH) {
888+
/* Prepare Out endpoint to receive next packet */
889+
USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, 0, 0);
890+
} else {
891+
/* Prepare Out endpoint to receive next packet */
892+
USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, 0, 0);
893+
}
894+
return USBD_OK;
895+
} else {
896+
return USBD_FAIL;
897+
}
898+
}
880899
/**
881900
* @}
882901
*/

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +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;
228-
uint32_t maxpacket;
229226
} USBD_EndpointTypeDef;
230227

231228
/* USB Device handle structure */
@@ -239,10 +236,11 @@ typedef struct _USBD_HandleTypeDef {
239236
USBD_EndpointTypeDef ep_out[15];
240237
uint32_t ep0_state;
241238
uint32_t ep0_data_len;
239+
uint32_t ep0_rem_len;
240+
uint32_t ep0_total_len;
242241
uint8_t dev_state;
243242
uint8_t dev_old_state;
244243
uint8_t dev_address;
245-
uint8_t dev_connection_status;
246244
uint8_t dev_test_mode;
247245
uint32_t dev_remote_wakeup;
248246

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

Lines changed: 9 additions & 20 deletions
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 > pep->maxpacket) {
299-
pep->rem_length -= pep->maxpacket;
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, pep->maxpacket));
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 > pep->maxpacket) {
348-
pep->rem_length -= pep->maxpacket;
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 % pep->maxpacket == 0U) &&
357-
(pep->total_length >= pep->maxpacket) &&
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

@@ -410,13 +402,10 @@ USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev)
410402
USBD_LL_OpenEP(pdev, 0x00U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE);
411403
pdev->ep_out[0x00U & 0xFU].is_used = 1U;
412404

413-
pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE;
414-
415405
/* Open EP0 IN */
416406
USBD_LL_OpenEP(pdev, 0x80U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE);
417407
pdev->ep_in[0x80U & 0xFU].is_used = 1U;
418408

419-
pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE;
420409
/* Upon Reset call user call back */
421410
pdev->dev_state = USBD_STATE_DEFAULT;
422411
pdev->ep0_state = USBD_EP0_IDLE;

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

Lines changed: 4 additions & 4 deletions
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)
Please sign in to comment.