Merge branch 'master' into edpt_close

This commit is contained in:
Nathan Conrad
2020-04-14 10:22:03 -04:00
94 changed files with 1013 additions and 403 deletions
+15 -1
View File
@@ -1,4 +1,18 @@
# TinyUSB changelog # TinyUSB Changelog
## Master branch (WIP)
### Breaking
- TinyUSB does not directly implement USB IRQ Handler function anymore. Application must implement IRQ Handler and invoke `tud_irq_handler(rhport)`. This is due to:
- IRQ Handler name can be different across system depending on the startup
- Some OS need to execute enterISR()/exitISR() to work properly, also tracing tool may need to insert trace ISR enter/exit to record usb event
- Give application full control of IRQ handler, can be useful e.g signaling there is new usb event without constant polling
### MCU
- All default IRQ Handler is renamed to `dcd_irq_handler()`
## 0.6.0 - 2019.03.30 ## 0.6.0 - 2019.03.30
+17 -2
View File
@@ -60,24 +60,38 @@ All of the code for the low-level device API is in `src/portable/<vendor>/<chip
#### Device Setup #### Device Setup
##### dcd_init ##### dcd_init
Initializes the USB peripheral for device mode and enables it.
#### dcd_int_enable / dcd_int_disable Initializes the USB peripheral for device mode and enables it.
This function should leave an internal D+/D- pull-up in its default power-on state. `dcd_connect` will be called by the USBD core following `dcd_init`.
##### dcd_int_enable / dcd_int_disable
Enables or disables the USB device interrupt(s). May be used to prevent concurrency issues when mutating data structures shared between main code and the interrupt handler. Enables or disables the USB device interrupt(s). May be used to prevent concurrency issues when mutating data structures shared between main code and the interrupt handler.
##### dcd_irq_handler
Processes all the hardware generated events e.g Bus reset, new data packet from host etc ... It will be called by application in the MCU USB interrupt handler.
##### dcd_set_address ##### dcd_set_address
Called when the device is given a new bus address. Called when the device is given a new bus address.
If your peripheral automatically changes address during enumeration (like the nrf52) you may leave this empty and also no queue an event for the corresponding SETUP packet. If your peripheral automatically changes address during enumeration (like the nrf52) you may leave this empty and also no queue an event for the corresponding SETUP packet.
##### dcd_set_config ##### dcd_set_config
Called when the device received SET_CONFIG request, you can leave this empty if your peripheral does not require any specific action. Called when the device received SET_CONFIG request, you can leave this empty if your peripheral does not require any specific action.
##### dcd_remote_wakeup ##### dcd_remote_wakeup
Called to remote wake up host when suspended (e.g hid keyboard) Called to remote wake up host when suspended (e.g hid keyboard)
##### dcd_connect / dcd_disconnect
Connect or disconnect the data-line pull-up resistor. Define only if MCU has an internal pull-up. (BSP may define for MCU without internal pull-up.)
#### Special events #### Special events
You must let TinyUSB know when certain events occur so that it can continue its work. There are a few methods you can call to queue events for TinyUSB to process. You must let TinyUSB know when certain events occur so that it can continue its work. There are a few methods you can call to queue events for TinyUSB to process.
##### dcd_event_bus_signal ##### dcd_event_bus_signal
@@ -96,6 +110,7 @@ The first `0` is the USB peripheral number. Statically saying 0 is common for si
The `true` indicates the call is from an interrupt handler and will always be the case when porting in this way. The `true` indicates the call is from an interrupt handler and will always be the case when porting in this way.
##### dcd_setup_received ##### dcd_setup_received
SETUP packets are a special type of transaction that can occur at any time on the control endpoint, numbered `0`. Since they are unique, most peripherals have special handling for them. Their data is always 8 bytes in length as well. SETUP packets are a special type of transaction that can occur at any time on the control endpoint, numbered `0`. Since they are unique, most peripherals have special handling for them. Their data is always 8 bytes in length as well.
Calls to this look like: Calls to this look like:
+6
View File
@@ -9,4 +9,10 @@ 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))
# 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 include ../../rules.mk
+8 -2
View File
@@ -56,7 +56,13 @@ StaticTimer_t blinky_tmdef;
TimerHandle_t blinky_tm; TimerHandle_t blinky_tm;
// static task for usbd // 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]; StackType_t usb_device_stack[USBD_STACK_SIZE];
StaticTask_t usb_device_taskdef; 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 ) if ( dtr && rts )
{ {
// print initial message when connected // 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");
} }
} }
@@ -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 OPT_NET_RNDIS_ECM : RNDIS should be valid on Linux and Windows hosts, and CDC-ECM should be valid on Linux and MacOS hosts
RNDIS should be valid on Linux and Windows hosts OPT_NET_EEM : CDC-EEM should be valid on Linux hosts
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. 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 "dhserver.h"
#include "dnserver.h" #include "dnserver.h"
#include "lwip/init.h" #include "lwip/init.h"
#include "lwip/timeouts.h"
#include "httpd.h" #include "httpd.h"
/* lwip context */ /* lwip context */
@@ -167,6 +169,8 @@ static void service_traffic(void)
received_frame = NULL; received_frame = NULL;
tud_network_recv_renew(); tud_network_recv_renew();
} }
sys_check_timeouts();
} }
void tud_network_init_cb(void) void tud_network_init_cb(void)
@@ -79,8 +79,7 @@
#define CFG_TUD_HID 0 #define CFG_TUD_HID 0
#define CFG_TUD_MIDI 0 #define CFG_TUD_MIDI 0
#define CFG_TUD_VENDOR 0 #define CFG_TUD_VENDOR 0
//#define CFG_TUD_NET OPT_NET_ECM #define CFG_TUD_NET OPT_NET_RNDIS_ECM
#define CFG_TUD_NET OPT_NET_RNDIS
//#define CFG_TUD_NET OPT_NET_EEM //#define CFG_TUD_NET OPT_NET_EEM
#ifdef __cplusplus #ifdef __cplusplus
@@ -63,13 +63,17 @@ tusb_desc_device_t const desc_device =
.idVendor = 0xCafe, .idVendor = 0xCafe,
.idProduct = USB_PID, .idProduct = USB_PID,
.bcdDevice = 0x0100, .bcdDevice = 0x0101,
.iManufacturer = STRID_MANUFACTURER, .iManufacturer = STRID_MANUFACTURER,
.iProduct = STRID_PRODUCT, .iProduct = STRID_PRODUCT,
.iSerialNumber = STRID_SERIAL, .iSerialNumber = STRID_SERIAL,
#if CFG_TUD_NET == OPT_NET_EEM
.bNumConfigurations = 0x01 .bNumConfigurations = 0x01
#else
.bNumConfigurations = 0x02
#endif
}; };
// Invoked when received GET DEVICE DESCRIPTOR // Invoked when received GET DEVICE DESCRIPTOR
@@ -85,16 +89,23 @@ uint8_t const * tud_descriptor_device_cb(void)
enum enum
{ {
ITF_NUM_CDC = 0, ITF_NUM_CDC = 0,
#if CFG_TUD_NET == OPT_NET_RNDIS_ECM
ITF_NUM_CDC_DATA, ITF_NUM_CDC_DATA,
#endif
ITF_NUM_TOTAL ITF_NUM_TOTAL
}; };
#if CFG_TUD_NET == OPT_NET_ECM enum
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_ECM_DESC_LEN) {
#elif CFG_TUD_NET == OPT_NET_RNDIS CONFIG_NUM_DEFAULT = 1,
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_RNDIS_DESC_LEN) CONFIG_NUM_ALTERNATE = 2,
#elif CFG_TUD_NET == OPT_NET_EEM };
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_EEM_DESC_LEN)
#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 #endif
#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX #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 #define EPNUM_CDC 2
#endif #endif
uint8_t const desc_configuration[] = static uint8_t const main_configuration[] =
{ {
// Config number, interface count, string index, total length, attribute, power in mA // 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 #if CFG_TUD_NET == OPT_NET_EEM
// 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
// Interface number, description string index, EP data address (out, in) and size. // 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), 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 #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 // Invoked when received GET CONFIGURATION DESCRIPTOR
// Application return pointer to descriptor // Application return pointer to descriptor
// Descriptor contents must exist long enough for transfer to complete // Descriptor contents must exist long enough for transfer to complete
uint8_t const * tud_descriptor_configuration_cb(uint8_t index) uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
{ {
#if CFG_TUD_NET == OPT_NET_EEM
(void) index; // for multiple configurations (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_LANGID] = (const char[]) { 0x09, 0x04 }, // supported language is English (0x0409)
[STRID_MANUFACTURER] = "TinyUSB", // Manufacturer [STRID_MANUFACTURER] = "TinyUSB", // Manufacturer
[STRID_PRODUCT] = "TinyUSB Device", // Product [STRID_PRODUCT] = "TinyUSB Device", // Product
[STRID_SERIAL] = "123456", // Serials [STRID_SERIAL] = "123456", // Serial
[STRID_INTERFACE] = "TinyUSB Network Interface" // CDC-ECM Interface [STRID_INTERFACE] = "TinyUSB Network Interface" // Interface Description
// STRID_MAC index is handled separately // STRID_MAC index is handled separately
}; };
+11 -3
View File
@@ -35,9 +35,17 @@
#include "nrf_soc.h" #include "nrf_soc.h"
#endif #endif
/*------------------------------------------------------------------*/ //--------------------------------------------------------------------+
/* MACRO TYPEDEF CONSTANT ENUM // Forward USB interrupt events to TinyUSB IRQ Handler
*------------------------------------------------------------------*/ //--------------------------------------------------------------------+
void USBD_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define _PINNUM(port, pin) ((port)*32 + (pin)) #define _PINNUM(port, pin) ((port)*32 + (pin))
#define LED_PIN _PINNUM(1, 1) #define LED_PIN _PINNUM(1, 1)
@@ -36,6 +36,14 @@
#include "nrf_soc.h" #include "nrf_soc.h"
#endif #endif
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USBD_IRQHandler(void)
{
tud_irq_handler(0);
}
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
/* MACRO TYPEDEF CONSTANT ENUM /* MACRO TYPEDEF CONSTANT ENUM
*------------------------------------------------------------------*/ *------------------------------------------------------------------*/
@@ -35,6 +35,14 @@
#include "nrf_soc.h" #include "nrf_soc.h"
#endif #endif
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USBD_IRQHandler(void)
{
tud_irq_handler(0);
}
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
/* MACRO TYPEDEF CONSTANT ENUM /* MACRO TYPEDEF CONSTANT ENUM
*------------------------------------------------------------------*/ *------------------------------------------------------------------*/
@@ -35,6 +35,14 @@
#include "hpl_pm_config.h" #include "hpl_pm_config.h"
#include "hpl/pm/hpl_pm_base.h" #include "hpl/pm/hpl_pm_base.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_Handler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION // MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@@ -134,6 +142,7 @@ int board_uart_write(void const * buf, int len)
} }
#if CFG_TUSB_OS == OPT_OS_NONE #if CFG_TUSB_OS == OPT_OS_NONE
volatile uint32_t system_ticks = 0; volatile uint32_t system_ticks = 0;
void SysTick_Handler (void) void SysTick_Handler (void)
{ {
@@ -144,4 +153,5 @@ uint32_t board_millis(void)
{ {
return system_ticks; return system_ticks;
} }
#endif #endif
+17 -15
View File
@@ -27,6 +27,23 @@
#include "chip.h" #include "chip.h"
#include "../board.h" #include "../board.h"
//--------------------------------------------------------------------+
// USB Interrupt Handler
//--------------------------------------------------------------------+
void USB_IRQHandler(void)
{
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
tuh_isr(0);
#endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_irq_handler(0);
#endif
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
#define LED_PORT 2 #define LED_PORT 2
#define LED_PIN 19 #define LED_PIN 19
@@ -113,21 +130,6 @@ void board_init(void)
LPC_USB->StCtrl = 0x3; LPC_USB->StCtrl = 0x3;
} }
//--------------------------------------------------------------------+
// USB Interrupt Handler
//--------------------------------------------------------------------+
void USB_IRQHandler(void)
{
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
tuh_isr(0);
#endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_isr(0);
#endif
}
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Board porting API // Board porting API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
+2 -2
View File
@@ -240,7 +240,7 @@ void USB0_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_isr(0); tud_irq_handler(0);
#endif #endif
} }
@@ -251,7 +251,7 @@ void USB1_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE
tud_isr(1); tud_irq_handler(1);
#endif #endif
} }
@@ -35,6 +35,14 @@
#include "hpl_pm_config.h" #include "hpl_pm_config.h"
#include "hpl/pm/hpl_pm_base.h" #include "hpl/pm/hpl_pm_base.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_Handler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION // MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@@ -32,6 +32,29 @@
#include "hpl/gclk/hpl_gclk_base.h" #include "hpl/gclk/hpl_gclk_base.h"
#include "hpl_mclk_config.h" #include "hpl_mclk_config.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_0_Handler (void)
{
tud_irq_handler(0);
}
void USB_1_Handler (void)
{
tud_irq_handler(0);
}
void USB_2_Handler (void)
{
tud_irq_handler(0);
}
void USB_3_Handler (void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION // MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@@ -36,6 +36,14 @@
#include "nrf_soc.h" #include "nrf_soc.h"
#endif #endif
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USBD_IRQHandler(void)
{
tud_irq_handler(0);
}
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
/* MACRO TYPEDEF CONSTANT ENUM /* MACRO TYPEDEF CONSTANT ENUM
*------------------------------------------------------------------*/ *------------------------------------------------------------------*/
@@ -92,6 +100,7 @@ void board_init(void)
nrfx_uarte_init(&_uart_id, &uart_cfg, NULL); //uart_handler); nrfx_uarte_init(&_uart_id, &uart_cfg, NULL); //uart_handler);
//------------- USB -------------//
#if TUSB_OPT_DEVICE_ENABLED #if TUSB_OPT_DEVICE_ENABLED
// Priorities 0, 1, 4 (nRF52) are reserved for SoftDevice // Priorities 0, 1, 4 (nRF52) are reserved for SoftDevice
// 2 is highest for application // 2 is highest for application
@@ -35,6 +35,14 @@
#include "nrf_soc.h" #include "nrf_soc.h"
#endif #endif
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USBD_IRQHandler(void)
{
tud_irq_handler(0);
}
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
/* MACRO TYPEDEF CONSTANT ENUM /* MACRO TYPEDEF CONSTANT ENUM
*------------------------------------------------------------------*/ *------------------------------------------------------------------*/
@@ -29,6 +29,18 @@
#include "stm32f4xx.h" #include "stm32f4xx.h"
#include "stm32f4xx_hal_conf.h" #include "stm32f4xx_hal_conf.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void OTG_FS_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
// Blue LED is chosen because the other LEDs are connected to ST-LINK lines. // Blue LED is chosen because the other LEDs are connected to ST-LINK lines.
#define LED_PORT GPIOC #define LED_PORT GPIOC
#define LED_PIN GPIO_PIN_1 #define LED_PIN GPIO_PIN_1
-5
View File
@@ -14,11 +14,6 @@ BSP_DIR = hw/bsp/fomu
# All source paths should be relative to the top level. # All source paths should be relative to the top level.
LD_FILE = hw/bsp/$(BOARD)/fomu.ld LD_FILE = hw/bsp/$(BOARD)/fomu.ld
# TODO remove later
SRC_C += src/portable/$(VENDOR)/$(CHIP_FAMILY)/hal_$(CHIP_FAMILY).c
SRC_C +=
SRC_S += hw/bsp/fomu/crt0-vexriscv.S SRC_S += hw/bsp/fomu/crt0-vexriscv.S
INC += \ INC += \
+3 -5
View File
@@ -26,7 +26,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "common/tusb_common.h" #include "../board.h"
#include "csr.h" #include "csr.h"
#include "irq.h" #include "irq.h"
@@ -34,8 +34,6 @@
// Board porting API // Board porting API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void hal_dcd_isr(uint8_t rhport);
void fomu_error(uint32_t line) void fomu_error(uint32_t line)
{ {
(void)line; (void)line;
@@ -65,7 +63,7 @@ void isr(void)
#if CFG_TUSB_RHPORT0_MODE == OPT_MODE_DEVICE #if CFG_TUSB_RHPORT0_MODE == OPT_MODE_DEVICE
if (irqs & (1 << USB_INTERRUPT)) { if (irqs & (1 << USB_INTERRUPT)) {
hal_dcd_isr(0); tud_irq_handler(0);
} }
#endif #endif
if (irqs & (1 << TIMER0_INTERRUPT)) { if (irqs & (1 << TIMER0_INTERRUPT)) {
@@ -114,4 +112,4 @@ uint32_t board_millis(void)
{ {
return system_ticks; return system_ticks;
} }
#endif #endif
+8
View File
@@ -35,6 +35,14 @@
#include "hpl_pm_config.h" #include "hpl_pm_config.h"
#include "hpl/pm/hpl_pm_base.h" #include "hpl/pm/hpl_pm_base.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_Handler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION // MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
+23
View File
@@ -32,6 +32,29 @@
#include "hpl/gclk/hpl_gclk_base.h" #include "hpl/gclk/hpl_gclk_base.h"
#include "hpl_mclk_config.h" #include "hpl_mclk_config.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_0_Handler (void)
{
tud_irq_handler(0);
}
void USB_1_Handler (void)
{
tud_irq_handler(0);
}
void USB_2_Handler (void)
{
tud_irq_handler(0);
}
void USB_3_Handler (void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION // MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
+11
View File
@@ -27,6 +27,17 @@
#include "chip.h" #include "chip.h"
#include "../board.h" #include "../board.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_IRQHandler(void)
{
tud_irq_handler(0);
}
//---------------------------------------------------------------- ----+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT 1 #define LED_PORT 1
#define LED_PIN 24 #define LED_PIN 24
#define LED_STATE_ON 0 #define LED_STATE_ON 0
+11
View File
@@ -27,6 +27,17 @@
#include "chip.h" #include "chip.h"
#include "../board.h" #include "../board.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT 2 #define LED_PORT 2
#define LED_PIN 17 #define LED_PIN 17
#define LED_STATE_ON 0 #define LED_STATE_ON 0
+11
View File
@@ -27,6 +27,17 @@
#include "chip.h" #include "chip.h"
#include "../board.h" #include "../board.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT 0 #define LED_PORT 0
#define LED_PIN 7 #define LED_PIN 7
+11
View File
@@ -27,6 +27,17 @@
#include "chip.h" #include "chip.h"
#include "../board.h" #include "../board.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT 0 #define LED_PORT 0
#define LED_PIN 25 #define LED_PIN 25
+17 -14
View File
@@ -27,6 +27,23 @@
#include "chip.h" #include "chip.h"
#include "../board.h" #include "../board.h"
//--------------------------------------------------------------------+
// USB Interrupt Handler
//--------------------------------------------------------------------+
void USB_IRQHandler(void)
{
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
tuh_isr(0);
#endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_irq_handler(0);
#endif
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT 0 #define LED_PORT 0
#define LED_PIN 22 #define LED_PIN 22
#define LED_STATE_ON 1 #define LED_STATE_ON 1
@@ -143,20 +160,6 @@ void board_init(void)
#endif #endif
} }
//--------------------------------------------------------------------+
// USB Interrupt Handler
//--------------------------------------------------------------------+
void USB_IRQHandler(void)
{
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
tuh_isr(0);
#endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_isr(0);
#endif
}
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Board porting API // Board porting API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
+11
View File
@@ -30,6 +30,17 @@
#include "fsl_power.h" #include "fsl_power.h"
#include "fsl_iocon.h" #include "fsl_iocon.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB0_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT 0 #define LED_PORT 0
#define LED_PIN 29 #define LED_PIN 29
#define LED_STATE_ON 0 #define LED_STATE_ON 0
+11
View File
@@ -30,6 +30,17 @@
#include "fsl_power.h" #include "fsl_power.h"
#include "fsl_iocon.h" #include "fsl_iocon.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB0_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT 0 #define LED_PORT 0
#define LED_PIN 29 #define LED_PIN 29
#define LED_STATE_ON 0 #define LED_STATE_ON 0
+16
View File
@@ -30,6 +30,22 @@
#include "fsl_power.h" #include "fsl_power.h"
#include "fsl_iocon.h" #include "fsl_iocon.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB0_IRQHandler(void)
{
tud_irq_handler(0);
}
void USB1_IRQHandler(void)
{
tud_irq_handler(1);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT 1 #define LED_PORT 1
#define LED_PIN 6 #define LED_PIN 6
#define LED_STATE_ON 0 #define LED_STATE_ON 0
+1 -1
View File
@@ -145,7 +145,7 @@ void USB_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_isr(0); tud_irq_handler(0);
#endif #endif
} }
+30 -27
View File
@@ -27,6 +27,35 @@
#include "chip.h" #include "chip.h"
#include "../board.h" #include "../board.h"
//--------------------------------------------------------------------+
// USB Interrupt Handler
//--------------------------------------------------------------------+
void USB0_IRQHandler(void)
{
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
tuh_isr(0);
#endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_irq_handler(0);
#endif
}
void USB1_IRQHandler(void)
{
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST
tuh_isr(1);
#endif
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE
tud_irq_handler(1);
#endif
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
// PD_10 // PD_10
#define LED_PORT 6 #define LED_PORT 6
#define LED_PIN 24 #define LED_PIN 24
@@ -35,9 +64,7 @@
#define BUTTON_PORT 2 #define BUTTON_PORT 2
#define BUTTON_PIN 0 #define BUTTON_PIN 0
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+
/* System configuration variables used by chip driver */ /* System configuration variables used by chip driver */
const uint32_t OscRateIn = 12000000; const uint32_t OscRateIn = 12000000;
const uint32_t ExtRateIn = 0; const uint32_t ExtRateIn = 0;
@@ -172,30 +199,6 @@ void board_init(void)
#endif #endif
} }
//--------------------------------------------------------------------+
// USB Interrupt Handler
//--------------------------------------------------------------------+
void USB0_IRQHandler(void)
{
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
tuh_isr(0);
#endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_isr(0);
#endif
}
void USB1_IRQHandler(void)
{
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_HOST
tuh_isr(1);
#endif
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE
tud_isr(1);
#endif
}
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Board porting API // Board porting API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@@ -35,6 +35,14 @@
#include "hpl_pm_config.h" #include "hpl_pm_config.h"
#include "hpl/pm/hpl_pm_base.h" #include "hpl/pm/hpl_pm_base.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_Handler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION // MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@@ -32,6 +32,29 @@
#include "hpl/gclk/hpl_gclk_base.h" #include "hpl/gclk/hpl_gclk_base.h"
#include "hpl_mclk_config.h" #include "hpl_mclk_config.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_0_Handler (void)
{
tud_irq_handler(0);
}
void USB_1_Handler (void)
{
tud_irq_handler(0);
}
void USB_2_Handler (void)
{
tud_irq_handler(0);
}
void USB_3_Handler (void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION // MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
+1 -1
View File
@@ -125,7 +125,7 @@ void USB_OTG1_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_isr(0); tud_irq_handler(0);
#endif #endif
} }
+1 -1
View File
@@ -125,7 +125,7 @@ void USB_OTG1_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_isr(0); tud_irq_handler(0);
#endif #endif
} }
+1 -1
View File
@@ -124,7 +124,7 @@ void USB_OTG1_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_isr(0); tud_irq_handler(0);
#endif #endif
} }
+2 -2
View File
@@ -128,7 +128,7 @@ void USB_OTG1_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_isr(0); tud_irq_handler(0);
#endif #endif
} }
@@ -139,7 +139,7 @@ void USB_OTG2_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE
tud_isr(1); tud_irq_handler(1);
#endif #endif
} }
+2 -2
View File
@@ -128,7 +128,7 @@ void USB_OTG1_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_isr(0); tud_irq_handler(0);
#endif #endif
} }
@@ -139,7 +139,7 @@ void USB_OTG2_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE
tud_isr(1); tud_irq_handler(1);
#endif #endif
} }
+2 -2
View File
@@ -128,7 +128,7 @@ void USB_OTG1_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_isr(0); tud_irq_handler(0);
#endif #endif
} }
@@ -139,7 +139,7 @@ void USB_OTG2_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE
tud_isr(1); tud_irq_handler(1);
#endif #endif
} }
@@ -28,6 +28,17 @@
#include "msp430.h" #include "msp430.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void __attribute__ ((interrupt(USB_UBM_VECTOR))) USB_UBM_ISR(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT P1OUT #define LED_PORT P1OUT
#define LED_PIN BIT0 #define LED_PIN BIT0
#define LED_STATE_ON 1 #define LED_STATE_ON 1
+2 -2
View File
@@ -229,7 +229,7 @@ void USB0_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_isr(0); tud_irq_handler(0);
#endif #endif
} }
@@ -240,7 +240,7 @@ void USB1_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE
tud_isr(1); tud_irq_handler(1);
#endif #endif
} }
@@ -35,6 +35,14 @@
#include "nrf_soc.h" #include "nrf_soc.h"
#endif #endif
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USBD_IRQHandler(void)
{
tud_irq_handler(0);
}
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
/* MACRO TYPEDEF CONSTANT ENUM /* MACRO TYPEDEF CONSTANT ENUM
*------------------------------------------------------------------*/ *------------------------------------------------------------------*/
+11
View File
@@ -29,6 +29,17 @@
#include "clk.h" #include "clk.h"
#include "sys.h" #include "sys.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USBD_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT PB #define LED_PORT PB
#define LED_PIN 4 #define LED_PIN 4
#define LED_PIN_IO PB4 #define LED_PIN_IO PB4
+11
View File
@@ -29,6 +29,17 @@
#include "clk.h" #include "clk.h"
#include "sys.h" #include "sys.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USBD_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT PB #define LED_PORT PB
#define LED_PIN 4 #define LED_PIN 4
#define LED_PIN_IO PB4 #define LED_PIN_IO PB4
+12
View File
@@ -29,6 +29,18 @@
#include "clk.h" #include "clk.h"
#include "sys.h" #include "sys.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USBD_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT PC #define LED_PORT PC
#define LED_PIN 9 #define LED_PIN 9
#define LED_PIN_IO PC9 #define LED_PIN_IO PC9
@@ -29,6 +29,17 @@
#include "clk.h" #include "clk.h"
#include "sys.h" #include "sys.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USBD_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT PB #define LED_PORT PB
#define LED_PIN 0 #define LED_PIN 0
#define LED_PIN_IO PB0 #define LED_PIN_IO PB0
@@ -27,6 +27,17 @@
#include "bsp/board.h" #include "bsp/board.h"
#include "NUC505Series.h" #include "NUC505Series.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USBD_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT PC #define LED_PORT PC
#define LED_PIN 3 #define LED_PIN 3
#define LED_STATE_ON 0 #define LED_STATE_ON 0
+8
View File
@@ -36,6 +36,14 @@
#include "nrf_soc.h" #include "nrf_soc.h"
#endif #endif
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USBD_IRQHandler(void)
{
tud_irq_handler(0);
}
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
/* MACRO TYPEDEF CONSTANT ENUM /* MACRO TYPEDEF CONSTANT ENUM
*------------------------------------------------------------------*/ *------------------------------------------------------------------*/
+8
View File
@@ -35,6 +35,14 @@
#include "nrf_soc.h" #include "nrf_soc.h"
#endif #endif
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USBD_IRQHandler(void)
{
tud_irq_handler(0);
}
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
/* MACRO TYPEDEF CONSTANT ENUM /* MACRO TYPEDEF CONSTANT ENUM
*------------------------------------------------------------------*/ *------------------------------------------------------------------*/
+8
View File
@@ -36,6 +36,14 @@
#include "nrf_soc.h" #include "nrf_soc.h"
#endif #endif
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USBD_IRQHandler(void)
{
tud_irq_handler(0);
}
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
/* MACRO TYPEDEF CONSTANT ENUM /* MACRO TYPEDEF CONSTANT ENUM
*------------------------------------------------------------------*/ *------------------------------------------------------------------*/
+12
View File
@@ -29,6 +29,18 @@
#include "stm32f4xx.h" #include "stm32f4xx.h"
#include "stm32f4xx_hal_conf.h" #include "stm32f4xx_hal_conf.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void OTG_FS_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
// Blue LED is chosen because the other LEDs are connected to ST-LINK lines. // Blue LED is chosen because the other LEDs are connected to ST-LINK lines.
#define LED_PORT GPIOB #define LED_PORT GPIOB
#define LED_PIN GPIO_PIN_4 #define LED_PIN GPIO_PIN_4
@@ -35,6 +35,14 @@
#include "nrf_soc.h" #include "nrf_soc.h"
#endif #endif
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USBD_IRQHandler(void)
{
tud_irq_handler(0);
}
/*------------------------------------------------------------------*/ /*------------------------------------------------------------------*/
/* MACRO TYPEDEF CONSTANT ENUM /* MACRO TYPEDEF CONSTANT ENUM
*------------------------------------------------------------------*/ *------------------------------------------------------------------*/
+1 -1
View File
@@ -100,7 +100,7 @@ void board_init(void)
void UDP_Handler(void) void UDP_Handler(void)
{ {
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_isr(0); tud_irq_handler(0);
#endif #endif
} }
+8
View File
@@ -35,6 +35,14 @@
#include "hpl_pm_config.h" #include "hpl_pm_config.h"
#include "hpl/pm/hpl_pm_base.h" #include "hpl/pm/hpl_pm_base.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_Handler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION // MACRO TYPEDEF CONSTANT ENUM DECLARATION
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
+11 -3
View File
@@ -25,9 +25,19 @@
*/ */
#include "../board.h" #include "../board.h"
#include "stm32f0xx_hal.h" #include "stm32f0xx_hal.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT GPIOA #define LED_PORT GPIOA
#define LED_PIN GPIO_PIN_5 #define LED_PIN GPIO_PIN_5
#define LED_STATE_ON 1 #define LED_STATE_ON 1
@@ -56,8 +66,6 @@ static void all_rcc_clk_enable(void)
void board_init(void) void board_init(void)
{ {
/* Configure the system clock to 48 MHz */ /* Configure the system clock to 48 MHz */
RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct;
+11 -1
View File
@@ -25,9 +25,19 @@
*/ */
#include "../board.h" #include "../board.h"
#include "stm32f0xx_hal.h" #include "stm32f0xx_hal.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT GPIOC #define LED_PORT GPIOC
#define LED_PIN GPIO_PIN_6 #define LED_PIN GPIO_PIN_6
#define LED_STATE_ON 1 #define LED_STATE_ON 1
+21 -1
View File
@@ -25,9 +25,29 @@
*/ */
#include "../board.h" #include "../board.h"
#include "stm32f1xx_hal.h" #include "stm32f1xx_hal.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_HP_IRQHandler(void)
{
tud_irq_handler(0);
}
void USB_LP_IRQHandler(void)
{
tud_irq_handler(0);
}
void USBWakeUp_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT GPIOC #define LED_PORT GPIOC
#define LED_PIN GPIO_PIN_13 #define LED_PIN GPIO_PIN_13
#define LED_STATE_ON 0 #define LED_STATE_ON 0
+12
View File
@@ -28,6 +28,18 @@
#include "stm32f2xx_hal.h" #include "stm32f2xx_hal.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void OTG_FS_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT GPIOB #define LED_PORT GPIOB
#define LED_PIN GPIO_PIN_14 #define LED_PIN GPIO_PIN_14
#define LED_STATE_ON 1 #define LED_STATE_ON 1
+33 -1
View File
@@ -25,9 +25,41 @@
*/ */
#include "../board.h" #include "../board.h"
#include "stm32f3xx_hal.h" #include "stm32f3xx_hal.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
// USB defaults to using interrupts 19, 20, and 42 (based on SYSCFG_CFGR1.USB_IT_RMP)
// FIXME: Do all three need to be handled, or just the LP one?
// USB high-priority interrupt (Channel 19): Triggered only by a correct
// transfer event for isochronous and double-buffer bulk transfer to reach
// the highest possible transfer rate.
void USB_HP_CAN_TX_IRQHandler(void)
{
tud_irq_handler(0);
}
// USB low-priority interrupt (Channel 20): Triggered by all USB events
// (Correct transfer, USB reset, etc.). The firmware has to check the
// interrupt source before serving the interrupt.
void USB_LP_CAN_RX0_IRQHandler(void)
{
tud_irq_handler(0);
}
// USB wakeup interrupt (Channel 42): Triggered by the wakeup event from the USB
// Suspend mode.
void USBWakeUp_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT GPIOE #define LED_PORT GPIOE
#define LED_PIN GPIO_PIN_9 #define LED_PIN GPIO_PIN_9
#define LED_STATE_ON 1 #define LED_STATE_ON 1
@@ -29,6 +29,18 @@
#include "stm32f4xx.h" #include "stm32f4xx.h"
#include "stm32f4xx_hal_conf.h" #include "stm32f4xx_hal_conf.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void OTG_FS_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT GPIOC #define LED_PORT GPIOC
#define LED_PIN GPIO_PIN_13 #define LED_PIN GPIO_PIN_13
#define LED_STATE_ON 1 #define LED_STATE_ON 1
+12
View File
@@ -28,6 +28,18 @@
#include "stm32f4xx_hal.h" #include "stm32f4xx_hal.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void OTG_FS_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT GPIOD #define LED_PORT GPIOD
#define LED_PIN GPIO_PIN_14 #define LED_PIN GPIO_PIN_14
#define LED_STATE_ON 1 #define LED_STATE_ON 1
@@ -28,6 +28,18 @@
#include "stm32f4xx_hal.h" #include "stm32f4xx_hal.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void OTG_FS_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT GPIOC #define LED_PORT GPIOC
#define LED_PIN GPIO_PIN_13 #define LED_PIN GPIO_PIN_13
#define LED_STATE_ON 1 #define LED_STATE_ON 1
+12 -1
View File
@@ -25,9 +25,20 @@
*/ */
#include "../board.h" #include "../board.h"
#include "stm32f4xx_hal.h" #include "stm32f4xx_hal.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void OTG_FS_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
// Orange LED // Orange LED
#define LED_PORT GPIOD #define LED_PORT GPIOD
#define LED_PIN GPIO_PIN_13 #define LED_PIN GPIO_PIN_13
+12
View File
@@ -28,6 +28,18 @@
#include "stm32f4xx_hal.h" #include "stm32f4xx_hal.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void OTG_FS_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT GPIOE #define LED_PORT GPIOE
#define LED_PIN GPIO_PIN_2 #define LED_PIN GPIO_PIN_2
#define LED_STATE_ON 0 #define LED_STATE_ON 0
+12
View File
@@ -29,6 +29,18 @@
#include "stm32f7xx_hal.h" #include "stm32f7xx_hal.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void OTG_FS_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT GPIOB #define LED_PORT GPIOB
#define LED_PIN GPIO_PIN_14 #define LED_PIN GPIO_PIN_14
#define LED_STATE_ON 1 #define LED_STATE_ON 1
+12
View File
@@ -29,6 +29,18 @@
#include "stm32h7xx_hal.h" #include "stm32h7xx_hal.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void OTG_FS_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT GPIOB #define LED_PORT GPIOB
#define LED_PIN GPIO_PIN_0 #define LED_PIN GPIO_PIN_0
#define LED_STATE_ON 1 #define LED_STATE_ON 1
+11 -1
View File
@@ -25,9 +25,19 @@
*/ */
#include "../board.h" #include "../board.h"
#include "stm32l0xx_hal.h" #include "stm32l0xx_hal.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT GPIOA #define LED_PORT GPIOA
#define LED_PIN GPIO_PIN_5 #define LED_PIN GPIO_PIN_5
#define LED_STATE_ON 1 #define LED_STATE_ON 1
+12
View File
@@ -28,6 +28,18 @@
#include "stm32l4xx_hal.h" #include "stm32l4xx_hal.h"
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void OTG_FS_IRQHandler(void)
{
tud_irq_handler(0);
}
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#define LED_PORT GPIOB #define LED_PORT GPIOB
#define LED_PIN GPIO_PIN_2 #define LED_PIN GPIO_PIN_2
#define LED_STATE_ON 1 #define LED_STATE_ON 1
+2 -2
View File
@@ -129,7 +129,7 @@ void USB_OTG1_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
tud_isr(0); tud_irq_handler(0);
#endif #endif
} }
@@ -140,7 +140,7 @@ void USB_OTG2_IRQHandler(void)
#endif #endif
#if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE #if CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE
tud_isr(1); tud_irq_handler(1);
#endif #endif
} }
+145 -73
View File
@@ -41,39 +41,57 @@ void rndis_class_set_handler(uint8_t *data, int size); /* found in ./misc/networ
typedef struct typedef struct
{ {
uint8_t itf_num; uint8_t itf_num;
#if CFG_TUD_NET == OPT_NET_RNDIS_ECM
uint8_t ep_notif; uint8_t ep_notif;
bool ecm_mode;
#endif
uint8_t ep_in; uint8_t ep_in;
uint8_t ep_out; uint8_t ep_out;
} netd_interface_t; } netd_interface_t;
#if CFG_TUD_NET == OPT_NET_ECM #if CFG_TUD_NET == OPT_NET_EEM
#define CFG_TUD_NET_PACKET_PREFIX_LEN 0
#define CFG_TUD_NET_PACKET_SUFFIX_LEN 0
#define CFG_TUD_NET_INTERFACESUBCLASS CDC_COMM_SUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL
#elif CFG_TUD_NET == OPT_NET_RNDIS
#define CFG_TUD_NET_PACKET_PREFIX_LEN sizeof(rndis_data_packet_t)
#define CFG_TUD_NET_PACKET_SUFFIX_LEN 0
#define CFG_TUD_NET_INTERFACESUBCLASS TUD_RNDIS_ITF_SUBCLASS
#elif CFG_TUD_NET == OPT_NET_EEM
#define CFG_TUD_NET_PACKET_PREFIX_LEN 2 #define CFG_TUD_NET_PACKET_PREFIX_LEN 2
#define CFG_TUD_NET_PACKET_SUFFIX_LEN 4 #define CFG_TUD_NET_PACKET_SUFFIX_LEN 4
#define CFG_TUD_NET_INTERFACESUBCLASS CDC_COMM_SUBCLASS_ETHERNET_EMULATION_MODEL #else
#define CFG_TUD_NET_PACKET_PREFIX_LEN sizeof(rndis_data_packet_t)
#define CFG_TUD_NET_PACKET_SUFFIX_LEN 0
#endif #endif
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t received[CFG_TUD_NET_PACKET_PREFIX_LEN + CFG_TUD_NET_MTU + CFG_TUD_NET_PACKET_PREFIX_LEN]; CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t received[CFG_TUD_NET_PACKET_PREFIX_LEN + CFG_TUD_NET_MTU + CFG_TUD_NET_PACKET_PREFIX_LEN];
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t transmitted[CFG_TUD_NET_PACKET_PREFIX_LEN + CFG_TUD_NET_MTU + CFG_TUD_NET_PACKET_PREFIX_LEN]; CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t transmitted[CFG_TUD_NET_PACKET_PREFIX_LEN + CFG_TUD_NET_MTU + CFG_TUD_NET_PACKET_PREFIX_LEN];
#if CFG_TUD_NET == OPT_NET_ECM struct ecm_notify_struct
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static tusb_control_request_t notify = {
{ tusb_control_request_t header;
.bmRequestType = 0x21, uint32_t downlink, uplink;
.bRequest = 0 /* NETWORK_CONNECTION */, };
static const struct ecm_notify_struct ecm_notify_nc =
{
.header = {
.bmRequestType = 0xA1,
.bRequest = 0 /* NETWORK_CONNECTION aka NetworkConnection */,
.wValue = 1 /* Connected */, .wValue = 1 /* Connected */,
.wLength = 0, .wLength = 0,
}; },
#elif CFG_TUD_NET == OPT_NET_RNDIS };
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t rndis_buf[120];
#endif static const struct ecm_notify_struct ecm_notify_csc =
{
.header = {
.bmRequestType = 0xA1,
.bRequest = 0x2A /* CONNECTION_SPEED_CHANGE aka ConnectionSpeedChange */,
.wLength = 8,
},
.downlink = 9728000,
.uplink = 9728000,
};
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static union
{
uint8_t rndis_buf[120];
struct ecm_notify_struct ecm_buf;
} notify;
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION // INTERNAL OBJECT & FUNCTION DECLARATION
@@ -95,7 +113,9 @@ static void do_in_xfer(uint8_t *buf, uint16_t len)
void netd_report(uint8_t *buf, uint16_t len) void netd_report(uint8_t *buf, uint16_t len)
{ {
#if CFG_TUD_NET == OPT_NET_RNDIS_ECM
usbd_edpt_xfer(TUD_OPT_RHPORT, _netd_itf.ep_notif, buf, len); usbd_edpt_xfer(TUD_OPT_RHPORT, _netd_itf.ep_notif, buf, len);
#endif
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@@ -106,6 +126,10 @@ void netd_init(void)
tu_memclr(&_netd_itf, sizeof(_netd_itf)); tu_memclr(&_netd_itf, sizeof(_netd_itf));
} }
void netd_init_data(void)
{
}
void netd_reset(uint8_t rhport) void netd_reset(uint8_t rhport)
{ {
(void) rhport; (void) rhport;
@@ -113,21 +137,26 @@ void netd_reset(uint8_t rhport)
netd_init(); netd_init();
} }
#if CFG_TUD_NET == OPT_NET_RNDIS_ECM
bool netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length) bool netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length)
{ {
// sanity check the descriptor // sanity check the descriptor
TU_ASSERT (CFG_TUD_NET_INTERFACESUBCLASS == itf_desc->bInterfaceSubClass); #if CFG_TUD_NET == OPT_NET_EEM
TU_VERIFY (CDC_COMM_SUBCLASS_ETHERNET_EMULATION_MODEL == itf_desc->bInterfaceSubClass);
#else
_netd_itf.ecm_mode = (CDC_COMM_SUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL == itf_desc->bInterfaceSubClass);
TU_VERIFY ( (TUD_RNDIS_ITF_SUBCLASS == itf_desc->bInterfaceSubClass) || _netd_itf.ecm_mode );
#endif
// confirm interface hasn't already been allocated // confirm interface hasn't already been allocated
TU_ASSERT(0 == _netd_itf.ep_in); TU_ASSERT(0 == _netd_itf.ep_notif);
//------------- first Interface -------------// //------------- Management Interface -------------//
_netd_itf.itf_num = itf_desc->bInterfaceNumber; _netd_itf.itf_num = itf_desc->bInterfaceNumber;
uint8_t const * p_desc = tu_desc_next( itf_desc ); uint8_t const * p_desc = tu_desc_next( itf_desc );
(*p_length) = sizeof(tusb_desc_interface_t); (*p_length) = sizeof(tusb_desc_interface_t);
#if CFG_TUD_NET != OPT_NET_EEM
// Communication Functional Descriptors // Communication Functional Descriptors
while ( TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) ) while ( TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) )
{ {
@@ -143,18 +172,28 @@ bool netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t
_netd_itf.ep_notif = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress; _netd_itf.ep_notif = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress;
(*p_length) += p_desc[DESC_OFFSET_LEN]; (*p_length) += p_desc[DESC_OFFSET_LEN];
p_desc = tu_desc_next(p_desc);
} }
//------------- second Interface -------------// return true;
if ( (TUSB_DESC_INTERFACE == p_desc[DESC_OFFSET_TYPE]) && }
#endif
bool netd_open_data(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length)
{
// confirm interface hasn't already been allocated
TU_ASSERT(0 == _netd_itf.ep_in);
uint8_t const * p_desc = tu_desc_next( itf_desc );
(*p_length) = sizeof(tusb_desc_interface_t);
//------------- Data Interface -------------//
while ( (TUSB_DESC_INTERFACE == p_desc[DESC_OFFSET_TYPE]) &&
(TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const *) p_desc)->bInterfaceClass) ) (TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const *) p_desc)->bInterfaceClass) )
{ {
// next to endpoint descriptor // next to endpoint descriptor
p_desc = tu_desc_next(p_desc); p_desc = tu_desc_next(p_desc);
(*p_length) += sizeof(tusb_desc_interface_t); (*p_length) += sizeof(tusb_desc_interface_t);
} }
#endif
if (TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE]) if (TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE])
{ {
@@ -184,18 +223,25 @@ bool netd_control_complete(uint8_t rhport, tusb_control_request_t const * reques
// Handle class request only // Handle class request only
TU_VERIFY (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS); TU_VERIFY (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS);
#if CFG_TUD_NET == OPT_NET_RNDIS_ECM
TU_VERIFY (_netd_itf.itf_num == request->wIndex); TU_VERIFY (_netd_itf.itf_num == request->wIndex);
#if CFG_TUD_NET == OPT_NET_RNDIS if ( !_netd_itf.ecm_mode && (request->bmRequestType_bit.direction == TUSB_DIR_OUT) )
if (request->bmRequestType_bit.direction == TUSB_DIR_OUT)
{ {
rndis_class_set_handler(rndis_buf, request->wLength); rndis_class_set_handler(notify.rndis_buf, request->wLength);
} }
#endif #endif
return true; return true;
} }
static void ecm_report(bool nc)
{
notify.ecm_buf = (nc) ? ecm_notify_nc : ecm_notify_csc;
notify.ecm_buf.header.wIndex = _netd_itf.itf_num;
netd_report((uint8_t *)&notify.ecm_buf, (nc) ? sizeof(notify.ecm_buf.header) : sizeof(notify.ecm_buf));
}
// Handle class control request // Handle class control request
// return false to stall control endpoint (e.g unsupported request) // return false to stall control endpoint (e.g unsupported request)
bool netd_control_request(uint8_t rhport, tusb_control_request_t const * request) bool netd_control_request(uint8_t rhport, tusb_control_request_t const * request)
@@ -205,28 +251,32 @@ bool netd_control_request(uint8_t rhport, tusb_control_request_t const * request
TU_VERIFY (_netd_itf.itf_num == request->wIndex); TU_VERIFY (_netd_itf.itf_num == request->wIndex);
#if CFG_TUD_NET == OPT_NET_ECM #if CFG_TUD_NET == OPT_NET_EEM
/* the only required CDC-ECM Management Element Request is SetEthernetPacketFilter */ (void)rhport;
if (0x43 /* SET_ETHERNET_PACKET_FILTER */ == request->bRequest) #else
if (_netd_itf.ecm_mode)
{ {
tud_control_xfer(rhport, request, NULL, 0); /* the only required CDC-ECM Management Element Request is SetEthernetPacketFilter */
notify.wIndex = request->wIndex; if (0x43 /* SET_ETHERNET_PACKET_FILTER */ == request->bRequest)
usbd_edpt_xfer(TUD_OPT_RHPORT, _netd_itf.ep_notif, (uint8_t *)&notify, sizeof(notify)); {
} tud_control_xfer(rhport, request, NULL, 0);
#elif CFG_TUD_NET == OPT_NET_RNDIS ecm_report(true);
if (request->bmRequestType_bit.direction == TUSB_DIR_IN) }
{
rndis_generic_msg_t *rndis_msg = (rndis_generic_msg_t *)rndis_buf;
uint32_t msglen = tu_le32toh(rndis_msg->MessageLength);
TU_ASSERT(msglen <= sizeof(rndis_buf));
tud_control_xfer(rhport, request, rndis_buf, msglen);
} }
else else
{ {
tud_control_xfer(rhport, request, rndis_buf, sizeof(rndis_buf)); if (request->bmRequestType_bit.direction == TUSB_DIR_IN)
{
rndis_generic_msg_t *rndis_msg = (rndis_generic_msg_t *)notify.rndis_buf;
uint32_t msglen = tu_le32toh(rndis_msg->MessageLength);
TU_ASSERT(msglen <= sizeof(notify.rndis_buf));
tud_control_xfer(rhport, request, notify.rndis_buf, msglen);
}
else
{
tud_control_xfer(rhport, request, notify.rndis_buf, sizeof(notify.rndis_buf));
}
} }
#else
(void)rhport;
#endif #endif
return true; return true;
@@ -244,18 +294,7 @@ static void handle_incoming_packet(uint32_t len)
uint8_t *pnt = received; uint8_t *pnt = received;
uint32_t size = 0; uint32_t size = 0;
#if CFG_TUD_NET == OPT_NET_ECM #if CFG_TUD_NET == OPT_NET_EEM
size = len;
#elif CFG_TUD_NET == OPT_NET_RNDIS
rndis_data_packet_t *r = (rndis_data_packet_t *)pnt;
if (len >= sizeof(rndis_data_packet_t))
if ( (r->MessageType == REMOTE_NDIS_PACKET_MSG) && (r->MessageLength <= len))
if ( (r->DataOffset + offsetof(rndis_data_packet_t, DataOffset) + r->DataLength) <= len)
{
pnt = &received[r->DataOffset + offsetof(rndis_data_packet_t, DataOffset)];
size = r->DataLength;
}
#elif CFG_TUD_NET == OPT_NET_EEM
struct cdc_eem_packet_header *hdr = (struct cdc_eem_packet_header *)pnt; struct cdc_eem_packet_header *hdr = (struct cdc_eem_packet_header *)pnt;
(void)len; (void)len;
@@ -271,26 +310,45 @@ static void handle_incoming_packet(uint32_t len)
pnt += CFG_TUD_NET_PACKET_PREFIX_LEN; pnt += CFG_TUD_NET_PACKET_PREFIX_LEN;
size = hdr->length - 4; /* discard the unused CRC-32 */ size = hdr->length - 4; /* discard the unused CRC-32 */
} }
#else
if (_netd_itf.ecm_mode)
{
size = len;
}
else
{
rndis_data_packet_t *r = (rndis_data_packet_t *)pnt;
if (len >= sizeof(rndis_data_packet_t))
if ( (r->MessageType == REMOTE_NDIS_PACKET_MSG) && (r->MessageLength <= len))
if ( (r->DataOffset + offsetof(rndis_data_packet_t, DataOffset) + r->DataLength) <= len)
{
pnt = &received[r->DataOffset + offsetof(rndis_data_packet_t, DataOffset)];
size = r->DataLength;
}
}
#endif #endif
bool accepted = false;
if (size) if (size)
{ {
struct pbuf *p = pbuf_alloc(PBUF_RAW, size, PBUF_POOL); struct pbuf *p = pbuf_alloc(PBUF_RAW, size, PBUF_POOL);
bool accepted = true;
if (p) if (p)
{ {
memcpy(p->payload, pnt, size); memcpy(p->payload, pnt, size);
p->len = size; p->len = size;
accepted = tud_network_recv_cb(p); accepted = tud_network_recv_cb(p);
}
if (!p || !accepted) if (!accepted) pbuf_free(p);
{
/* if a buffer couldn't be allocated or accepted by the callback, we must discard this packet */
tud_network_recv_renew();
} }
} }
if (!accepted)
{
/* if a buffer was never handled by user code, we must renew on the user's behalf */
tud_network_recv_renew();
}
} }
bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
@@ -320,6 +378,13 @@ bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
} }
} }
#if CFG_TUD_NET == OPT_NET_RNDIS_ECM
if ( _netd_itf.ecm_mode && (ep_addr == _netd_itf.ep_notif) )
{
if (sizeof(notify.ecm_buf.header) == xferred_bytes) ecm_report(false);
}
#endif
return true; return true;
} }
@@ -337,7 +402,11 @@ void tud_network_xmit(struct pbuf *p)
if (!can_xmit) if (!can_xmit)
return; return;
#if CFG_TUD_NET == OPT_NET_EEM
len = CFG_TUD_NET_PACKET_PREFIX_LEN; len = CFG_TUD_NET_PACKET_PREFIX_LEN;
#else
len = (_netd_itf.ecm_mode) ? 0 : CFG_TUD_NET_PACKET_PREFIX_LEN;
#endif
data = transmitted + len; data = transmitted + len;
for(q = p; q != NULL; q = q->next) for(q = p; q != NULL; q = q->next)
@@ -347,14 +416,7 @@ void tud_network_xmit(struct pbuf *p)
len += q->len; len += q->len;
} }
#if CFG_TUD_NET == OPT_NET_RNDIS #if CFG_TUD_NET == OPT_NET_EEM
rndis_data_packet_t *hdr = (rndis_data_packet_t *)transmitted;
memset(hdr, 0, sizeof(rndis_data_packet_t));
hdr->MessageType = REMOTE_NDIS_PACKET_MSG;
hdr->MessageLength = len;
hdr->DataOffset = sizeof(rndis_data_packet_t) - offsetof(rndis_data_packet_t, DataOffset);
hdr->DataLength = len - sizeof(rndis_data_packet_t);
#elif CFG_TUD_NET == OPT_NET_EEM
struct cdc_eem_packet_header *hdr = (struct cdc_eem_packet_header *)transmitted; struct cdc_eem_packet_header *hdr = (struct cdc_eem_packet_header *)transmitted;
/* append a fake CRC-32; the standard allows 0xDEADBEEF, which takes less CPU time */ /* append a fake CRC-32; the standard allows 0xDEADBEEF, which takes less CPU time */
data[0] = 0xDE; data[1] = 0xAD; data[2] = 0xBE; data[3] = 0xEF; data[0] = 0xDE; data[1] = 0xAD; data[2] = 0xBE; data[3] = 0xEF;
@@ -363,6 +425,16 @@ void tud_network_xmit(struct pbuf *p)
hdr->bmType = 0; /* EEM Data Packet */ hdr->bmType = 0; /* EEM Data Packet */
hdr->length = len - sizeof(struct cdc_eem_packet_header); hdr->length = len - sizeof(struct cdc_eem_packet_header);
hdr->bmCRC = 0; /* Ethernet Frame CRC-32 set to 0xDEADBEEF */ hdr->bmCRC = 0; /* Ethernet Frame CRC-32 set to 0xDEADBEEF */
#else
if (!_netd_itf.ecm_mode)
{
rndis_data_packet_t *hdr = (rndis_data_packet_t *)transmitted;
memset(hdr, 0, sizeof(rndis_data_packet_t));
hdr->MessageType = REMOTE_NDIS_PACKET_MSG;
hdr->MessageLength = len;
hdr->DataOffset = sizeof(rndis_data_packet_t) - offsetof(rndis_data_packet_t, DataOffset);
hdr->DataLength = len - sizeof(rndis_data_packet_t);
}
#endif #endif
do_in_xfer(transmitted, len); do_in_xfer(transmitted, len);
+2
View File
@@ -73,8 +73,10 @@ void tud_network_xmit(struct pbuf *p);
// INTERNAL USBD-CLASS DRIVER API // INTERNAL USBD-CLASS DRIVER API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void netd_init (void); void netd_init (void);
void netd_init_data (void);
void netd_reset (uint8_t rhport); void netd_reset (uint8_t rhport);
bool netd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length); bool netd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length);
bool netd_open_data (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length);
bool netd_control_request (uint8_t rhport, tusb_control_request_t const * request); bool netd_control_request (uint8_t rhport, tusb_control_request_t const * request);
bool netd_control_complete (uint8_t rhport, tusb_control_request_t const * request); bool netd_control_complete (uint8_t rhport, tusb_control_request_t const * request);
bool netd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes); bool netd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
+5 -5
View File
@@ -89,7 +89,7 @@ typedef struct TU_ATTR_ALIGNED(4)
void dcd_init (uint8_t rhport); void dcd_init (uint8_t rhport);
// Interrupt Handler // Interrupt Handler
void dcd_isr (uint8_t rhport); void dcd_irq_handler(uint8_t rhport) TU_ATTR_USED;
// Enable device interrupt // Enable device interrupt
void dcd_int_enable (uint8_t rhport); void dcd_int_enable (uint8_t rhport);
@@ -106,11 +106,11 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num);
// Wake up host // Wake up host
void dcd_remote_wakeup(uint8_t rhport); void dcd_remote_wakeup(uint8_t rhport);
// disconnect by disabling internal pull-up resistor on D+/D- // Connect or disconnect D+/D- line pull-up resistor.
void dcd_disconnect(uint8_t rhport) TU_ATTR_WEAK; // Defined in dcd source if MCU has internal pull-up.
// Otherwise, may be defined in BSP.
// connect by enabling internal pull-up resistor on D+/D-
void dcd_connect(uint8_t rhport) TU_ATTR_WEAK; void dcd_connect(uint8_t rhport) TU_ATTR_WEAK;
void dcd_disconnect(uint8_t rhport) TU_ATTR_WEAK;
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Endpoint API // Endpoint API
+34 -7
View File
@@ -184,21 +184,47 @@ static usbd_class_driver_t const _usbd_driver[] =
#endif #endif
#if CFG_TUD_NET #if CFG_TUD_NET
#if CFG_TUD_NET != OPT_NET_EEM
/* RNDIS management interface */
{ {
.class_code = .class_code = TUD_RNDIS_ITF_CLASS,
#if CFG_TUD_NET == OPT_NET_RNDIS
TUD_RNDIS_ITF_CLASS,
#else
TUSB_CLASS_CDC,
#endif
.init = netd_init, .init = netd_init,
.reset = netd_reset, .reset = netd_reset,
.open = netd_open, .open = netd_open,
.control_request = netd_control_request, .control_request = netd_control_request,
.control_complete = netd_control_complete, .control_complete = netd_control_complete,
.xfer_cb = netd_xfer_cb, .xfer_cb = netd_xfer_cb,
.sof = NULL .sof = NULL,
}, },
#endif
/* CDC-ECM management interface; CDC-EEM data interface */
{
.class_code = TUSB_CLASS_CDC,
.init = netd_init,
.reset = netd_reset,
#if CFG_TUD_NET == OPT_NET_EEM
.open = netd_open_data,
#else
.open = netd_open,
#endif
.control_request = netd_control_request,
.control_complete = netd_control_complete,
.xfer_cb = netd_xfer_cb,
.sof = NULL,
},
/* RNDIS/CDC-ECM data interface */
#if CFG_TUD_NET != OPT_NET_EEM
{
.class_code = TUSB_CLASS_CDC_DATA,
.init = netd_init_data,
.reset = NULL,
.open = netd_open_data,
.control_request = NULL,
.control_complete = NULL,
.xfer_cb = netd_xfer_cb,
.sof = NULL,
},
#endif
#endif #endif
}; };
@@ -332,6 +358,7 @@ bool tud_init (void)
// Init device controller driver // Init device controller driver
dcd_init(TUD_OPT_RHPORT); dcd_init(TUD_OPT_RHPORT);
tud_connect();
dcd_int_enable(TUD_OPT_RHPORT); dcd_int_enable(TUD_OPT_RHPORT);
return true; return true;
+8 -6
View File
@@ -48,7 +48,7 @@ bool tud_init (void);
void tud_task (void); void tud_task (void);
// Interrupt handler, name alias to DCD // Interrupt handler, name alias to DCD
#define tud_isr dcd_isr #define tud_irq_handler dcd_irq_handler
// Check if device is connected and configured // Check if device is connected and configured
bool tud_mounted(void); bool tud_mounted(void);
@@ -342,8 +342,8 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re
//------------- CDC-ECM -------------// //------------- CDC-ECM -------------//
// Length of template descriptor: 62 bytes // Length of template descriptor: 71 bytes
#define TUD_CDC_ECM_DESC_LEN (9+5+5+13+7+9+7+7) #define TUD_CDC_ECM_DESC_LEN (9+5+5+13+7+9+9+7+7)
// CDC-ECM Descriptor Template // CDC-ECM Descriptor Template
// Interface number, description string index, MAC address string index, EP notification address and size, EP data address (out, in), and size, max segment size. // Interface number, description string index, MAC address string index, EP notification address and size, EP data address (out, in), and size, max segment size.
@@ -358,8 +358,10 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re
13, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_ETHERNET_NETWORKING, _mac_stridx, 0, 0, 0, 0, U16_TO_U8S_LE(_maxsegmentsize), U16_TO_U8S_LE(0), 0,\ 13, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_ETHERNET_NETWORKING, _mac_stridx, 0, 0, 0, 0, U16_TO_U8S_LE(_maxsegmentsize), U16_TO_U8S_LE(0), 0,\
/* Endpoint Notification */\ /* Endpoint Notification */\
7, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 1,\ 7, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 1,\
/* CDC Data Interface */\ /* CDC Data Interface (default inactive) */\
9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 0, 2, TUSB_CLASS_CDC_DATA, 0, 0, 0,\ 9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 0, 0, TUSB_CLASS_CDC_DATA, 0, 0, 0,\
/* CDC Data Interface (alternative active) */\
9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 1, 2, TUSB_CLASS_CDC_DATA, 0, 0, 0,\
/* Endpoint In */\ /* Endpoint In */\
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\ 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
/* Endpoint Out */\ /* Endpoint Out */\
@@ -372,7 +374,7 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re
/* Windows XP */ /* Windows XP */
#define TUD_RNDIS_ITF_CLASS TUSB_CLASS_CDC #define TUD_RNDIS_ITF_CLASS TUSB_CLASS_CDC
#define TUD_RNDIS_ITF_SUBCLASS CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL #define TUD_RNDIS_ITF_SUBCLASS CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL
#define TUD_RNDIS_ITF_PROTOCOL CDC_COMM_PROTOCOL_MICROSOFT_RNDIS #define TUD_RNDIS_ITF_PROTOCOL 0xFF /* CDC_COMM_PROTOCOL_MICROSOFT_RNDIS */
#else #else
/* Windows 7+ */ /* Windows 7+ */
#define TUD_RNDIS_ITF_CLASS 0xE0 #define TUD_RNDIS_ITF_CLASS 0xE0
+3 -5
View File
@@ -331,9 +331,8 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t to
USB0.dtknqr4_fifoemptymsk |= (1 << epnum); USB0.dtknqr4_fifoemptymsk |= (1 << epnum);
} else { } else {
// Each complete packet for OUT xfers triggers XFRC. // Each complete packet for OUT xfers triggers XFRC.
USB0.out_ep_reg[epnum].doeptsiz = USB_PKTCNT0_M | USB0.out_ep_reg[epnum].doeptsiz |= USB_PKTCNT0_M | ((xfer->max_size & USB_XFERSIZE0_V) << USB_XFERSIZE0_S);
((xfer->max_size & USB_XFERSIZE0_V) << USB_XFERSIZE0_S); USB0.out_ep_reg[epnum].doepctl |= USB_EPENA0_M | USB_CNAK0_M;
USB0.out_ep_reg[epnum].doepctl |= USB_EPENA0_M | USB_CNAK0_M;
} }
return true; return true;
} }
@@ -603,8 +602,7 @@ static void handle_epout_ints(void)
dcd_event_xfer_complete(0, n, xfer->queued_len, XFER_RESULT_SUCCESS, true); dcd_event_xfer_complete(0, n, xfer->queued_len, XFER_RESULT_SUCCESS, true);
} else { } else {
// Schedule another packet to be received. // Schedule another packet to be received.
USB0.out_ep_reg[n].doeptsiz = USB_PKTCNT0_M | USB0.out_ep_reg[n].doeptsiz |= USB_PKTCNT0_M | ((xfer->max_size & USB_XFERSIZE0_V) << USB_XFERSIZE0_S);
((xfer->max_size & USB_XFERSIZE0_V) << USB_XFERSIZE0_S);
USB0.out_ep_reg[n].doepctl |= USB_EPENA0_M | USB_CNAK0_M; USB0.out_ep_reg[n].doepctl |= USB_EPENA0_M | USB_CNAK0_M;
} }
} }
+3 -53
View File
@@ -331,13 +331,13 @@ void maybe_transfer_complete(void) {
} }
void dcd_isr (uint8_t rhport) void dcd_irq_handler (uint8_t rhport)
{ {
(void) rhport; (void) rhport;
uint32_t int_status = USB->DEVICE.INTFLAG.reg & USB->DEVICE.INTENSET.reg; uint32_t int_status = USB->DEVICE.INTFLAG.reg & USB->DEVICE.INTENSET.reg;
/*------------- Interrupt Processing -------------*/ // Start of Frame
if ( int_status & USB_DEVICE_INTFLAG_SOF ) if ( int_status & USB_DEVICE_INTFLAG_SOF )
{ {
USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_SOF; USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_SOF;
@@ -370,6 +370,7 @@ void dcd_isr (uint8_t rhport)
dcd_event_bus_signal(0, DCD_EVENT_RESUME, true); dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
} }
// Enable of Reset
if ( int_status & USB_DEVICE_INTFLAG_EORST ) if ( int_status & USB_DEVICE_INTFLAG_EORST )
{ {
USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_EORST; USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_EORST;
@@ -394,55 +395,4 @@ void dcd_isr (uint8_t rhport)
maybe_transfer_complete(); maybe_transfer_complete();
} }
#if CFG_TUSB_MCU == OPT_MCU_SAMD51
/*
*------------------------------------------------------------------*/
/* USB_EORSM_DNRSM, USB_EORST_RST, USB_LPMSUSP_DDISC, USB_LPM_DCONN,
USB_MSOF, USB_RAMACER, USB_RXSTP_TXSTP_0, USB_RXSTP_TXSTP_1,
USB_RXSTP_TXSTP_2, USB_RXSTP_TXSTP_3, USB_RXSTP_TXSTP_4,
USB_RXSTP_TXSTP_5, USB_RXSTP_TXSTP_6, USB_RXSTP_TXSTP_7,
USB_STALL0_STALL_0, USB_STALL0_STALL_1, USB_STALL0_STALL_2,
USB_STALL0_STALL_3, USB_STALL0_STALL_4, USB_STALL0_STALL_5,
USB_STALL0_STALL_6, USB_STALL0_STALL_7, USB_STALL1_0, USB_STALL1_1,
USB_STALL1_2, USB_STALL1_3, USB_STALL1_4, USB_STALL1_5, USB_STALL1_6,
USB_STALL1_7, USB_SUSPEND, USB_TRFAIL0_TRFAIL_0, USB_TRFAIL0_TRFAIL_1,
USB_TRFAIL0_TRFAIL_2, USB_TRFAIL0_TRFAIL_3, USB_TRFAIL0_TRFAIL_4,
USB_TRFAIL0_TRFAIL_5, USB_TRFAIL0_TRFAIL_6, USB_TRFAIL0_TRFAIL_7,
USB_TRFAIL1_PERR_0, USB_TRFAIL1_PERR_1, USB_TRFAIL1_PERR_2,
USB_TRFAIL1_PERR_3, USB_TRFAIL1_PERR_4, USB_TRFAIL1_PERR_5,
USB_TRFAIL1_PERR_6, USB_TRFAIL1_PERR_7, USB_UPRSM, USB_WAKEUP */
void USB_0_Handler(void) {
dcd_isr(0);
}
/* USB_SOF_HSOF */
void USB_1_Handler(void) {
dcd_isr(0);
}
// Bank zero is for OUT and SETUP transactions.
/* USB_TRCPT0_0, USB_TRCPT0_1, USB_TRCPT0_2,
USB_TRCPT0_3, USB_TRCPT0_4, USB_TRCPT0_5,
USB_TRCPT0_6, USB_TRCPT0_7 */
void USB_2_Handler(void) {
dcd_isr(0);
}
// Bank one is used for IN transactions.
/* USB_TRCPT1_0, USB_TRCPT1_1, USB_TRCPT1_2,
USB_TRCPT1_3, USB_TRCPT1_4, USB_TRCPT1_5,
USB_TRCPT1_6, USB_TRCPT1_7 */
void USB_3_Handler(void) {
dcd_isr(0);
}
#elif CFG_TUSB_MCU == OPT_MCU_SAMD21
void USB_Handler(void) {
dcd_isr(0);
}
#endif
#endif #endif
+1 -1
View File
@@ -333,7 +333,7 @@ void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// ISR // ISR
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void dcd_isr(uint8_t rhport) void dcd_irq_handler(uint8_t rhport)
{ {
uint32_t const intr_mask = UDP->UDP_IMR; uint32_t const intr_mask = UDP->UDP_IMR;
uint32_t const intr_status = UDP->UDP_ISR & intr_mask; uint32_t const intr_status = UDP->UDP_ISR & intr_mask;
+3 -1
View File
@@ -373,8 +373,10 @@ void bus_reset(void)
_dcd.xfer[0][TUSB_DIR_OUT].mps = MAX_PACKET_SIZE; _dcd.xfer[0][TUSB_DIR_OUT].mps = MAX_PACKET_SIZE;
} }
void USBD_IRQHandler(void) void dcd_irq_handler(uint8_t rhport)
{ {
(void) rhport;
uint32_t const inten = NRF_USBD->INTEN; uint32_t const inten = NRF_USBD->INTEN;
uint32_t int_status = 0; uint32_t int_status = 0;
+3 -7
View File
@@ -306,8 +306,10 @@ void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
ep->CFG |= USBD_CFG_CSTALL_Msk; ep->CFG |= USBD_CFG_CSTALL_Msk;
} }
void USBD_IRQHandler(void) void dcd_irq_handler(uint8_t rhport)
{ {
(void) rhport;
uint32_t status = USBD->INTSTS; uint32_t status = USBD->INTSTS;
uint32_t state = USBD->ATTR & 0xf; uint32_t state = USBD->ATTR & 0xf;
@@ -424,12 +426,6 @@ void USBD_IRQHandler(void)
USBD->INTSTS = status & enabled_irqs; USBD->INTSTS = status & enabled_irqs;
} }
void dcd_isr(uint8_t rhport)
{
(void) rhport;
USBD_IRQHandler();
}
void dcd_disconnect(uint8_t rhport) void dcd_disconnect(uint8_t rhport)
{ {
(void) rhport; (void) rhport;
+3 -7
View File
@@ -312,8 +312,10 @@ void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
ep->CFG |= USBD_CFG_CSTALL_Msk; ep->CFG |= USBD_CFG_CSTALL_Msk;
} }
void USBD_IRQHandler(void) void dcd_irq_handler(uint8_t rhport)
{ {
(void) rhport;
uint32_t status = USBD->INTSTS; uint32_t status = USBD->INTSTS;
#ifdef SUPPORT_LPM #ifdef SUPPORT_LPM
uint32_t state = USBD->ATTR & 0x300f; uint32_t state = USBD->ATTR & 0x300f;
@@ -440,12 +442,6 @@ void USBD_IRQHandler(void)
USBD->INTSTS = status & enabled_irqs; USBD->INTSTS = status & enabled_irqs;
} }
void dcd_isr(uint8_t rhport)
{
(void) rhport;
USBD_IRQHandler();
}
void dcd_disconnect(uint8_t rhport) void dcd_disconnect(uint8_t rhport)
{ {
(void) rhport; (void) rhport;
+3 -7
View File
@@ -435,8 +435,10 @@ void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
} }
} }
void USBD_IRQHandler(void) void dcd_irq_handler(uint8_t rhport)
{ {
(void) rhport;
uint32_t status = USBD->GINTSTS; uint32_t status = USBD->GINTSTS;
/* USB interrupt */ /* USB interrupt */
@@ -646,12 +648,6 @@ void USBD_IRQHandler(void)
} }
} }
void dcd_isr(uint8_t rhport)
{
(void) rhport;
USBD_IRQHandler();
}
void dcd_disconnect(uint8_t rhport) void dcd_disconnect(uint8_t rhport)
{ {
(void) rhport; (void) rhport;
+1 -1
View File
@@ -495,7 +495,7 @@ static void dd_complete_isr(uint8_t rhport, uint8_t ep_id)
} }
// main USB IRQ handler // main USB IRQ handler
void dcd_isr(uint8_t rhport) void dcd_irq_handler(uint8_t rhport)
{ {
uint32_t const dev_int_status = LPC_USB->DevIntSt & LPC_USB->DevIntEn; uint32_t const dev_int_status = LPC_USB->DevIntSt & LPC_USB->DevIntEn;
LPC_USB->DevIntClr = dev_int_status;// Acknowledge handled interrupt LPC_USB->DevIntClr = dev_int_status;// Acknowledge handled interrupt
+3 -3
View File
@@ -49,13 +49,11 @@
// LPC 11Uxx, 13xx, 15xx use lpcopen // LPC 11Uxx, 13xx, 15xx use lpcopen
#include "chip.h" #include "chip.h"
#define DCD_REGS LPC_USB #define DCD_REGS LPC_USB
#define DCD_IRQHandler USB_IRQHandler
#elif CFG_TUSB_MCU == OPT_MCU_LPC51UXX || CFG_TUSB_MCU == OPT_MCU_LPC54XXX || \ #elif CFG_TUSB_MCU == OPT_MCU_LPC51UXX || CFG_TUSB_MCU == OPT_MCU_LPC54XXX || \
CFG_TUSB_MCU == OPT_MCU_LPC55XX // TODO 55xx has dual usb controllers CFG_TUSB_MCU == OPT_MCU_LPC55XX // TODO 55xx has dual usb controllers
#include "fsl_device_registers.h" #include "fsl_device_registers.h"
#define DCD_REGS USB0 #define DCD_REGS USB0
#define DCD_IRQHandler USB0_IRQHandler
#endif #endif
@@ -335,8 +333,10 @@ static void process_xfer_isr(uint32_t int_status)
} }
} }
void DCD_IRQHandler(void) void dcd_irq_handler(uint8_t rhport)
{ {
(void) rhport; // TODO support multiple USB on supported mcu such as LPC55s69
uint32_t const cmd_stat = DCD_REGS->DEVCMDSTAT; uint32_t const cmd_stat = DCD_REGS->DEVCMDSTAT;
uint32_t int_status = DCD_REGS->INTSTAT & DCD_REGS->INTEN; uint32_t int_status = DCD_REGS->INTSTAT & DCD_REGS->INTEN;
@@ -492,7 +492,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t t
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// ISR // ISR
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void dcd_isr(uint8_t rhport) void dcd_irq_handler(uint8_t rhport)
{ {
dcd_registers_t* const dcd_reg = _dcd_controller[rhport].regs; dcd_registers_t* const dcd_reg = _dcd_controller[rhport].regs;
+24 -62
View File
@@ -257,17 +257,29 @@ void dcd_init (uint8_t rhport)
} }
USB->CNTR |= USB_CNTR_RESETM | USB_CNTR_SOFM | USB_CNTR_ESOFM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM; USB->CNTR |= USB_CNTR_RESETM | USB_CNTR_SOFM | USB_CNTR_ESOFM | USB_CNTR_CTRM | USB_CNTR_SUSPM | USB_CNTR_WKUPM;
dcd_handle_bus_reset(); dcd_handle_bus_reset();
// And finally enable pull-up, which may trigger the RESET IRQ if the host is connected. // Data-line pull-up is left disconnected.
// (if this MCU has an internal pullup)
#if defined(USB_BCDR_DPPU)
USB->BCDR |= USB_BCDR_DPPU;
#else
// FIXME: callback to the user to ask them to twiddle a GPIO to disable/enable D+???
#endif
} }
// Define only on MCU with internal pull-up. BSP can define on MCU without internal PU.
#if defined(USB_BCDR_DPPU)
// Disable internal D+ PU
void dcd_disconnect(uint8_t rhport)
{
(void) rhport;
USB->BCDR &= ~(USB_BCDR_DPPU);
}
// Enable internal D+ PU
void dcd_connect(uint8_t rhport)
{
(void) rhport;
USB->BCDR |= USB_BCDR_DPPU;
}
#endif
// Enable device interrupt // Enable device interrupt
void dcd_int_enable (uint8_t rhport) void dcd_int_enable (uint8_t rhport)
{ {
@@ -506,7 +518,9 @@ static void dcd_ep_ctr_handler(void)
} }
} }
static void dcd_fs_irqHandler(void) { void dcd_irq_handler(uint8_t rhport) {
(void) rhport;
uint32_t int_status = USB->ISTR; uint32_t int_status = USB->ISTR;
//const uint32_t handled_ints = USB_ISTR_CTR | USB_ISTR_RESET | USB_ISTR_WKUP //const uint32_t handled_ints = USB_ISTR_CTR | USB_ISTR_RESET | USB_ISTR_WKUP
@@ -869,57 +883,5 @@ static bool dcd_read_packet_memory(void *__restrict dst, uint16_t src, size_t wN
return true; return true;
} }
// Interrupt handlers
#if CFG_TUSB_MCU == OPT_MCU_STM32F0 || CFG_TUSB_MCU == OPT_MCU_STM32L0
void USB_IRQHandler(void)
{
dcd_fs_irqHandler();
}
#elif CFG_TUSB_MCU == OPT_MCU_STM32F1
void USB_HP_IRQHandler(void)
{
dcd_fs_irqHandler();
}
void USB_LP_IRQHandler(void)
{
dcd_fs_irqHandler();
}
void USBWakeUp_IRQHandler(void)
{
dcd_fs_irqHandler();
}
#elif (CFG_TUSB_MCU) == (OPT_MCU_STM32F3)
// USB defaults to using interrupts 19, 20, and 42 (based on SYSCFG_CFGR1.USB_IT_RMP)
// FIXME: Do all three need to be handled, or just the LP one?
// USB high-priority interrupt (Channel 19): Triggered only by a correct
// transfer event for isochronous and double-buffer bulk transfer to reach
// the highest possible transfer rate.
void USB_HP_CAN_TX_IRQHandler(void)
{
dcd_fs_irqHandler();
}
// USB low-priority interrupt (Channel 20): Triggered by all USB events
// (Correct transfer, USB reset, etc.). The firmware has to check the
// interrupt source before serving the interrupt.
void USB_LP_CAN_RX0_IRQHandler(void)
{
dcd_fs_irqHandler();
}
// USB wakeup interrupt (Channel 42): Triggered by the wakeup event from the USB
// Suspend mode.
void USBWakeUp_IRQHandler(void)
{
dcd_fs_irqHandler();
}
#else
#error Which IRQ handler do you need?
#endif
#endif #endif
+4 -1
View File
@@ -656,7 +656,10 @@ static void handle_epin_ints(USB_OTG_DeviceTypeDef * dev, USB_OTG_INEndpointType
} }
} }
void OTG_FS_IRQHandler(void) { void dcd_irq_handler(uint8_t rhport) {
(void) rhport;
USB_OTG_DeviceTypeDef * dev = DEVICE_BASE; USB_OTG_DeviceTypeDef * dev = DEVICE_BASE;
USB_OTG_OUTEndpointTypeDef * out_ep = OUT_EP_BASE; USB_OTG_OUTEndpointTypeDef * out_ep = OUT_EP_BASE;
USB_OTG_INEndpointTypeDef * in_ep = IN_EP_BASE; USB_OTG_INEndpointTypeDef * in_ep = IN_EP_BASE;
+14
View File
@@ -45,6 +45,20 @@ void dcd_init (uint8_t rhport)
(void) rhport; (void) rhport;
} }
#if HAS_INTERNAL_PULLUP
// Enable internal D+/D- pullup
void dcd_connect(uint8_t rhport) TU_ATTR_WEAK
{
(void) rhport;
}
// Disable internal D+/D- pullup
void dcd_disconnect(uint8_t rhport) TU_ATTR_WEAK
{
(void) rhport;
}
#endif
// Enable device interrupt // Enable device interrupt
void dcd_int_enable (uint8_t rhport) void dcd_int_enable (uint8_t rhport)
{ {
+3 -1
View File
@@ -539,8 +539,10 @@ static void handle_setup_packet(void)
dcd_event_setup_received(0, (uint8_t*) &_setup_packet[0], true); dcd_event_setup_received(0, (uint8_t*) &_setup_packet[0], true);
} }
void __attribute__ ((interrupt(USB_UBM_VECTOR))) USB_UBM_ISR(void) void dcd_irq_handler(uint8_t rhport)
{ {
(void) rhport;
// Setup is special- reading USBVECINT to handle setup packets is done to // Setup is special- reading USBVECINT to handle setup packets is done to
// stop hardware-generated NAKs on EP0. // stop hardware-generated NAKs on EP0.
uint8_t setup_status = USBIFG & SETUPIFG; uint8_t setup_status = USBIFG & SETUPIFG;
+1 -1
View File
@@ -613,7 +613,7 @@ static void handle_setup(void)
usb_setup_ev_pending_write(1); usb_setup_ev_pending_write(1);
} }
void hal_dcd_isr(uint8_t rhport) void dcd_irq_handler(uint8_t rhport)
{ {
(void)rhport; (void)rhport;
uint8_t next_ev; uint8_t next_ev;
-33
View File
@@ -1,33 +0,0 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/
#include "common/tusb_common.h"
#if (CFG_TUSB_MCU == OPT_MCU_VALENTYUSB_EPTRI)
// No HAL-specific stuff here!
#endif
+2 -3
View File
@@ -128,9 +128,8 @@
* \ref CFG_TUD_NET must be defined to one of these * \ref CFG_TUD_NET must be defined to one of these
* @{ */ * @{ */
#define OPT_NET_NONE 0 ///< No network interface #define OPT_NET_NONE 0 ///< No network interface
#define OPT_NET_ECM 1 ///< CDC-ECM #define OPT_NET_RNDIS_ECM 1 ///< RNDIS+CDC-ECM
#define OPT_NET_RNDIS 2 ///< RNDIS #define OPT_NET_EEM 2 ///< CDC-EEM
#define OPT_NET_EEM 3 ///< CDC-EEM
/** @} */ /** @} */
#ifndef CFG_TUSB_RHPORT0_MODE #ifndef CFG_TUSB_RHPORT0_MODE
+1
View File
@@ -199,6 +199,7 @@ void setUp(void)
if ( !tusb_inited() ) if ( !tusb_inited() )
{ {
dcd_init_Expect(rhport); dcd_init_Expect(rhport);
dcd_connect_Expect(rhport);
tusb_init(); tusb_init();
} }
+1
View File
@@ -127,6 +127,7 @@ void setUp(void)
{ {
mscd_init_Expect(); mscd_init_Expect();
dcd_init_Expect(rhport); dcd_init_Expect(rhport);
dcd_connect_Expect(rhport);
tusb_init(); tusb_init();
} }
} }