add LPC1549, add FRDM-KL46Z, fix epComplete bit operation.

Dependents:   XBee-ExplorerLite USBLocalFileSystem USB-to-UART-bridge USBLocalFileSystem

Fork of USBDevice by mbed official

Files at this revision

API Documentation at this revision

Comitter:
va009039
Date:
Thu May 08 22:45:45 2014 +0900
Parent:
20:b5a68b899fd1
Child:
22:8615d80a0568
Commit message:
merge

Changed in this revision

USBDevice/USBDevice.cpp Show annotated file Show diff for this revision Revisions of this file
USBDevice/USBDevice.h Show annotated file Show diff for this revision Revisions of this file
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
USBHID/USBHID.cpp Show annotated file Show diff for this revision Revisions of this file
USBMSD/USBMSD.cpp Show annotated file Show diff for this revision Revisions of this file
USBMSD/USBMSD.h Show annotated file Show diff for this revision Revisions of this file
USBSerial/USBCDC.cpp Show annotated file Show diff for this revision Revisions of this file
USBSerial/USBCDC.h Show annotated file Show diff for this revision Revisions of this file
USBSerial/USBSerial.h Show annotated file Show diff for this revision Revisions of this file
--- a/USBDevice/USBDevice.cpp	Thu Mar 20 03:27:54 2014 +0000
+++ b/USBDevice/USBDevice.cpp	Thu May 08 22:45:45 2014 +0900
@@ -703,12 +703,15 @@
     return (device.state == CONFIGURED);
 }
 
-void USBDevice::connect(void)
+void USBDevice::connect(bool blocking)
 {
     /* Connect device */
     USBHAL::connect();
-    /* Block if not configured */
-    while (!configured());
+    
+    if (blocking) {
+        /* Block if not configured */
+        while (!configured());
+    }
 }
 
 void USBDevice::disconnect(void)
--- a/USBDevice/USBDevice.h	Thu Mar 20 03:27:54 2014 +0000
+++ b/USBDevice/USBDevice.h	Thu May 08 22:45:45 2014 +0900
@@ -37,8 +37,10 @@
     
     /*
     * Connect a device
+    * 
+    * @param blocking: block if not configured
     */
-    void connect(void);
+    void connect(bool blocking = true);
     
     /*
     * Disconnect a device
--- a/USBDevice/USBEndpoints.h	Thu Mar 20 03:27:54 2014 +0000
+++ b/USBDevice/USBEndpoints.h	Thu May 08 22:45:45 2014 +0900
@@ -41,7 +41,7 @@
 #include "USBEndpoints_LPC17_LPC23.h"
 #elif defined(TARGET_LPC11UXX) || defined(TARGET_LPC1347)||defined(TARGET_LPC1549)
 #include "USBEndpoints_LPC11U.h"
-#elif defined(TARGET_KL25Z) || defined(TARGET_KL46Z)
+#elif defined(TARGET_KL25Z) | defined(TARGET_KL46Z) | defined(TARGET_K20D5M) | defined(TARGET_K64F)
 #include "USBEndpoints_KL25Z.h"
 #elif defined (TARGET_STM32F4XX)
 #include "USBEndpoints_STM32F4.h"
--- a/USBDevice/USBHAL_KL25Z.cpp	Thu Mar 20 03:27:54 2014 +0000
+++ b/USBDevice/USBHAL_KL25Z.cpp	Thu May 08 22:45:45 2014 +0900
@@ -16,7 +16,7 @@
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
-#if defined(TARGET_KL25Z)|| defined(TARGET_KL46Z)
+#if defined(TARGET_KL25Z) | defined(TARGET_KL46Z) | defined(TARGET_K20D5M) | defined(TARGET_K64F)
 
 #include "USBHAL.h"
 
@@ -62,7 +62,7 @@
     uint8_t   dummy;      // RSVD: BD[8:15]
     uint16_t  byte_count; // BD[16:32]
     uint32_t  address;    // Addr
-} BDT; 
+} BDT;
 
 
 // there are:
@@ -85,10 +85,13 @@
     return 0;
 }
 
-USBHAL::USBHAL(void) {    
+USBHAL::USBHAL(void) {
     // Disable IRQ
     NVIC_DisableIRQ(USB0_IRQn);
-    
+
+#if defined(TARGET_K64F)
+    MPU->CESR=0;
+#endif
     // fill in callback array
     epCallback[0] = &USBHAL::EP1_OUT_callback;
     epCallback[1] = &USBHAL::EP1_IN_callback;
@@ -120,11 +123,11 @@
     epCallback[27] = &USBHAL::EP14_IN_callback;
     epCallback[28] = &USBHAL::EP15_OUT_callback;
     epCallback[29] = &USBHAL::EP15_IN_callback;
-    
-    
+
+
     // choose usb src as PLL
     SIM->SOPT2 |= (SIM_SOPT2_USBSRC_MASK | SIM_SOPT2_PLLFLLSEL_MASK);
-    
+
     // enable OTG clock
     SIM->SCGC4 |= SIM_SCGC4_USBOTG_MASK;
 
@@ -132,29 +135,29 @@
     instance = this;
     NVIC_SetVector(USB0_IRQn, (uint32_t)&_usbisr);
     NVIC_EnableIRQ(USB0_IRQn);
-    
+
     // USB Module Configuration
     // Reset USB Module
     USB0->USBTRC0 |= USB_USBTRC0_USBRESET_MASK;
     while(USB0->USBTRC0 & USB_USBTRC0_USBRESET_MASK);
-    
+
     // Set BDT Base Register
-    USB0->BDTPAGE1=(uint8_t)((uint32_t)bdt>>8);
-    USB0->BDTPAGE2=(uint8_t)((uint32_t)bdt>>16);
-    USB0->BDTPAGE3=(uint8_t)((uint32_t)bdt>>24);
+    USB0->BDTPAGE1 = (uint8_t)((uint32_t)bdt>>8);
+    USB0->BDTPAGE2 = (uint8_t)((uint32_t)bdt>>16);
+    USB0->BDTPAGE3 = (uint8_t)((uint32_t)bdt>>24);
 
     // Clear interrupt flag
     USB0->ISTAT = 0xff;
 
     // USB Interrupt Enablers
-    USB0->INTEN |= USB_INTEN_TOKDNEEN_MASK | 
-                   USB_INTEN_SOFTOKEN_MASK | 
+    USB0->INTEN |= USB_INTEN_TOKDNEEN_MASK |
+                   USB_INTEN_SOFTOKEN_MASK |
                    USB_INTEN_ERROREN_MASK  |
                    USB_INTEN_USBRSTEN_MASK;
-    
-    // Disable weak pull downs 
-    USB0->USBCTRL &= ~(USB_USBCTRL_PDE_MASK | USB_USBCTRL_SUSP_MASK);   
-    
+
+    // Disable weak pull downs
+    USB0->USBCTRL &= ~(USB_USBCTRL_PDE_MASK | USB_USBCTRL_SUSP_MASK);
+
     USB0->USBTRC0 |= 0x40;
 }
 
@@ -299,9 +302,9 @@
     uint32_t n, sz, idx, setup = 0;
     uint8_t not_iso;
     uint8_t * ep_buf;
-    
+
     uint32_t log_endpoint = PHY_TO_LOG(endpoint);
-    
+
     if (endpoint > NUMBER_OF_PHYSICAL_ENDPOINTS - 1) {
         return EP_INVALID;
     }
@@ -338,7 +341,7 @@
     if (((Data1 >> endpoint) & 1) == ((bdt[idx].info >> 6) & 1)) {
         if (setup && (buffer[6] == 0))  // if no setup data stage,
             Data1 &= ~1UL;              // set DATA0
-        else 
+        else
             Data1 ^= (1 << endpoint);
     }
 
@@ -348,7 +351,7 @@
     else {
         bdt[idx].info = BD_DTS_MASK | BD_OWN_MASK;
     }
-        
+
     USB0->CTL &= ~USB_CTL_TXSUSPENDTOKENBUSY_MASK;
     *bytesRead = sz;
 
@@ -371,27 +374,27 @@
 
     idx = EP_BDT_IDX(PHY_TO_LOG(endpoint), TX, 0);
     bdt[idx].byte_count = size;
-    
-    
+
+
     // non iso endpoint
     if (USB0->ENDPOINT[PHY_TO_LOG(endpoint)].ENDPT & USB_ENDPT_EPHSHK_MASK) {
         ep_buf = endpoint_buffer[idx];
     } else {
         ep_buf = endpoint_buffer_iso[2];
     }
-    
+
     for (n = 0; n < size; n++) {
         ep_buf[n] = data[n];
     }
-    
+
     if ((Data1 >> endpoint) & 1) {
         bdt[idx].info = BD_OWN_MASK | BD_DTS_MASK;
     } else {
         bdt[idx].info = BD_OWN_MASK | BD_DTS_MASK | BD_DATA01_MASK;
     }
-    
+
     Data1 ^= (1 << endpoint);
-    
+
     return EP_PENDING;
 }
 
@@ -432,7 +435,7 @@
     uint8_t istat = USB0->ISTAT;
 
     // reset interrupt
-    if (istat & USB_ISTAT_USBRST_MASK) {            
+    if (istat & USB_ISTAT_USBRST_MASK) {
         // disable all endpt
         for(i = 0; i < 16; i++) {
             USB0->ENDPOINT[i].ENDPT = 0x00;
@@ -460,11 +463,11 @@
 
     // SOF interrupt
     if (istat & USB_ISTAT_SOFTOK_MASK) {
-        USB0->ISTAT = USB_ISTAT_SOFTOK_MASK;  
+        USB0->ISTAT = USB_ISTAT_SOFTOK_MASK;
         // SOF event, read frame number
         SOF(frameNumber());
     }
-    
+
     // stall interrupt
     if (istat & 1<<7) {
         if (USB0->ENDPOINT[0].ENDPT & USB_ENDPT_EPSTALL_MASK)
@@ -486,7 +489,7 @@
 
             // EP0 SETUP event (SETUP data received)
             EP0setupCallback();
-                    
+
         } else {
             // OUT packet
             if (TOK_PID((EP_BDT_IDX(num, dir, ev_odd))) == OUT_TOKEN) {
@@ -520,11 +523,11 @@
 
         USB0->ISTAT = USB_ISTAT_TOKDNE_MASK;
     }
-        
+
     // sleep interrupt
     if (istat & 1<<4) {
         USB0->ISTAT |= USB_ISTAT_SLEEP_MASK;
-    }    
+    }
 
     // error interrupt
     if (istat & USB_ISTAT_ERROR_MASK) {
--- a/USBHID/USBHID.cpp	Thu Mar 20 03:27:54 2014 +0000
+++ b/USBHID/USBHID.cpp	Thu May 08 22:45:45 2014 +0900
@@ -59,6 +59,9 @@
     uint32_t bytesRead = 0;
     bool result;
     result = USBDevice::readEP_NB(EPINT_OUT, report->data, &bytesRead, MAX_HID_REPORT_SIZE);
+    // if readEP_NB did not succeed, does not issue a readStart
+    if (!result)
+        return false;
     report->length = bytesRead;
     if(!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE))
         return false;
--- a/USBMSD/USBMSD.cpp	Thu Mar 20 03:27:54 2014 +0000
+++ b/USBMSD/USBMSD.cpp	Thu May 08 22:45:45 2014 +0900
@@ -103,8 +103,7 @@
 }
 
 
-bool USBMSD::connect() {
-
+bool USBMSD::connect(bool blocking) {
     //disk initialization
     if (disk_status() & NO_INIT) {
         if (disk_initialize()) {
@@ -131,7 +130,7 @@
     }
 
     //connect the device
-    USBDevice::connect();
+    USBDevice::connect(blocking);
     return true;
 }
 
--- a/USBMSD/USBMSD.h	Thu Mar 20 03:27:54 2014 +0000
+++ b/USBMSD/USBMSD.h	Thu May 08 22:45:45 2014 +0900
@@ -70,9 +70,10 @@
     /**
     * Connect the USB MSD device. Establish disk initialization before really connect the device.
     *
+    * @param blocking if not configured
     * @returns true if successful
     */
-    bool connect();
+    bool connect(bool blocking = true);
 
     /**
     * Disconnect the USB MSD device.
--- a/USBSerial/USBCDC.cpp	Thu Mar 20 03:27:54 2014 +0000
+++ b/USBSerial/USBCDC.cpp	Thu May 08 22:45:45 2014 +0900
@@ -29,9 +29,9 @@
 
 #define MAX_CDC_REPORT_SIZE MAX_PACKET_SIZE_EPBULK
 
-USBCDC::USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release): USBDevice(vendor_id, product_id, product_release) {
+USBCDC::USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking): USBDevice(vendor_id, product_id, product_release) {
     terminal_connected = false;
-    USBDevice::connect();
+    USBDevice::connect(connect_blocking);
 }
 
 bool USBCDC::USBCallback_request(void) {
--- a/USBSerial/USBCDC.h	Thu Mar 20 03:27:54 2014 +0000
+++ b/USBSerial/USBCDC.h	Thu May 08 22:45:45 2014 +0900
@@ -35,8 +35,9 @@
     * @param vendor_id Your vendor_id
     * @param product_id Your product_id
     * @param product_release Your preoduct_release
+    * @param connect_blocking define if the connection must be blocked if USB not plugged in
     */
-    USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
+    USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking);
 
 protected:
     
--- a/USBSerial/USBSerial.h	Thu Mar 20 03:27:54 2014 +0000
+++ b/USBSerial/USBSerial.h	Thu May 08 22:45:45 2014 +0900
@@ -53,9 +53,10 @@
     * @param vendor_id Your vendor_id (default: 0x1f00)
     * @param product_id Your product_id (default: 0x2012)
     * @param product_release Your preoduct_release (default: 0x0001)
+    * @param connect_blocking define if the connection must be blocked if USB not plugged in
     *
     */
-    USBSerial(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001): USBCDC(vendor_id, product_id, product_release), buf(128){
+    USBSerial(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001, bool connect_blocking = true): USBCDC(vendor_id, product_id, product_release, connect_blocking), buf(128){
         settingsChangedCallback = 0;
     };