2626#endif
2727#endif
2828
29- #if defined(TARGET_DISCO_F746NG_HS ) || defined(TARGET_DISCO_F769NI )
29+ #if defined(TARGET_DISCO_F746NG_HS ) || defined(TARGET_DISCO_F769NI ) || defined( TARGET_GIGA )
3030#define USBHAL_IRQn OTG_HS_IRQn
3131#else
3232#define USBHAL_IRQn OTG_FS_IRQn
3838
3939#define TOTAL_SIZE (HCCA_SIZE + (MAX_ENDPOINT * ED_SIZE) + (MAX_TD * TD_SIZE))
4040
41+ #define MAX_NYET_RETRY 5
42+
4143/* STM device FS have 11 channels (definition is for 60 channels) */
4244static volatile uint8_t usb_buf [TOTAL_SIZE ];
4345
@@ -100,6 +102,11 @@ static gpio_t gpio_powerpin;
100102#define USB_POWER_OFF 1
101103#define USB_POWERPIN_CONFIG {}
102104
105+ #elif defined(TARGET_GIGA )
106+ #define USB_POWER_ON 1
107+ #define USB_POWER_OFF 0
108+ #define USB_POWERPIN_CONFIG {__HAL_RCC_GPIOA_CLK_ENABLE();gpio_init_out_ex(&gpio_powerpin, PA_15, USB_POWER_OFF);}
109+
103110#elif defined(TARGET_DISCO_F769NI )
104111#define USB_POWER_ON 0
105112#define USB_POWER_OFF 1
@@ -136,7 +143,7 @@ void usb_vbus(uint8_t state)
136143 } else {
137144 /* The board does not have GPIO pin to control usb supply */
138145 }
139- rtos ::ThisThread ::sleep_for (0.2 );
146+ rtos ::ThisThread ::sleep_for (1.0f );
140147}
141148
142149
@@ -157,6 +164,34 @@ USBHALHost::USBHALHost()
157164 hhcd -> Instance = USB_OTG_HS ;
158165 hhcd -> Init .speed = HCD_SPEED_HIGH ;
159166 hhcd -> Init .phy_itface = HCD_PHY_ULPI ;
167+
168+ #elif defined(TARGET_GIGA )
169+ hhcd -> Instance = USB_OTG_HS ;
170+ hhcd -> Init .speed = HCD_SPEED_FULL ;
171+ hhcd -> Init .phy_itface = USB_OTG_EMBEDDED_PHY ;
172+
173+ #if 1
174+ /* Configure the clock recovery system (CRS) ********************************/
175+ /* Enable CRS Clock */
176+ __CRS_CLK_ENABLE ();
177+
178+ static RCC_CRSInitTypeDef RCC_CRSInitStruct ;
179+
180+ /* Default Synchro Signal division factor (not divided) */
181+ RCC_CRSInitStruct .Prescaler = RCC_CRS_SYNC_DIV1 ;
182+ /* Set the SYNCSRC[1:0] bits according to CRS_Source value */
183+ RCC_CRSInitStruct .Source = RCC_CRS_SYNC_SOURCE_USB2 ;
184+ /* HSI48 is synchronized with USB SOF at 1KHz rate */
185+ RCC_CRSInitStruct .ReloadValue = __HAL_RCC_CRS_CALCULATE_RELOADVALUE (48000000 , 1000 );
186+ RCC_CRSInitStruct .ErrorLimitValue = RCC_CRS_ERRORLIMIT_DEFAULT ;
187+ /* Set the TRIM[5:0] to the default value */
188+ RCC_CRSInitStruct .HSI48CalibrationValue = 0x1D ;
189+ /* Start automatic synchronization */
190+ HAL_RCCEx_CRSConfig (& RCC_CRSInitStruct );
191+
192+ HAL_RCCEx_CRSWaitSynchronization (1000 );
193+ #endif
194+
160195#else
161196 hhcd -> Instance = USB_OTG_FS ;
162197 hhcd -> Init .speed = HCD_SPEED_FULL ;
@@ -169,6 +204,7 @@ USBHALHost::USBHALHost()
169204 hhcd -> Init .Sof_enable = 0 ;
170205 hhcd -> Init .vbus_sensing_enable = 0 ;
171206 hhcd -> Init .use_external_vbus = 1 ;
207+ hhcd -> Init .battery_charging_enable = 0 ;
172208 hhcd -> Init .lpm_enable = 0 ;
173209
174210 HALPriv -> inst = this ;
@@ -224,6 +260,11 @@ USBHALHost::USBHALHost()
224260 __HAL_RCC_GPIOJ_CLK_ENABLE ();
225261 pin_function (PJ_12 , STM_PIN_DATA (STM_MODE_AF_PP , GPIO_NOPULL , GPIO_AF10_OTG_FS )); // VBUS
226262
263+ #elif defined(TARGET_GIGA )
264+ __HAL_RCC_GPIOB_CLK_ENABLE ();
265+ pin_function (PB_14 , STM_PIN_DEFINE_SPEED (STM_MODE_AF_PP , GPIO_NOPULL , GPIO_AF12_OTG2_FS , GPIO_SPEED_FREQ_VERY_HIGH )); // DM
266+ pin_function (PB_15 , STM_PIN_DEFINE_SPEED (STM_MODE_AF_PP , GPIO_NOPULL , GPIO_AF12_OTG2_FS , GPIO_SPEED_FREQ_VERY_HIGH )); // DM
267+
227268#elif defined(TARGET_DISCO_F746NG_HS )
228269 __HAL_RCC_GPIOA_CLK_ENABLE ();
229270 __HAL_RCC_GPIOB_CLK_ENABLE ();
@@ -288,6 +329,8 @@ USBHALHost::USBHALHost()
288329#error "USB pins are not configured !"
289330#endif
290331
332+ NVIC_DisableIRQ (USBHAL_IRQn );
333+
291334 // Configure USB POWER pin
292335 USB_POWERPIN_CONFIG ;
293336
@@ -297,6 +340,10 @@ USBHALHost::USBHALHost()
297340#if defined(TARGET_DISCO_F746NG_HS ) || defined(TARGET_DISCO_F769NI )
298341 __HAL_RCC_USB_OTG_HS_ULPI_CLK_ENABLE ();
299342 __HAL_RCC_USB_OTG_HS_CLK_ENABLE ();
343+ #elif defined(TARGET_GIGA )
344+ __HAL_RCC_USB_OTG_HS_ULPI_CLK_SLEEP_DISABLE ();
345+ __HAL_RCC_USB_OTG_HS_CLK_SLEEP_ENABLE ();
346+ __HAL_RCC_USB_OTG_HS_CLK_ENABLE ();
300347#else
301348 __HAL_RCC_USB_OTG_FS_CLK_ENABLE ();
302349#endif
0 commit comments