USB device stack with Nucleo F401RE support. NOTE: the default clock config needs to be changed to in order for USB to work.

Fork of USBDevice by Tomas Cerskus

Slightly modified original USBDevice library to support F401RE.

On F401RE the data pins of your USB connector should be attached to PA12 (D+) and PA11(D-). It is also required to connect the +5V USB line to PA9.

F401RE requires 48MHz clock for USB. Therefore in order for this to work you will need to change the default clock settings:

Clock settings for USB

#include "stm32f4xx_hal.h"

RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 16;
RCC_OscInitStruct.PLL.PLLN = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
RCC_OscInitStruct.PLL.PLLQ = 7;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
    error("RTC error: LSI clock initialization failed."); 
}

NOTE: Changing the clock frequency might affect the behavior of other libraries. I only tested the Serial library.

UPDATE: Clock settings should not to be changed anymore! Looks like the newer mbed library has the required clock enabled.

Files at this revision

API Documentation at this revision

Comitter:
tolaipner
Date:
Sun Mar 30 07:30:18 2014 +0000
Parent:
23:ee5d634d099e
Commit message:
Added Nucleo F401RE support

Changed in this revision

USBDevice/USBHAL_STM32F4.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r ee5d634d099e -r 4ed3e25c3edc USBDevice/USBHAL_STM32F4.cpp
--- a/USBDevice/USBHAL_STM32F4.cpp	Sun Mar 30 07:24:27 2014 +0000
+++ b/USBDevice/USBHAL_STM32F4.cpp	Sun Mar 30 07:30:18 2014 +0000
@@ -62,6 +62,14 @@
     pin_function(PA_10, STM_PIN_DATA(2, 10));
     pin_function(PA_11, STM_PIN_DATA(2, 10));
     pin_function(PA_12, STM_PIN_DATA(2, 10));
+    
+    // Set ID pin to open drain with pull-up resistor
+    pin_mode(PA_10, OpenDrain);
+    GPIOA->PUPDR &= ~(0x3 << 20);
+    GPIOA->PUPDR |= 1 << 20;
+
+    // Set VBUS pin to open drain
+    pin_mode(PA_9, OpenDrain);
 #endif
 
     RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;