@@ -39,6 +39,7 @@ static const uint32_t tx_ep_sizes[NUM_ENDPOINTS] = {
39
39
MAX_PACKET_SIZE_ISO
40
40
};
41
41
42
+ #if (MBED_CONF_TARGET_USB_SPEED != USE_USB_NO_OTG)
42
43
uint32_t HAL_PCDEx_GetTxFiFo (PCD_HandleTypeDef *hpcd, uint8_t fifo)
43
44
{
44
45
uint32_t len;
@@ -49,15 +50,23 @@ uint32_t HAL_PCDEx_GetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo)
49
50
}
50
51
return len * 4 ;
51
52
}
53
+ #endif
52
54
55
+ /* weak function redefinition */
53
56
void HAL_PCD_SOFCallback (PCD_HandleTypeDef *hpcd)
54
57
{
55
58
USBPhyHw *priv = ((USBPhyHw *)(hpcd->pData ));
59
+ #if (MBED_CONF_TARGET_USB_SPEED == USE_USB_NO_OTG)
60
+ if (priv->sof_enabled ) {
61
+ priv->events ->sof ((hpcd->Instance ->FNR ) & USB_FNR_FN);
62
+ }
63
+ #else
56
64
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance ;
57
65
uint32_t USBx_BASE = (uint32_t )USBx;
58
66
if (priv->sof_enabled ) {
59
67
priv->events ->sof ((USBx_DEVICE->DSTS & USB_OTG_DSTS_FNSOF) >> 8 );
60
68
}
69
+ #endif
61
70
}
62
71
63
72
/* this call at device reception completion on a Out Enpoint */
@@ -244,7 +253,37 @@ void USBPhyHw::init(USBPhyEvents *events)
244
253
HAL_StatusTypeDef ret = HAL_PCD_Init (&hpcd);
245
254
MBED_ASSERT (ret == HAL_OK);
246
255
256
+ // Configure FIFOs
257
+ #if (MBED_CONF_TARGET_USB_SPEED == USE_USB_NO_OTG)
258
+
259
+ // EP0
260
+ #define PMA_EP0_OUT_ADDR (8 * 4 )
261
+ #define PMA_EP0_IN_ADDR (PMA_EP0_OUT_ADDR + MAX_PACKET_SIZE_EP0)
262
+ HAL_PCDEx_PMAConfig (&hpcd, LOG_OUT_TO_EP (0 ), PCD_SNG_BUF, PMA_EP0_OUT_ADDR); // HAL_PCDEx_PMAConfig always returns HAL_OK
263
+ HAL_PCDEx_PMAConfig (&hpcd, LOG_IN_TO_EP (0 ), PCD_SNG_BUF, PMA_EP0_IN_ADDR); // HAL_PCDEx_PMAConfig always returns HAL_OK
264
+ // EP1
265
+ #define PMA_EP1_OUT_BASE (PMA_EP0_IN_ADDR + MAX_PACKET_SIZE_EP0)
266
+ #define PMA_EP1_OUT_ADDR ((PMA_EP1_OUT_BASE + MAX_PACKET_SIZE_NON_ISO) | (PMA_EP1_OUT_BASE << 16U ))
267
+ #define PMA_EP1_IN_ADDR (PMA_EP1_OUT_BASE + MAX_PACKET_SIZE_NON_ISO)
268
+ #define PMA_EP1_CMD_ADDR (PMA_EP1_IN_ADDR + MAX_PACKET_SIZE_NON_ISO)
269
+ HAL_PCDEx_PMAConfig (&hpcd, LOG_OUT_TO_EP (1 ), PCD_SNG_BUF, PMA_EP1_OUT_ADDR); // HAL_PCDEx_PMAConfig always returns HAL_OK
270
+ HAL_PCDEx_PMAConfig (&hpcd, LOG_IN_TO_EP (1 ), PCD_SNG_BUF, PMA_EP1_CMD_ADDR); // HAL_PCDEx_PMAConfig always returns HAL_OK
271
+ // EP2
272
+ #define PMA_EP2_OUT_BASE (PMA_EP1_IN_ADDR + MAX_PACKET_SIZE_NON_ISO)
273
+ #define PMA_EP2_OUT_ADDR ((PMA_EP2_OUT_BASE + MAX_PACKET_SIZE_NON_ISO) | (PMA_EP2_OUT_BASE << 16U ))
274
+ #define PMA_EP2_IN_ADDR (PMA_EP2_OUT_BASE + MAX_PACKET_SIZE_NON_ISO * 2 )
275
+ #define PMA_EP2_CMD_ADDR (PMA_EP2_IN_ADDR + MAX_PACKET_SIZE_NON_ISO)
276
+ HAL_PCDEx_PMAConfig (&hpcd, LOG_OUT_TO_EP (2 ), PCD_DBL_BUF, PMA_EP2_OUT_ADDR); // HAL_PCDEx_PMAConfig always returns HAL_OK
277
+ HAL_PCDEx_PMAConfig (&hpcd, LOG_IN_TO_EP (2 ), PCD_SNG_BUF, PMA_EP2_CMD_ADDR); // HAL_PCDEx_PMAConfig always returns HAL_OK
278
+ // EP3
279
+ #define PMA_EP3_OUT_BASE (PMA_EP2_IN_ADDR + MAX_PACKET_SIZE_NON_ISO)
280
+ #define PMA_EP3_OUT_ADDR ((PMA_EP3_OUT_BASE + MAX_PACKET_SIZE_ISO) | (PMA_EP3_OUT_BASE << 16U ))
281
+ #define PMA_EP3_IN_ADDR (PMA_EP3_OUT_BASE + MAX_PACKET_SIZE_ISO)
282
+ #define PMA_EP3_CMD_ADDR (PMA_EP3_IN_ADDR + MAX_PACKET_SIZE_ISO)
283
+ HAL_PCDEx_PMAConfig (&hpcd, LOG_OUT_TO_EP (3 ), PCD_SNG_BUF, PMA_EP3_OUT_ADDR); // HAL_PCDEx_PMAConfig always returns HAL_OK
284
+ HAL_PCDEx_PMAConfig (&hpcd, LOG_IN_TO_EP (3 ), PCD_SNG_BUF, PMA_EP3_CMD_ADDR); // HAL_PCDEx_PMAConfig always returns HAL_OK
247
285
286
+ #else
248
287
uint32_t total_bytes = 0 ;
249
288
250
289
/* Reserve space in the RX buffer for:
@@ -266,6 +305,7 @@ void USBPhyHw::init(USBPhyEvents *events)
266
305
267
306
/* 1.25 kbytes */
268
307
MBED_ASSERT (total_bytes <= 1280 );
308
+ #endif
269
309
270
310
// Configure interrupt vector
271
311
NVIC_SetVector (USBHAL_IRQn, (uint32_t )&_usbisr);
@@ -293,8 +333,21 @@ bool USBPhyHw::powered()
293
333
294
334
void USBPhyHw::connect ()
295
335
{
336
+ #if (MBED_CONF_TARGET_USB_SPEED == USE_USB_NO_OTG)
337
+ DigitalOut usb_disc_pin (USB_DP, 1 ) ;
338
+ wait_ns (1000 );
339
+ usb_disc_pin = 0 ;
340
+
341
+ uint32_t wInterrupt_Mask = USB_CNTR_CTRM | USB_CNTR_WKUPM | USB_CNTR_SUSPM | USB_CNTR_ERRM |
342
+ USB_CNTR_SOFM | USB_CNTR_ESOFM | USB_CNTR_RESETM;
343
+ /* Set interrupt mask*/
344
+ hpcd.Instance ->CNTR = wInterrupt_Mask;
345
+ HAL_PCD_DevConnect (&hpcd); // HAL_PCD_DevConnect always return HAL_OK
346
+ wait_us (10000 );
347
+ #else
296
348
HAL_StatusTypeDef ret = HAL_PCD_Start (&hpcd);
297
349
MBED_ASSERT (ret == HAL_OK);
350
+ #endif
298
351
}
299
352
300
353
void USBPhyHw::disconnect ()
@@ -405,6 +458,7 @@ void USBPhyHw::ep0_stall()
405
458
406
459
bool USBPhyHw::endpoint_add (usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type)
407
460
{
461
+ #if (MBED_CONF_TARGET_USB_SPEED != USE_USB_NO_OTG)
408
462
uint32_t len;
409
463
410
464
/*
@@ -415,6 +469,8 @@ bool USBPhyHw::endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_
415
469
len = HAL_PCDEx_GetTxFiFo (&hpcd, endpoint & 0x7f );
416
470
MBED_ASSERT (len >= max_packet);
417
471
}
472
+ #endif
473
+
418
474
HAL_StatusTypeDef ret = HAL_PCD_EP_Open (&hpcd, endpoint, max_packet, type);
419
475
MBED_ASSERT (ret != HAL_BUSY);
420
476
return (ret == HAL_OK) ? true : false ;
0 commit comments