device selection macros simplified
This commit is contained in:
		
							parent
							
								
									2a40a41687
								
							
						
					
					
						commit
						2f4320170d
					
				@ -4,9 +4,11 @@
 | 
			
		||||
#if defined(STM32H745xx) || defined(STM32H743xx)
 | 
			
		||||
#include <stm32h7xx.h>
 | 
			
		||||
#include <stm32h7xx_hal.h>
 | 
			
		||||
#elif defined(STM32F407xx)
 | 
			
		||||
#include <stm32f407xx.h>
 | 
			
		||||
#define USB_STM32H7
 | 
			
		||||
#elif defined(STM32F407xx) || defined(STM32F401xC)
 | 
			
		||||
#include <stm32f4xx.h>
 | 
			
		||||
#include <stm32f4xx_hal.h>
 | 
			
		||||
#define USB_STM32F4
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define USBG (USB_OTG_FS)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										20
									
								
								usb_driver.c
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								usb_driver.c
									
									
									
									
									
								
							@ -42,9 +42,9 @@ static const char *FIFO_STATUS_STR[6] = {
 | 
			
		||||
 | 
			
		||||
// ---------------
 | 
			
		||||
 | 
			
		||||
#if defined(STM32H745xx) || defined(STM32H743xx)
 | 
			
		||||
#if defined(USB_STM32H7)
 | 
			
		||||
#define USB_GPIO_AF (GPIO_AF10_OTG2_FS)
 | 
			
		||||
#elif defined(STM32F407xx)
 | 
			
		||||
#elif defined(USB_STM32F4)
 | 
			
		||||
#define USB_GPIO_AF (GPIO_AF10_OTG_FS)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@ -132,10 +132,10 @@ void usbdrv_init_global_state() {
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if defined(STM32H745xx) || defined(STM32H743xx)
 | 
			
		||||
#if defined(USB_STM32H7)
 | 
			
		||||
#define TOCAL_VALUE (0x00)
 | 
			
		||||
#define TRDT_VALUE (0x05)
 | 
			
		||||
#elif defined(STM32F407xx)
 | 
			
		||||
#elif defined(USB_STM32F4)
 | 
			
		||||
#define TOCAL_VALUE (0x07)
 | 
			
		||||
#define TRDT_VALUE (0x06)
 | 
			
		||||
#endif
 | 
			
		||||
@ -146,7 +146,7 @@ void usbdrv_init_global_state() {
 | 
			
		||||
 | 
			
		||||
// initialize USB peripheral
 | 
			
		||||
void usbdrv_periph_init() {
 | 
			
		||||
#if defined(STM32H745xx) || defined(STM32H743xx)
 | 
			
		||||
#if defined(USB_STM32H7)
 | 
			
		||||
    HAL_PWREx_EnableUSBVoltageDetector();
 | 
			
		||||
    WAIT_FOR_nBIT(PWR->CR3, PWR_CR3_USB33RDY);
 | 
			
		||||
#endif
 | 
			
		||||
@ -159,7 +159,7 @@ void usbdrv_periph_init() {
 | 
			
		||||
    //__HAL_RCC_USB_OTG_FS_FORCE_RESET();
 | 
			
		||||
    //__HAL_RCC_USB_OTG_FS_RELEASE_RESET();
 | 
			
		||||
 | 
			
		||||
#if defined(STM32H745xx) || defined(STM32H743xx)
 | 
			
		||||
#if defined(USB_STM32H7)
 | 
			
		||||
    SET_BIT(USBG->GUSBCFG, USB_OTG_GUSBCFG_PHYSEL); // select the internal FS PHY
 | 
			
		||||
 | 
			
		||||
    SET_BIT(USBG->GRSTCTL, USB_OTG_GRSTCTL_CSRST); // reset USB core
 | 
			
		||||
@ -174,10 +174,10 @@ void usbdrv_periph_init() {
 | 
			
		||||
    WRITE_FIELD(USBG->GUSBCFG, USB_OTG_GUSBCFG_TOCAL, TOCAL_VALUE);            // set TOCAL
 | 
			
		||||
    SET_BIT(USBG->GUSBCFG, USB_OTG_GUSBCFG_FDMOD);                             // force Device mode
 | 
			
		||||
 | 
			
		||||
#if defined(STM32H745xx) || defined(STM32H743xx)
 | 
			
		||||
#if defined(USB_STM32H7)
 | 
			
		||||
    CLEAR_BIT(USBG->GCCFG, USB_OTG_GCCFG_VBDEN);                                // turn on VBUSSENSE
 | 
			
		||||
    SET_BIT(USBG->GOTGCTL, USB_OTG_GOTGCTL_BVALOEN | USB_OTG_GOTGCTL_BVALOVAL); // force B-session
 | 
			
		||||
#elif defined(STM32F407xx)
 | 
			
		||||
#elif defined(USB_STM32F4)
 | 
			
		||||
    SET_BIT(USBG->GCCFG, USB_OTG_GCCFG_NOVBUSSENS); // turn off VBUSSENSE
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@ -305,9 +305,9 @@ void usbdrv_fetch_endpoint_configuration(uint8_t config_index) {
 | 
			
		||||
#define USB_RX_FIFO_SETUP_RESERVATION_DWORDS (10)
 | 
			
		||||
#define USB_MIN_GROSS_TX_FIFO_SIZE (2 * USB_MIN_EP_FIFO_SIZE)
 | 
			
		||||
 | 
			
		||||
#ifdef STM32F407xx
 | 
			
		||||
#if defined(USB_STM32F4)
 | 
			
		||||
#define USB_MIN_GROSS_RX_FIFO_SIZE (2 * USB_MIN_EP_FIFO_SIZE + USB_RX_FIFO_SETUP_RESERVATION_DWORDS * 4)
 | 
			
		||||
#elif defined(STM32H745xx) || defined(STM32H743xx)
 | 
			
		||||
#elif defined(USB_STM32H7)
 | 
			
		||||
#define USB_MIN_GROSS_RX_FIFO_SIZE (256)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user