diff options
| author | Nathan Conrad <[email protected]> | 2020-04-14 10:22:03 -0400 |
|---|---|---|
| committer | Nathan Conrad <[email protected]> | 2020-04-14 10:22:03 -0400 |
| commit | 16f65890eb161e14157f3f10872218ce3c2a981b (patch) | |
| tree | c8b359f92347868898df867fcdae32bb30c9cdcb /examples/device | |
| parent | bbc59f1ceb73131b5fc2158cdd3483b61408d59d (diff) | |
| parent | 57ffa94a5251c2b28cddf63b1897282988019e4d (diff) | |
Merge branch 'master' into edpt_close
Diffstat (limited to 'examples/device')
| -rw-r--r-- | examples/device/board_test/Makefile | 6 | ||||
| -rw-r--r-- | examples/device/cdc_msc_freertos/src/main.c | 10 | ||||
| -rw-r--r-- | examples/device/net_lwip_webserver/src/main.c | 14 | ||||
| -rw-r--r-- | examples/device/net_lwip_webserver/src/tusb_config.h | 3 | ||||
| -rw-r--r-- | examples/device/net_lwip_webserver/src/usb_descriptors.c | 61 |
5 files changed, 66 insertions, 28 deletions
diff --git a/examples/device/board_test/Makefile b/examples/device/board_test/Makefile index 5a455078e..66d8571cf 100644 --- a/examples/device/board_test/Makefile +++ b/examples/device/board_test/Makefile @@ -9,4 +9,10 @@ INC += \ EXAMPLE_SOURCE += $(wildcard src/*.c) SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE)) +# board_test example is special example that doesn't enable device or host stack +# This can cause some TinyUSB API missing, this hack to allow us to fill those API +# to pass the compilation process +CFLAGS += \ + -D"tud_irq_handler(x)= " \ + include ../../rules.mk diff --git a/examples/device/cdc_msc_freertos/src/main.c b/examples/device/cdc_msc_freertos/src/main.c index f093d8ea0..a847f4915 100644 --- a/examples/device/cdc_msc_freertos/src/main.c +++ b/examples/device/cdc_msc_freertos/src/main.c @@ -56,7 +56,13 @@ StaticTimer_t blinky_tmdef; TimerHandle_t blinky_tm; // static task for usbd -#define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) +// Increase stack size when debug log is enabled +#if CFG_TUSB_DEBUG + #define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE) +#else + #define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) +#endif + StackType_t usb_device_stack[USBD_STACK_SIZE]; StaticTask_t usb_device_taskdef; @@ -194,7 +200,7 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) if ( dtr && rts ) { // print initial message when connected - tud_cdc_write_str("\r\nTinyUSB CDC MSC HID device with FreeRTOS example\r\n"); + tud_cdc_write_str("\r\nTinyUSB CDC MSC device with FreeRTOS example\r\n"); } } diff --git a/examples/device/net_lwip_webserver/src/main.c b/examples/device/net_lwip_webserver/src/main.c index fe904e8e8..26c6401e6 100644 --- a/examples/device/net_lwip_webserver/src/main.c +++ b/examples/device/net_lwip_webserver/src/main.c @@ -26,13 +26,14 @@ */ /* -depending on the value of CFG_TUD_NET (tusb_config.h), this can be a CDC-ECM, RNDIS, or CDC-EEM USB virtual network adapter +depending on the value of CFG_TUD_NET (tusb_config.h), this can be a RNDIS+CDC-ECM or CDC-EEM USB virtual network adapter -CDC-ECM should be valid on Linux and MacOS hosts -RNDIS should be valid on Linux and Windows hosts -CDC-EEM should be valid on Linux hosts +OPT_NET_RNDIS_ECM : RNDIS should be valid on Linux and Windows hosts, and CDC-ECM should be valid on Linux and MacOS hosts +OPT_NET_EEM : CDC-EEM should be valid on Linux hosts -You *must* customize tusb_config.h to set the CFG_TUD_NET definition to the type of these network adapters to emulate. +OPT_NET_RNDIS_ECM should be the best choice, as it makes for a hopefully universal solution. + +You *must* customize tusb_config.h to set the CFG_TUD_NET definition to the type of these network option. The MCU appears to the host as IP address 192.168.7.1, and provides a DHCP server, DNS server, and web server. */ @@ -43,6 +44,7 @@ The MCU appears to the host as IP address 192.168.7.1, and provides a DHCP serve #include "dhserver.h" #include "dnserver.h" #include "lwip/init.h" +#include "lwip/timeouts.h" #include "httpd.h" /* lwip context */ @@ -167,6 +169,8 @@ static void service_traffic(void) received_frame = NULL; tud_network_recv_renew(); } + + sys_check_timeouts(); } void tud_network_init_cb(void) diff --git a/examples/device/net_lwip_webserver/src/tusb_config.h b/examples/device/net_lwip_webserver/src/tusb_config.h index 0b40fefab..d8c750d5c 100644 --- a/examples/device/net_lwip_webserver/src/tusb_config.h +++ b/examples/device/net_lwip_webserver/src/tusb_config.h @@ -79,8 +79,7 @@ #define CFG_TUD_HID 0 #define CFG_TUD_MIDI 0 #define CFG_TUD_VENDOR 0 -//#define CFG_TUD_NET OPT_NET_ECM -#define CFG_TUD_NET OPT_NET_RNDIS +#define CFG_TUD_NET OPT_NET_RNDIS_ECM //#define CFG_TUD_NET OPT_NET_EEM #ifdef __cplusplus diff --git a/examples/device/net_lwip_webserver/src/usb_descriptors.c b/examples/device/net_lwip_webserver/src/usb_descriptors.c index 6ce36cfef..39c542eca 100644 --- a/examples/device/net_lwip_webserver/src/usb_descriptors.c +++ b/examples/device/net_lwip_webserver/src/usb_descriptors.c @@ -63,13 +63,17 @@ tusb_desc_device_t const desc_device = .idVendor = 0xCafe, .idProduct = USB_PID, - .bcdDevice = 0x0100, + .bcdDevice = 0x0101, .iManufacturer = STRID_MANUFACTURER, .iProduct = STRID_PRODUCT, .iSerialNumber = STRID_SERIAL, +#if CFG_TUD_NET == OPT_NET_EEM .bNumConfigurations = 0x01 +#else + .bNumConfigurations = 0x02 +#endif }; // Invoked when received GET DEVICE DESCRIPTOR @@ -85,16 +89,23 @@ uint8_t const * tud_descriptor_device_cb(void) enum { ITF_NUM_CDC = 0, +#if CFG_TUD_NET == OPT_NET_RNDIS_ECM ITF_NUM_CDC_DATA, +#endif ITF_NUM_TOTAL }; -#if CFG_TUD_NET == OPT_NET_ECM - #define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_ECM_DESC_LEN) -#elif CFG_TUD_NET == OPT_NET_RNDIS - #define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_RNDIS_DESC_LEN) -#elif CFG_TUD_NET == OPT_NET_EEM - #define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_EEM_DESC_LEN) +enum +{ + CONFIG_NUM_DEFAULT = 1, + CONFIG_NUM_ALTERNATE = 2, +}; + +#if CFG_TUD_NET == OPT_NET_EEM + #define MAIN_CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_EEM_DESC_LEN) +#else + #define MAIN_CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_RNDIS_DESC_LEN) + #define ALT_CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_ECM_DESC_LEN) #endif #if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX @@ -105,30 +116,42 @@ enum #define EPNUM_CDC 2 #endif -uint8_t const desc_configuration[] = +static uint8_t const main_configuration[] = { // Config number, interface count, string index, total length, attribute, power in mA - TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0, 100), + TUD_CONFIG_DESCRIPTOR(CONFIG_NUM_DEFAULT, ITF_NUM_TOTAL, 0, MAIN_CONFIG_TOTAL_LEN, 0, 100), -#if CFG_TUD_NET == OPT_NET_ECM - // Interface number, description string index, MAC address string index, EP notification address and size, EP data address (out, in), and size, max segment size. - TUD_CDC_ECM_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, STRID_MAC, 0x81, 64, EPNUM_CDC, 0x80 | EPNUM_CDC, CFG_TUD_NET_ENDPOINT_SIZE, CFG_TUD_NET_MTU), -#elif CFG_TUD_NET == OPT_NET_RNDIS - // Interface number, string index, EP notification address and size, EP data address (out, in) and size. - TUD_RNDIS_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, 0x81, 8, EPNUM_CDC, 0x80 | EPNUM_CDC, CFG_TUD_NET_ENDPOINT_SIZE), -#elif CFG_TUD_NET == OPT_NET_EEM +#if CFG_TUD_NET == OPT_NET_EEM // Interface number, description string index, EP data address (out, in) and size. TUD_CDC_EEM_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, EPNUM_CDC, 0x80 | EPNUM_CDC, CFG_TUD_NET_ENDPOINT_SIZE), +#else + // Interface number, string index, EP notification address and size, EP data address (out, in) and size. + TUD_RNDIS_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, 0x81, 8, EPNUM_CDC, 0x80 | EPNUM_CDC, CFG_TUD_NET_ENDPOINT_SIZE), #endif }; +#if CFG_TUD_NET == OPT_NET_RNDIS_ECM +static uint8_t const alt_configuration[] = +{ + // Config number, interface count, string index, total length, attribute, power in mA + TUD_CONFIG_DESCRIPTOR(CONFIG_NUM_ALTERNATE, ITF_NUM_TOTAL, 0, ALT_CONFIG_TOTAL_LEN, 0, 100), + + // Interface number, description string index, MAC address string index, EP notification address and size, EP data address (out, in), and size, max segment size. + TUD_CDC_ECM_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, STRID_MAC, 0x81, 64, EPNUM_CDC, 0x80 | EPNUM_CDC, CFG_TUD_NET_ENDPOINT_SIZE, CFG_TUD_NET_MTU), +}; +#endif + // Invoked when received GET CONFIGURATION DESCRIPTOR // Application return pointer to descriptor // Descriptor contents must exist long enough for transfer to complete uint8_t const * tud_descriptor_configuration_cb(uint8_t index) { +#if CFG_TUD_NET == OPT_NET_EEM (void) index; // for multiple configurations - return desc_configuration; + return main_configuration; +#else + return (0 == index) ? main_configuration : alt_configuration; +#endif } //--------------------------------------------------------------------+ @@ -141,8 +164,8 @@ static char const* string_desc_arr [] = [STRID_LANGID] = (const char[]) { 0x09, 0x04 }, // supported language is English (0x0409) [STRID_MANUFACTURER] = "TinyUSB", // Manufacturer [STRID_PRODUCT] = "TinyUSB Device", // Product - [STRID_SERIAL] = "123456", // Serials - [STRID_INTERFACE] = "TinyUSB Network Interface" // CDC-ECM Interface + [STRID_SERIAL] = "123456", // Serial + [STRID_INTERFACE] = "TinyUSB Network Interface" // Interface Description // STRID_MAC index is handled separately }; |
