diff --git a/arch/arm/src/stm32/stm32_otgfshost.c b/arch/arm/src/stm32/stm32_otgfshost.c index bebb325861..e3efc1ec8f 100644 --- a/arch/arm/src/stm32/stm32_otgfshost.c +++ b/arch/arm/src/stm32/stm32_otgfshost.c @@ -5125,7 +5125,7 @@ static void stm32_host_initialize(FAR struct stm32_usbhost_s *priv) stm32_putreg(STM32_OTGFS_HCINTMSK(i), 0); } - /* Driver Vbus +5V (the smoke test). Should be done elsewhere in OTG + /* Drive Vbus +5V (the smoke test). Should be done elsewhere in OTG * mode. */ diff --git a/configs/viewtool-stm32f107/Kconfig b/configs/viewtool-stm32f107/Kconfig index 23587e0f68..35adc88c83 100644 --- a/configs/viewtool-stm32f107/Kconfig +++ b/configs/viewtool-stm32f107/Kconfig @@ -87,6 +87,14 @@ config VIEWTOOL_MAX3421E_FREQUENCY default 20000000 range 400000 26000000 +config VIEWTOOL_MAX3421E_RST + bool "MAX3421E reset pin" + default y + +config VIEWTOOL_MAX3421E_PWR + bool "USB Host power control" + default n + config VIEWTOOL_MAX3421E_CONNMON_STACKSIZE int "MAX3421E USB connection monitor stack size" default 2048 diff --git a/configs/viewtool-stm32f107/src/stm32_max3421e.c b/configs/viewtool-stm32f107/src/stm32_max3421e.c index 93f3496a96..742c4186b4 100644 --- a/configs/viewtool-stm32f107/src/stm32_max3421e.c +++ b/configs/viewtool-stm32f107/src/stm32_max3421e.c @@ -102,6 +102,8 @@ static int max3421e_attach(FAR const struct max3421e_lowerhalf_s *lower, static void max3421e_enable(FAR const struct max3421e_lowerhalf_s *lower, bool enable); static void max3421e_acknowledge(FAR const struct max3421e_lowerhalf_s *lower); +static void max3421e_power(FAR const struct max3421e_lowerhalf_s *lower, + bool enable); /**************************************************************************** * Private Data @@ -130,6 +132,7 @@ static struct viewtool_max3421elower_s g_max3421e_lower = .attach = max3421e_attach, /* Attach interrupt handler */ .enable = max3421e_enable, /* Enable interrupt */ .acknowledge = max3421e_acknowledge, /* Acknowledge/clear interrupt */ + .power = max3421e_power, /* Enable VBUS power */ }, }; @@ -149,6 +152,7 @@ static FAR struct usbhost_connection_s *g_usbconn; * attach - Attach the ADS7843E interrupt handler to the GPIO interrupt * enable - Enable or disable the GPIO interrupt * acknowledge - Acknowledge/clear any pending GPIO interrupt as necessary. + * power - Enable or disable 5V VBUS power * ****************************************************************************/ @@ -219,6 +223,14 @@ static void max3421e_acknowledge(FAR const struct max3421e_lowerhalf_s *lower) /* Does nothing */ } +static void max3421e_power(FAR const struct max3421e_lowerhalf_s *lower, + bool enable) +{ +#ifdef CONFIG_VIEWTOOL_MAX3421E_PWR + stm32_gpiowrite(GPIO_MAX3421E_PWR, enable); +#endif +} + /***************************************************************************** * Name: usbhost_detect * @@ -271,13 +283,20 @@ int stm32_max3421e_setup(void) pid_t monpid; int ret; - /* Configure the MAX3421E interrupt pin and VBUS pins as an inputs and the - * reset pin as an output. Device is initially in reset. + /* Configure the MAX3421E interrupt pin as an input and the reset and power + * pins as an outputs. Device is initially in reset and 5V power is not + * provided. */ (void)stm32_configgpio(GPIO_MAX3421E_INT); + +#ifdef CONFIG_VIEWTOOL_MAX3421E_RST (void)stm32_configgpio(GPIO_MAX3421E_RST); - (void)stm32_configgpio(GPIO_MAX3421E_VBUS); +#endif + +#ifdef CONFIG_VIEWTOOL_MAX3421E_PWR + (void)stm32_configgpio(GPIO_MAX3421E_PWR); +#endif /* Get an instance of the SPI interface for the touchscreen chip select */ @@ -357,9 +376,11 @@ int stm32_max3421e_setup(void) } #endif +#ifdef CONFIG_VIEWTOOL_MAX3421E_RST /* Take the MAX3412E out of reset */ stm32_gpiowrite(GPIO_MAX3421E_RST, true); +#endif /* Initialize and register the MAX3421E device */ diff --git a/configs/viewtool-stm32f107/src/viewtool_stm32f107.h b/configs/viewtool-stm32f107/src/viewtool_stm32f107.h index e2561c98cc..cc55bb479a 100644 --- a/configs/viewtool-stm32f107/src/viewtool_stm32f107.h +++ b/configs/viewtool-stm32f107/src/viewtool_stm32f107.h @@ -333,9 +333,8 @@ * ------ ----------- -------------------- * CS# J8 Pin 12 PA4/NSS1 (For SPI1) * CS# J8 Pin 6 PB12/NSS2 (For SPI2) - * INT# J18 Pin 6 PC5 + * INT# J18 Pin 10 PA0 * RST# J18 Pin 8 PA1 - * VBUS J18 Pin 10 PA0 */ #if defined(CONFIG_VIEWTOOL_MAX3421E_SPI1) @@ -348,11 +347,9 @@ GPIO_OUTPUT_SET | GPIO_PORTB | GPIO_PIN12) #endif #define GPIO_MAX3421E_INT (GPIO_INPUT | GPIO_CNF_INFLOAT | GPIO_MODE_INPUT | \ - GPIO_EXTI | GPIO_PORTC | GPIO_PIN5) -#define GPIO_MAX3421E_RST (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz | \ - GPIO_OUTPUT_CLEAR | GPIO_PORTA| GPIO_PIN1) -#define GPIO_MAX3421E_VBUS (GPIO_INPUT | GPIO_CNF_INFLOAT | GPIO_MODE_INPUT | \ GPIO_EXTI | GPIO_PORTA | GPIO_PIN0) +#define GPIO_MAX3421E_RST (GPIO_OUTPUT | GPIO_CNF_OUTPP | GPIO_MODE_50MHz | \ + GPIO_OUTPUT_CLEAR | GPIO_PORTA | GPIO_PIN1) /**************************************************************************** * Public Functions diff --git a/drivers/usbhost/usbhost_max3421e.c b/drivers/usbhost/usbhost_max3421e.c index 05f0e5a345..6865254e4a 100644 --- a/drivers/usbhost/usbhost_max3421e.c +++ b/drivers/usbhost/usbhost_max3421e.c @@ -4705,7 +4705,8 @@ max3421e_usbhost_initialize(FAR const struct max3421e_lowerhalf_s *lower) int ret; DEBUGASSERT(lower != NULL && lower->spi != NULL && lower->attach != NULL && - lower->attach != NULL && lower->acknowledge != NULL); + lower->attach != NULL && lower->acknowledge != NULL && + lower->power != NULL); /* Allocate and instance of the MAX4321E state structure */ @@ -4737,7 +4738,15 @@ max3421e_usbhost_initialize(FAR const struct max3421e_lowerhalf_s *lower) goto errout_with_alloc; } - /* Enable interrupts at the interrupt controller */ + /* Drive Vbus +5V (the smoke test). + * + * REVISIT: Should be done elsewhere in order to support device self- + * powered mode? How does the MAX3421E VBUS detect logic work? + */ + + lower->power(lower, true); + + /* Enable host interrupts */ lower->enable(lower, true); return &conn->conn; diff --git a/include/nuttx/usb/max3421e.h b/include/nuttx/usb/max3421e.h index 5cf1bb75e7..a762715799 100644 --- a/include/nuttx/usb/max3421e.h +++ b/include/nuttx/usb/max3421e.h @@ -459,6 +459,7 @@ struct max3421e_lowerhalf_s * attach - Attach the interrupt handler to the GPIO interrupt * enable - Enable or disable the GPIO interrupt * acknowledge - Acknowledge/clear any pending GPIO interrupt + * power - Enable or disable 5V VBUS power */ CODE int (*attach)(FAR const struct max3421e_lowerhalf_s *lower, @@ -466,6 +467,8 @@ struct max3421e_lowerhalf_s CODE void (*enable)(FAR const struct max3421e_lowerhalf_s *lower, bool enable); CODE void (*acknowledge)(FAR const struct max3421e_lowerhalf_s *lower); + CODE void (*power)(FAR const struct max3421e_lowerhalf_s *lower, + bool enable); /* Additional, driver-specific state data may follow */ };