Przeglądaj źródła

- fix bug when unplugged unmounted-already device (mostly plugged when power on)
- add hal_debugger_is_attached & hal_debugger_breakpoint
- assert will suspend (place breakpoint) if the condition is failed and debugger is attached. Otherwise, a message to uart is printed
- fix get control qhd function when dev_addr is not zero (shifted 1)
- fix wrong logic for unsupported class

hathach 13 lat temu
rodzic
commit
dbaf6c0d30

+ 6 - 1
demos/bsp/boards/board.c

@@ -134,5 +134,10 @@ void HardFault_HandlerC(unsigned long *hardfault_args){
   // Bus Fault Address Register
   // Bus Fault Address Register
   _BFAR = (*((volatile unsigned long *)(0xE000ED38))) ;
   _BFAR = (*((volatile unsigned long *)(0xE000ED38))) ;
 
 
-  __asm("BKPT #0\n") ; // Break into the debugger
+//  if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)==CoreDebug_DHCSR_C_DEBUGEN_Msk) /* if there is debugger connected */
+//  {
+//    __asm("BKPT #0\n");
+//  }
+
+  hal_debugger_breakpoint();
 }
 }

Plik diff jest za duży
+ 5 - 1131
demos/host/.cproject


+ 3 - 3
demos/host/.project

@@ -89,12 +89,12 @@
 		<link>
 		<link>
 			<name>tinyusb</name>
 			<name>tinyusb</name>
 			<type>2</type>
 			<type>2</type>
-			<location>C:/Users/hathach/Dropbox/tinyusb/workspace/tinyusb/tinyusb</location>
+			<locationURI>PARENT-2-PROJECT_LOC/tinyusb</locationURI>
 		</link>
 		</link>
 	</linkedResources>
 	</linkedResources>
 	<filteredResources>
 	<filteredResources>
 		<filter>
 		<filter>
-			<id>1363062796914</id>
+			<id>1363923583856</id>
 			<name></name>
 			<name></name>
 			<type>26</type>
 			<type>26</type>
 			<matcher>
 			<matcher>
@@ -103,7 +103,7 @@
 			</matcher>
 			</matcher>
 		</filter>
 		</filter>
 		<filter>
 		<filter>
-			<id>1363062796957</id>
+			<id>1363923583890</id>
 			<name></name>
 			<name></name>
 			<type>26</type>
 			<type>26</type>
 			<matcher>
 			<matcher>

+ 3 - 3
tests/test/host/ehci/test_ehci_pipe_open.c

@@ -142,7 +142,7 @@ void test_control_open_addr0_qhd_data(void)
 
 
 void test_control_open_qhd_data(void)
 void test_control_open_qhd_data(void)
 {
 {
-  ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr].control.qhd;
+  ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr-1].control.qhd;
 
 
   //------------- Code Under TEST -------------//
   //------------- Code Under TEST -------------//
   hcd_pipe_control_open(dev_addr, control_max_packet_size);
   hcd_pipe_control_open(dev_addr, control_max_packet_size);
@@ -170,7 +170,7 @@ void test_control_open_highspeed(void)
 
 
 void test_control_open_non_highspeed(void)
 void test_control_open_non_highspeed(void)
 {
 {
-  ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr].control.qhd;
+  ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr-1].control.qhd;
 
 
   usbh_device_info_pool[dev_addr].speed   = TUSB_SPEED_FULL;
   usbh_device_info_pool[dev_addr].speed   = TUSB_SPEED_FULL;
 
 
@@ -195,7 +195,7 @@ void test_control_addr0_close(void)
 
 
 void test_control_close(void)
 void test_control_close(void)
 {
 {
-  ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr].control.qhd;
+  ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr-1].control.qhd;
 
 
   hcd_pipe_control_open(dev_addr, control_max_packet_size);
   hcd_pipe_control_open(dev_addr, control_max_packet_size);
 
 

+ 3 - 3
tests/test/host/ehci/test_ehci_pipe_xfer_control.c

@@ -164,7 +164,7 @@ void test_control_addr0_xfer_get_check_qhd_qtd_mapping(void)
 
 
 void test_control_xfer_get(void)
 void test_control_xfer_get(void)
 {
 {
-  ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr].control.qhd;
+  ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr-1].control.qhd;
   hcd_pipe_control_open(dev_addr, control_max_packet_size);
   hcd_pipe_control_open(dev_addr, control_max_packet_size);
 
 
   //------------- Code Under TEST -------------//
   //------------- Code Under TEST -------------//
@@ -209,7 +209,7 @@ void test_control_xfer_set(void)
       .wValue   = 3
       .wValue   = 3
   };
   };
 
 
-  ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr].control.qhd;
+  ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr-1].control.qhd;
   hcd_pipe_control_open(dev_addr, control_max_packet_size);
   hcd_pipe_control_open(dev_addr, control_max_packet_size);
 
 
   //------------- Code Under TEST -------------//
   //------------- Code Under TEST -------------//
@@ -233,7 +233,7 @@ void test_control_xfer_set(void)
 
 
 void test_control_xfer_isr(void)
 void test_control_xfer_isr(void)
 {
 {
-  ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr].control.qhd;
+  ehci_qhd_t * const p_qhd = &ehci_data.device[dev_addr-1].control.qhd;
   hcd_pipe_control_open(dev_addr, control_max_packet_size);
   hcd_pipe_control_open(dev_addr, control_max_packet_size);
 
 
   hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data);
   hcd_pipe_control_xfer(dev_addr, &request_get_dev_desc, xfer_data);

+ 15 - 0
tests/test/host/ehci/test_ehci_usbh_hcd_integration.c

@@ -78,6 +78,7 @@ void setUp(void)
     usbh_device_info_pool[i].hub_addr = hub_addr;
     usbh_device_info_pool[i].hub_addr = hub_addr;
     usbh_device_info_pool[i].hub_port = hub_port;
     usbh_device_info_pool[i].hub_port = hub_port;
     usbh_device_info_pool[i].speed    = TUSB_SPEED_HIGH;
     usbh_device_info_pool[i].speed    = TUSB_SPEED_HIGH;
+    usbh_device_info_pool[i].status   = TUSB_DEVICE_STATUS_READY;
   }
   }
 
 
   regs = get_operational_register(hostid);
   regs = get_operational_register(hostid);
@@ -178,3 +179,17 @@ void test_bulk_pipe_close(void)
   TEST_ASSERT_FALSE(p_qtd_head->used);
   TEST_ASSERT_FALSE(p_qtd_head->used);
   TEST_ASSERT_FALSE(p_qtd_tail->used);
   TEST_ASSERT_FALSE(p_qtd_tail->used);
 }
 }
+
+void test_device_unplugged_status(void)
+{
+  ehci_controller_device_unplug(hostid);
+  hcd_isr(hostid);
+
+  regs->usb_sts_bit.async_advance = 1;
+  hcd_isr(hostid); // async advance
+
+  //------------- Code Under Test -------------//
+
+  TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_REMOVING, usbh_device_info_pool[dev_addr].status);
+
+}

+ 13 - 0
tests/test/host/test_usbh.c

@@ -162,6 +162,19 @@ void class_close_expect(void)
   hidh_close_Expect(1);
   hidh_close_Expect(1);
 }
 }
 
 
+// device is not mounted before, even the control pipe is not open, do nothing
+void test_usbh_device_unplugged_isr_device_not_previously_mounted(void)
+{
+  uint8_t dev_addr = 1;
+
+  usbh_device_info_pool[dev_addr].status   = TUSB_DEVICE_STATUS_UNPLUG;
+  usbh_device_info_pool[dev_addr].core_id  = 0;
+  usbh_device_info_pool[dev_addr].hub_addr = 0;
+  usbh_device_info_pool[dev_addr].hub_port = 0;
+
+  usbh_device_unplugged_isr(0);
+}
+
 void test_usbh_device_unplugged_isr(void)
 void test_usbh_device_unplugged_isr(void)
 {
 {
   uint8_t dev_addr = 1;
   uint8_t dev_addr = 1;

+ 8 - 2
tinyusb/common/assertion.h

@@ -57,6 +57,7 @@ extern "C"
 #endif
 #endif
 
 
 #include "tusb_option.h"
 #include "tusb_option.h"
+#include "hal/hal.h"
 
 
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // Compile-time Assert
 // Compile-time Assert
@@ -92,7 +93,8 @@ extern "C"
 #endif
 #endif
 
 
 #ifndef _TEST_ASSERT_
 #ifndef _TEST_ASSERT_
-  #define ASSERT_ERROR_HANDLER(x, para)  return (x)
+  #define ASSERT_ERROR_HANDLER(x, para)  \
+    return (x)
 #else
 #else
   #define ASSERT_ERROR_HANDLER(x, para)  Throw(x)
   #define ASSERT_ERROR_HANDLER(x, para)  Throw(x)
 #endif
 #endif
@@ -101,7 +103,11 @@ extern "C"
   do{\
   do{\
     setup_statement;\
     setup_statement;\
 	  if (!(condition)) {\
 	  if (!(condition)) {\
-	    ASSERT_MESSAGE(format, __VA_ARGS__);\
+	    if (hal_debugger_is_attached()){\
+	      hal_debugger_breakpoint();\
+	    }else{\
+	      ASSERT_MESSAGE(format, __VA_ARGS__);\
+	    }\
 	    error_handler(error, handler_para);\
 	    error_handler(error, handler_para);\
 	  }\
 	  }\
 	}while(0)
 	}while(0)

+ 0 - 6
tinyusb/common/common.h

@@ -83,12 +83,6 @@
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // MACROS
 // MACROS
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
-#ifndef _TEST_
-  #define ASM_BREAKPOINT __asm("BKPT #0\n")          // Place breakpoint to stop the debugger at desire
-#else
-  #define ASM_BREAKPOINT
-#endif
-
 #define STRING_(x)  #x                             // stringify without expand
 #define STRING_(x)  #x                             // stringify without expand
 #define XSTRING_(x) STRING_(x)                     // expand then stringify
 #define XSTRING_(x) STRING_(x)                     // expand then stringify
 #define STRING_CONCAT_(a, b) a##b                  // concat without expand
 #define STRING_CONCAT_(a, b) a##b                  // concat without expand

+ 1 - 0
tinyusb/common/errors.h

@@ -49,6 +49,7 @@
 #ifndef _TUSB_ERRORS_H_
 #ifndef _TUSB_ERRORS_H_
 #define _TUSB_ERRORS_H_
 #define _TUSB_ERRORS_H_
 
 
+#include "primitive_types.h"
 #include "tusb_option.h"
 #include "tusb_option.h"
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus

+ 22 - 0
tinyusb/hal/hal.h

@@ -52,6 +52,7 @@
 #define _TUSB_HAL_H_
 #define _TUSB_HAL_H_
 
 
 #include "tusb_option.h"
 #include "tusb_option.h"
+#include "common/errors.h"
 #include "common/compiler/compiler.h"
 #include "common/compiler/compiler.h"
 
 
 #if MCU == 0
 #if MCU == 0
@@ -91,6 +92,27 @@ static inline void hal_interrupt_enable() ATTR_ALWAYS_INLINE;
  */
  */
 static inline void hal_interrupt_disable() ATTR_ALWAYS_INLINE;
 static inline void hal_interrupt_disable() ATTR_ALWAYS_INLINE;
 
 
+static inline bool hal_debugger_is_attached() ATTR_PURE ATTR_ALWAYS_INLINE;
+static inline bool hal_debugger_is_attached()
+{
+#ifndef _TEST_
+  return (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) == CoreDebug_DHCSR_C_DEBUGEN_Msk;
+#else
+  return false;
+#endif
+}
+
+static inline void hal_debugger_breakpoint() ATTR_ALWAYS_INLINE;
+static inline void hal_debugger_breakpoint()
+{
+#ifndef _TEST_
+  if (hal_debugger_is_attached()) /* if there is debugger connected */
+  {
+    __asm("BKPT #0\n");
+  }
+#endif
+}
+
 #ifdef __cplusplus
 #ifdef __cplusplus
  }
  }
 #endif
 #endif

+ 2 - 5
tinyusb/host/ehci/ehci.c

@@ -221,10 +221,7 @@ void port_connect_status_change_isr(uint8_t hostid)
     usbh_device_plugged_isr(hostid, regs->portsc_bit.nxp_port_speed); // NXP specific port speed
     usbh_device_plugged_isr(hostid, regs->portsc_bit.nxp_port_speed); // NXP specific port speed
   }else // device unplugged
   }else // device unplugged
   {
   {
-    printf("%s %d\n", __FUNCTION__, __LINE__);
-
     usbh_device_unplugged_isr(hostid);
     usbh_device_unplugged_isr(hostid);
-
     regs->usb_cmd_bit.advacne_async = 1; // Async doorbell check EHCI 4.8.2 for operational details
     regs->usb_cmd_bit.advacne_async = 1; // Async doorbell check EHCI 4.8.2 for operational details
   }
   }
 
 
@@ -280,7 +277,7 @@ void hcd_isr(uint8_t hostid)
   {
   {
     // TODO handle Queue Head halted
     // TODO handle Queue Head halted
     // TODO invoke some error callback if not async head
     // TODO invoke some error callback if not async head
-    ASM_BREAKPOINT;
+    hal_debugger_breakpoint();
   }
   }
 
 
   //------------- some QTD/SITD/ITD with IOC set is completed -------------//
   //------------- some QTD/SITD/ITD with IOC set is completed -------------//
@@ -666,7 +663,7 @@ static inline ehci_qhd_t* get_control_qhd(uint8_t dev_addr)
 {
 {
   return (dev_addr == 0) ?
   return (dev_addr == 0) ?
       get_async_head( usbh_device_info_pool[dev_addr].core_id ) :
       get_async_head( usbh_device_info_pool[dev_addr].core_id ) :
-      &ehci_data.device[dev_addr].control.qhd;
+      &ehci_data.device[dev_addr-1].control.qhd;
 }
 }
 static inline ehci_qtd_t* get_control_qtds(uint8_t dev_addr)
 static inline ehci_qtd_t* get_control_qtds(uint8_t dev_addr)
 {
 {

+ 15 - 14
tinyusb/host/usbh.c

@@ -201,13 +201,15 @@ void usbh_device_plugged_isr(uint8_t hostid, tusb_speed_t speed)
 
 
 void usbh_device_unplugged_isr(uint8_t hostid)
 void usbh_device_unplugged_isr(uint8_t hostid)
 {
 {
-  printf("%s %d\n", __FUNCTION__, __LINE__);
-
   //------------- find the device address that is unplugged -------------//
   //------------- find the device address that is unplugged -------------//
   uint8_t dev_addr=1;
   uint8_t dev_addr=1;
-  while ( dev_addr <= TUSB_CFG_HOST_DEVICE_MAX && ! (usbh_device_info_pool[dev_addr].core_id == hostid &&
-      usbh_device_info_pool[dev_addr].hub_addr == 0 &&
-      usbh_device_info_pool[dev_addr].hub_port ==0))
+  while ( dev_addr <= TUSB_CFG_HOST_DEVICE_MAX &&
+          !(usbh_device_info_pool[dev_addr].core_id  == hostid &&
+            usbh_device_info_pool[dev_addr].hub_addr == 0 &&
+            usbh_device_info_pool[dev_addr].hub_port == 0 &&
+            usbh_device_info_pool[dev_addr].status   != TUSB_DEVICE_STATUS_UNPLUG
+          )
+  )
   {
   {
     dev_addr++;
     dev_addr++;
   }
   }
@@ -370,20 +372,19 @@ OSAL_TASK_DECLARE(usbh_enumeration_task)
     if (class_code == 0)
     if (class_code == 0)
     {
     {
       TASK_ASSERT( false ); // corrupted data, abort enumeration
       TASK_ASSERT( false ); // corrupted data, abort enumeration
-    } else if ( class_code < TUSB_CLASS_MAX_CONSEC_NUMBER)
+    }
+    // supported class
+    else if ( class_code < TUSB_CLASS_MAX_CONSEC_NUMBER && usbh_class_drivers[class_code].open_subtask)
     {
     {
-      if ( usbh_class_drivers[class_code].open_subtask )
-      {
-        uint16_t length;
-        OSAL_SUBTASK_INVOKED_AND_WAIT ( // parameters in task/sub_task must be static storage (static or global)
-            usbh_class_drivers[ ((tusb_descriptor_interface_t*) p_desc)->bInterfaceClass ].open_subtask(new_addr, p_desc, &length) );
-        p_desc += length;
-      }
+      uint16_t length;
+      OSAL_SUBTASK_INVOKED_AND_WAIT ( // parameters in task/sub_task must be static storage (static or global)
+          usbh_class_drivers[ ((tusb_descriptor_interface_t*) p_desc)->bInterfaceClass ].open_subtask(new_addr, p_desc, &length) );
+      p_desc += length;
     } else // unsupported class (not enable or yet implemented)
     } else // unsupported class (not enable or yet implemented)
     {
     {
       do
       do
       {
       {
-        p_desc += (*p_desc);
+        p_desc += (*p_desc); // skip the descriptor, increase by the descriptor's length
       } while ( (p_desc < enum_data_buffer + ((tusb_descriptor_configuration_t*)enum_data_buffer)->wTotalLength)
       } while ( (p_desc < enum_data_buffer + ((tusb_descriptor_configuration_t*)enum_data_buffer)->wTotalLength)
           && TUSB_DESC_INTERFACE != p_desc[1] );
           && TUSB_DESC_INTERFACE != p_desc[1] );
     }
     }

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików