diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE/TARGET_NUCLEO_F303ZE/PinNames.h b/targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE/TARGET_NUCLEO_F303ZE/PinNames.h index d1c76fab8f8..caaad197767 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE/TARGET_NUCLEO_F303ZE/PinNames.h +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE/TARGET_NUCLEO_F303ZE/PinNames.h @@ -355,6 +355,9 @@ typedef enum { #define LED3 PB_14 // LD3 [Red] #define BUTTON1 PC_13 // USER_Btn [B1] +// USB +#define USB_PULLUP_CONTROL PG_6 // USB_Disconnect in the schematics + #ifdef __cplusplus } #endif diff --git a/targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE/system_clock.c b/targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE/system_clock.c index 05873573cbe..863fb9c281a 100644 --- a/targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE/system_clock.c +++ b/targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE/system_clock.c @@ -93,7 +93,6 @@ uint8_t SetSysClock_PLL_HSE(uint8_t bypass) { RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct; - RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit; /* Enable HSE oscillator and activate PLL with HSE as source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; @@ -120,11 +119,14 @@ uint8_t SetSysClock_PLL_HSE(uint8_t bypass) return 0; // FAIL } +#if DEVICE_USBDEVICE + RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit; RCC_PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; RCC_PeriphClkInit.USBClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5; if (HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInit) != HAL_OK) { return 0; // FAIL } +#endif /* Output clock on MCO1 pin(PA8) for debugging purpose */ //if (bypass == 0) @@ -144,7 +146,6 @@ uint8_t SetSysClock_PLL_HSI(void) { RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct; - RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit; /* Enable HSI oscillator and activate PLL with HSI as source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE; @@ -169,11 +170,14 @@ uint8_t SetSysClock_PLL_HSI(void) return 0; // FAIL } +#if DEVICE_USBDEVICE + RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit; RCC_PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB; RCC_PeriphClkInit.USBClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5; if (HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInit) != HAL_OK) { return 0; // FAIL } +#endif /* Output clock on MCO1 pin(PA8) for debugging purpose */ //HAL_RCC_MCOConfig(RCC_MCO, RCC_MCOSOURCE_HSI, RCC_MCO_DIV1); // 8 MHz diff --git a/targets/TARGET_STM/USBPhyHw.h b/targets/TARGET_STM/USBPhyHw.h index fc3f8c64a6c..3bce84f633e 100644 --- a/targets/TARGET_STM/USBPhyHw.h +++ b/targets/TARGET_STM/USBPhyHw.h @@ -43,8 +43,10 @@ #if MBED_CONF_TARGET_USB_SPEED == USE_USB_NO_OTG -#if defined(TARGET_STM32F1) || defined(TARGET_STM32F3) || defined(TARGET_STM32L1) || defined(TARGET_STM32WB) || defined(TARGET_STM32G4) +#if defined(TARGET_STM32F1) || defined(TARGET_STM32L1) || defined(TARGET_STM32WB) || defined(TARGET_STM32G4) #define USBHAL_IRQn USB_LP_IRQn +#elif defined(TARGET_STM32F3) +#define USBHAL_IRQn USB_LP_CAN_RX0_IRQn #elif defined(TARGET_STM32L5) #define USBHAL_IRQn USB_FS_IRQn #else diff --git a/targets/TARGET_STM/USBPhy_STM32.cpp b/targets/TARGET_STM/USBPhy_STM32.cpp index 7f0c8d31420..28068ee972d 100644 --- a/targets/TARGET_STM/USBPhy_STM32.cpp +++ b/targets/TARGET_STM/USBPhy_STM32.cpp @@ -192,7 +192,7 @@ USBPhyHw::~USBPhyHw() } -#if defined(TARGET_STM32F1) || defined(SYSCFG_PMC_USB_PU) +#if defined(TARGET_STM32F1) || defined(TARGET_STM32F3) || defined(SYSCFG_PMC_USB_PU) #include "drivers/DigitalOut.h" @@ -203,9 +203,14 @@ void USB_reenumerate() LL_SYSCFG_DisableUSBPullUp(); wait_us(10000); // 10ms LL_SYSCFG_EnableUSBPullUp(); +#elif defined(USB_PULLUP_CONTROL) + mbed::DigitalOut usb_dp_pin(USB_PULLUP_CONTROL, 0); + wait_us(1000); + usb_dp_pin = 1; + wait_us(1000); #else // Force USB_DP pin (with external pull up) to 0 - mbed::DigitalOut usb_dp_pin(USB_DP, 0) ; + mbed::DigitalOut usb_dp_pin(USB_DP, 0); wait_us(10000); // 10ms #endif } @@ -295,7 +300,7 @@ void USBPhyHw::init(USBPhyEvents *events) map = PinMap_USB_FS; -#if defined(TARGET_STM32F1) || defined(SYSCFG_PMC_USB_PU) +#if defined(TARGET_STM32F1) || defined(TARGET_STM32F3) || defined(SYSCFG_PMC_USB_PU) // USB_DevConnect is empty USB_reenumerate(); #endif @@ -418,7 +423,7 @@ void USBPhyHw::connect() // Initializes the USB controller registers USB_DevInit(hpcd.Instance, hpcd.Init); // hpcd.Init not used -#if defined(TARGET_STM32F1) || defined(SYSCFG_PMC_USB_PU) +#if defined(TARGET_STM32F1) || defined(TARGET_STM32F3) || defined(SYSCFG_PMC_USB_PU) // USB_DevConnect is empty USB_reenumerate(); #endif diff --git a/targets/targets.json b/targets/targets.json index 15bce670951..fb651436dbd 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -1718,6 +1718,9 @@ "detect_code": [ "0747" ], + "device_has_add": [ + "USBDEVICE" + ], "device_name": "STM32F303ZETx" }, "MCU_STM32F334x8": {