|
|
|
@ -73,6 +73,7 @@ void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state); |
|
|
|
|
/* MSP Init */ |
|
|
|
|
void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) |
|
|
|
|
{ |
|
|
|
|
#if defined(USB) |
|
|
|
|
if(pcdHandle->Instance==USB) |
|
|
|
|
{ |
|
|
|
|
/* USER CODE BEGIN USB_MspInit 0 */ |
|
|
|
@ -109,10 +110,35 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle) |
|
|
|
|
|
|
|
|
|
/* USER CODE END USB_MspInit 1 */ |
|
|
|
|
} |
|
|
|
|
#elif defined(USB_OTG_FS) |
|
|
|
|
// This is for F407 with USB OTG peripheral
|
|
|
|
|
if (pcdHandle->Instance==USB_OTG_FS) { |
|
|
|
|
/**USB_OTG_FS GPIO Configuration
|
|
|
|
|
PA11 ------> USB_OTG_FS_DM |
|
|
|
|
PA12 ------> USB_OTG_FS_DP |
|
|
|
|
*/ |
|
|
|
|
__HAL_RCC_GPIOA_CLK_ENABLE(); |
|
|
|
|
|
|
|
|
|
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_11, LL_GPIO_MODE_ALTERNATE); |
|
|
|
|
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_12, LL_GPIO_MODE_ALTERNATE); |
|
|
|
|
LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_11, LL_GPIO_AF_10); |
|
|
|
|
LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_12, LL_GPIO_AF_10); |
|
|
|
|
|
|
|
|
|
/* Peripheral clock enable */ |
|
|
|
|
__HAL_RCC_USB_OTG_FS_CLK_ENABLE(); |
|
|
|
|
|
|
|
|
|
/* Peripheral interrupt init */ |
|
|
|
|
HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0); |
|
|
|
|
HAL_NVIC_EnableIRQ(OTG_FS_IRQn); |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
#error "BAD USB!" |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) |
|
|
|
|
{ |
|
|
|
|
#if defined(USB) |
|
|
|
|
if(pcdHandle->Instance==USB) |
|
|
|
|
{ |
|
|
|
|
/* USER CODE BEGIN USB_MspDeInit 0 */ |
|
|
|
@ -136,6 +162,20 @@ void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle) |
|
|
|
|
|
|
|
|
|
/* USER CODE END USB_MspDeInit 1 */ |
|
|
|
|
} |
|
|
|
|
#elif defined(USB_OTG_FS) |
|
|
|
|
// This is for F407 with USB OTG peripheral
|
|
|
|
|
if (pcdHandle->Instance==USB_OTG_FS) { |
|
|
|
|
__HAL_RCC_USB_OTG_FS_CLK_DISABLE(); |
|
|
|
|
|
|
|
|
|
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_11, LL_GPIO_MODE_ANALOG); |
|
|
|
|
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_12, LL_GPIO_MODE_ANALOG); |
|
|
|
|
|
|
|
|
|
/* Peripheral interrupt init */ |
|
|
|
|
HAL_NVIC_DisableIRQ(OTG_FS_IRQn); |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
#error "BAD USB!" |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -216,6 +256,11 @@ void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) |
|
|
|
|
{ |
|
|
|
|
/* Inform USB library that core enters in suspend Mode */ |
|
|
|
|
USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData); |
|
|
|
|
|
|
|
|
|
#if PLAT_USB_PHYCLOCK |
|
|
|
|
__HAL_PCD_GATE_PHYCLOCK(hpcd); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
/*Enter in STOP mode */ |
|
|
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
|
if (hpcd->Init.low_power_enable) |
|
|
|
@ -290,7 +335,39 @@ void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) |
|
|
|
|
* @retval USBD Status |
|
|
|
|
*/ |
|
|
|
|
USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev) |
|
|
|
|
{
|
|
|
|
|
{ |
|
|
|
|
#if PLAT_USB_OTGFS |
|
|
|
|
/* Init USB_IP */ |
|
|
|
|
if (pdev->id == DEVICE_FS) { |
|
|
|
|
/* Link The driver to the stack */ |
|
|
|
|
hpcd_USB_FS.pData = pdev; |
|
|
|
|
pdev->pData = &hpcd_USB_FS; |
|
|
|
|
|
|
|
|
|
hpcd_USB_FS.Instance = USB_OTG_FS; |
|
|
|
|
hpcd_USB_FS.Init.dev_endpoints = 4; |
|
|
|
|
hpcd_USB_FS.Init.speed = PCD_SPEED_FULL; |
|
|
|
|
hpcd_USB_FS.Init.dma_enable = DISABLE; |
|
|
|
|
hpcd_USB_FS.Init.ep0_mps = DEP0CTL_MPS_8; |
|
|
|
|
hpcd_USB_FS.Init.phy_itface = PCD_PHY_EMBEDDED; |
|
|
|
|
hpcd_USB_FS.Init.Sof_enable = DISABLE; |
|
|
|
|
hpcd_USB_FS.Init.low_power_enable = DISABLE; |
|
|
|
|
hpcd_USB_FS.Init.lpm_enable = DISABLE; |
|
|
|
|
hpcd_USB_FS.Init.vbus_sensing_enable = DISABLE; |
|
|
|
|
hpcd_USB_FS.Init.use_dedicated_ep1 = DISABLE; |
|
|
|
|
if (HAL_PCD_Init(&hpcd_USB_FS) != HAL_OK) |
|
|
|
|
{ |
|
|
|
|
_Error_Handler(__FILE__, __LINE__); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// FIXME this is likely wrong
|
|
|
|
|
HAL_PCDEx_SetRxFiFo(&hpcd_USB_FS, 0x80); |
|
|
|
|
|
|
|
|
|
HAL_PCDEx_SetTxFiFo(&hpcd_USB_FS, 0, 0x40); // EP0
|
|
|
|
|
HAL_PCDEx_SetTxFiFo(&hpcd_USB_FS, MSC_EPOUT_ADDR, 0x40); |
|
|
|
|
HAL_PCDEx_SetTxFiFo(&hpcd_USB_FS, CDC_OUT_EP, 0x40); |
|
|
|
|
// EP 3 is Rx only
|
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
/* Init USB_IP */ |
|
|
|
|
/* Link The driver to the stack */ |
|
|
|
|
hpcd_USB_FS.pData = pdev; |
|
|
|
@ -322,8 +399,8 @@ USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev) |
|
|
|
|
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_IN_EP , PCD_SNG_BUF, ptr += 64); // 64
|
|
|
|
|
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_OUT_EP , PCD_SNG_BUF, ptr += 64); // 64
|
|
|
|
|
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_CMD_EP , PCD_SNG_BUF, ptr += 16); // 16
|
|
|
|
|
|
|
|
|
|
(void)ptr; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
return USBD_OK; |
|
|
|
|
} |
|
|
|
@ -509,6 +586,43 @@ uint32_t USBD_LL_GetRxDataSize (USBD_HandleTypeDef *pdev, uint8_t ep_addr) |
|
|
|
|
return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#if (USBD_LPM_ENABLED == 1) |
|
|
|
|
/**
|
|
|
|
|
* @brief HAL_PCDEx_LPM_Callback : Send LPM message to user layer |
|
|
|
|
* @param hpcd: PCD handle |
|
|
|
|
* @param msg: LPM message |
|
|
|
|
* @retval HAL status |
|
|
|
|
*/ |
|
|
|
|
void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) |
|
|
|
|
{ |
|
|
|
|
switch ( msg) |
|
|
|
|
{ |
|
|
|
|
case PCD_LPM_L0_ACTIVE: |
|
|
|
|
if (hpcd->Init.low_power_enable) |
|
|
|
|
{ |
|
|
|
|
SystemClock_Config(); |
|
|
|
|
|
|
|
|
|
/* Reset SLEEPDEEP bit of Cortex System Control Register */ |
|
|
|
|
SCB->SCR &= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); |
|
|
|
|
} |
|
|
|
|
__HAL_PCD_UNGATE_PHYCLOCK(hpcd); |
|
|
|
|
USBD_LL_Resume(hpcd->pData); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case PCD_LPM_L1_ACTIVE: |
|
|
|
|
__HAL_PCD_GATE_PHYCLOCK(hpcd); |
|
|
|
|
USBD_LL_Suspend(hpcd->pData); |
|
|
|
|
|
|
|
|
|
/*Enter in STOP mode */ |
|
|
|
|
if (hpcd->Init.low_power_enable) |
|
|
|
|
{ |
|
|
|
|
/* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register */ |
|
|
|
|
SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk)); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
/**
|
|
|
|
|
* @brief Delays routine for the USB Device Library. |
|
|
|
|
* @param Delay: Delay in ms |
|
|
|
|