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:
bogdanm
Date:
Tue Sep 10 15:14:55 2013 +0300
Parent:
12:6030a12b6c62
Child:
14:d495202c90f4
Commit message:
Sync with git revision 171dda705c947bf910926a0b73d6a4797802554d

Changed in this revision

USBDevice/USBEndpoints.h Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBHAL_KL25Z.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/USBDevice/USBEndpoints.h	Thu Aug 08 15:56:46 2013 +0100
+++ b/USBDevice/USBEndpoints.h	Tue Sep 10 15:14:55 2013 +0300
@@ -39,7 +39,7 @@
 /* Include configuration for specific target */
 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC4088)
 #include "USBEndpoints_LPC17_LPC23.h"
-#elif defined(TARGET_LPC11U24) || defined(TARGET_LPC1347)
+#elif defined(TARGET_LPC11UXX) || defined(TARGET_LPC1347)
 #include "USBEndpoints_LPC11U.h"
 #elif defined(TARGET_KL25Z)
 #include "USBEndpoints_KL25Z.h"
--- a/USBDevice/USBHAL_KL25Z.cpp	Thu Aug 08 15:56:46 2013 +0100
+++ b/USBDevice/USBHAL_KL25Z.cpp	Tue Sep 10 15:14:55 2013 +0300
@@ -75,7 +75,7 @@
 static uint32_t Data1  = 0x55555555;
 
 static uint32_t frameNumber() {
-    return((USB0->FRMNUML | (USB0->FRMNUMH << 8) & 0x07FF));
+    return((USB0->FRMNUML | (USB0->FRMNUMH << 8)) & 0x07FF);
 }
 
 uint32_t USBHAL::endpointReadcore(uint8_t endpoint, uint8_t *buffer) {