Skip to content

Commit 83593a1

Browse files
committed
Start of USB host API
This allows you to list and explore connected USB devices. It only stubs out the methods to communicate to endpoints. That will come in a follow up once TinyUSB has it. (It's in progress.) Related to #5986
1 parent b439464 commit 83593a1

File tree

56 files changed

+1823
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1823
-114
lines changed

lib/tinyusb

Submodule tinyusb updated 195 files

ports/atmel-samd/supervisor/usb.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,25 @@ void init_usb_hardware(void) {
6363

6464
#ifdef SAMD21
6565
void USB_Handler(void) {
66-
usb_irq_handler();
66+
usb_irq_handler(0);
6767
}
6868
#endif
6969

7070
#ifdef SAM_D5X_E5X
71+
// These are different subsets of USB interrupts, *NOT* different USB peripherals.
7172
void USB_0_Handler(void) {
72-
usb_irq_handler();
73+
usb_irq_handler(0);
7374
}
7475

7576
void USB_1_Handler(void) {
76-
usb_irq_handler();
77+
usb_irq_handler(0);
7778
}
7879

7980
void USB_2_Handler(void) {
80-
usb_irq_handler();
81+
usb_irq_handler(0);
8182
}
8283

8384
void USB_3_Handler(void) {
84-
usb_irq_handler();
85+
usb_irq_handler(0);
8586
}
8687
#endif

ports/broadcom/mpconfigport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#define MICROPY_PORT_ROOT_POINTERS \
6161
CIRCUITPY_COMMON_ROOT_POINTERS
6262

63-
#define DEBUG_UART_TX (&pin_GPIO14)
64-
#define DEBUG_UART_RX (&pin_GPIO15)
63+
#define CIRCUITPY_DEBUG_UART_TX (&pin_GPIO14)
64+
#define CIRCUITPY_DEBUG_UART_RX (&pin_GPIO15)
6565

6666
#endif // __INCLUDED_MPCONFIGPORT_H

ports/broadcom/supervisor/usb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
uint32_t SystemCoreClock = 700 * 1000 * 1000;
3636

3737
void USB_IRQHandler(void) {
38-
usb_irq_handler();
38+
usb_irq_handler(0);
3939
}
4040

4141
void init_usb_hardware(void) {

ports/espressif/boards/adafruit_qtpy_esp32s2/mpconfigboard.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,3 @@
4949
#define CIRCUITPY_BOARD_UART_PIN {{.tx = &pin_GPIO5, .rx = &pin_GPIO16}}
5050

5151
#define DOUBLE_TAP_PIN (&pin_GPIO10)
52-
53-
#ifdef DEBUG
54-
#define DEBUG_UART_RX (&pin_GPIO16)
55-
#define DEBUG_UART_TX (&pin_GPIO5)
56-
#endif

ports/espressif/boards/ai_thinker_esp32-c3s-2m/mpconfigboard.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
3838

3939
// Serial over UART
40-
#define DEBUG_UART_RX DEFAULT_UART_BUS_RX
41-
#define DEBUG_UART_TX DEFAULT_UART_BUS_TX
40+
#define CIRCUITPY_DEBUG_UART_RX DEFAULT_UART_BUS_RX
41+
#define CIRCUITPY_DEBUG_UART_TX DEFAULT_UART_BUS_TX
4242

4343
// For entering safe mode
4444
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO9)

ports/espressif/boards/ai_thinker_esp32-c3s/mpconfigboard.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
3838

3939
// Serial over UART
40-
#define DEBUG_UART_RX DEFAULT_UART_BUS_RX
41-
#define DEBUG_UART_TX DEFAULT_UART_BUS_TX
40+
#define CIRCUITPY_DEBUG_UART_RX DEFAULT_UART_BUS_RX
41+
#define CIRCUITPY_DEBUG_UART_TX DEFAULT_UART_BUS_TX
4242

4343
// For entering safe mode
4444
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO9)

ports/espressif/boards/espressif_esp32c3_devkitm_1_n4/mpconfigboard.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
3838

3939
// Serial over UART
40-
#define DEBUG_UART_RX DEFAULT_UART_BUS_RX
41-
#define DEBUG_UART_TX DEFAULT_UART_BUS_TX
40+
#define CIRCUITPY_DEBUG_UART_RX DEFAULT_UART_BUS_RX
41+
#define CIRCUITPY_DEBUG_UART_TX DEFAULT_UART_BUS_TX
4242

4343
// For entering safe mode
4444
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO2)

ports/espressif/boards/microdev_micro_c3/mpconfigboard.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)
4545

4646
// Serial over UART
47-
#define DEBUG_UART_RX DEFAULT_UART_BUS_RX
48-
#define DEBUG_UART_TX DEFAULT_UART_BUS_TX
47+
#define CIRCUITPY_DEBUG_UART_RX DEFAULT_UART_BUS_RX
48+
#define CIRCUITPY_DEBUG_UART_TX DEFAULT_UART_BUS_TX
4949

5050
// For entering safe mode
5151
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO9)

ports/litex/mphalport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void isr(void) {
6464
nesting_count += 1;
6565
#ifdef CFG_TUSB_MCU
6666
if (irqs & (1 << USB_INTERRUPT)) {
67-
usb_irq_handler();
67+
usb_irq_handler(0);
6868
}
6969
#endif
7070
if (irqs & (1 << TIMER0_INTERRUPT)) {

ports/mimxrt10xx/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ SRC_C += \
164164
reset.c \
165165
supervisor/flexspi_nor_flash_ops.c
166166

167+
ifeq ($(CIRCUITPY_USB_HOST), 1)
168+
SRC_C += \
169+
lib/tinyusb/src/portable/chipidea/ci_hs/hcd_ci_hs.c \
170+
lib/tinyusb/src/portable/ehci/ehci.c \
171+
172+
endif
173+
167174
# TODO
168175
#ifeq ($(CIRCUITPY_AUDIOBUSIO),1)
169176
#SRC_C += peripherals/samd/i2s.c peripherals/samd/$(CHIP_FAMILY)/i2s.c
@@ -219,3 +226,13 @@ include $(TOP)/py/mkrules.mk
219226
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
220227
print-%:
221228
@echo $* = $($*)
229+
230+
ifeq ($(CHIP_FAMILY), MIMXRT1062)
231+
PYOCD_TARGET = mimxrt1060
232+
endif
233+
234+
# Flash using pyocd
235+
PYOCD_OPTION ?=
236+
flash: $(BUILD)/firmware.hex
237+
pyocd flash -t $(PYOCD_TARGET) $(PYOCD_OPTION) $<
238+
pyocd reset -t $(PYOCD_TARGET)

ports/mimxrt10xx/boards/imxrt1060_evk/mpconfigboard.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,19 @@
77

88
#define BOARD_FLASH_SIZE (8 * 1024 * 1024)
99

10+
#define MICROPY_HW_LED_STATUS (&pin_GPIO_AD_B0_09)
11+
1012
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO_AD_B1_00)
1113
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO_AD_B1_01)
1214

1315
#define DEFAULT_UART_BUS_RX (&pin_GPIO_AD_B1_07)
1416
#define DEFAULT_UART_BUS_TX (&pin_GPIO_AD_B1_06)
17+
18+
#define CIRCUITPY_DEBUG_UART_TX (&pin_GPIO_AD_B0_12)
19+
#define CIRCUITPY_DEBUG_UART_RX (&pin_GPIO_AD_B0_13)
20+
21+
22+
// Put host on the first USB so that right angle OTG adapters can fit. This is
23+
// the right port when looking at the board.
24+
#define CIRCUITPY_USB_DEVICE_INSTANCE 1
25+
#define CIRCUITPY_USB_HOST_INSTANCE 0

ports/mimxrt10xx/boards/imxrt1060_evk/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ USB_MANUFACTURER = "NXP"
66
CHIP_VARIANT = MIMXRT1062DVJ6A
77
CHIP_FAMILY = MIMXRT1062
88
FLASH = IS25WP064A
9+
10+
CIRCUITPY_USB_HOST = 1

ports/mimxrt10xx/boards/imxrt1060_evk/pins.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
125125
{ MP_ROM_QSTR(MP_QSTR_CAN_RX), MP_ROM_PTR(&pin_GPIO_AD_B0_15) },
126126
{ MP_ROM_QSTR(MP_QSTR_CAN_STBY), MP_ROM_PTR(&pin_GPIO_AD_B0_05) },
127127

128+
// USB
129+
#if CIRCUITPY_USB_HOST_INSTANCE == 0
130+
{ MP_ROM_QSTR(MP_QSTR_USB_HOST_DP), MP_ROM_PTR(&pin_USB_OTG1_DP) },
131+
{ MP_ROM_QSTR(MP_QSTR_USB_HOST_DM), MP_ROM_PTR(&pin_USB_OTG1_DN) },
132+
#elif CIRCUITPY_USB_HOST_INSTANCE == 1
133+
{ MP_ROM_QSTR(MP_QSTR_USB_HOST_DP), MP_ROM_PTR(&pin_USB_OTG2_DP) },
134+
{ MP_ROM_QSTR(MP_QSTR_USB_HOST_DM), MP_ROM_PTR(&pin_USB_OTG2_DN) },
135+
#endif
136+
128137
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
129138
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
130139
};

ports/mimxrt10xx/boards/teensy41/mpconfigboard.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616

1717
#define DEFAULT_UART_BUS_RX (&pin_GPIO_AD_B0_03)
1818
#define DEFAULT_UART_BUS_TX (&pin_GPIO_AD_B0_02)
19+
20+
#define CIRCUITPY_USB_DEVICE_INSTANCE 0
21+
#define CIRCUITPY_USB_HOST_INSTANCE 1

ports/mimxrt10xx/boards/teensy41/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ CHIP_VARIANT = MIMXRT1062DVJ6A
77
CHIP_FAMILY = MIMXRT1062
88
FLASH = W25Q64JV
99
CIRCUITPY__EVE = 1
10+
CIRCUITPY_USB_HOST = 1

0 commit comments

Comments
 (0)