- doxygen styling added - CDC -> ACM refactor - type refactoring - examples categorized - flatUSB_config.h examples added
82 lines
1.8 KiB
C
82 lines
1.8 KiB
C
#ifndef SRC_FLATUSB_CONFIG
|
|
#define SRC_FLATUSB_CONFIG
|
|
|
|
#include <stm32h7xx_hal.h>
|
|
|
|
#define USB_VBUSSENSE (0)
|
|
|
|
// H723
|
|
#if 1
|
|
static inline void usbdrv_gpio_init() {
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
#if USB_VBUSSENSE
|
|
// FIXME
|
|
#endif
|
|
}
|
|
// H743
|
|
#elif 1
|
|
static inline void usbdrv_gpio_init() {
|
|
__HAL_RCC_GPIOA_CLK_ENABLE(); // turn ON GPIOA clocks
|
|
|
|
GPIO_InitTypeDef gpio_init;
|
|
gpio_init.Mode = GPIO_MODE_AF_PP;
|
|
gpio_init.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
gpio_init.Pull = GPIO_NOPULL;
|
|
gpio_init.Alternate = GPIO_AF10_OTG_FS;
|
|
|
|
gpio_init.Pin = GPIO_PIN_11 | GPIO_PIN_12;
|
|
HAL_GPIO_Init(GPIOA, &gpio_init); // USB D-, D+
|
|
|
|
#if USB_VBUSSENSE
|
|
// FIXME
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
// H723
|
|
#if 1
|
|
#define USB_IRQ_N OTG_HS_IRQn
|
|
#define USB_IRQ_HANDLER OTG_HS_IRQHandler
|
|
|
|
// H743
|
|
#elif 1
|
|
#define USB_IRQ_N OTG_FS_IRQn
|
|
#define USB_IRQ_HANDLER OTG_FS_IRQHandler
|
|
#endif
|
|
|
|
#define USB_IRQ_PRIORITY (8)
|
|
#define USB_IRQ_SET_PRIORITY(irq, priority) HAL_NVIC_SetPriority((irq),(priority),0)
|
|
#define USB_IRQ_ENABLE(irq) HAL_NVIC_EnableIRQ((irq))
|
|
#define USB_IRQ_DISABLE(irq) HAL_NVIC_DisableIRQ((irq))
|
|
|
|
// H723
|
|
#if 1
|
|
#define USBG (USB_OTG_HS)
|
|
|
|
// H743
|
|
#elif 1
|
|
#define USBG (USB_OTG_FS)
|
|
#endif
|
|
|
|
#define USB_STM32H7_ENABLE_USB_VOLTAGE_DETECTOR() HAL_PWREx_EnableUSBVoltageDetector(); WAIT_FOR_nBIT_DELAY(PWR->CR3, PWR_CR3_USB33RDY, 1)
|
|
|
|
// STM32H723
|
|
#if 1
|
|
#define USB_CLOCK_ENABLE() USB_STM32H7_ENABLE_USB_VOLTAGE_DETECTOR(); __HAL_RCC_USB1_OTG_HS_CLK_ENABLE()
|
|
|
|
// STM32H743
|
|
#elif 1
|
|
#define USB_CLOCK_ENABLE() USB_STM32H7_ENABLE_USB_VOLTAGE_DETECTOR(); __HAL_RCC_USB2_OTG_FS_CLK_ENABLE()
|
|
#endif
|
|
|
|
#define USB_INTERNAL (1)
|
|
#define USB_UPLI (0)
|
|
|
|
#include "embfmt/embformat.h"
|
|
#define SNPRINTF(str, n, fmt, ...) embfmt(str, n, fmt, __VA_ARGS__)
|
|
|
|
#ifdef USBDBGMSG
|
|
#define USBMSG(...) MSG(__VA_ARGS__)
|
|
#endif
|
|
|
|
#endif /* SRC_FLATUSB_CONFIG */ |