Skip to content

Commit

Permalink
Improvements on USB communication, fixes #393
Browse files Browse the repository at this point in the history
  • Loading branch information
evoggy committed Jun 5, 2019
1 parent 24de989 commit 1becef7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
25 changes: 11 additions & 14 deletions src/hal/src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
__ALIGN_BEGIN USB_OTG_CORE_HANDLE USB_OTG_dev __ALIGN_END ;

static bool isInit = false;
static bool doingTransfer = false;

static xQueueHandle usbDataRx;
static xQueueHandle usbDataTx;
Expand Down Expand Up @@ -219,15 +220,8 @@ static uint8_t usbd_cf_DeInit (void *pdev,
*/
static uint8_t usbd_cf_DataIn (void *pdev, uint8_t epnum)
{
portBASE_TYPE xTaskWokenByReceive = pdFALSE;

if (xQueueReceiveFromISR(usbDataTx, &outPacket, &xTaskWokenByReceive) == pdTRUE)
{
DCD_EP_Tx (pdev,
IN_EP,
(uint8_t*)outPacket.data,
outPacket.size);
}
doingTransfer = false;

return USBD_OK;
}
Expand All @@ -236,12 +230,15 @@ static uint8_t usbd_cf_SOF (void *pdev)
{
portBASE_TYPE xTaskWokenByReceive = pdFALSE;

if (xQueueReceiveFromISR(usbDataTx, &outPacket, &xTaskWokenByReceive) == pdTRUE)
{
DCD_EP_Tx (pdev,
IN_EP,
(uint8_t*)outPacket.data,
outPacket.size);
if (!doingTransfer) {
if (xQueueReceiveFromISR(usbDataTx, &outPacket, &xTaskWokenByReceive) == pdTRUE)
{
doingTransfer = true;
DCD_EP_Tx (pdev,
IN_EP,
(uint8_t*)outPacket.data,
outPacket.size);
}
}

return USBD_OK;
Expand Down
2 changes: 1 addition & 1 deletion src/hal/src/usblink.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static void usblinkTask(void *param)
p.size = usbIn.size - 1;
memcpy(&p.raw, usbIn.data, usbIn.size);
// This queuing will copy a CRTP packet size from usbIn
xQueueSend(crtpPacketDelivery, &p, 0);
ASSERT(xQueueSend(crtpPacketDelivery, &p, 0) == pdTRUE);
}

}
Expand Down
16 changes: 7 additions & 9 deletions src/lib/STM32_USB_OTG_Driver/src/usb_dcd_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,10 @@ static uint32_t DCD_HandleInEP_ISR(USB_OTG_CORE_HANDLE *pdev)

uint32_t ep_intr;
uint32_t epnum = 0;
uint32_t fifoemptymsk;
diepint.d32 = 0;
ep_intr = USB_OTG_ReadDevAllInEPItr(pdev);

while ( ep_intr )
{
if (ep_intr&0x1) /* In ITR */
Expand Down Expand Up @@ -475,9 +476,13 @@ static uint32_t DCD_HandleInEP_ISR(USB_OTG_CORE_HANDLE *pdev)
}
if (diepint.b.emptyintr)
{

DCD_WriteEmptyTxFifo(pdev , epnum);

fifoemptymsk = 0x1 << epnum;
USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPEMPMSK, fifoemptymsk, 0);

CLEAR_IN_EP_INTR(epnum, emptyintr);
}
}
epnum++;
Expand Down Expand Up @@ -681,13 +686,6 @@ static uint32_t DCD_WriteEmptyTxFifo(USB_OTG_CORE_HANDLE *pdev, uint32_t epnum)

txstatus.d32 = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[epnum]->DTXFSTS);
}

/* Switch off FIFO empty after all the data has been queued up */
if (len < ep->maxpacket)
{
uint32_t fifoemptymsk = 0x1 << epnum;
USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPEMPMSK, fifoemptymsk, 0);
}

return 1;
}
Expand Down

0 comments on commit 1becef7

Please sign in to comment.