From a91aa1aad65c5f5da38511175c79a72c019b271b Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Tue, 28 Apr 2015 11:58:32 +0200 Subject: ucoo/hal/usb: add configuration item to select OTG HS driver --- ucoo/hal/usb/Config | 2 ++ ucoo/hal/usb/usb.stm32.cc | 24 ++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ucoo/hal/usb/Config b/ucoo/hal/usb/Config index 9adaece..80341e8 100644 --- a/ucoo/hal/usb/Config +++ b/ucoo/hal/usb/Config @@ -10,3 +10,5 @@ self_powered = 0 max_power = 100 # End point size, you should use 64. ep_size = 64 +# Use HS driver instead of FS +driver_hs = false diff --git a/ucoo/hal/usb/usb.stm32.cc b/ucoo/hal/usb/usb.stm32.cc index 04f0b70..79f73d2 100644 --- a/ucoo/hal/usb/usb.stm32.cc +++ b/ucoo/hal/usb/usb.stm32.cc @@ -30,6 +30,14 @@ #include "usb_desc.stm32.h" +#if UCOO_CONFIG_HAL_USB_DRIVER_HS +# define usb_isr otg_hs_isr +# define usb_driver otghs_usb_driver +#else +# define usb_isr otg_fs_isr +# define usb_driver otgfs_usb_driver +#endif + static usbd_device *usbdev; // Buffer for control requests. @@ -38,7 +46,7 @@ static uint8_t usb_control_buffer[128]; extern "C" { void -otg_fs_isr () +usb_isr () { usbd_poll (usbdev); } @@ -66,16 +74,28 @@ UsbStreamControl::UsbStreamControl (const char *vendor, const char *product) instance_ = this; strings[0] = vendor; strings[1] = product; +#if UCOO_CONFIG_HAL_USB_DRIVER_HS + rcc_periph_clock_enable (RCC_OTGHS); + rcc_periph_clock_enable (RCC_GPIOB); + gpio_mode_setup (GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, + GPIO13 | GPIO14 | GPIO15); + gpio_set_af (GPIOB, GPIO_AF12, GPIO13 | GPIO14 | GPIO15); +#else rcc_periph_clock_enable (RCC_OTGFS); rcc_periph_clock_enable (RCC_GPIOA); gpio_mode_setup (GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9 | GPIO11 | GPIO12); gpio_set_af (GPIOA, GPIO_AF10, GPIO9 | GPIO11 | GPIO12); - usbdev = usbd_init (&otgfs_usb_driver, &usb_desc_dev, &usb_desc_config, +#endif + usbdev = usbd_init (&usb_driver, &usb_desc_dev, &usb_desc_config, strings, lengthof (strings), usb_control_buffer, sizeof (usb_control_buffer)); usbd_register_set_config_callback (usbdev, set_config); +#if UCOO_CONFIG_HAL_USB_DRIVER_HS + nvic_enable_irq (NVIC_OTG_HS_IRQ); +#else nvic_enable_irq (NVIC_OTG_FS_IRQ); +#endif } void -- cgit v1.2.3