drivers: usb_dc_stm32: Add usb disconnect pin support

Add usb disconnect pin support.
Some boards use a GPIO pin to controll a transistor,
which drives the pull-up resistor on USB DP pin.

Signed-off-by: Yannis Damigos <giannis.damigos@gmail.com>
This commit is contained in:
Yannis Damigos 2017-10-27 20:31:51 +03:00 committed by Kumar Gala
commit 55dada2592
2 changed files with 55 additions and 0 deletions

View file

@ -79,4 +79,36 @@ config SYS_LOG_USB_DRIVER_LEVEL
- 4 DEBUG, write SYS_LOG_DBG in addition to previous levels
config USB_DC_STM32_DISCONN_ENABLE
bool
depends on USB_DC_STM32
default n
help
Say Y if your board uses USB DISCONNECT pin to enable the
pull-up resistor on USB DP.
config USB_DC_STM32_DISCONN_GPIO_PORT_NAME
string
depends on USB_DC_STM32_DISCONN_ENABLE
default "GPIOC"
help
GPIO controller where the USB DISCONNECT pin is attached to.
config USB_DC_STM32_DISCONN_PIN
int
depends on USB_DC_STM32_DISCONN_ENABLE
default 12
help
USB DISCONNECT pin.
config USB_DC_STM32_DISCONN_PIN_LEVEL
int
depends on USB_DC_STM32_DISCONN_ENABLE
default 0
help
USB DISCONNECT pin active level:
- 0, USB DISCONNECT PIN is active low
- 1, USB DISCONNECT PIN is active high
endif # USB

View file

@ -50,6 +50,7 @@
#include <usb/usb_device.h>
#include <clock_control/stm32_clock_control.h>
#include <misc/util.h>
#include <gpio.h>
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_USB_DRIVER_LEVEL
#include <logging/sys_log.h>
@ -770,3 +771,25 @@ void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, u8_t epnum)
ep_state->cb(ep, USB_DC_EP_DATA_IN);
}
}
#if defined(USB) && defined(CONFIG_USB_DC_STM32_DISCONN_ENABLE)
void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state)
{
struct device *usb_disconnect;
usb_disconnect = device_get_binding(
CONFIG_USB_DC_STM32_DISCONN_GPIO_PORT_NAME);
gpio_pin_configure(usb_disconnect,
CONFIG_USB_DC_STM32_DISCONN_PIN, GPIO_DIR_OUT);
if (state) {
gpio_pin_write(usb_disconnect,
CONFIG_USB_DC_STM32_DISCONN_PIN,
CONFIG_USB_DC_STM32_DISCONN_PIN_LEVEL);
} else {
gpio_pin_write(usb_disconnect,
CONFIG_USB_DC_STM32_DISCONN_PIN,
!CONFIG_USB_DC_STM32_DISCONN_PIN_LEVEL);
}
}
#endif /* USB && CONFIG_USB_DC_STM32_DISCONN_ENABLE */