- H723 added
- some H7-related defines reworked
This commit is contained in:
parent
d671bac4af
commit
4ddb02fb17
@ -1,9 +1,16 @@
|
|||||||
#ifndef CORE_USB_USB_COMMON_DEFS
|
#ifndef CORE_USB_USB_COMMON_DEFS
|
||||||
#define CORE_USB_USB_COMMON_DEFS
|
#define CORE_USB_USB_COMMON_DEFS
|
||||||
|
|
||||||
#if defined(STM32H745xx) || defined(STM32H743xx)
|
#if defined(STM32H745xx) || defined(STM32H743xx) || defined(STM32H723xx)
|
||||||
#include <stm32h7xx.h>
|
#include <stm32h7xx.h>
|
||||||
#include <stm32h7xx_hal.h>
|
#include <stm32h7xx_hal.h>
|
||||||
|
|
||||||
|
#if defined(STM32H745xx) || defined(STM32H743xx)
|
||||||
|
#define USBG (USB_OTG_FS)
|
||||||
|
#elif defined(STM32H723xx)
|
||||||
|
#define USBG (USB_OTG_HS)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define USB_STM32H7
|
#define USB_STM32H7
|
||||||
#elif defined(STM32F407xx) || defined(STM32F401xC)
|
#elif defined(STM32F407xx) || defined(STM32F401xC)
|
||||||
#include <stm32f4xx.h>
|
#include <stm32f4xx.h>
|
||||||
|
27
usb_driver.c
27
usb_driver.c
@ -52,7 +52,11 @@ static const char *FIFO_STATUS_STR[6] = {
|
|||||||
// ---------------
|
// ---------------
|
||||||
|
|
||||||
#if defined(USB_STM32H7)
|
#if defined(USB_STM32H7)
|
||||||
|
#ifndef STM32H723xx
|
||||||
#define USB_GPIO_AF (GPIO_AF10_OTG2_FS)
|
#define USB_GPIO_AF (GPIO_AF10_OTG2_FS)
|
||||||
|
#else
|
||||||
|
//#define USB_GPIO_AF (GPIO_AF10_OTG1_HS)
|
||||||
|
#endif
|
||||||
#elif defined(USB_STM32F4)
|
#elif defined(USB_STM32F4)
|
||||||
#ifdef USB_HIGH_SPEED
|
#ifdef USB_HIGH_SPEED
|
||||||
#define USB_GPIO_AF (GPIO_AF10_OTG_HS)
|
#define USB_GPIO_AF (GPIO_AF10_OTG_HS)
|
||||||
@ -66,11 +70,13 @@ static const char *FIFO_STATUS_STR[6] = {
|
|||||||
void usbdrv_gpio_init() {
|
void usbdrv_gpio_init() {
|
||||||
// turn GPIO-s into AF mode
|
// turn GPIO-s into AF mode
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE(); // turn ON GPIOA clocks
|
__HAL_RCC_GPIOA_CLK_ENABLE(); // turn ON GPIOA clocks
|
||||||
|
|
||||||
#ifdef USB_HIGH_SPEED
|
#ifdef USB_HIGH_SPEED
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef USB_GPIO_AF
|
||||||
GPIO_InitTypeDef gpio_init;
|
GPIO_InitTypeDef gpio_init;
|
||||||
gpio_init.Mode = GPIO_MODE_AF_PP;
|
gpio_init.Mode = GPIO_MODE_AF_PP;
|
||||||
gpio_init.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
gpio_init.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||||
@ -112,6 +118,7 @@ void usbdrv_gpio_init() {
|
|||||||
|
|
||||||
// HAL_GPIO_Init(GPIOA, &gpio_init); // USB VBUSSENSE
|
// HAL_GPIO_Init(GPIOA, &gpio_init); // USB VBUSSENSE
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------
|
// ---------------
|
||||||
@ -119,7 +126,11 @@ void usbdrv_gpio_init() {
|
|||||||
#ifdef USB_HIGH_SPEED
|
#ifdef USB_HIGH_SPEED
|
||||||
#define USB_IRQn OTG_HS_IRQn
|
#define USB_IRQn OTG_HS_IRQn
|
||||||
#else
|
#else
|
||||||
|
#ifndef STM32H723xx
|
||||||
#define USB_IRQn OTG_FS_IRQn
|
#define USB_IRQn OTG_FS_IRQn
|
||||||
|
#else
|
||||||
|
#define USB_IRQn OTG_HS_IRQn
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// initialize USB subsystem
|
// initialize USB subsystem
|
||||||
@ -201,7 +212,9 @@ __weak void usbdrv_ulpi_init() {
|
|||||||
void usbdrv_periph_init() {
|
void usbdrv_periph_init() {
|
||||||
#if defined(USB_STM32H7)
|
#if defined(USB_STM32H7)
|
||||||
HAL_PWREx_EnableUSBVoltageDetector();
|
HAL_PWREx_EnableUSBVoltageDetector();
|
||||||
WAIT_FOR_nBIT(PWR->CR3, PWR_CR3_USB33RDY);
|
//WAIT_FOR_nBIT(PWR->CR3, PWR_CR3_USB33RDY);
|
||||||
|
|
||||||
|
__HAL_RCC_USB1_OTG_HS_CLK_ENABLE();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USB_STM32F4
|
#ifdef USB_STM32F4
|
||||||
@ -214,7 +227,7 @@ void usbdrv_periph_init() {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// HAL_Delay(1000);
|
HAL_Delay(1000);
|
||||||
|
|
||||||
//__HAL_RCC_USB_OTG_FS_ULPI_CLK_ENABLE();
|
//__HAL_RCC_USB_OTG_FS_ULPI_CLK_ENABLE();
|
||||||
//__HAL_RCC_USB_OTG_FS_FORCE_RESET();
|
//__HAL_RCC_USB_OTG_FS_FORCE_RESET();
|
||||||
@ -224,6 +237,7 @@ void usbdrv_periph_init() {
|
|||||||
SET_BIT(USBG->GUSBCFG, USB_OTG_GUSBCFG_PHYSEL); // select the internal FS PHY
|
SET_BIT(USBG->GUSBCFG, USB_OTG_GUSBCFG_PHYSEL); // select the internal FS PHY
|
||||||
|
|
||||||
SET_BIT(USBG->GRSTCTL, USB_OTG_GRSTCTL_CSRST); // reset USB core
|
SET_BIT(USBG->GRSTCTL, USB_OTG_GRSTCTL_CSRST); // reset USB core
|
||||||
|
HAL_Delay(1);
|
||||||
WAIT_FOR_BIT(USBG->GRSTCTL, USB_OTG_GRSTCTL_CSRST);
|
WAIT_FOR_BIT(USBG->GRSTCTL, USB_OTG_GRSTCTL_CSRST);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@ -243,11 +257,6 @@ void usbdrv_periph_init() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
(uint32_t *)(((uint32_t)USBG) + 0x028), // DIEPTXF0
|
|
||||||
(uint32_t *)(((uint32_t)USBG) + 0x104), // DIEPTXF1
|
|
||||||
(uint32_t *)(((uint32_t)USBG) + 0x108), // DIEPTXF2
|
|
||||||
(uint32_t *)(((uint32_t)USBG) + 0x10C), // DIEPTXF3
|
|
||||||
|
|
||||||
CLEAR_BIT(USBG->GCCFG, USB_OTG_GCCFG_PWRDWN); // power down the peripheral
|
CLEAR_BIT(USBG->GCCFG, USB_OTG_GCCFG_PWRDWN); // power down the peripheral
|
||||||
|
|
||||||
CLEAR_BIT(USBG->GAHBCFG, USB_OTG_GAHBCFG_GINT); // mask all interrupts for now
|
CLEAR_BIT(USBG->GAHBCFG, USB_OTG_GAHBCFG_GINT); // mask all interrupts for now
|
||||||
@ -1029,7 +1038,11 @@ bool usbdrv_get_endpoint_interrupt_flag(uint8_t ep, uint8_t dir) {
|
|||||||
#ifdef USB_HIGH_SPEED
|
#ifdef USB_HIGH_SPEED
|
||||||
void OTG_HS_IRQHandler()
|
void OTG_HS_IRQHandler()
|
||||||
#else
|
#else
|
||||||
|
#ifndef STM32H723xx
|
||||||
void OTG_FS_IRQHandler()
|
void OTG_FS_IRQHandler()
|
||||||
|
#else
|
||||||
|
void OTG_HS_IRQHandler()
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user