diff --git a/cpu/stm32/include/periph/cpu_usbdev.h b/cpu/stm32/include/periph/cpu_usbdev.h index 8e97b0b440bd..63219683952a 100644 --- a/cpu/stm32/include/periph/cpu_usbdev.h +++ b/cpu/stm32/include/periph/cpu_usbdev.h @@ -10,7 +10,7 @@ #pragma once /** - * @ingroup cpu_stm32 + * @ingroup cpu_stm32_usbdev * @{ * * @file @@ -38,18 +38,30 @@ extern "C" { */ #define USBDEV_CPU_DMA_REQUIREMENTS __attribute__((aligned(USBDEV_CPU_DMA_ALIGNMENT))) +/** + * @name Flags used in @ref stm32_usbdev_fs_config_t + * @{ + */ +/** + * @brief Indicates that logic levels are inverted compared to a GPIO connected + * directly via a 1.5 kOhm resistor to the USB D+ signal. + */ +#define STM32_USBDEV_FS_CONFIG_FLAG_DISCONN_INVERTED 0x01 +/** @} */ + /** * @brief stm32 USB device FS configuration */ typedef struct { uintptr_t base_addr; /**< USB peripheral base address */ uint32_t rcc_mask; /**< bit in clock enable register */ - uint8_t irqn; /**< IRQ channel */ - uint8_t apb; /**< APB bus */ gpio_t dm; /**< Data- gpio */ gpio_t dp; /**< Data+ gpio */ gpio_af_t af; /**< Alternative function */ gpio_t disconn; /**< GPIO if used for USB disconnect */ + uint8_t irqn; /**< IRQ channel */ + uint8_t apb; /**< APB bus */ + uint8_t flags; /**< Configuration flags */ } stm32_usbdev_fs_config_t; #ifdef __cplusplus diff --git a/cpu/stm32/periph/usbdev_fs.c b/cpu/stm32/periph/usbdev_fs.c index 5ffd3d837741..88cd6743d49f 100644 --- a/cpu/stm32/periph/usbdev_fs.c +++ b/cpu/stm32/periph/usbdev_fs.c @@ -240,7 +240,7 @@ static void _enable_gpio(const stm32_usbdev_fs_config_t *conf) /* In case the MCU has no internal D+ pullup, a GPIO is used to * connect/disconnect from USB bus */ gpio_init(conf->disconn, GPIO_OUT); - gpio_clear(conf->disconn); + gpio_write(conf->disconn, (conf->flags & STM32_USBDEV_FS_CONFIG_FLAG_DISCONN_INVERTED)); } } @@ -283,7 +283,7 @@ static inline void _usb_attach(stm32_usbdev_fs_t *usbdev) #else /* If configuration uses a GPIO for USB connect/disconnect */ if (conf->disconn != GPIO_UNDEF) { - gpio_set(conf->disconn); + gpio_write(conf->disconn, !(conf->flags & STM32_USBDEV_FS_CONFIG_FLAG_DISCONN_INVERTED)); } #endif /* USB_BCDR_DPPU */ } @@ -301,7 +301,7 @@ static inline void _usb_detach(stm32_usbdev_fs_t *usbdev) #else /* If configuration uses a GPIO for USB connect/disconnect */ if (conf->disconn != GPIO_UNDEF) { - gpio_clear(conf->disconn); + gpio_write(conf->disconn, (conf->flags & STM32_USBDEV_FS_CONFIG_FLAG_DISCONN_INVERTED)); } #endif }