Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start of USB host API #6125

Merged
merged 6 commits into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tinyusb
Submodule tinyusb updated 195 files
11 changes: 6 additions & 5 deletions ports/atmel-samd/supervisor/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,25 @@ void init_usb_hardware(void) {

#ifdef SAMD21
void USB_Handler(void) {
usb_irq_handler();
usb_irq_handler(0);
}
#endif

#ifdef SAM_D5X_E5X
// These are different subsets of USB interrupts, *NOT* different USB peripherals.
void USB_0_Handler(void) {
usb_irq_handler();
usb_irq_handler(0);
}

void USB_1_Handler(void) {
usb_irq_handler();
usb_irq_handler(0);
}

void USB_2_Handler(void) {
usb_irq_handler();
usb_irq_handler(0);
}

void USB_3_Handler(void) {
usb_irq_handler();
usb_irq_handler(0);
}
#endif
4 changes: 2 additions & 2 deletions ports/broadcom/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
#define MICROPY_PORT_ROOT_POINTERS \
CIRCUITPY_COMMON_ROOT_POINTERS

#define DEBUG_UART_TX (&pin_GPIO14)
#define DEBUG_UART_RX (&pin_GPIO15)
#define CIRCUITPY_DEBUG_UART_TX (&pin_GPIO14)
#define CIRCUITPY_DEBUG_UART_RX (&pin_GPIO15)

#endif // __INCLUDED_MPCONFIGPORT_H
2 changes: 1 addition & 1 deletion ports/broadcom/supervisor/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
uint32_t SystemCoreClock = 700 * 1000 * 1000;

void USB_IRQHandler(void) {
usb_irq_handler();
usb_irq_handler(0);
}

void init_usb_hardware(void) {
Expand Down
5 changes: 0 additions & 5 deletions ports/espressif/boards/adafruit_qtpy_esp32s2/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,3 @@
#define CIRCUITPY_BOARD_UART_PIN {{.tx = &pin_GPIO5, .rx = &pin_GPIO16}}

#define DOUBLE_TAP_PIN (&pin_GPIO10)

#ifdef DEBUG
#define DEBUG_UART_RX (&pin_GPIO16)
#define DEBUG_UART_TX (&pin_GPIO5)
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)

// Serial over UART
#define DEBUG_UART_RX DEFAULT_UART_BUS_RX
#define DEBUG_UART_TX DEFAULT_UART_BUS_TX
#define CIRCUITPY_DEBUG_UART_RX DEFAULT_UART_BUS_RX
#define CIRCUITPY_DEBUG_UART_TX DEFAULT_UART_BUS_TX

// For entering safe mode
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO9)
Expand Down
4 changes: 2 additions & 2 deletions ports/espressif/boards/ai_thinker_esp32-c3s/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)

// Serial over UART
#define DEBUG_UART_RX DEFAULT_UART_BUS_RX
#define DEBUG_UART_TX DEFAULT_UART_BUS_TX
#define CIRCUITPY_DEBUG_UART_RX DEFAULT_UART_BUS_RX
#define CIRCUITPY_DEBUG_UART_TX DEFAULT_UART_BUS_TX

// For entering safe mode
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO9)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)

// Serial over UART
#define DEBUG_UART_RX DEFAULT_UART_BUS_RX
#define DEBUG_UART_TX DEFAULT_UART_BUS_TX
#define CIRCUITPY_DEBUG_UART_RX DEFAULT_UART_BUS_RX
#define CIRCUITPY_DEBUG_UART_TX DEFAULT_UART_BUS_TX

// For entering safe mode
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO2)
Expand Down
4 changes: 2 additions & 2 deletions ports/espressif/boards/microdev_micro_c3/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
#define DEFAULT_UART_BUS_TX (&pin_GPIO21)

// Serial over UART
#define DEBUG_UART_RX DEFAULT_UART_BUS_RX
#define DEBUG_UART_TX DEFAULT_UART_BUS_TX
#define CIRCUITPY_DEBUG_UART_RX DEFAULT_UART_BUS_RX
#define CIRCUITPY_DEBUG_UART_TX DEFAULT_UART_BUS_TX

// For entering safe mode
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO9)
Expand Down
2 changes: 1 addition & 1 deletion ports/litex/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void isr(void) {
nesting_count += 1;
#ifdef CFG_TUSB_MCU
if (irqs & (1 << USB_INTERRUPT)) {
usb_irq_handler();
usb_irq_handler(0);
}
#endif
if (irqs & (1 << TIMER0_INTERRUPT)) {
Expand Down
17 changes: 17 additions & 0 deletions ports/mimxrt10xx/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ SRC_C += \
reset.c \
supervisor/flexspi_nor_flash_ops.c

ifeq ($(CIRCUITPY_USB_HOST), 1)
SRC_C += \
lib/tinyusb/src/portable/chipidea/ci_hs/hcd_ci_hs.c \
lib/tinyusb/src/portable/ehci/ehci.c \

endif

# TODO
#ifeq ($(CIRCUITPY_AUDIOBUSIO),1)
#SRC_C += peripherals/samd/i2s.c peripherals/samd/$(CHIP_FAMILY)/i2s.c
Expand Down Expand Up @@ -219,3 +226,13 @@ include $(TOP)/py/mkrules.mk
# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
print-%:
@echo $* = $($*)

ifeq ($(CHIP_FAMILY), MIMXRT1062)
PYOCD_TARGET = mimxrt1060
endif

# Flash using pyocd
PYOCD_OPTION ?=
flash: $(BUILD)/firmware.hex
pyocd flash -t $(PYOCD_TARGET) $(PYOCD_OPTION) $<
pyocd reset -t $(PYOCD_TARGET)
12 changes: 12 additions & 0 deletions ports/mimxrt10xx/boards/imxrt1060_evk/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@

#define BOARD_FLASH_SIZE (8 * 1024 * 1024)

#define MICROPY_HW_LED_STATUS (&pin_GPIO_AD_B0_09)
#define MICROPY_HW_LED_STATUS_INVERTED (1)

#define DEFAULT_I2C_BUS_SCL (&pin_GPIO_AD_B1_00)
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO_AD_B1_01)

#define DEFAULT_UART_BUS_RX (&pin_GPIO_AD_B1_07)
#define DEFAULT_UART_BUS_TX (&pin_GPIO_AD_B1_06)

#define CIRCUITPY_DEBUG_UART_TX (&pin_GPIO_AD_B0_12)
#define CIRCUITPY_DEBUG_UART_RX (&pin_GPIO_AD_B0_13)


// Put host on the first USB so that right angle OTG adapters can fit. This is
// the right port when looking at the board.
#define CIRCUITPY_USB_DEVICE_INSTANCE 1
#define CIRCUITPY_USB_HOST_INSTANCE 0
2 changes: 2 additions & 0 deletions ports/mimxrt10xx/boards/imxrt1060_evk/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ USB_MANUFACTURER = "NXP"
CHIP_VARIANT = MIMXRT1062DVJ6A
CHIP_FAMILY = MIMXRT1062
FLASH = IS25WP064A

CIRCUITPY_USB_HOST = 1
9 changes: 9 additions & 0 deletions ports/mimxrt10xx/boards/imxrt1060_evk/pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_CAN_RX), MP_ROM_PTR(&pin_GPIO_AD_B0_15) },
{ MP_ROM_QSTR(MP_QSTR_CAN_STBY), MP_ROM_PTR(&pin_GPIO_AD_B0_05) },

// USB
#if CIRCUITPY_USB_HOST_INSTANCE == 0
{ MP_ROM_QSTR(MP_QSTR_USB_HOST_DP), MP_ROM_PTR(&pin_USB_OTG1_DP) },
{ MP_ROM_QSTR(MP_QSTR_USB_HOST_DM), MP_ROM_PTR(&pin_USB_OTG1_DN) },
#elif CIRCUITPY_USB_HOST_INSTANCE == 1
{ MP_ROM_QSTR(MP_QSTR_USB_HOST_DP), MP_ROM_PTR(&pin_USB_OTG2_DP) },
{ MP_ROM_QSTR(MP_QSTR_USB_HOST_DM), MP_ROM_PTR(&pin_USB_OTG2_DN) },
#endif

{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
};
Expand Down
3 changes: 3 additions & 0 deletions ports/mimxrt10xx/boards/teensy41/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@

#define DEFAULT_UART_BUS_RX (&pin_GPIO_AD_B0_03)
#define DEFAULT_UART_BUS_TX (&pin_GPIO_AD_B0_02)

#define CIRCUITPY_USB_DEVICE_INSTANCE 0
#define CIRCUITPY_USB_HOST_INSTANCE 1
1 change: 1 addition & 0 deletions ports/mimxrt10xx/boards/teensy41/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ CHIP_VARIANT = MIMXRT1062DVJ6A
CHIP_FAMILY = MIMXRT1062
FLASH = W25Q64JV
CIRCUITPY__EVE = 1
CIRCUITPY_USB_HOST = 1
5 changes: 5 additions & 0 deletions ports/mimxrt10xx/boards/teensy41/pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_D54), MP_ROM_PTR(&pin_GPIO_EMC_29) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_QSPI_IO3), MP_ROM_PTR(&pin_GPIO_EMC_29) },

// USB Host
{ MP_ROM_QSTR(MP_QSTR_USB_HOST_POWER), MP_ROM_PTR(&pin_GPIO_EMC_40) },
{ MP_ROM_QSTR(MP_QSTR_USB_HOST_DP), MP_ROM_PTR(&pin_USB_OTG2_DP) },
{ MP_ROM_QSTR(MP_QSTR_USB_HOST_DM), MP_ROM_PTR(&pin_USB_OTG2_DN) },

{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
Expand Down
Loading