[HAL][LL][USB] fix device connection in case battery charging used with HS instance linked to internal FS PHY
Signed-off-by: Aymen Bouattay <aymen.bouattay@st.com>
diff --git a/Src/stm32f7xx_hal_hcd.c b/Src/stm32f7xx_hal_hcd.c
index 1f8b118..381babb 100644
--- a/Src/stm32f7xx_hal_hcd.c
+++ b/Src/stm32f7xx_hal_hcd.c
@@ -109,7 +109,9 @@
   */
 HAL_StatusTypeDef HAL_HCD_Init(HCD_HandleTypeDef *hhcd)
 {
-  USB_OTG_GlobalTypeDef *USBx;
+#if defined (USB_OTG_FS)
+  const USB_OTG_GlobalTypeDef *USBx;
+#endif /* defined (USB_OTG_FS) */
 
   /* Check the HCD handle allocation */
   if (hhcd == NULL)
@@ -120,7 +122,9 @@
   /* Check the parameters */
   assert_param(IS_HCD_ALL_INSTANCE(hhcd->Instance));
 
+#if defined (USB_OTG_FS)
   USBx = hhcd->Instance;
+#endif /* defined (USB_OTG_FS) */
 
   if (hhcd->State == HAL_HCD_STATE_RESET)
   {
@@ -150,11 +154,13 @@
 
   hhcd->State = HAL_HCD_STATE_BUSY;
 
+#if defined (USB_OTG_FS)
   /* Disable DMA mode for FS instance */
-  if ((USBx->CID & (0x1U << 8)) == 0U)
+  if (USBx == USB_OTG_FS)
   {
     hhcd->Init.dma_enable = 0U;
   }
+#endif /* defined (USB_OTG_FS) */
 
   /* Disable the Interrupts */
   __HAL_HCD_DISABLE(hhcd);
diff --git a/Src/stm32f7xx_hal_pcd.c b/Src/stm32f7xx_hal_pcd.c
index 603a57e..eb026aa 100644
--- a/Src/stm32f7xx_hal_pcd.c
+++ b/Src/stm32f7xx_hal_pcd.c
@@ -122,7 +122,9 @@
   */
 HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd)
 {
-  USB_OTG_GlobalTypeDef *USBx;
+#if defined (USB_OTG_FS)
+  const USB_OTG_GlobalTypeDef *USBx;
+#endif /* defined (USB_OTG_FS) */
   uint8_t i;
 
   /* Check the PCD handle allocation */
@@ -134,7 +136,9 @@
   /* Check the parameters */
   assert_param(IS_PCD_ALL_INSTANCE(hpcd->Instance));
 
+#if defined (USB_OTG_FS)
   USBx = hpcd->Instance;
+#endif /* defined (USB_OTG_FS) */
 
   if (hpcd->State == HAL_PCD_STATE_RESET)
   {
@@ -169,11 +173,13 @@
 
   hpcd->State = HAL_PCD_STATE_BUSY;
 
+#if defined (USB_OTG_FS)
   /* Disable DMA mode for FS instance */
-  if ((USBx->CID & (0x1U << 8)) == 0U)
+  if (USBx == USB_OTG_FS)
   {
     hpcd->Init.dma_enable = 0U;
   }
+#endif /* defined (USB_OTG_FS) */
 
   /* Disable the Interrupts */
   __HAL_PCD_DISABLE(hpcd);
@@ -1419,16 +1425,17 @@
   */
 void HAL_PCD_WKUP_IRQHandler(PCD_HandleTypeDef *hpcd)
 {
+#if defined (USB_OTG_FS)
   USB_OTG_GlobalTypeDef *USBx;
-
   USBx = hpcd->Instance;
 
-  if ((USBx->CID & (0x1U << 8)) == 0U)
+  if (USBx == USB_OTG_FS)
   {
     /* Clear EXTI pending Bit */
     __HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG();
   }
   else
+#endif /* defined (USB_OTG_FS) */
   {
     /* Clear EXTI pending Bit */
     __HAL_USB_OTG_HS_WAKEUP_EXTI_CLEAR_FLAG();
diff --git a/Src/stm32f7xx_ll_usb.c b/Src/stm32f7xx_ll_usb.c
index 947e13c..470aac4 100644
--- a/Src/stm32f7xx_ll_usb.c
+++ b/Src/stm32f7xx_ll_usb.c
@@ -1620,7 +1620,7 @@
   /* Disable VBUS sensing */
   USBx->GCCFG &= ~(USB_OTG_GCCFG_VBDEN);
 
-  if ((USBx->CID & (0x1U << 8)) != 0U)
+  if ((USBx->GUSBCFG & USB_OTG_GUSBCFG_PHYSEL) == 0U)
   {
     if (cfg.speed == USBH_FSLS_SPEED)
     {
@@ -1662,8 +1662,8 @@
 
   /* Clear any pending interrupts */
   USBx->GINTSTS = 0xFFFFFFFFU;
-
-  if ((USBx->CID & (0x1U << 8)) != 0U)
+#if defined (USB_OTG_HS)
+  if (USBx == USB_OTG_HS)
   {
     /* set Rx FIFO size */
     USBx->GRXFSIZ  = 0x200U;
@@ -1671,6 +1671,7 @@
     USBx->HPTXFSIZ = (uint32_t)(((0xE0U << 16) & USB_OTG_HPTXFSIZ_PTXFD) | 0x300U);
   }
   else
+#endif /* defined (USB_OTG_HS) */
   {
     /* set Rx FIFO size */
     USBx->GRXFSIZ  = 0x80U;
@@ -1865,11 +1866,13 @@
       }
       else
       {
-        if ((USBx->CID & (0x1U << 8)) != 0U)
+#if defined (USB_OTG_HS)
+        if (USBx == USB_OTG_HS)
         {
           USBx_HC((uint32_t)ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_NYET |
                                                  USB_OTG_HCINTMSK_ACKM;
         }
+#endif /* defined (USB_OTG_HS) */
       }
       break;
 
@@ -1970,7 +1973,8 @@
   uint16_t num_packets;
   uint16_t max_hc_pkt_count = 256U;
 
-  if (((USBx->CID & (0x1U << 8)) != 0U) && (hc->speed == USBH_HS_SPEED))
+#if defined (USB_OTG_HS)
+  if (USBx == USB_OTG_HS)
   {
     /* 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)))
@@ -1985,6 +1989,7 @@
       (void)USB_DoPing(USBx, hc->ch_num);
       return HAL_OK;
     }
+#endif /* defined (USB_OTG_HS) */
 
   }