/* Write USB Device Endpoint Data Parameters: EPNum: Device Endpoint Number EPNum.0..3: Address EPNum.7: Dir pData: Pointer to Data Buffer cnt: Number of bytes to write Return Value: Number of bytes written  */
U32 USBD_WriteEP(U32 EPNum, U8 *pData, U32 cnt)
/* Write USB Device Endpoint Data Parameters: EPNum: Device Endpoint Number EPNum.0..3: Address EPNum.7: Dir pData: Pointer to Data Buffer cnt: Number of bytes to write Return Value: Number of bytes written  */
U32 USBD_WriteEP(U32 EPNum, U8 *pData, U32 cnt)
{
    U32 num, *pv, n;
    U16 statusEP;
    num = EPNum & 0x0F;
    pv  = (U32 *)(USB_PMA_ADDR + 2 * ((pBUF_DSCR + num)->ADDR_TX));
    for (n = 0; n < (cnt + 1) / 2; n++) {
        *pv++ = __UNALIGNED_UINT16_READ(pData);
        pData += 2;
    }
    (pBUF_DSCR + num)->COUNT_TX = cnt;
    statusEP = EPxREG(num);
    if ((statusEP & EP_STAT_TX) != EP_TX_STALL) {
        EP_Status(EPNum, EP_TX_VALID);
    }
    return (cnt);
}