Skip to content

Commit 4587080

Browse files
authored
Merge pull request #15116 from jeromecoutant/PR_USB_F3
STM32F3 - enable USB_DEVICE for NUCLEO_F303ZE
2 parents b57fe3f + 8d35879 commit 4587080

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE/TARGET_NUCLEO_F303ZE/PinNames.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ typedef enum {
355355
#define LED3 PB_14 // LD3 [Red]
356356
#define BUTTON1 PC_13 // USER_Btn [B1]
357357

358+
// USB
359+
#define USB_PULLUP_CONTROL PG_6 // USB_Disconnect in the schematics
360+
358361
#ifdef __cplusplus
359362
}
360363
#endif

targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303xE/system_clock.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
9393
{
9494
RCC_ClkInitTypeDef RCC_ClkInitStruct;
9595
RCC_OscInitTypeDef RCC_OscInitStruct;
96-
RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit;
9796

9897
/* Enable HSE oscillator and activate PLL with HSE as source */
9998
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
@@ -120,11 +119,14 @@ uint8_t SetSysClock_PLL_HSE(uint8_t bypass)
120119
return 0; // FAIL
121120
}
122121

122+
#if DEVICE_USBDEVICE
123+
RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit;
123124
RCC_PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
124125
RCC_PeriphClkInit.USBClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
125126
if (HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInit) != HAL_OK) {
126127
return 0; // FAIL
127128
}
129+
#endif
128130

129131
/* Output clock on MCO1 pin(PA8) for debugging purpose */
130132
//if (bypass == 0)
@@ -144,7 +146,6 @@ uint8_t SetSysClock_PLL_HSI(void)
144146
{
145147
RCC_ClkInitTypeDef RCC_ClkInitStruct;
146148
RCC_OscInitTypeDef RCC_OscInitStruct;
147-
RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit;
148149

149150
/* Enable HSI oscillator and activate PLL with HSI as source */
150151
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE;
@@ -169,11 +170,14 @@ uint8_t SetSysClock_PLL_HSI(void)
169170
return 0; // FAIL
170171
}
171172

173+
#if DEVICE_USBDEVICE
174+
RCC_PeriphCLKInitTypeDef RCC_PeriphClkInit;
172175
RCC_PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB;
173176
RCC_PeriphClkInit.USBClockSelection = RCC_USBCLKSOURCE_PLL_DIV1_5;
174177
if (HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphClkInit) != HAL_OK) {
175178
return 0; // FAIL
176179
}
180+
#endif
177181

178182
/* Output clock on MCO1 pin(PA8) for debugging purpose */
179183
//HAL_RCC_MCOConfig(RCC_MCO, RCC_MCOSOURCE_HSI, RCC_MCO_DIV1); // 8 MHz

targets/TARGET_STM/USBPhyHw.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343

4444
#if MBED_CONF_TARGET_USB_SPEED == USE_USB_NO_OTG
4545

46-
#if defined(TARGET_STM32F1) || defined(TARGET_STM32F3) || defined(TARGET_STM32L1) || defined(TARGET_STM32WB) || defined(TARGET_STM32G4)
46+
#if defined(TARGET_STM32F1) || defined(TARGET_STM32L1) || defined(TARGET_STM32WB) || defined(TARGET_STM32G4)
4747
#define USBHAL_IRQn USB_LP_IRQn
48+
#elif defined(TARGET_STM32F3)
49+
#define USBHAL_IRQn USB_LP_CAN_RX0_IRQn
4850
#elif defined(TARGET_STM32L5)
4951
#define USBHAL_IRQn USB_FS_IRQn
5052
#else

targets/TARGET_STM/USBPhy_STM32.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ USBPhyHw::~USBPhyHw()
192192

193193
}
194194

195-
#if defined(TARGET_STM32F1) || defined(SYSCFG_PMC_USB_PU)
195+
#if defined(TARGET_STM32F1) || defined(TARGET_STM32F3) || defined(SYSCFG_PMC_USB_PU)
196196

197197
#include "drivers/DigitalOut.h"
198198

@@ -203,9 +203,14 @@ void USB_reenumerate()
203203
LL_SYSCFG_DisableUSBPullUp();
204204
wait_us(10000); // 10ms
205205
LL_SYSCFG_EnableUSBPullUp();
206+
#elif defined(USB_PULLUP_CONTROL)
207+
mbed::DigitalOut usb_dp_pin(USB_PULLUP_CONTROL, 0);
208+
wait_us(1000);
209+
usb_dp_pin = 1;
210+
wait_us(1000);
206211
#else
207212
// Force USB_DP pin (with external pull up) to 0
208-
mbed::DigitalOut usb_dp_pin(USB_DP, 0) ;
213+
mbed::DigitalOut usb_dp_pin(USB_DP, 0);
209214
wait_us(10000); // 10ms
210215
#endif
211216
}
@@ -295,7 +300,7 @@ void USBPhyHw::init(USBPhyEvents *events)
295300

296301
map = PinMap_USB_FS;
297302

298-
#if defined(TARGET_STM32F1) || defined(SYSCFG_PMC_USB_PU)
303+
#if defined(TARGET_STM32F1) || defined(TARGET_STM32F3) || defined(SYSCFG_PMC_USB_PU)
299304
// USB_DevConnect is empty
300305
USB_reenumerate();
301306
#endif
@@ -418,7 +423,7 @@ void USBPhyHw::connect()
418423
// Initializes the USB controller registers
419424
USB_DevInit(hpcd.Instance, hpcd.Init); // hpcd.Init not used
420425

421-
#if defined(TARGET_STM32F1) || defined(SYSCFG_PMC_USB_PU)
426+
#if defined(TARGET_STM32F1) || defined(TARGET_STM32F3) || defined(SYSCFG_PMC_USB_PU)
422427
// USB_DevConnect is empty
423428
USB_reenumerate();
424429
#endif

targets/targets.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,6 +1718,9 @@
17181718
"detect_code": [
17191719
"0747"
17201720
],
1721+
"device_has_add": [
1722+
"USBDEVICE"
1723+
],
17211724
"device_name": "STM32F303ZETx"
17221725
},
17231726
"MCU_STM32F334x8": {

0 commit comments

Comments
 (0)