GFX Develop Branch
This commit is contained in:
@ -262,9 +262,9 @@ HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx, USB_OTG_ModeTy
|
||||
|
||||
do
|
||||
{
|
||||
HAL_Delay(1U);
|
||||
ms++;
|
||||
} while ((USB_GetMode(USBx) != (uint32_t)USB_HOST_MODE) && (ms < 50U));
|
||||
HAL_Delay(10U);
|
||||
ms += 10U;
|
||||
} while ((USB_GetMode(USBx) != (uint32_t)USB_HOST_MODE) && (ms < HAL_USB_CURRENT_MODE_MAX_DELAY_MS));
|
||||
}
|
||||
else if (mode == USB_DEVICE_MODE)
|
||||
{
|
||||
@ -272,16 +272,16 @@ HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx, USB_OTG_ModeTy
|
||||
|
||||
do
|
||||
{
|
||||
HAL_Delay(1U);
|
||||
ms++;
|
||||
} while ((USB_GetMode(USBx) != (uint32_t)USB_DEVICE_MODE) && (ms < 50U));
|
||||
HAL_Delay(10U);
|
||||
ms += 10U;
|
||||
} while ((USB_GetMode(USBx) != (uint32_t)USB_DEVICE_MODE) && (ms < HAL_USB_CURRENT_MODE_MAX_DELAY_MS));
|
||||
}
|
||||
else
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
|
||||
if (ms == 50U)
|
||||
if (ms == HAL_USB_CURRENT_MODE_MAX_DELAY_MS)
|
||||
{
|
||||
return HAL_ERROR;
|
||||
}
|
||||
@ -329,9 +329,6 @@ HAL_StatusTypeDef USB_DevInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cf
|
||||
/* Restart the Phy Clock */
|
||||
USBx_PCGCCTL = 0U;
|
||||
|
||||
/* Device mode configuration */
|
||||
USBx_DEVICE->DCFG |= DCFG_FRAME_INTERVAL_80;
|
||||
|
||||
if (cfg.phy_itface == USB_OTG_ULPI_PHY)
|
||||
{
|
||||
if (cfg.speed == USBD_HS_SPEED)
|
||||
@ -461,7 +458,7 @@ HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num)
|
||||
{
|
||||
count++;
|
||||
|
||||
if (count > 200000U)
|
||||
if (count > HAL_USB_TIMEOUT)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
@ -475,7 +472,7 @@ HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num)
|
||||
{
|
||||
count++;
|
||||
|
||||
if (count > 200000U)
|
||||
if (count > HAL_USB_TIMEOUT)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
@ -498,7 +495,7 @@ HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx)
|
||||
{
|
||||
count++;
|
||||
|
||||
if (count > 200000U)
|
||||
if (count > HAL_USB_TIMEOUT)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
@ -512,7 +509,7 @@ HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx)
|
||||
{
|
||||
count++;
|
||||
|
||||
if (count > 200000U)
|
||||
if (count > HAL_USB_TIMEOUT)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
@ -532,7 +529,7 @@ HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx)
|
||||
* @arg USB_OTG_SPEED_FULL: Full speed mode
|
||||
* @retval Hal status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_SetDevSpeed(USB_OTG_GlobalTypeDef *USBx, uint8_t speed)
|
||||
HAL_StatusTypeDef USB_SetDevSpeed(const USB_OTG_GlobalTypeDef *USBx, uint8_t speed)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
|
||||
@ -548,7 +545,7 @@ HAL_StatusTypeDef USB_SetDevSpeed(USB_OTG_GlobalTypeDef *USBx, uint8_t speed)
|
||||
* @arg USBD_HS_SPEED: High speed mode
|
||||
* @arg USBD_FS_SPEED: Full speed mode
|
||||
*/
|
||||
uint8_t USB_GetDevSpeed(USB_OTG_GlobalTypeDef *USBx)
|
||||
uint8_t USB_GetDevSpeed(const USB_OTG_GlobalTypeDef *USBx)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint8_t speed;
|
||||
@ -577,7 +574,7 @@ uint8_t USB_GetDevSpeed(USB_OTG_GlobalTypeDef *USBx)
|
||||
* @param ep pointer to endpoint structure
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_ActivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
|
||||
HAL_StatusTypeDef USB_ActivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint32_t epnum = (uint32_t)ep->num;
|
||||
@ -615,7 +612,7 @@ HAL_StatusTypeDef USB_ActivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTy
|
||||
* @param ep pointer to endpoint structure
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
|
||||
HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint32_t epnum = (uint32_t)ep->num;
|
||||
@ -654,7 +651,7 @@ HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB
|
||||
* @param ep pointer to endpoint structure
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_DeactivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
|
||||
HAL_StatusTypeDef USB_DeactivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint32_t epnum = (uint32_t)ep->num;
|
||||
@ -701,7 +698,7 @@ HAL_StatusTypeDef USB_DeactivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EP
|
||||
* @param ep pointer to endpoint structure
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
|
||||
HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint32_t epnum = (uint32_t)ep->num;
|
||||
@ -915,7 +912,7 @@ HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef
|
||||
* @param ep pointer to endpoint structure
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_EPStopXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
|
||||
HAL_StatusTypeDef USB_EPStopXfer(const USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
|
||||
{
|
||||
__IO uint32_t count = 0U;
|
||||
HAL_StatusTypeDef ret = HAL_OK;
|
||||
@ -979,7 +976,7 @@ HAL_StatusTypeDef USB_EPStopXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef
|
||||
* 1 : DMA feature used
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src,
|
||||
HAL_StatusTypeDef USB_WritePacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *src,
|
||||
uint8_t ch_ep_num, uint16_t len, uint8_t dma)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
@ -1010,7 +1007,7 @@ HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src,
|
||||
* @param len Number of bytes to read
|
||||
* @retval pointer to destination buffer
|
||||
*/
|
||||
void *USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len)
|
||||
void *USB_ReadPacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint8_t *pDest = dest;
|
||||
@ -1052,7 +1049,7 @@ void *USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len)
|
||||
* @param ep pointer to endpoint structure
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_EPSetStall(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
|
||||
HAL_StatusTypeDef USB_EPSetStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint32_t epnum = (uint32_t)ep->num;
|
||||
@ -1083,7 +1080,7 @@ HAL_StatusTypeDef USB_EPSetStall(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef
|
||||
* @param ep pointer to endpoint structure
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_EPClearStall(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
|
||||
HAL_StatusTypeDef USB_EPClearStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint32_t epnum = (uint32_t)ep->num;
|
||||
@ -1153,7 +1150,7 @@ HAL_StatusTypeDef USB_StopDevice(USB_OTG_GlobalTypeDef *USBx)
|
||||
* This parameter can be a value from 0 to 255
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_SetDevAddress(USB_OTG_GlobalTypeDef *USBx, uint8_t address)
|
||||
HAL_StatusTypeDef USB_SetDevAddress(const USB_OTG_GlobalTypeDef *USBx, uint8_t address)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
|
||||
@ -1168,7 +1165,7 @@ HAL_StatusTypeDef USB_SetDevAddress(USB_OTG_GlobalTypeDef *USBx, uint8_t address
|
||||
* @param USBx Selected device
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_DevConnect(USB_OTG_GlobalTypeDef *USBx)
|
||||
HAL_StatusTypeDef USB_DevConnect(const USB_OTG_GlobalTypeDef *USBx)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
|
||||
@ -1185,7 +1182,7 @@ HAL_StatusTypeDef USB_DevConnect(USB_OTG_GlobalTypeDef *USBx)
|
||||
* @param USBx Selected device
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_DevDisconnect(USB_OTG_GlobalTypeDef *USBx)
|
||||
HAL_StatusTypeDef USB_DevDisconnect(const USB_OTG_GlobalTypeDef *USBx)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
|
||||
@ -1202,7 +1199,7 @@ HAL_StatusTypeDef USB_DevDisconnect(USB_OTG_GlobalTypeDef *USBx)
|
||||
* @param USBx Selected device
|
||||
* @retval USB Global Interrupt status
|
||||
*/
|
||||
uint32_t USB_ReadInterrupts(USB_OTG_GlobalTypeDef *USBx)
|
||||
uint32_t USB_ReadInterrupts(USB_OTG_GlobalTypeDef const *USBx)
|
||||
{
|
||||
uint32_t tmpreg;
|
||||
|
||||
@ -1218,7 +1215,7 @@ uint32_t USB_ReadInterrupts(USB_OTG_GlobalTypeDef *USBx)
|
||||
* @param chnum Channel number
|
||||
* @retval USB Channel Interrupt status
|
||||
*/
|
||||
uint32_t USB_ReadChInterrupts(USB_OTG_GlobalTypeDef *USBx, uint8_t chnum)
|
||||
uint32_t USB_ReadChInterrupts(const USB_OTG_GlobalTypeDef *USBx, uint8_t chnum)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint32_t tmpreg;
|
||||
@ -1234,7 +1231,7 @@ uint32_t USB_ReadChInterrupts(USB_OTG_GlobalTypeDef *USBx, uint8_t chnum)
|
||||
* @param USBx Selected device
|
||||
* @retval USB Device OUT EP interrupt status
|
||||
*/
|
||||
uint32_t USB_ReadDevAllOutEpInterrupt(USB_OTG_GlobalTypeDef *USBx)
|
||||
uint32_t USB_ReadDevAllOutEpInterrupt(const USB_OTG_GlobalTypeDef *USBx)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint32_t tmpreg;
|
||||
@ -1250,7 +1247,7 @@ uint32_t USB_ReadDevAllOutEpInterrupt(USB_OTG_GlobalTypeDef *USBx)
|
||||
* @param USBx Selected device
|
||||
* @retval USB Device IN EP interrupt status
|
||||
*/
|
||||
uint32_t USB_ReadDevAllInEpInterrupt(USB_OTG_GlobalTypeDef *USBx)
|
||||
uint32_t USB_ReadDevAllInEpInterrupt(const USB_OTG_GlobalTypeDef *USBx)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint32_t tmpreg;
|
||||
@ -1268,7 +1265,7 @@ uint32_t USB_ReadDevAllInEpInterrupt(USB_OTG_GlobalTypeDef *USBx)
|
||||
* This parameter can be a value from 0 to 15
|
||||
* @retval Device OUT EP Interrupt register
|
||||
*/
|
||||
uint32_t USB_ReadDevOutEPInterrupt(USB_OTG_GlobalTypeDef *USBx, uint8_t epnum)
|
||||
uint32_t USB_ReadDevOutEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint32_t tmpreg;
|
||||
@ -1286,7 +1283,7 @@ uint32_t USB_ReadDevOutEPInterrupt(USB_OTG_GlobalTypeDef *USBx, uint8_t epnum)
|
||||
* This parameter can be a value from 0 to 15
|
||||
* @retval Device IN EP Interrupt register
|
||||
*/
|
||||
uint32_t USB_ReadDevInEPInterrupt(USB_OTG_GlobalTypeDef *USBx, uint8_t epnum)
|
||||
uint32_t USB_ReadDevInEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint32_t tmpreg;
|
||||
@ -1309,7 +1306,7 @@ uint32_t USB_ReadDevInEPInterrupt(USB_OTG_GlobalTypeDef *USBx, uint8_t epnum)
|
||||
*/
|
||||
void USB_ClearInterrupts(USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt)
|
||||
{
|
||||
USBx->GINTSTS |= interrupt;
|
||||
USBx->GINTSTS &= interrupt;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1320,7 +1317,7 @@ void USB_ClearInterrupts(USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt)
|
||||
* 0 : Host
|
||||
* 1 : Device
|
||||
*/
|
||||
uint32_t USB_GetMode(USB_OTG_GlobalTypeDef *USBx)
|
||||
uint32_t USB_GetMode(const USB_OTG_GlobalTypeDef *USBx)
|
||||
{
|
||||
return ((USBx->GINTSTS) & 0x1U);
|
||||
}
|
||||
@ -1330,7 +1327,7 @@ uint32_t USB_GetMode(USB_OTG_GlobalTypeDef *USBx)
|
||||
* @param USBx Selected device
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_ActivateSetup(USB_OTG_GlobalTypeDef *USBx)
|
||||
HAL_StatusTypeDef USB_ActivateSetup(const USB_OTG_GlobalTypeDef *USBx)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
|
||||
@ -1352,10 +1349,10 @@ HAL_StatusTypeDef USB_ActivateSetup(USB_OTG_GlobalTypeDef *USBx)
|
||||
* @param psetup pointer to setup packet
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_EP0_OutStart(USB_OTG_GlobalTypeDef *USBx, uint8_t dma, uint8_t *psetup)
|
||||
HAL_StatusTypeDef USB_EP0_OutStart(const USB_OTG_GlobalTypeDef *USBx, uint8_t dma, const uint8_t *psetup)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint32_t gSNPSiD = *(__IO uint32_t *)(&USBx->CID + 0x1U);
|
||||
uint32_t gSNPSiD = *(__IO const uint32_t *)(&USBx->CID + 0x1U);
|
||||
|
||||
if (gSNPSiD > USB_OTG_CORE_ID_300A)
|
||||
{
|
||||
@ -1394,7 +1391,7 @@ static HAL_StatusTypeDef USB_CoreReset(USB_OTG_GlobalTypeDef *USBx)
|
||||
{
|
||||
count++;
|
||||
|
||||
if (count > 200000U)
|
||||
if (count > HAL_USB_TIMEOUT)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
@ -1408,7 +1405,7 @@ static HAL_StatusTypeDef USB_CoreReset(USB_OTG_GlobalTypeDef *USBx)
|
||||
{
|
||||
count++;
|
||||
|
||||
if (count > 200000U)
|
||||
if (count > HAL_USB_TIMEOUT)
|
||||
{
|
||||
return HAL_TIMEOUT;
|
||||
}
|
||||
@ -1441,7 +1438,7 @@ HAL_StatusTypeDef USB_HostInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef c
|
||||
USBx->GCCFG &= ~(USB_OTG_GCCFG_BCDEN);
|
||||
|
||||
|
||||
if ((USBx->CID & (0x1U << 8)) != 0U)
|
||||
if ((USBx->GUSBCFG & USB_OTG_GUSBCFG_PHYSEL) == 0U)
|
||||
{
|
||||
if (cfg.speed == USBH_FSLS_SPEED)
|
||||
{
|
||||
@ -1483,21 +1480,10 @@ HAL_StatusTypeDef USB_HostInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef c
|
||||
|
||||
/* Clear any pending interrupts */
|
||||
USBx->GINTSTS = CLEAR_INTERRUPT_MASK;
|
||||
|
||||
if ((USBx->CID & (0x1U << 8)) != 0U)
|
||||
{
|
||||
/* set Rx FIFO size */
|
||||
USBx->GRXFSIZ = 0x200U;
|
||||
USBx->DIEPTXF0_HNPTXFSIZ = (uint32_t)(((0x100U << 16) & USB_OTG_NPTXFD) | 0x200U);
|
||||
USBx->HPTXFSIZ = (uint32_t)(((0xE0U << 16) & USB_OTG_HPTXFSIZ_PTXFD) | 0x300U);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* set Rx FIFO size */
|
||||
USBx->GRXFSIZ = 0x80U;
|
||||
USBx->DIEPTXF0_HNPTXFSIZ = (uint32_t)(((0x60U << 16) & USB_OTG_NPTXFD) | 0x80U);
|
||||
USBx->HPTXFSIZ = (uint32_t)(((0x40U << 16)& USB_OTG_HPTXFSIZ_PTXFD) | 0xE0U);
|
||||
}
|
||||
/* set Rx FIFO size */
|
||||
USBx->GRXFSIZ = 0x200U;
|
||||
USBx->DIEPTXF0_HNPTXFSIZ = (uint32_t)(((0x100U << 16) & USB_OTG_NPTXFD) | 0x200U);
|
||||
USBx->HPTXFSIZ = (uint32_t)(((0xE0U << 16) & USB_OTG_HPTXFSIZ_PTXFD) | 0x300U);
|
||||
|
||||
/* Enable the common interrupts */
|
||||
if (cfg.dma_enable == 0U)
|
||||
@ -1523,7 +1509,7 @@ HAL_StatusTypeDef USB_HostInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef c
|
||||
* HCFG_6_MHZ : Low Speed 6 MHz Clock
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_InitFSLSPClkSel(USB_OTG_GlobalTypeDef *USBx, uint8_t freq)
|
||||
HAL_StatusTypeDef USB_InitFSLSPClkSel(const USB_OTG_GlobalTypeDef *USBx, uint8_t freq)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
|
||||
@ -1553,7 +1539,7 @@ HAL_StatusTypeDef USB_InitFSLSPClkSel(USB_OTG_GlobalTypeDef *USBx, uint8_t freq)
|
||||
* @note (1)The application must wait at least 10 ms
|
||||
* before clearing the reset bit.
|
||||
*/
|
||||
HAL_StatusTypeDef USB_ResetPort(USB_OTG_GlobalTypeDef *USBx)
|
||||
HAL_StatusTypeDef USB_ResetPort(const USB_OTG_GlobalTypeDef *USBx)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
|
||||
@ -1580,7 +1566,7 @@ HAL_StatusTypeDef USB_ResetPort(USB_OTG_GlobalTypeDef *USBx)
|
||||
* 1 : Activate VBUS
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_DriveVbus(USB_OTG_GlobalTypeDef *USBx, uint8_t state)
|
||||
HAL_StatusTypeDef USB_DriveVbus(const USB_OTG_GlobalTypeDef *USBx, uint8_t state)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
__IO uint32_t hprt0 = 0U;
|
||||
@ -1610,7 +1596,7 @@ HAL_StatusTypeDef USB_DriveVbus(USB_OTG_GlobalTypeDef *USBx, uint8_t state)
|
||||
* @arg HCD_SPEED_FULL: Full speed mode
|
||||
* @arg HCD_SPEED_LOW: Low speed mode
|
||||
*/
|
||||
uint32_t USB_GetHostSpeed(USB_OTG_GlobalTypeDef *USBx)
|
||||
uint32_t USB_GetHostSpeed(USB_OTG_GlobalTypeDef const *USBx)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
__IO uint32_t hprt0 = 0U;
|
||||
@ -1624,7 +1610,7 @@ uint32_t USB_GetHostSpeed(USB_OTG_GlobalTypeDef *USBx)
|
||||
* @param USBx Selected device
|
||||
* @retval current frame number
|
||||
*/
|
||||
uint32_t USB_GetCurrentFrame(USB_OTG_GlobalTypeDef *USBx)
|
||||
uint32_t USB_GetCurrentFrame(USB_OTG_GlobalTypeDef const *USBx)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
|
||||
@ -1686,11 +1672,8 @@ HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num,
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((USBx->CID & (0x1U << 8)) != 0U)
|
||||
{
|
||||
USBx_HC((uint32_t)ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_NYET |
|
||||
USB_OTG_HCINTMSK_ACKM;
|
||||
}
|
||||
USBx_HC((uint32_t)ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_NYET |
|
||||
USB_OTG_HCINTMSK_ACKM;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1727,6 +1710,9 @@ HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num,
|
||||
break;
|
||||
}
|
||||
|
||||
/* Clear Hub Start Split transaction */
|
||||
USBx_HC((uint32_t)ch_num)->HCSPLT = 0U;
|
||||
|
||||
/* Enable host channel Halt interrupt */
|
||||
USBx_HC((uint32_t)ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_CHHM;
|
||||
|
||||
@ -1792,51 +1778,111 @@ HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDe
|
||||
uint16_t num_packets;
|
||||
uint16_t max_hc_pkt_count = HC_MAX_PKT_CNT;
|
||||
|
||||
if (((USBx->CID & (0x1U << 8)) != 0U) && (hc->speed == USBH_HS_SPEED))
|
||||
/* in DMA mode host Core automatically issues ping in case of NYET/NAK */
|
||||
if (dma == 1U)
|
||||
{
|
||||
/* in DMA mode host Core automatically issues ping in case of NYET/NAK */
|
||||
if ((dma == 1U) && ((hc->ep_type == EP_TYPE_CTRL) || (hc->ep_type == EP_TYPE_BULK)))
|
||||
if ((hc->ep_type == EP_TYPE_CTRL) || (hc->ep_type == EP_TYPE_BULK))
|
||||
{
|
||||
|
||||
USBx_HC((uint32_t)ch_num)->HCINTMSK &= ~(USB_OTG_HCINTMSK_NYET |
|
||||
USB_OTG_HCINTMSK_ACKM |
|
||||
USB_OTG_HCINTMSK_NAKM);
|
||||
}
|
||||
|
||||
if ((dma == 0U) && (hc->do_ping == 1U))
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((hc->speed == USBH_HS_SPEED) && (hc->do_ping == 1U))
|
||||
{
|
||||
(void)USB_DoPing(USBx, hc->ch_num);
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Compute the expected number of packets associated to the transfer */
|
||||
if (hc->xfer_len > 0U)
|
||||
if (hc->do_ssplit == 1U)
|
||||
{
|
||||
num_packets = (uint16_t)((hc->xfer_len + hc->max_packet - 1U) / hc->max_packet);
|
||||
/* Set number of packet to 1 for Split transaction */
|
||||
num_packets = 1U;
|
||||
|
||||
if (num_packets > max_hc_pkt_count)
|
||||
if (hc->ep_is_in != 0U)
|
||||
{
|
||||
num_packets = max_hc_pkt_count;
|
||||
hc->XferSize = (uint32_t)num_packets * hc->max_packet;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hc->ep_type == EP_TYPE_ISOC)
|
||||
{
|
||||
if (hc->xfer_len > ISO_SPLT_MPS)
|
||||
{
|
||||
/* Isochrone Max Packet Size for Split mode */
|
||||
hc->XferSize = hc->max_packet;
|
||||
hc->xfer_len = hc->XferSize;
|
||||
|
||||
if ((hc->iso_splt_xactPos == HCSPLT_BEGIN) || (hc->iso_splt_xactPos == HCSPLT_MIDDLE))
|
||||
{
|
||||
hc->iso_splt_xactPos = HCSPLT_MIDDLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
hc->iso_splt_xactPos = HCSPLT_BEGIN;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hc->XferSize = hc->xfer_len;
|
||||
|
||||
if ((hc->iso_splt_xactPos != HCSPLT_BEGIN) && (hc->iso_splt_xactPos != HCSPLT_MIDDLE))
|
||||
{
|
||||
hc->iso_splt_xactPos = HCSPLT_FULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
hc->iso_splt_xactPos = HCSPLT_END;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((dma == 1U) && (hc->xfer_len > hc->max_packet))
|
||||
{
|
||||
hc->XferSize = (uint32_t)num_packets * hc->max_packet;
|
||||
}
|
||||
else
|
||||
{
|
||||
hc->XferSize = hc->xfer_len;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
num_packets = 1U;
|
||||
}
|
||||
/* Compute the expected number of packets associated to the transfer */
|
||||
if (hc->xfer_len > 0U)
|
||||
{
|
||||
num_packets = (uint16_t)((hc->xfer_len + hc->max_packet - 1U) / hc->max_packet);
|
||||
|
||||
/*
|
||||
* For IN channel HCTSIZ.XferSize is expected to be an integer multiple of
|
||||
* max_packet size.
|
||||
*/
|
||||
if (hc->ep_is_in != 0U)
|
||||
{
|
||||
hc->XferSize = (uint32_t)num_packets * hc->max_packet;
|
||||
}
|
||||
else
|
||||
{
|
||||
hc->XferSize = hc->xfer_len;
|
||||
if (num_packets > max_hc_pkt_count)
|
||||
{
|
||||
num_packets = max_hc_pkt_count;
|
||||
hc->XferSize = (uint32_t)num_packets * hc->max_packet;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
num_packets = 1U;
|
||||
}
|
||||
|
||||
/*
|
||||
* For IN channel HCTSIZ.XferSize is expected to be an integer multiple of
|
||||
* max_packet size.
|
||||
*/
|
||||
if (hc->ep_is_in != 0U)
|
||||
{
|
||||
hc->XferSize = (uint32_t)num_packets * hc->max_packet;
|
||||
}
|
||||
else
|
||||
{
|
||||
hc->XferSize = hc->xfer_len;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize the HCTSIZn register */
|
||||
@ -1854,6 +1900,65 @@ HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDe
|
||||
USBx_HC(ch_num)->HCCHAR &= ~USB_OTG_HCCHAR_ODDFRM;
|
||||
USBx_HC(ch_num)->HCCHAR |= (uint32_t)is_oddframe << 29;
|
||||
|
||||
if (hc->do_ssplit == 1U)
|
||||
{
|
||||
/* Set Hub start Split transaction */
|
||||
USBx_HC((uint32_t)ch_num)->HCSPLT = ((uint32_t)hc->hub_addr << USB_OTG_HCSPLT_HUBADDR_Pos) |
|
||||
(uint32_t)hc->hub_port_nbr | USB_OTG_HCSPLT_SPLITEN;
|
||||
|
||||
/* unmask ack & nyet for IN/OUT transactions */
|
||||
USBx_HC((uint32_t)ch_num)->HCINTMSK |= (USB_OTG_HCINTMSK_ACKM |
|
||||
USB_OTG_HCINTMSK_NYET);
|
||||
|
||||
if ((hc->do_csplit == 1U) && (hc->ep_is_in == 0U))
|
||||
{
|
||||
USBx_HC((uint32_t)ch_num)->HCSPLT |= USB_OTG_HCSPLT_COMPLSPLT;
|
||||
USBx_HC((uint32_t)ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_NYET;
|
||||
}
|
||||
|
||||
if (((hc->ep_type == EP_TYPE_ISOC) || (hc->ep_type == EP_TYPE_INTR)) &&
|
||||
(hc->do_csplit == 1U) && (hc->ep_is_in == 1U))
|
||||
{
|
||||
USBx_HC((uint32_t)ch_num)->HCSPLT |= USB_OTG_HCSPLT_COMPLSPLT;
|
||||
}
|
||||
|
||||
/* Position management for iso out transaction on split mode */
|
||||
if ((hc->ep_type == EP_TYPE_ISOC) && (hc->ep_is_in == 0U))
|
||||
{
|
||||
/* Set data payload position */
|
||||
switch (hc->iso_splt_xactPos)
|
||||
{
|
||||
case HCSPLT_BEGIN:
|
||||
/* First data payload for OUT Transaction */
|
||||
USBx_HC((uint32_t)ch_num)->HCSPLT |= USB_OTG_HCSPLT_XACTPOS_1;
|
||||
break;
|
||||
|
||||
case HCSPLT_MIDDLE:
|
||||
/* Middle data payload for OUT Transaction */
|
||||
USBx_HC((uint32_t)ch_num)->HCSPLT |= USB_OTG_HCSPLT_XACTPOS_Pos;
|
||||
break;
|
||||
|
||||
case HCSPLT_END:
|
||||
/* End data payload for OUT Transaction */
|
||||
USBx_HC((uint32_t)ch_num)->HCSPLT |= USB_OTG_HCSPLT_XACTPOS_0;
|
||||
break;
|
||||
|
||||
case HCSPLT_FULL:
|
||||
/* Entire data payload for OUT Transaction */
|
||||
USBx_HC((uint32_t)ch_num)->HCSPLT |= USB_OTG_HCSPLT_XACTPOS;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Clear Hub Start Split transaction */
|
||||
USBx_HC((uint32_t)ch_num)->HCSPLT = 0U;
|
||||
}
|
||||
|
||||
/* Set host channel enable */
|
||||
tmpreg = USBx_HC(ch_num)->HCCHAR;
|
||||
tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
|
||||
@ -1875,7 +1980,7 @@ HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDe
|
||||
return HAL_OK;
|
||||
}
|
||||
|
||||
if ((hc->ep_is_in == 0U) && (hc->xfer_len > 0U))
|
||||
if ((hc->ep_is_in == 0U) && (hc->xfer_len > 0U) && (hc->do_csplit == 0U))
|
||||
{
|
||||
switch (hc->ep_type)
|
||||
{
|
||||
@ -1921,7 +2026,7 @@ HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDe
|
||||
* @param USBx Selected device
|
||||
* @retval HAL state
|
||||
*/
|
||||
uint32_t USB_HC_ReadInterrupt(USB_OTG_GlobalTypeDef *USBx)
|
||||
uint32_t USB_HC_ReadInterrupt(const USB_OTG_GlobalTypeDef *USBx)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
|
||||
@ -1935,16 +2040,21 @@ uint32_t USB_HC_ReadInterrupt(USB_OTG_GlobalTypeDef *USBx)
|
||||
* This parameter can be a value from 1 to 15
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_StatusTypeDef USB_HC_Halt(USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num)
|
||||
HAL_StatusTypeDef USB_HC_Halt(const USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint32_t hcnum = (uint32_t)hc_num;
|
||||
__IO uint32_t count = 0U;
|
||||
uint32_t HcEpType = (USBx_HC(hcnum)->HCCHAR & USB_OTG_HCCHAR_EPTYP) >> 18;
|
||||
uint32_t ChannelEna = (USBx_HC(hcnum)->HCCHAR & USB_OTG_HCCHAR_CHENA) >> 31;
|
||||
uint32_t SplitEna = (USBx_HC(hcnum)->HCSPLT & USB_OTG_HCSPLT_SPLITEN) >> 31;
|
||||
|
||||
if (((USBx->GAHBCFG & USB_OTG_GAHBCFG_DMAEN) == USB_OTG_GAHBCFG_DMAEN) &&
|
||||
(ChannelEna == 0U))
|
||||
/* In buffer DMA, Channel disable must not be programmed for non-split periodic channels.
|
||||
At the end of the next uframe/frame (in the worst case), the core generates a channel halted
|
||||
and disables the channel automatically. */
|
||||
|
||||
if ((((USBx->GAHBCFG & USB_OTG_GAHBCFG_DMAEN) == USB_OTG_GAHBCFG_DMAEN) && (SplitEna == 0U)) &&
|
||||
((ChannelEna == 0U) || (((HcEpType == HCCHAR_ISOC) || (HcEpType == HCCHAR_INTR)))))
|
||||
{
|
||||
return HAL_OK;
|
||||
}
|
||||
@ -1975,6 +2085,10 @@ HAL_StatusTypeDef USB_HC_Halt(USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num)
|
||||
USBx_HC(hcnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBx_HC(hcnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2010,7 +2124,7 @@ HAL_StatusTypeDef USB_HC_Halt(USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num)
|
||||
* This parameter can be a value from 1 to 15
|
||||
* @retval HAL state
|
||||
*/
|
||||
HAL_StatusTypeDef USB_DoPing(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num)
|
||||
HAL_StatusTypeDef USB_DoPing(const USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
uint32_t chnum = (uint32_t)ch_num;
|
||||
@ -2099,7 +2213,7 @@ HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx)
|
||||
* @param USBx Selected device
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_OTG_GlobalTypeDef *USBx)
|
||||
HAL_StatusTypeDef USB_ActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
|
||||
@ -2117,7 +2231,7 @@ HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_OTG_GlobalTypeDef *USBx)
|
||||
* @param USBx Selected device
|
||||
* @retval HAL status
|
||||
*/
|
||||
HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_OTG_GlobalTypeDef *USBx)
|
||||
HAL_StatusTypeDef USB_DeActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx)
|
||||
{
|
||||
uint32_t USBx_BASE = (uint32_t)USBx;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user