Adaptation of the official mbed USBHost repository to work with the LPC4088 Display Module

Dependents:   DMSupport DMSupport DMSupport DMSupport

Fork of DM_USBHost by EmbeddedArtists AB

Revision:
33:819bbf04163b
Parent:
32:f2d129436056
--- a/USBHost/USBHALHost.cpp	Wed Oct 23 06:58:55 2019 +0000
+++ b/USBHost/USBHALHost.cpp	Mon Nov 04 14:30:07 2019 +0000
@@ -39,10 +39,10 @@
 
 #define TOTAL_SIZE (HCCA_SIZE + (MAX_ENDPOINT*ED_SIZE) + (MAX_TD*TD_SIZE))
 
-// Put the USB structures in the only memory accessible by the USB stack - the AHBSRAM0
-static volatile uint8_t usb_buf[TOTAL_SIZE] __attribute__((section("AHBSRAM0"),aligned(256)));// __attribute__((section("AHBSRAM0"),aligned(256)));  //256 bytes aligned!
+// Put the USB structures in the only memory accessible by the USB stack - the AHBSRAM1
+static volatile uint8_t usb_buf[TOTAL_SIZE] __attribute__((section("AHBSRAM1"),aligned(256)));// __attribute__((section("AHBSRAM0"),aligned(256)));  //256 bytes aligned!
 
-// A very basic implementation of malloc to allocate in the AHBSRAM0
+// A very basic implementation of malloc to allocate in the AHBSRAM1
 #define SAFE_MEM_TO_USE     (10*1024)
 #define SAFE_MEM_BLOCK_SIZE (512)
 #define SAFE_MEM_NUM_BLOCKS (SAFE_MEM_TO_USE/SAFE_MEM_BLOCK_SIZE)
@@ -51,7 +51,7 @@
     bool used;
 } safe_mem_info_t;
 static safe_mem_info_t safe_mem_list[SAFE_MEM_NUM_BLOCKS];
-static uint8_t safe_mem_data[SAFE_MEM_TO_USE] __attribute__((section("AHBSRAM0"),aligned(256)));//__attribute__((section("AHBSRAM0"),aligned));  //256 bytes aligned!
+static uint8_t safe_mem_data[SAFE_MEM_TO_USE] __attribute__((section("AHBSRAM1"),aligned(256)));//__attribute__((section("AHBSRAM0"),aligned));  //256 bytes aligned!
 
 // To detect when memory outside of the AHBSRAM0 is passed to the USB stack
 void assert_mem_region(uint32_t ptr)
@@ -78,6 +78,7 @@
         safe_mem_list[i].used = false;
         safe_mem_list[i].ptr = safe_mem_data + SAFE_MEM_BLOCK_SIZE*i;
     }
+    
 }
 
 uint8_t* USBHALHost::getSafeMem(uint32_t size) {
@@ -198,9 +199,7 @@
     LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC;
     LPC_USB->HcRhPortStatus2 = OR_RH_PORT_CSC;
     LPC_USB->HcRhPortStatus2 = OR_RH_PORT_PRSC;
-    
     resetRootHub();
-
     NVIC_SetPriority(USB_IRQn, 0);
     NVIC_EnableIRQ(USB_IRQn);
 
@@ -358,11 +357,12 @@
 
 void USBHALHost::_usbisr(void) {
     if (instHost) {
-        instHost->UsbIrqhandler();
+        instHost->UsbIrqhandler();        
     }
 }
 
 void USBHALHost::UsbIrqhandler() {
+
     if( LPC_USB->HcInterruptStatus & LPC_USB->HcInterruptEnable ) //Is there something to actually process?
     {
         uint32_t int_status = LPC_USB->HcInterruptStatus & LPC_USB->HcInterruptEnable;
@@ -378,8 +378,8 @@
                     //Root device connected
                     if (LPC_USB->HcRhPortStatus2 & OR_RH_PORT_CCS) {
 
-                        // wait 150ms to avoid bounce
-                        ThisThread::sleep_for(150);
+                        // wait 150ms to avoid bounce (removed since wait is not allowed in isr)
+                        //ThisThread::sleep_for(150);
 
                         //Hub 0 (root hub), Port 2 (count starts at 1), Low or High speed
                         deviceConnected(0, 2, LPC_USB->HcRhPortStatus2 & OR_RH_PORT_LSDA);
@@ -392,8 +392,8 @@
                             usb_hcca->DoneHead = 0;
                         }
 
-                        // wait 200ms to avoid bounce
-                        ThisThread::sleep_for(200);
+                        // wait 200ms to avoid bounce (removed since wait is not allowed in isr)
+                        //wait_ms(200);
 
                         deviceDisconnected(0, 2, NULL, usb_hcca->DoneHead & 0xFFFFFFFE);