Skip to content

Commit 81ac026

Browse files
committed
USB_ReadPMA moved under PCD_FreeUserBuffer. It's valid move.
An interrupt is triggered when the USB hardware has processed one buffer and waits for the resolution of the firmware to process the next. That is, USB will process the second buffer or will not process anything at all. It does not pretend to the current buffer.
1 parent a2e95a2 commit 81ac026

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

Diff for: system/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pcd.c

+12-16
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,7 @@ static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd)
11901190
{
11911191
PCD_EPTypeDef *ep = NULL;
11921192
uint16_t count = 0;
1193+
uint16_t pmaBuffer = 0;
11931194
uint8_t epindex = 0;
11941195
__IO uint16_t wIstr = 0;
11951196
__IO uint16_t wEPVal = 0;
@@ -1284,34 +1285,29 @@ static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd)
12841285
/* OUT double Buffering*/
12851286
if (ep->doublebuffer == 0U)
12861287
{
1287-
count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
1288-
if (count != 0U)
1289-
{
1290-
USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, count);
1291-
}
1288+
count = (uint16_t) PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
1289+
pmaBuffer = ep->pmaadress;
12921290
}
12931291
else
12941292
{
1295-
if (PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_RX)
1293+
if (wEPVal & USB_EP_DTOG_RX)
12961294
{
12971295
/*read from endpoint BUF0Addr buffer*/
1298-
count = PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num);
1299-
if (count != 0U)
1300-
{
1301-
USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, count);
1302-
}
1296+
count = (uint16_t) PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num);
1297+
pmaBuffer = ep->pmaaddr0;
13031298
}
13041299
else
13051300
{
13061301
/*read from endpoint BUF1Addr buffer*/
1307-
count = PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num);
1308-
if (count != 0U)
1309-
{
1310-
USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, count);
1311-
}
1302+
count = (uint16_t) PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num);
1303+
pmaBuffer = ep->pmaaddr1;
13121304
}
13131305
PCD_FreeUserBuffer(hpcd->Instance, ep->num, PCD_EP_DBUF_OUT);
13141306
}
1307+
if (count != 0U)
1308+
{
1309+
USB_ReadPMA(hpcd->Instance, ep->xfer_buff, pmaBuffer, count);
1310+
}
13151311
/*multi-packet on the NON control OUT endpoint*/
13161312
ep->xfer_count+=count;
13171313
ep->xfer_buff+=count;

0 commit comments

Comments
 (0)