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:
mbed_official
Date:
Thu Jan 23 17:30:20 2014 +0000
Parent:
16:4f6df64750bd
Child:
18:78bdbce94509
Commit message:
Synchronized with git revision b7a925e3cf046d2c5a95f80b14d6c285afbdfa7e

Full URL: https://github.com/mbedmicro/mbed/commit/b7a925e3cf046d2c5a95f80b14d6c285afbdfa7e/

LPC11U35 support for USBDevice and mbed-rtos

Changed in this revision

USBDevice/USBDevice.cpp Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBDevice_Types.h Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBHAL_LPC11U.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/USBDevice/USBDevice.cpp	Thu Dec 05 13:00:15 2013 +0000
+++ b/USBDevice/USBDevice.cpp	Thu Jan 23 17:30:20 2014 +0000
@@ -926,7 +926,7 @@
     static uint8_t stringLangidDescriptor[] = {
         0x04,               /*bLength*/
         STRING_DESCRIPTOR,  /*bDescriptorType 0x03*/
-        0x09,0x00,          /*bString Lang ID - 0x009 - English*/
+        0x09,0x04,          /*bString Lang ID - 0x0409 - English*/
     };
     return stringLangidDescriptor;
 }
--- a/USBDevice/USBDevice_Types.h	Thu Dec 05 13:00:15 2013 +0000
+++ b/USBDevice/USBDevice_Types.h	Thu Jan 23 17:30:20 2014 +0000
@@ -49,7 +49,7 @@
 
 /* Descriptors */
 #define DESCRIPTOR_TYPE(wValue)  (wValue >> 8)
-#define DESCRIPTOR_INDEX(wValue) (wValue & 0xf)
+#define DESCRIPTOR_INDEX(wValue) (wValue & 0xff)
 
 typedef struct {
     struct {
--- a/USBDevice/USBHAL_LPC11U.cpp	Thu Dec 05 13:00:15 2013 +0000
+++ b/USBDevice/USBHAL_LPC11U.cpp	Thu Jan 23 17:30:20 2014 +0000
@@ -16,11 +16,11 @@
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#if defined(TARGET_LPC11U24) || defined(TARGET_LPC1347)
+#if defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401) || defined(TARGET_LPC1347)
 
 #if defined(TARGET_LPC1347)
 #define USB_IRQ USB_IRQ_IRQn
-#elif defined(TARGET_LPC11U24)
+#elif defined(TARGET_LPC11U24) || defined(TARGET_LPC11U35_401)
 #define USB_IRQ USB_IRQn
 #endif
 
@@ -145,6 +145,11 @@
     epCallback[6] = &USBHAL::EP4_OUT_callback;
     epCallback[7] = &USBHAL::EP4_IN_callback;
 
+    #if defined(TARGET_LPC11U35_401)
+    // USB_VBUS input with pull-down
+    LPC_IOCON->PIO0_3 = 0x00000009;
+    #endif
+    
     // nUSB_CONNECT output
     LPC_IOCON->PIO0_6 = 0x00000001;