Răsfoiți Sursa

suppress null-dereference by usbh and lwip

hathach 4 ani în urmă
părinte
comite
6fcf4bee8c

+ 3 - 0
examples/device/net_lwip_webserver/Makefile

@@ -7,6 +7,9 @@ CFLAGS += \
   -DPBUF_POOL_SIZE=2 \
   -DPBUF_POOL_SIZE=2 \
   -DTCP_WND=2*TCP_MSS \
   -DTCP_WND=2*TCP_MSS \
   -DHTTPD_USE_CUSTOM_FSDATA=0
   -DHTTPD_USE_CUSTOM_FSDATA=0
+  
+# suppress warning caused by lwip
+CFLAGS += -Wno-error=null-dereference
 
 
 INC += \
 INC += \
   src \
   src \

+ 2 - 1
examples/host/cdc_msc_hid/Makefile

@@ -9,7 +9,8 @@ INC += \
 EXAMPLE_SOURCE += $(wildcard src/*.c)
 EXAMPLE_SOURCE += $(wildcard src/*.c)
 SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
 SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
 
 
-CFLAGS += -Wno-error=cast-align
+# TODO: suppress warning caused by host stack
+CFLAGS += -Wno-error=cast-align -Wno-error=null-dereference
 
 
 # TinyUSB Host Stack source
 # TinyUSB Host Stack source
 SRC_C += \
 SRC_C += \

+ 2 - 1
examples/host/hid_controller/Makefile

@@ -12,7 +12,8 @@ EXAMPLE_SOURCE += \
 	
 	
 SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
 SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
 
 
-CFLAGS += -Wno-error=cast-align
+# TODO: suppress warning caused by host stack
+CFLAGS += -Wno-error=cast-align -Wno-error=null-dereference
 
 
 # TinyUSB Host Stack source
 # TinyUSB Host Stack source
 SRC_C += \
 SRC_C += \

+ 27 - 19
src/host/usbh.c

@@ -53,13 +53,39 @@
 // USBH-HCD common data structure
 // USBH-HCD common data structure
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 
 
+// device0 struct must be strictly a subset of normal device struct
+typedef struct
+{
+  // port
+  uint8_t rhport;
+  uint8_t hub_addr;
+  uint8_t hub_port;
+  uint8_t speed;
+
+  volatile struct TU_ATTR_PACKED
+  {
+    uint8_t connected    : 1;
+    uint8_t addressed    : 1;
+    uint8_t configured   : 1;
+    uint8_t suspended    : 1;
+  };
+} usbh_dev0_t;
+
 typedef struct {
 typedef struct {
-  //------------- port -------------//
+  // port
   uint8_t rhport;
   uint8_t rhport;
   uint8_t hub_addr;
   uint8_t hub_addr;
   uint8_t hub_port;
   uint8_t hub_port;
   uint8_t speed;
   uint8_t speed;
 
 
+  volatile struct TU_ATTR_PACKED
+  {
+    uint8_t connected    : 1;
+    uint8_t addressed    : 1;
+    uint8_t configured   : 1;
+    uint8_t suspended    : 1;
+  };
+
   //------------- device descriptor -------------//
   //------------- device descriptor -------------//
   uint16_t vid;
   uint16_t vid;
   uint16_t pid;
   uint16_t pid;
@@ -73,14 +99,6 @@ typedef struct {
   // uint8_t interface_count; // bNumInterfaces alias
   // uint8_t interface_count; // bNumInterfaces alias
 
 
   //------------- device -------------//
   //------------- device -------------//
-  struct TU_ATTR_PACKED
-  {
-    uint8_t connected    : 1;
-    uint8_t addressed    : 1;
-    uint8_t configured   : 1;
-    uint8_t suspended    : 1;
-  };
-
   volatile uint8_t state;            // device state, value from enum tusbh_device_state_t
   volatile uint8_t state;            // device state, value from enum tusbh_device_state_t
 
 
   uint8_t itf2drv[16];               // map interface number to driver (0xff is invalid)
   uint8_t itf2drv[16];               // map interface number to driver (0xff is invalid)
@@ -103,16 +121,6 @@ typedef struct {
 
 
 } usbh_device_t;
 } usbh_device_t;
 
 
-typedef struct
-{
-  uint8_t rhport;
-  uint8_t hub_addr;
-  uint8_t hub_port;
-  uint8_t speed;
-
-  volatile uint8_t connected;
-} usbh_dev0_t;
-
 
 
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // MACRO CONSTANT TYPEDEF
 // MACRO CONSTANT TYPEDEF