From 29c43d9e33c9200f83b059ea317b9c7485e5863a Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Sun, 11 Dec 2016 10:33:52 +0100 Subject: [PATCH] Projectkk2glider/usb hardening (#4125) * USB fixes: * USB initialized when USB cable is inserted and de-initialized when disconnected (this was the original way, which proved itself unreliable in the past. Now with the new USB library it appears to work without any problems. Used in this way result in safer operation - USB controller is disabled while unconnected) Works without force device mod * Serial: initialization of global variables * Reduced RAM usage - data moved to FLASH * Detailed USB interrupt counters (+ debug print fix) --- radio/src/debug.cpp | 36 +++++++++++++- radio/src/debug.h | 46 +++++++++++++++++- radio/src/main_arm.cpp | 18 +------ radio/src/targets/common/arm/CMakeLists.txt | 4 ++ .../src/targets/common/arm/stm32/usbd_cdc.cpp | 4 +- .../common/arm/stm32/usbd_storage_msd.cpp | 17 ++----- radio/src/targets/horus/board.cpp | 1 + radio/src/targets/taranis/board.cpp | 1 + radio/src/targets/taranis/bootloader/boot.cpp | 3 ++ .../Class/cdc/inc/usbd_cdc_core.h | 2 +- .../Class/cdc/src/usbd_cdc_core.c | 47 +++++++++++-------- .../Class/msc/inc/usbd_msc_core.h | 2 +- .../Class/msc/inc/usbd_msc_mem.h | 2 +- .../Class/msc/src/usbd_msc_core.c | 21 +++++---- .../Core/src/usbd_core.c | 4 -- .../STM32_USB_OTG_Driver/src/usb_dcd_int.c | 18 +++++++ 16 files changed, 157 insertions(+), 69 deletions(-) diff --git a/radio/src/debug.cpp b/radio/src/debug.cpp index 5f28c57ae..d67f0431b 100644 --- a/radio/src/debug.cpp +++ b/radio/src/debug.cpp @@ -118,8 +118,25 @@ void dumpTraceBuffer() "Tim1 ", // INT_TIM1CC, "Tim2 ", // INT_TIM2, "Tim3 ", // INT_TIM3, - "Usb " // INT_OTG_FS, "BlueT", // INT_BLUETOOTH, + "USB ", // INT_OTG_FS, +#if defined(DEBUG_USB_INTERRUPTS) + " spur", // INT_OTG_FS_SPURIOUS, + " out", // INT_OTG_FS_OUT_EP, + " in", // INT_OTG_FS_IN_EP, + " miss", // INT_OTG_FS_MODEMISMATCH, + " wake", // INT_OTG_FS_WAKEUP, + " susp", // INT_OTG_FS_SUSPEND, + " sof", // INT_OTG_FS_SOF, + " rxst", // INT_OTG_FS_RX_STAT, + " rst", // INT_OTG_FS_RESET, + " enum", // INT_OTG_FS_ENUM, + " inci", // INT_OTG_FS_INCOMPLETE_IN, + " inco", // INT_OTG_FS_INCOMPLETE_OUT, + " sess", // INT_OTG_FS_SESSION, + " otg", // INT_OTG_FS_OTG, + " notd", // INT_OTG_FS_RX_NOT_DEVICE, +#endif // #if defined(DEBUG_USB_INTERRUPTS) }; #elif defined(PCBTARANIS) const char * interruptNames[INT_LAST] = { @@ -136,6 +153,23 @@ void dumpTraceBuffer() "TelUs", // INT_TELEM_USART, "Train", // INT_TRAINER, "Usb ", // INT_OTG_FS, +#if defined(DEBUG_USB_INTERRUPTS) + " spur", // INT_OTG_FS_SPURIOUS, + " out", // INT_OTG_FS_OUT_EP, + " in", // INT_OTG_FS_IN_EP, + " miss", // INT_OTG_FS_MODEMISMATCH, + " wake", // INT_OTG_FS_WAKEUP, + " susp", // INT_OTG_FS_SUSPEND, + " sof", // INT_OTG_FS_SOF, + " rxst", // INT_OTG_FS_RX_STAT, + " rst", // INT_OTG_FS_RESET, + " enum", // INT_OTG_FS_ENUM, + " inci", // INT_OTG_FS_INCOMPLETE_IN, + " inco", // INT_OTG_FS_INCOMPLETE_OUT, + " sess", // INT_OTG_FS_SESSION, + " otg", // INT_OTG_FS_OTG, + " notd", // INT_OTG_FS_RX_NOT_DEVICE, +#endif // #if defined(DEBUG_USB_INTERRUPTS) }; #endif diff --git a/radio/src/debug.h b/radio/src/debug.h index 96c5d5ff6..7a0982c26 100644 --- a/radio/src/debug.h +++ b/radio/src/debug.h @@ -210,8 +210,25 @@ enum InterruptNames { INT_TIM1CC, INT_TIM2, INT_TRAINER, - INT_OTG_FS, INT_BLUETOOTH, + INT_OTG_FS, +#if defined(DEBUG_USB_INTERRUPTS) + INT_OTG_FS_SPURIOUS, + INT_OTG_FS_OUT_EP, + INT_OTG_FS_IN_EP, + INT_OTG_FS_MODEMISMATCH, + INT_OTG_FS_WAKEUP, + INT_OTG_FS_SUSPEND, + INT_OTG_FS_SOF, + INT_OTG_FS_RX_STAT, + INT_OTG_FS_RESET, + INT_OTG_FS_ENUM, + INT_OTG_FS_INCOMPLETE_IN, + INT_OTG_FS_INCOMPLETE_OUT, + INT_OTG_FS_SESSION, + INT_OTG_FS_OTG, + INT_OTG_FS_RX_NOT_DEVICE, +#endif // #if defined(DEBUG_USB_INTERRUPTS) INT_LAST }; #elif defined(PCBTARANIS) @@ -229,6 +246,23 @@ enum InterruptNames { INT_TELEM_USART, INT_TRAINER, INT_OTG_FS, +#if defined(DEBUG_USB_INTERRUPTS) + INT_OTG_FS_SPURIOUS, + INT_OTG_FS_OUT_EP, + INT_OTG_FS_IN_EP, + INT_OTG_FS_MODEMISMATCH, + INT_OTG_FS_WAKEUP, + INT_OTG_FS_SUSPEND, + INT_OTG_FS_SOF, + INT_OTG_FS_RX_STAT, + INT_OTG_FS_RESET, + INT_OTG_FS_ENUM, + INT_OTG_FS_INCOMPLETE_IN, + INT_OTG_FS_INCOMPLETE_OUT, + INT_OTG_FS_SESSION, + INT_OTG_FS_OTG, + INT_OTG_FS_RX_NOT_DEVICE, +#endif // #if defined(DEBUG_USB_INTERRUPTS) INT_LAST }; #endif @@ -243,8 +277,18 @@ extern const char * interruptNames[INT_LAST]; extern struct InterruptCounters interruptCounters; #define DEBUG_INTERRUPT(int) (++interruptCounters.cnt[int]) + +#if defined(DEBUG_USB_INTERRUPTS) + #define DEBUG_USB_INTERRUPT(int) DEBUG_INTERRUPT(int) #else + #define DEBUG_USB_INTERRUPT(int) +#endif + +#else //#if defined(DEBUG_INTERRUPTS) + #define DEBUG_INTERRUPT(int) +#define DEBUG_USB_INTERRUPT(int) + #endif //#if defined(DEBUG_INTERRUPTS) #if defined(DEBUG_TASKS) diff --git a/radio/src/main_arm.cpp b/radio/src/main_arm.cpp index 963e6ff92..13c656806 100644 --- a/radio/src/main_arm.cpp +++ b/radio/src/main_arm.cpp @@ -31,22 +31,7 @@ void handleUsbConnection() if (!usbStarted && usbPlugged()) { usbStarted = true; - - /* - We used to initialize USB peripheral and driver here. - According to my tests this is way too late. The USB peripheral - therefore does not have enough information to start responding to - USB host request, which causes very slow USB device recognition, - multiple USB device resets, etc... - - If we want to change the USB profile, the procedure is simple: - * USB cable must be disconnected - * call usbDeInit(); - * call usbUnit(); which initializes USB with the new profile. - Obviously the usbInit() should be modified to have a runtime - selection of the USB profile. - */ - + usbInit(); #if defined(USB_MASS_STORAGE) opentxClose(false); usbPluggedIn(); @@ -54,6 +39,7 @@ void handleUsbConnection() } if (usbStarted && !usbPlugged()) { usbStarted = false; + usbDeInit(); #if defined(USB_MASS_STORAGE) && !defined(EEPROM) opentxResume(); #endif diff --git a/radio/src/targets/common/arm/CMakeLists.txt b/radio/src/targets/common/arm/CMakeLists.txt index 3067b80b1..a74978a01 100644 --- a/radio/src/targets/common/arm/CMakeLists.txt +++ b/radio/src/targets/common/arm/CMakeLists.txt @@ -9,6 +9,7 @@ option(DEBUG_TRACE_BUFFER "Debug Trace Screen" OFF) option(MULTIMODULE "DIY Multiprotocol TX Module (https://github.com/pascallanger/DIY-Multiprotocol-TX-Module)" OFF) option(SUPPORT_D16_EU_ONLY "XJT module only supports D16-EU and LR12-EU" OFF) # TODO rename to XJT_EU_ONLY option(DEBUG_INTERRUPTS "Count interrupts" OFF) +option(DEBUG_USB_INTERRUPTS "Count individual USB interrupts" OFF) option(DEBUG_TASKS "Task switching statistics" OFF) option(DEBUG_TIMERS "Time critical parts of the code" OFF) @@ -41,6 +42,9 @@ endif() if(DEBUG_INTERRUPTS) add_definitions(-DDEBUG_INTERRUPTS) set(DEBUG ON) + if(DEBUG_USB_INTERRUPTS) + add_definitions(-DDEBUG_USB_INTERRUPTS) + endif() endif() if(DEBUG_TASKS) add_definitions(-DDEBUG_TASKS) diff --git a/radio/src/targets/common/arm/stm32/usbd_cdc.cpp b/radio/src/targets/common/arm/stm32/usbd_cdc.cpp index ab2c00617..1bc2fef4a 100644 --- a/radio/src/targets/common/arm/stm32/usbd_cdc.cpp +++ b/radio/src/targets/common/arm/stm32/usbd_cdc.cpp @@ -51,9 +51,7 @@ static uint16_t VCP_DeInit (void); static uint16_t VCP_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len); static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len); -// static uint16_t VCP_COMConfig(uint8_t Conf); - -CDC_IF_Prop_TypeDef VCP_fops = +extern "C" const CDC_IF_Prop_TypeDef VCP_fops = { VCP_Init, VCP_DeInit, diff --git a/radio/src/targets/common/arm/stm32/usbd_storage_msd.cpp b/radio/src/targets/common/arm/stm32/usbd_storage_msd.cpp index 7d490be0b..3a5854d2f 100644 --- a/radio/src/targets/common/arm/stm32/usbd_storage_msd.cpp +++ b/radio/src/targets/common/arm/stm32/usbd_storage_msd.cpp @@ -96,7 +96,7 @@ int8_t STORAGE_Write (uint8_t lun, int8_t STORAGE_GetMaxLun (void); -USBD_STORAGE_cb_TypeDef USBD_MICRO_SDIO_fops = +const USBD_STORAGE_cb_TypeDef USBD_MICRO_SDIO_fops = // modified my OpenTX { STORAGE_Init, STORAGE_GetCapacity, @@ -108,9 +108,7 @@ USBD_STORAGE_cb_TypeDef USBD_MICRO_SDIO_fops = (int8_t *)STORAGE_Inquirydata, }; -USBD_STORAGE_cb_TypeDef *USBD_STORAGE_fops = &USBD_MICRO_SDIO_fops; - -__IO uint32_t count = 0; +const USBD_STORAGE_cb_TypeDef * const USBD_STORAGE_fops = &USBD_MICRO_SDIO_fops; // modified my OpenTX #if defined(__cplusplus) && !defined(SIMU) } @@ -172,14 +170,9 @@ uint8_t lunReady[STORAGE_LUN_NBR]; void usbPluggedIn() { - if (lunReady[STORAGE_SDCARD_LUN] == 0) { - lunReady[STORAGE_SDCARD_LUN] = 1; - } - + lunReady[STORAGE_SDCARD_LUN] = 1; #if defined(EEPROM) - if (lunReady[STORAGE_EEPROM_LUN] == 0) { - lunReady[STORAGE_EEPROM_LUN] = 1; - } + lunReady[STORAGE_EEPROM_LUN] = 1; #endif } @@ -719,7 +712,7 @@ int32_t fat12Write(const uint8_t * buffer, uint16_t sector, uint16_t count) FATWRITE_FIRMWARE }; - static unsigned int operation = FATWRITE_NONE; + static uint8_t operation = FATWRITE_NONE; TRACE("FAT12 Write(sector=%d, count=%d)", sector, count); diff --git a/radio/src/targets/horus/board.cpp b/radio/src/targets/horus/board.cpp index 10b7b2adc..f9b4b2acb 100644 --- a/radio/src/targets/horus/board.cpp +++ b/radio/src/targets/horus/board.cpp @@ -175,6 +175,7 @@ void boardInit() init2MhzTimer(); init1msTimer(); usbInit(); + usbDeInit(); hapticInit(); bluetoothInit(BLUETOOTH_FACTORY_BAUDRATE); gpsInit(GPS_USART_BAUDRATE); diff --git a/radio/src/targets/taranis/board.cpp b/radio/src/targets/taranis/board.cpp index 6f3ebab90..d26d78cbb 100644 --- a/radio/src/targets/taranis/board.cpp +++ b/radio/src/targets/taranis/board.cpp @@ -138,6 +138,7 @@ void boardInit() __enable_irq(); i2cInit(); usbInit(); + usbDeInit(); #if defined(DEBUG) && !defined(PCBX7D) serial2Init(0, 0); // default serial mode (None if DEBUG not defined) diff --git a/radio/src/targets/taranis/bootloader/boot.cpp b/radio/src/targets/taranis/bootloader/boot.cpp index 115312022..1979139e0 100644 --- a/radio/src/targets/taranis/bootloader/boot.cpp +++ b/radio/src/targets/taranis/bootloader/boot.cpp @@ -361,6 +361,7 @@ int main() // SD card detect pin sdInit(); usbInit(); + usbDeInit(); #endif for (;;) { @@ -383,6 +384,7 @@ int main() unlocked = 1; unlockFlash(); } + usbInit(); usbPluggedIn(); } } @@ -417,6 +419,7 @@ int main() lcdDrawTextAlignedLeft(4*FH, STR_USB_CONNECTED); if (usbPlugged() == 0) { vpos = 0; + usbDeInit(); if (unlocked) { lockFlash(); unlocked = 0; diff --git a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/cdc/inc/usbd_cdc_core.h b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/cdc/inc/usbd_cdc_core.h index 2be7072f8..a9711727e 100644 --- a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/cdc/inc/usbd_cdc_core.h +++ b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/cdc/inc/usbd_cdc_core.h @@ -117,7 +117,7 @@ CDC_IF_Prop_TypeDef; * @{ */ -extern USBD_Class_cb_TypeDef USBD_CDC_cb; +extern const USBD_Class_cb_TypeDef USBD_CDC_cb; // modified my OpenTX /** * @} */ diff --git a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_core.c b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_core.c index fe744a114..448e4916f 100644 --- a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_core.c +++ b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/cdc/src/usbd_cdc_core.c @@ -138,22 +138,24 @@ static uint8_t *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length); /** @defgroup usbd_cdc_Private_Variables * @{ */ -extern CDC_IF_Prop_TypeDef APP_FOPS; +extern const CDC_IF_Prop_TypeDef APP_FOPS; // modified my OpenTX extern const uint8_t USBD_DeviceDesc [USB_SIZ_DEVICE_DESC]; // modified by OpenTX -#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED - #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 - #endif -#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ -__ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc [USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END ; +// modified my OpenTX +// #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED +// #if defined ( __ICCARM__ ) /*!< IAR Compiler */ +// #pragma data_alignment=4 +// #endif +// #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ +// __ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc [USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END ; -#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED - #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 - #endif -#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ -__ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc [USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END ; +// modified my OpenTX +// #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED +// #if defined ( __ICCARM__ ) /*!< IAR Compiler */ +// #pragma data_alignment=4 +// #endif +// #endif USB_OTG_HS_INTERNAL_DMA_ENABLED +// __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc [USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END ; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ @@ -191,10 +193,10 @@ uint32_t APP_Rx_length = 0; uint8_t USB_Tx_State = USB_CDC_IDLE; static uint32_t cdcCmd = 0xFF; -static uint32_t cdcLen = 0; +static uint8_t cdcLen = 0; // modified by OpenTX /* CDC interface class callbacks structure */ -USBD_Class_cb_TypeDef USBD_CDC_cb = +const USBD_Class_cb_TypeDef USBD_CDC_cb = // modified by OpenTX { usbd_cdc_Init, usbd_cdc_DeInit, @@ -218,7 +220,7 @@ USBD_Class_cb_TypeDef USBD_CDC_cb = #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* USB CDC device Configuration Descriptor */ -__ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = +__ALIGN_BEGIN const uint8_t usbd_cdc_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = // modified by OpenTX { /*Configuration Descriptor*/ 0x09, /* bLength: Configuration Descriptor size */ @@ -323,7 +325,7 @@ __ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = #pragma data_alignment=4 #endif #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ -__ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = +__ALIGN_BEGIN const uint8_t usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = // modified by OpenTX { 0x09, /* bLength: Configuration Descriptor size */ USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, @@ -436,6 +438,13 @@ uint8_t usbd_cdc_Init (void *pdev, { uint8_t *pbuf; + APP_Rx_ptr_in = 0; // modified by OpenTX + APP_Rx_ptr_out = 0; // modified by OpenTX + APP_Rx_length = 0; // modified by OpenTX + USB_Tx_State = USB_CDC_IDLE; // modified by OpenTX + cdcCmd = 0xFF; // modified by OpenTX + cdcLen = 0; // modified by OpenTX + /* Open EP IN */ DCD_EP_Open(pdev, CDC_IN_EP, @@ -702,9 +711,9 @@ uint8_t usbd_cdc_DataOut (void *pdev, uint8_t epnum) */ uint8_t usbd_cdc_SOF (void *pdev) { - static uint32_t FrameCount = 0; + static uint8_t FrameCount = 0; // modified by OpenTX - if (FrameCount++ == CDC_IN_FRAME_INTERVAL) + if (FrameCount++ >= CDC_IN_FRAME_INTERVAL) // modified by OpenTX { /* Reset the frame counter */ FrameCount = 0; diff --git a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_core.h b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_core.h index dfa5d6d79..f6bc1b247 100644 --- a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_core.h +++ b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_core.h @@ -61,7 +61,7 @@ * @{ */ -extern USBD_Class_cb_TypeDef USBD_MSC_cb; +extern const USBD_Class_cb_TypeDef USBD_MSC_cb; // modified my OpenTX /** * @} */ diff --git a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_mem.h b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_mem.h index 1fd477fc7..a31e18632 100644 --- a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_mem.h +++ b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/msc/inc/usbd_msc_mem.h @@ -92,7 +92,7 @@ typedef struct _USBD_STORAGE /** @defgroup USBD_MEM_Exported_FunctionsPrototype * @{ */ -extern USBD_STORAGE_cb_TypeDef *USBD_STORAGE_fops; +extern const USBD_STORAGE_cb_TypeDef * const USBD_STORAGE_fops; // modified my OpenTX /** * @} */ diff --git a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_core.c b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_core.c index bbe654a9d..f642b19be 100644 --- a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_core.c +++ b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_core.c @@ -110,7 +110,7 @@ uint8_t *USBD_MSC_GetOtherCfgDesc (uint8_t speed, #endif -uint8_t USBD_MSC_CfgDesc[USB_MSC_CONFIG_DESC_SIZ]; +// uint8_t USBD_MSC_CfgDesc[USB_MSC_CONFIG_DESC_SIZ]; // modified by OpenTX @@ -125,7 +125,7 @@ uint8_t USBD_MSC_CfgDesc[USB_MSC_CONFIG_DESC_SIZ]; */ -USBD_Class_cb_TypeDef USBD_MSC_cb = +const USBD_Class_cb_TypeDef USBD_MSC_cb = // modified by OpenTX { USBD_MSC_Init, USBD_MSC_DeInit, @@ -150,7 +150,7 @@ USBD_Class_cb_TypeDef USBD_MSC_cb = #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ /* USB Mass storage device Configuration Descriptor */ /* All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */ -__ALIGN_BEGIN uint8_t USBD_MSC_CfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = +__ALIGN_BEGIN const uint8_t USBD_MSC_CfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END = // modified by OpenTX { 0x09, /* bLength: Configuation Descriptor size */ @@ -240,12 +240,13 @@ __ALIGN_BEGIN uint8_t USBD_MSC_OtherCfgDesc[USB_MSC_CONFIG_DESC_SIZ] __ALIGN_END }; #endif -#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED - #if defined ( __ICCARM__ ) /*!< IAR Compiler */ - #pragma data_alignment=4 - #endif -#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ -__ALIGN_BEGIN static uint8_t USBD_MSC_MaxLun __ALIGN_END = 0; +// modified my OpenTX +// #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED +// #if defined ( __ICCARM__ ) /*!< IAR Compiler */ +// #pragma data_alignment=4 +// #endif +// #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ +// __ALIGN_BEGIN static uint8_t USBD_MSC_MaxLun __ALIGN_END = 0; #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #if defined ( __ICCARM__ ) /*!< IAR Compiler */ @@ -334,6 +335,7 @@ uint8_t USBD_MSC_Setup (void *pdev, USB_SETUP_REQ *req) (req->wLength == 1) && ((req->bmRequest & 0x80) == 0x80)) { + __ALIGN_BEGIN uint8_t USBD_MSC_MaxLun __ALIGN_END; // modified by OpenTX USBD_MSC_MaxLun = USBD_STORAGE_fops->GetMaxLun(); if(USBD_MSC_MaxLun > 0) { @@ -345,7 +347,6 @@ uint8_t USBD_MSC_Setup (void *pdev, USB_SETUP_REQ *req) { USBD_CtlError(pdev , req); return USBD_FAIL; - } } else diff --git a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Core/src/usbd_core.c b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Core/src/usbd_core.c index 6eb1d2195..c3c9c8741 100644 --- a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Core/src/usbd_core.c +++ b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_Device_Library/Core/src/usbd_core.c @@ -153,10 +153,6 @@ void USBD_Init(USB_OTG_CORE_HANDLE *pdev, /* Upon Init call usr callback */ pdev->dev.usr_cb->Init(); - /* Force Device Mode*/ - // IMPORTANT: without this here, the USB works upon radio start only in 50% cases - USB_OTG_SetCurrentMode(pdev, DEVICE_MODE); // modified by OpenTX - /* Enable Interrupts */ USB_OTG_BSP_EnableInterrupt(pdev); } diff --git a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_OTG_Driver/src/usb_dcd_int.c b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_OTG_Driver/src/usb_dcd_int.c index cc17ed6db..f1db9adaf 100644 --- a/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_OTG_Driver/src/usb_dcd_int.c +++ b/radio/src/thirdparty/STM32_USB-Host-Device_Lib_V2.2.0/Libraries/STM32_USB_OTG_Driver/src/usb_dcd_int.c @@ -28,6 +28,7 @@ /* Includes ------------------------------------------------------------------*/ #include "usb_dcd_int.h" #include "board.h" // modified by OpenTX +#include "debug.h" // modified by OpenTX /** @addtogroup USB_OTG_DRIVER * @{ @@ -216,21 +217,25 @@ uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev) gintr_status.d32 = USB_OTG_ReadCoreItr(pdev); if (!gintr_status.d32) /* avoid spurious interrupt */ { + DEBUG_USB_INTERRUPT(INT_OTG_FS_SPURIOUS); // modified by OpenTX return 0; } if (gintr_status.b.outepintr) { + DEBUG_USB_INTERRUPT(INT_OTG_FS_OUT_EP); // modified by OpenTX retval |= DCD_HandleOutEP_ISR(pdev); } if (gintr_status.b.inepint) { + DEBUG_USB_INTERRUPT(INT_OTG_FS_IN_EP); // modified by OpenTX retval |= DCD_HandleInEP_ISR(pdev); } if (gintr_status.b.modemismatch) { + DEBUG_USB_INTERRUPT(INT_OTG_FS_MODEMISMATCH); // modified by OpenTX USB_OTG_GINTSTS_TypeDef gintsts; /* Clear interrupt */ @@ -241,56 +246,69 @@ uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev) if (gintr_status.b.wkupintr) { + DEBUG_USB_INTERRUPT(INT_OTG_FS_WAKEUP); // modified by OpenTX retval |= DCD_HandleResume_ISR(pdev); } if (gintr_status.b.usbsuspend) { + DEBUG_USB_INTERRUPT(INT_OTG_FS_SUSPEND); // modified by OpenTX retval |= DCD_HandleUSBSuspend_ISR(pdev); } if (gintr_status.b.sofintr) { + DEBUG_USB_INTERRUPT(INT_OTG_FS_SOF); // modified by OpenTX retval |= DCD_HandleSof_ISR(pdev); } if (gintr_status.b.rxstsqlvl) { + DEBUG_USB_INTERRUPT(INT_OTG_FS_RX_STAT); // modified by OpenTX retval |= DCD_HandleRxStatusQueueLevel_ISR(pdev); } if (gintr_status.b.usbreset) { + DEBUG_USB_INTERRUPT(INT_OTG_FS_RESET); // modified by OpenTX retval |= DCD_HandleUsbReset_ISR(pdev); } if (gintr_status.b.enumdone) { + DEBUG_USB_INTERRUPT(INT_OTG_FS_ENUM); // modified by OpenTX retval |= DCD_HandleEnumDone_ISR(pdev); } if (gintr_status.b.incomplisoin) { + DEBUG_USB_INTERRUPT(INT_OTG_FS_INCOMPLETE_IN); // modified by OpenTX retval |= DCD_IsoINIncomplete_ISR(pdev); } if (gintr_status.b.incomplisoout) { + DEBUG_USB_INTERRUPT(INT_OTG_FS_INCOMPLETE_OUT); // modified by OpenTX retval |= DCD_IsoOUTIncomplete_ISR(pdev); } #ifdef VBUS_SENSING_ENABLED if (gintr_status.b.sessreqintr) { + DEBUG_USB_INTERRUPT(INT_OTG_FS_SESSION); // modified by OpenTX retval |= DCD_SessionRequest_ISR(pdev); } if (gintr_status.b.otgintr) { + DEBUG_USB_INTERRUPT(INT_OTG_FS_OTG); // modified by OpenTX retval |= DCD_OTG_ISR(pdev); } #endif } + else { + DEBUG_USB_INTERRUPT(INT_OTG_FS_RX_NOT_DEVICE); // modified by OpenTX + } return retval; }