Projectkk2glider/issue 4086 usb and serial (#4097)

* Serial2 changes:
  * stm32 driver moved to common dir.
  * earlier start of driver (Taranis)
  * wait for free buffer time limited
USB changes:
 * Upgrade to ST USB-Host-Device_Lib_V2.2.0 (from V2.1.0) - this fixed a problem with USB serial #4086)
 * other fixes for #4086

* USB-Host-Device_Lib: renamed directory to V2.2.0 (from V2.1.0)
This commit is contained in:
Damjan Adamic
2016-12-06 20:32:30 +01:00
committed by Bertrand Songis
parent 9a6e64e67b
commit 5a5cf7cf33
77 changed files with 2772 additions and 749 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ set(TRANSLATIONS "EN" CACHE STRING "Radio language")
option(HELI "Heli menu" ON) option(HELI "Heli menu" ON)
option(FLIGHT_MODES "Flight Modes" ON) option(FLIGHT_MODES "Flight Modes" ON)
option(CURVES "Curves" ON) option(CURVES "Curves" ON)
option(GVARS "Global variables") option(GVARS "Global variables" ON)
option(GUI "GUI enabled" ON) option(GUI "GUI enabled" ON)
option(SPLASH "Splash enabled" ON) option(SPLASH "Splash enabled" ON)
set(PPM_UNIT "PERCENT_PREC1" CACHE STRING "PPM display unit (US/PERCENT_PREC1/PERCENT_PREC0)") set(PPM_UNIT "PERCENT_PREC1" CACHE STRING "PPM display unit (US/PERCENT_PREC1/PERCENT_PREC0)")
+3
View File
@@ -95,6 +95,7 @@ void menuStatisticsView(event_t event)
extern uint16_t usbWraps; extern uint16_t usbWraps;
extern uint16_t charsWritten; extern uint16_t charsWritten;
extern "C" volatile uint32_t APP_Rx_ptr_in; extern "C" volatile uint32_t APP_Rx_ptr_in;
extern "C" volatile uint32_t APP_Rx_ptr_out;
#endif #endif
void menuStatisticsDebug(event_t event) void menuStatisticsDebug(event_t event)
@@ -171,6 +172,8 @@ void menuStatisticsDebug(event_t event)
lcdDrawText(lcdLastPos, MENU_DEBUG_Y_USB, " "); lcdDrawText(lcdLastPos, MENU_DEBUG_Y_USB, " ");
lcdDrawNumber(lcdLastPos, MENU_DEBUG_Y_USB, APP_Rx_ptr_in, LEFT); lcdDrawNumber(lcdLastPos, MENU_DEBUG_Y_USB, APP_Rx_ptr_in, LEFT);
lcdDrawText(lcdLastPos, MENU_DEBUG_Y_USB, " "); lcdDrawText(lcdLastPos, MENU_DEBUG_Y_USB, " ");
lcdDrawNumber(lcdLastPos, MENU_DEBUG_Y_USB, APP_Rx_ptr_out, LEFT);
lcdDrawText(lcdLastPos, MENU_DEBUG_Y_USB, " ");
lcdDrawNumber(lcdLastPos, MENU_DEBUG_Y_USB, usbWraps, LEFT); lcdDrawNumber(lcdLastPos, MENU_DEBUG_Y_USB, usbWraps, LEFT);
#endif #endif
+4 -4
View File
@@ -2451,6 +2451,10 @@ void opentxInit(OPENTX_INIT_ARGS)
storageReadAll(); storageReadAll();
#endif #endif
#if defined(SERIAL2)
serial2Init(g_eeGeneral.serial2Mode, MODEL_TELEMETRY_PROTOCOL());
#endif
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
BACKLIGHT_ENABLE(); BACKLIGHT_ENABLE();
#endif #endif
@@ -2507,10 +2511,6 @@ void opentxInit(OPENTX_INIT_ARGS)
#endif #endif
backlightOn(); backlightOn();
#if defined(SERIAL2)
serial2Init(g_eeGeneral.serial2Mode, MODEL_TELEMETRY_PROTOCOL());
#endif
#if defined(PCBSKY9X) && !defined(SIMU) #if defined(PCBSKY9X) && !defined(SIMU)
init_trainer_capture(); init_trainer_capture();
#endif #endif
@@ -107,7 +107,6 @@ set(TARGET_SRC
trainer_driver.cpp trainer_driver.cpp
audio_driver.cpp audio_driver.cpp
telemetry_driver.cpp telemetry_driver.cpp
${SERIAL2_DRIVER}
) )
set(FIRMWARE_SRC set(FIRMWARE_SRC
${FIRMWARE_SRC} ${FIRMWARE_SRC}
@@ -1,7 +1,7 @@
set(LUA "NO" CACHE STRING "Lua scripts (YES/NO/NO_MODEL_SCRIPTS)") set(LUA "NO" CACHE STRING "Lua scripts (YES/NO/NO_MODEL_SCRIPTS)")
set(USB "JOYSTICK" CACHE STRING "USB option (JOYSTICK/MASSSTORAGE/SERIAL)") set(USB "JOYSTICK" CACHE STRING "USB option (JOYSTICK/MASSSTORAGE/SERIAL)")
set(ARCH ARM) set(ARCH ARM)
set(STM32USB_DIR ${THIRDPARTY_DIR}/STM32_USB-Host-Device_Lib_V2.1.0/Libraries) set(STM32USB_DIR ${THIRDPARTY_DIR}/STM32_USB-Host-Device_Lib_V2.2.0/Libraries)
add_definitions(-DSTM32 -DLUA_INPUTS -DVARIO -DSBUS -DCROSSFIRE) add_definitions(-DSTM32 -DLUA_INPUTS -DVARIO -DSBUS -DCROSSFIRE)
include_directories(${RADIO_SRC_DIRECTORY}/targets/common/arm/stm32) include_directories(${RADIO_SRC_DIRECTORY}/targets/common/arm/stm32)
include_directories(${STM32USB_DIR}/STM32_USB_OTG_Driver/inc) include_directories(${STM32USB_DIR}/STM32_USB_OTG_Driver/inc)
@@ -9,6 +9,8 @@ include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Core/inc)
include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Class/msc/inc) include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Class/msc/inc)
include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Class/hid/inc) include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Class/hid/inc)
include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Class/cdc/inc) include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Class/cdc/inc)
include_directories(${STM32USB_DIR}/STM32_USB_Device_Library/Core/inc/)
include_directories(${STM32USB_DIR}/STM32_USB_OTG_Driver/inc)
set(STM32USB_SRC set(STM32USB_SRC
STM32_USB_OTG_Driver/src/usb_core.c STM32_USB_OTG_Driver/src/usb_core.c
STM32_USB_OTG_Driver/src/usb_dcd.c STM32_USB_OTG_Driver/src/usb_dcd.c
@@ -21,6 +23,7 @@ set(TARGET_SRC
${TARGET_SRC} ${TARGET_SRC}
../common/arm/stm32/rtc_driver.cpp ../common/arm/stm32/rtc_driver.cpp
../common/arm/stm32/cpu_id.cpp ../common/arm/stm32/cpu_id.cpp
${SERIAL2_DRIVER}
) )
set(FIRMWARE_TARGET_SRC set(FIRMWARE_TARGET_SRC
${FIRMWARE_TARGET_SRC} ${FIRMWARE_TARGET_SRC}
@@ -106,9 +106,15 @@ void serial2Init(unsigned int mode, unsigned int protocol)
void serial2Putc(char c) void serial2Putc(char c)
{ {
while (serial2TxFifo.isFull()); #if !defined(SIMU)
int n = 0;
while (serial2TxFifo.isFull()) {
delay_ms(1);
if (++n > 100) return;
}
serial2TxFifo.push(c); serial2TxFifo.push(c);
USART_ITConfig(SERIAL_USART, USART_IT_TXE, ENABLE); USART_ITConfig(SERIAL_USART, USART_IT_TXE, ENABLE);
#endif
} }
void serial2SbusInit() void serial2SbusInit()
@@ -19,7 +19,7 @@
*/ */
#include "board.h" #include "board.h"
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h" #include "usb_dcd_int.h"
#include "debug.h" #include "debug.h"
int usbPlugged(void) int usbPlugged(void)
+32 -14
View File
@@ -153,27 +153,45 @@ uint16_t charsWritten = 0;
void usbSerialPutc(uint8_t c) void usbSerialPutc(uint8_t c)
{ {
/*
Apparently there is no reliable way to tell if the
virtual serial port is opened or not.
The cdcConnected variable only reports the state
of the physical USB connection.
*/
if (!cdcConnected) return; if (!cdcConnected) return;
uint32_t txDataLen; uint32_t prim = __get_PRIMASK();
do { __disable_irq();
txDataLen = APP_RX_DATA_SIZE + APP_Rx_ptr_in - APP_Rx_ptr_out; uint32_t txDataLen = APP_RX_DATA_SIZE + APP_Rx_ptr_in - APP_Rx_ptr_out;
if (txDataLen >= APP_RX_DATA_SIZE) { if (!prim) __enable_irq();
txDataLen -= APP_RX_DATA_SIZE;
} if (txDataLen >= APP_RX_DATA_SIZE) {
// TODO timeout exit txDataLen -= APP_RX_DATA_SIZE;
} while (txDataLen >= (APP_RX_DATA_SIZE - CDC_DATA_MAX_PACKET_SIZE)); }
if (txDataLen > (APP_RX_DATA_SIZE - CDC_DATA_MAX_PACKET_SIZE)) return; // buffer is too full, skip this write
APP_Rx_Buffer[APP_Rx_ptr_in] = c;
++charsWritten; ++charsWritten;
/* To avoid buffer overflow */
if (APP_Rx_ptr_in >= APP_RX_DATA_SIZE-1) { /*
APP_Rx_Buffer and associated variables must be modified
atomically, because they are used from the interrupt
*/
/* Read PRIMASK register, check interrupt status before you disable them */
/* Returns 0 if they are enabled, or non-zero if disabled */
prim = __get_PRIMASK();
__disable_irq();
APP_Rx_Buffer[APP_Rx_ptr_in++] = c;
if(APP_Rx_ptr_in >= APP_RX_DATA_SIZE)
{
APP_Rx_ptr_in = 0; APP_Rx_ptr_in = 0;
++usbWraps; ++usbWraps;
} }
else { if (!prim) __enable_irq();
APP_Rx_ptr_in++;
}
} }
/** /**
@@ -138,6 +138,8 @@ __ALIGN_BEGIN const uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END
HIBYTE(USBD_LANGID_STRING), HIBYTE(USBD_LANGID_STRING),
}; };
__ALIGN_BEGIN uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ] __ALIGN_END ; // modified by OpenTX
/* /*
* @brief USBD_USR_DeviceDescriptor * @brief USBD_USR_DeviceDescriptor
* return the device descriptor * return the device descriptor
+1 -1
View File
@@ -66,7 +66,7 @@ if(INTERNAL_GPS)
add_definitions(-DINTERNAL_GPS) add_definitions(-DINTERNAL_GPS)
message("Internal GPS enabled") message("Internal GPS enabled")
endif() endif()
set(SERIAL2_DRIVER serial2_driver.cpp) set(SERIAL2_DRIVER ../common/arm/stm32/serial2_driver.cpp)
set(GVAR_SCREEN model_gvars.cpp) set(GVAR_SCREEN model_gvars.cpp)
set(TARGET_SRC set(TARGET_SRC
${TARGET_SRC} ${TARGET_SRC}
+4 -2
View File
@@ -23,8 +23,8 @@
#if defined(__cplusplus) && !defined(SIMU) #if defined(__cplusplus) && !defined(SIMU)
extern "C" { extern "C" {
#endif #endif
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h" #include "usb_dcd_int.h"
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_bsp.h" #include "usb_bsp.h"
#if defined(__cplusplus) && !defined(SIMU) #if defined(__cplusplus) && !defined(SIMU)
} }
#endif #endif
@@ -158,7 +158,9 @@ void boardInit()
// FrSky removed the volume chip in latest board, that's why it doesn't answer! // FrSky removed the volume chip in latest board, that's why it doesn't answer!
// i2cInit(); // i2cInit();
#if defined(DEBUG)
serial2Init(0, 0); // default serial mode (None if DEBUG not defined) serial2Init(0, 0); // default serial mode (None if DEBUG not defined)
#endif
__enable_irq(); __enable_irq();
+1 -2
View File
@@ -96,6 +96,7 @@ set(TARGET_SRC
haptic_driver.cpp haptic_driver.cpp
sdcard_driver.cpp sdcard_driver.cpp
massstorage.cpp massstorage.cpp
serial2_driver.cpp
) )
set(FIRMWARE_SRC set(FIRMWARE_SRC
@@ -107,5 +108,3 @@ set(SRC
${SRC} ${SRC}
debug.cpp debug.cpp
) )
set(SERIAL2_DRIVER serial2_driver.cpp)
+3 -3
View File
@@ -17,7 +17,7 @@ if(PCB STREQUAL X9E)
bluetooth_driver.cpp bluetooth_driver.cpp
startup_stm32f40_41xxx.s startup_stm32f40_41xxx.s
) )
set(SERIAL2_DRIVER serial2_driver.cpp) set(SERIAL2_DRIVER ../common/arm/stm32/serial2_driver.cpp)
if(STICKS STREQUAL HORUS) if(STICKS STREQUAL HORUS)
add_definitions(-DHORUS_STICKS) add_definitions(-DHORUS_STICKS)
endif() endif()
@@ -38,7 +38,7 @@ elseif(PCB STREQUAL X9D+)
set(GUI_SRC ${GUI_SRC} bmp.cpp) set(GUI_SRC ${GUI_SRC} bmp.cpp)
set(BITMAPS_TARGET taranis_bitmaps) set(BITMAPS_TARGET taranis_bitmaps)
set(LCD_DRIVER lcd_driver_spi.cpp) set(LCD_DRIVER lcd_driver_spi.cpp)
set(SERIAL2_DRIVER serial2_driver.cpp) set(SERIAL2_DRIVER ../common/arm/stm32/serial2_driver.cpp)
set(GVAR_SCREEN model_gvars.cpp) set(GVAR_SCREEN model_gvars.cpp)
elseif(PCB STREQUAL X9D) elseif(PCB STREQUAL X9D)
set(CPU_TYPE STM32F2) set(CPU_TYPE STM32F2)
@@ -52,7 +52,7 @@ elseif(PCB STREQUAL X9D)
set(GUI_SRC ${GUI_SRC} bmp.cpp) set(GUI_SRC ${GUI_SRC} bmp.cpp)
set(BITMAPS_TARGET taranis_bitmaps) set(BITMAPS_TARGET taranis_bitmaps)
set(LCD_DRIVER lcd_driver_aspi.cpp) set(LCD_DRIVER lcd_driver_aspi.cpp)
set(SERIAL2_DRIVER serial2_driver.cpp) set(SERIAL2_DRIVER ../common/arm/stm32/serial2_driver.cpp)
set(GVAR_SCREEN model_gvars.cpp) set(GVAR_SCREEN model_gvars.cpp)
elseif(PCB STREQUAL X7D) elseif(PCB STREQUAL X7D)
set(CPU_TYPE STM32F2) set(CPU_TYPE STM32F2)
+7 -2
View File
@@ -23,8 +23,8 @@
#if defined(__cplusplus) && !defined(SIMU) #if defined(__cplusplus) && !defined(SIMU)
extern "C" { extern "C" {
#endif #endif
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_dcd_int.h" #include "usb_dcd_int.h"
#include "STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/inc/usb_bsp.h" #include "usb_bsp.h"
#if defined(__cplusplus) && !defined(SIMU) #if defined(__cplusplus) && !defined(SIMU)
} }
#endif #endif
@@ -139,6 +139,11 @@ void boardInit()
i2cInit(); i2cInit();
usbInit(); usbInit();
#if defined(DEBUG)
serial2Init(0, 0); // default serial mode (None if DEBUG not defined)
TRACE("\nTaranis board started :)");
#endif
#if defined(HAPTIC) #if defined(HAPTIC)
hapticInit(); hapticInit();
#endif #endif
@@ -1,165 +0,0 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "opentx.h"
uint8_t serial2Mode = 0;
Fifo<uint8_t, 512> serial2TxFifo;
DMAFifo<32> serial2RxFifo __DMA (SERIAL_DMA_Stream_RX);
void uart3Setup(unsigned int baudrate, bool dma)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_PinAFConfig(SERIAL_GPIO, SERIAL_GPIO_PinSource_RX, SERIAL_GPIO_AF);
GPIO_PinAFConfig(SERIAL_GPIO, SERIAL_GPIO_PinSource_TX, SERIAL_GPIO_AF);
GPIO_InitStructure.GPIO_Pin = SERIAL_GPIO_PIN_TX | SERIAL_GPIO_PIN_RX;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(SERIAL_GPIO, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = baudrate;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_Init(SERIAL_USART, &USART_InitStructure);
if (dma) {
DMA_InitTypeDef DMA_InitStructure;
serial2RxFifo.clear();
USART_ITConfig(SERIAL_USART, USART_IT_RXNE, DISABLE);
USART_ITConfig(SERIAL_USART, USART_IT_TXE, DISABLE);
DMA_InitStructure.DMA_Channel = SERIAL_DMA_Channel_RX;
DMA_InitStructure.DMA_PeripheralBaseAddr = CONVERT_PTR_UINT(&SERIAL_USART->DR);
DMA_InitStructure.DMA_Memory0BaseAddr = CONVERT_PTR_UINT(serial2RxFifo.buffer());
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = serial2RxFifo.size();
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_Low;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(SERIAL_DMA_Stream_RX, &DMA_InitStructure);
USART_DMACmd(SERIAL_USART, USART_DMAReq_Rx, ENABLE);
USART_Cmd(SERIAL_USART, ENABLE);
DMA_Cmd(SERIAL_DMA_Stream_RX, ENABLE);
}
else {
USART_Cmd(SERIAL_USART, ENABLE);
USART_ITConfig(SERIAL_USART, USART_IT_RXNE, ENABLE);
USART_ITConfig(SERIAL_USART, USART_IT_TXE, DISABLE);
NVIC_SetPriority(SERIAL_USART_IRQn, 7);
NVIC_EnableIRQ(SERIAL_USART_IRQn);
}
}
void serial2Init(unsigned int mode, unsigned int protocol)
{
serial2Stop();
serial2Mode = mode;
switch (mode) {
case UART_MODE_TELEMETRY_MIRROR:
uart3Setup(FRSKY_SPORT_BAUDRATE, false);
break;
#if !defined(USB_SERIAL) && (defined(DEBUG) || defined(CLI))
case UART_MODE_DEBUG:
uart3Setup(DEBUG_BAUDRATE, false);
break;
#endif
case UART_MODE_TELEMETRY:
if (protocol == PROTOCOL_FRSKY_D_SECONDARY) {
uart3Setup(FRSKY_D_BAUDRATE, true);
}
break;
}
}
void serial2Putc(char c)
{
while (serial2TxFifo.isFull());
serial2TxFifo.push(c);
USART_ITConfig(SERIAL_USART, USART_IT_TXE, ENABLE);
}
void serial2SbusInit()
{
uart3Setup(SBUS_BAUDRATE, true);
SERIAL_USART->CR1 |= USART_CR1_M | USART_CR1_PCE ;
}
void serial2Stop()
{
DMA_DeInit(SERIAL_DMA_Stream_RX);
USART_DeInit(SERIAL_USART);
}
uint8_t serial2TracesEnabled()
{
#if defined(DEBUG)
return (serial2Mode == UART_MODE_DEBUG);
#else
return false;
#endif
}
extern "C" void SERIAL_USART_IRQHandler(void)
{
DEBUG_INTERRUPT(INT_SER2);
// Send
if (USART_GetITStatus(SERIAL_USART, USART_IT_TXE) != RESET) {
uint8_t txchar;
if (serial2TxFifo.pop(txchar)) {
/* Write one byte to the transmit data register */
USART_SendData(SERIAL_USART, txchar);
}
else {
USART_ITConfig(SERIAL_USART, USART_IT_TXE, DISABLE);
}
}
#if !defined(USB_SERIAL) && defined(CLI)
// Receive
uint32_t status = SERIAL_USART->SR;
while (status & (USART_FLAG_RXNE | USART_FLAG_ERRORS)) {
uint8_t data = SERIAL_USART->DR;
if (!(status & USART_FLAG_ERRORS)) {
switch (serial2Mode) {
case UART_MODE_DEBUG:
cliRxFifo.push(data);
break;
}
}
status = SERIAL_USART->SR;
}
#endif
}
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_audio_core.h * @file usbd_audio_core.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief header file for the usbd_audio_core.c file. * @brief header file for the usbd_audio_core.c file.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -30,9 +30,9 @@
#ifndef __USB_AUDIO_CORE_H_ #ifndef __USB_AUDIO_CORE_H_
#define __USB_AUDIO_CORE_H_ #define __USB_AUDIO_CORE_H_
#include "usbd_desc.h"
#include "usbd_ioreq.h" #include "usbd_ioreq.h"
#include "usbd_req.h" #include "usbd_req.h"
#include "usbd_desc.h"
@@ -152,7 +152,7 @@ extern USBD_Class_cb_TypeDef AUDIO_cb;
* @} * @}
*/ */
#endif // __USB_AUDIO_CORE_H_ #endif /* __USB_AUDIO_CORE_H_ */
/** /**
* @} * @}
*/ */
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_audio_out_if.h * @file usbd_audio_out_if.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief header file for the usbd_audio_out_if.c file. * @brief header file for the usbd_audio_out_if.c file.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -51,7 +51,7 @@
/** @defgroup usbd_audio_Exported_Defines /** @defgroup usbd_audio_Exported_Defines
* @{ * @{
*/ */
/* Audio Commands enmueration */ /* Audio Commands enumeration */
typedef enum typedef enum
{ {
AUDIO_CMD_PLAY = 1, AUDIO_CMD_PLAY = 1,
@@ -2,8 +2,8 @@
****************************************************************************** ******************************************************************************
* @file usbd_audio_core.c * @file usbd_audio_core.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief This file provides the high layer firmware functions to manage the * @brief This file provides the high layer firmware functions to manage the
* following functionalities of the USB Audio Class: * following functionalities of the USB Audio Class:
* - Initialization and Configuration of high and low layer * - Initialization and Configuration of high and low layer
@@ -44,7 +44,7 @@
* This driver doesn't implement the following aspects of the specification * This driver doesn't implement the following aspects of the specification
* (but it is possible to manage these features with some modifications on this driver): * (but it is possible to manage these features with some modifications on this driver):
* - AudioControl Endpoint management * - AudioControl Endpoint management
* - AudioControl requsests other than SET_CUR and GET_CUR * - AudioControl requests other than SET_CUR and GET_CUR
* - Abstraction layer for AudioControl requests (only Mute functionality is managed) * - Abstraction layer for AudioControl requests (only Mute functionality is managed)
* - Audio Synchronization type: Adaptive * - Audio Synchronization type: Adaptive
* - Audio Compression modules and interfaces * - Audio Compression modules and interfaces
@@ -59,7 +59,7 @@
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -149,7 +149,7 @@ uint8_t IsocOutBuff [TOTAL_OUT_BUF_SIZE * 2];
uint8_t* IsocOutWrPtr = IsocOutBuff; uint8_t* IsocOutWrPtr = IsocOutBuff;
uint8_t* IsocOutRdPtr = IsocOutBuff; uint8_t* IsocOutRdPtr = IsocOutBuff;
/* Main Buffer for Audio Control Rrequests transfers and its relative variables */ /* Main Buffer for Audio Control Requests transfers and its relative variables */
uint8_t AudioCtl[64]; uint8_t AudioCtl[64];
uint8_t AudioCtlCmd = 0; uint8_t AudioCtlCmd = 0;
uint32_t AudioCtlLen = 0; uint32_t AudioCtlLen = 0;
@@ -337,7 +337,7 @@ static uint8_t usbd_audio_CfgDesc[AUDIO_CONFIG_DESC_SIZE] =
/** /**
* @brief usbd_audio_Init * @brief usbd_audio_Init
* Initilaizes the AUDIO interface. * Initializes the AUDIO interface.
* @param pdev: device instance * @param pdev: device instance
* @param cfgidx: Configuration index * @param cfgidx: Configuration index
* @retval status * @retval status
@@ -465,7 +465,7 @@ static uint8_t usbd_audio_Setup (void *pdev,
/** /**
* @brief usbd_audio_EP0_RxReady * @brief usbd_audio_EP0_RxReady
* Handles audio control requests data. * Handles audio control requests data.
* @param pdev: device device instance * @param pdev: device instance
* @retval status * @retval status
*/ */
static uint8_t usbd_audio_EP0_RxReady (void *pdev) static uint8_t usbd_audio_EP0_RxReady (void *pdev)
@@ -507,8 +507,10 @@ static uint8_t usbd_audio_DataIn (void *pdev, uint8_t epnum)
* @param epnum: endpoint number * @param epnum: endpoint number
* @retval status * @retval status
*/ */
__IO uint32_t DataOutCounter = 0;
static uint8_t usbd_audio_DataOut (void *pdev, uint8_t epnum) static uint8_t usbd_audio_DataOut (void *pdev, uint8_t epnum)
{ {
DataOutCounter++;
if (epnum == AUDIO_OUT_EP) if (epnum == AUDIO_OUT_EP)
{ {
/* Increment the Buffer pointer or roll it back when all buffers are full */ /* Increment the Buffer pointer or roll it back when all buffers are full */
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_audio_out_if.c * @file usbd_audio_out_if.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief This file provides the Audio Out (palyback) interface API. * @brief This file provides the Audio Out (palyback) interface API.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -105,7 +105,7 @@ static uint8_t AudioState = AUDIO_STATE_INACTIVE;
/** /**
* @brief Init * @brief Init
* Initialize and configures all required resources for audio play function. * Initialize and configures all required resources for audio play function.
* @param AudioFreq: Statrtup audio frequency. * @param AudioFreq: Startup audio frequency.
* @param Volume: Startup volume to be set. * @param Volume: Startup volume to be set.
* @param options: specific options passed to low layer function. * @param options: specific options passed to low layer function.
* @retval AUDIO_OK if all operations succeed, AUDIO_FAIL else. * @retval AUDIO_OK if all operations succeed, AUDIO_FAIL else.
@@ -120,7 +120,11 @@ static uint8_t Init (uint32_t AudioFreq,
if (Initialized == 0) if (Initialized == 0)
{ {
/* Call low layer function */ /* Call low layer function */
if (EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, Volume, AudioFreq) != 0) #if defined (USE_STM324x9I_EVAL)
if (EVAL_AUDIO_Init(OUTPUT_DEVICE_BOTH, Volume, AudioFreq) != 0)
#else
if (EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, Volume, AudioFreq) != 0)
#endif
{ {
AudioState = AUDIO_STATE_ERROR; AudioState = AUDIO_STATE_ERROR;
return AUDIO_FAIL; return AUDIO_FAIL;
@@ -153,7 +157,7 @@ static uint8_t DeInit (uint32_t options)
/** /**
* @brief AudioCmd * @brief AudioCmd
* Play, Stop, Pause or Resume current file. * Play, Stop, Pause or Resume current file.
* @param pbuf: address from which file shoud be played. * @param pbuf: address from which file should be played.
* @param size: size of the current buffer/file. * @param size: size of the current buffer/file.
* @param cmd: command to be executed, can be AUDIO_CMD_PLAY , AUDIO_CMD_PAUSE, * @param cmd: command to be executed, can be AUDIO_CMD_PLAY , AUDIO_CMD_PAUSE,
* AUDIO_CMD_RESUME or AUDIO_CMD_STOP. * AUDIO_CMD_RESUME or AUDIO_CMD_STOP.
@@ -186,8 +190,12 @@ static uint8_t AudioCmd(uint8_t* pbuf,
/* If current state is Paused */ /* If current state is Paused */
else if (AudioState == AUDIO_STATE_PAUSED) else if (AudioState == AUDIO_STATE_PAUSED)
{ {
if (EVAL_AUDIO_PauseResume(AUDIO_RESUME, (uint32_t)pbuf, (size/2)) != 0) #if defined (USE_STM324x9I_EVAL)
{ if (EVAL_AUDIO_PauseResume(AUDIO_RESUME) != 0)
#else
if (EVAL_AUDIO_PauseResume(AUDIO_RESUME, (uint32_t)pbuf, (size/2)) != 0)
#endif
{
AudioState = AUDIO_STATE_ERROR; AudioState = AUDIO_STATE_ERROR;
return AUDIO_FAIL; return AUDIO_FAIL;
} }
@@ -227,7 +235,11 @@ static uint8_t AudioCmd(uint8_t* pbuf,
/* Unsupported command */ /* Unsupported command */
return AUDIO_FAIL; return AUDIO_FAIL;
} }
#if defined (USE_STM324x9I_EVAL)
else if (EVAL_AUDIO_PauseResume(AUDIO_PAUSE) != 0)
#else
else if (EVAL_AUDIO_PauseResume(AUDIO_PAUSE, (uint32_t)pbuf, (size/2)) != 0) else if (EVAL_AUDIO_PauseResume(AUDIO_PAUSE, (uint32_t)pbuf, (size/2)) != 0)
#endif
{ {
AudioState = AUDIO_STATE_ERROR; AudioState = AUDIO_STATE_ERROR;
return AUDIO_FAIL; return AUDIO_FAIL;
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_cdc_core.h * @file usbd_cdc_core.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief header file for the usbd_cdc_core.c file. * @brief header file for the usbd_cdc_core.c file.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -48,8 +48,6 @@
#define USB_CDC_CONFIG_DESC_SIZ (67) #define USB_CDC_CONFIG_DESC_SIZ (67)
#define USB_CDC_DESC_SIZ (67-9) #define USB_CDC_DESC_SIZ (67-9)
#define CDC_DESCRIPTOR_TYPE 0x21
#define DEVICE_CLASS_CDC 0x02 #define DEVICE_CLASS_CDC 0x02
#define DEVICE_SUBCLASS_CDC 0x00 #define DEVICE_SUBCLASS_CDC 0x00
@@ -97,7 +95,7 @@ typedef struct _CDC_IF_PROP
uint16_t (*pIf_Init) (void); uint16_t (*pIf_Init) (void);
uint16_t (*pIf_DeInit) (void); uint16_t (*pIf_DeInit) (void);
uint16_t (*pIf_Ctrl) (uint32_t Cmd, uint8_t* Buf, uint32_t Len); uint16_t (*pIf_Ctrl) (uint32_t Cmd, uint8_t* Buf, uint32_t Len);
uint16_t (*pIf_DataTx) (uint8_t* Buf, uint32_t Len); uint16_t (*pIf_DataTx) (void);
uint16_t (*pIf_DataRx) (uint8_t* Buf, uint32_t Len); uint16_t (*pIf_DataRx) (uint8_t* Buf, uint32_t Len);
} }
CDC_IF_Prop_TypeDef; CDC_IF_Prop_TypeDef;
@@ -131,7 +129,7 @@ extern USBD_Class_cb_TypeDef USBD_CDC_cb;
* @} * @}
*/ */
#endif // __USB_CDC_CORE_H_ #endif /* __USB_CDC_CORE_H_ */
/** /**
* @} * @}
*/ */
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_cdc_if_template.h * @file usbd_cdc_if_template.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Header for dfu_mal.c file. * @brief Header for dfu_mal.c file.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -2,8 +2,8 @@
****************************************************************************** ******************************************************************************
* @file usbd_cdc_core.c * @file usbd_cdc_core.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief This file provides the high layer firmware functions to manage the * @brief This file provides the high layer firmware functions to manage the
* following functionalities of the USB CDC Class: * following functionalities of the USB CDC Class:
* - Initialization and Configuration of high and low layer * - Initialization and Configuration of high and low layer
@@ -46,7 +46,7 @@
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -64,8 +64,7 @@
*/ */
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "../inc/usbd_cdc_core.h" #include "usbd_cdc_core.h"
#include "usbd_desc.h" #include "usbd_desc.h"
#include "usbd_req.h" #include "usbd_req.h"
@@ -91,6 +90,11 @@
/** @defgroup usbd_cdc_Private_Defines /** @defgroup usbd_cdc_Private_Defines
* @{ * @{
*/ */
#define USB_CDC_IDLE 0
#define USB_CDC_BUSY 1
#define USB_CDC_ZLP 2
/** /**
* @} * @}
*/ */
@@ -111,19 +115,19 @@
/********************************************* /*********************************************
CDC Device library callbacks CDC Device library callbacks
*********************************************/ *********************************************/
static uint8_t usbd_cdc_Init (void *pdev, uint8_t cfgidx); uint8_t usbd_cdc_Init (void *pdev, uint8_t cfgidx);
static uint8_t usbd_cdc_DeInit (void *pdev, uint8_t cfgidx); uint8_t usbd_cdc_DeInit (void *pdev, uint8_t cfgidx);
static uint8_t usbd_cdc_Setup (void *pdev, USB_SETUP_REQ *req); uint8_t usbd_cdc_Setup (void *pdev, USB_SETUP_REQ *req);
static uint8_t usbd_cdc_EP0_RxReady (void *pdev); uint8_t usbd_cdc_EP0_RxReady (void *pdev);
static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum); uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum);
static uint8_t usbd_cdc_DataOut (void *pdev, uint8_t epnum); uint8_t usbd_cdc_DataOut (void *pdev, uint8_t epnum);
static uint8_t usbd_cdc_SOF (void *pdev); uint8_t usbd_cdc_SOF (void *pdev);
/********************************************* /*********************************************
CDC specific management functions CDC specific management functions
*********************************************/ *********************************************/
static void Handle_USBAsynchXfer (void *pdev); static void Handle_USBAsynchXfer (void *pdev);
static const uint8_t *USBD_cdc_GetCfgDesc (uint8_t speed, uint16_t *length); static const uint8_t *USBD_cdc_GetCfgDesc (uint8_t speed, uint16_t *length); // modified by OpenTX
#ifdef USE_USB_OTG_HS #ifdef USE_USB_OTG_HS
static uint8_t *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length); static uint8_t *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length);
#endif #endif
@@ -135,7 +139,7 @@ static uint8_t *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length);
* @{ * @{
*/ */
extern CDC_IF_Prop_TypeDef APP_FOPS; extern CDC_IF_Prop_TypeDef APP_FOPS;
extern const uint8_t USBD_DeviceDesc [USB_SIZ_DEVICE_DESC]; extern const uint8_t USBD_DeviceDesc [USB_SIZ_DEVICE_DESC]; // modified by OpenTX
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
#if defined ( __ICCARM__ ) /*!< IAR Compiler */ #if defined ( __ICCARM__ ) /*!< IAR Compiler */
@@ -180,11 +184,11 @@ __ALIGN_BEGIN uint8_t APP_Rx_Buffer [APP_RX_DATA_SIZE] __ALIGN_END ;
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
__ALIGN_BEGIN uint8_t CmdBuff[CDC_CMD_PACKET_SZE] __ALIGN_END ; __ALIGN_BEGIN uint8_t CmdBuff[CDC_CMD_PACKET_SZE] __ALIGN_END ;
volatile uint32_t APP_Rx_ptr_in = 0; volatile uint32_t APP_Rx_ptr_in = 0; // modified by OpenTX
volatile uint32_t APP_Rx_ptr_out = 0; volatile uint32_t APP_Rx_ptr_out = 0; // modified by OpenTX
uint32_t APP_Rx_length = 0; uint32_t APP_Rx_length = 0;
uint8_t USB_Tx_State = 0; uint8_t USB_Tx_State = USB_CDC_IDLE;
static uint32_t cdcCmd = 0xFF; static uint32_t cdcCmd = 0xFF;
static uint32_t cdcLen = 0; static uint32_t cdcLen = 0;
@@ -321,7 +325,7 @@ __ALIGN_BEGIN uint8_t usbd_cdc_CfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
__ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
{ {
0x09, /* bLength: Configuation Descriptor size */ 0x09, /* bLength: Configuration Descriptor size */
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
USB_CDC_CONFIG_DESC_SIZ, USB_CDC_CONFIG_DESC_SIZ,
0x00, 0x00,
@@ -422,12 +426,12 @@ __ALIGN_BEGIN uint8_t usbd_cdc_OtherCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_EN
/** /**
* @brief usbd_cdc_Init * @brief usbd_cdc_Init
* Initilaize the CDC interface * Initialize the CDC interface
* @param pdev: device instance * @param pdev: device instance
* @param cfgidx: Configuration index * @param cfgidx: Configuration index
* @retval status * @retval status
*/ */
static uint8_t usbd_cdc_Init (void *pdev, uint8_t usbd_cdc_Init (void *pdev,
uint8_t cfgidx) uint8_t cfgidx)
{ {
uint8_t *pbuf; uint8_t *pbuf;
@@ -473,7 +477,7 @@ static uint8_t usbd_cdc_Init (void *pdev,
* @param cfgidx: Configuration index * @param cfgidx: Configuration index
* @retval status * @retval status
*/ */
static uint8_t usbd_cdc_DeInit (void *pdev, uint8_t usbd_cdc_DeInit (void *pdev,
uint8_t cfgidx) uint8_t cfgidx)
{ {
/* Open EP IN */ /* Open EP IN */
@@ -501,12 +505,9 @@ static uint8_t usbd_cdc_DeInit (void *pdev,
* @param req: usb requests * @param req: usb requests
* @retval status * @retval status
*/ */
static uint8_t usbd_cdc_Setup (void *pdev, uint8_t usbd_cdc_Setup (void *pdev,
USB_SETUP_REQ *req) USB_SETUP_REQ *req)
{ {
uint16_t len=USB_CDC_DESC_SIZ;
uint8_t *pbuf=usbd_cdc_CfgDesc + 9;
switch (req->bmRequest & USB_REQ_TYPE_MASK) switch (req->bmRequest & USB_REQ_TYPE_MASK)
{ {
/* CDC Class Requests -------------------------------*/ /* CDC Class Requests -------------------------------*/
@@ -525,7 +526,7 @@ static uint8_t usbd_cdc_Setup (void *pdev,
CmdBuff, CmdBuff,
req->wLength); req->wLength);
} }
else /* Host-to-Device requeset */ else /* Host-to-Device request */
{ {
/* Set the value of the current command to be processed */ /* Set the value of the current command to be processed */
cdcCmd = req->bRequest; cdcCmd = req->bRequest;
@@ -551,27 +552,13 @@ static uint8_t usbd_cdc_Setup (void *pdev,
USBD_CtlError (pdev, req); USBD_CtlError (pdev, req);
return USBD_FAIL; return USBD_FAIL;
/* Standard Requests -------------------------------*/ /* Standard Requests -------------------------------*/
case USB_REQ_TYPE_STANDARD: case USB_REQ_TYPE_STANDARD:
switch (req->bRequest) switch (req->bRequest)
{ {
case USB_REQ_GET_DESCRIPTOR: case USB_REQ_GET_DESCRIPTOR:
if( (req->wValue >> 8) == CDC_DESCRIPTOR_TYPE) USBD_CtlError (pdev, req);
{ return USBD_FAIL;
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
pbuf = usbd_cdc_Desc;
#else
pbuf = usbd_cdc_CfgDesc + 9 + (9 * USBD_ITF_MAX_NUM);
#endif
len = MIN(USB_CDC_DESC_SIZ , req->wLength);
}
USBD_CtlSendData (pdev,
pbuf,
len);
break;
case USB_REQ_GET_INTERFACE : case USB_REQ_GET_INTERFACE :
USBD_CtlSendData (pdev, USBD_CtlSendData (pdev,
@@ -598,10 +585,10 @@ static uint8_t usbd_cdc_Setup (void *pdev,
/** /**
* @brief usbd_cdc_EP0_RxReady * @brief usbd_cdc_EP0_RxReady
* Data received on control endpoint * Data received on control endpoint
* @param pdev: device device instance * @param pdev: device instance
* @retval status * @retval status
*/ */
static uint8_t usbd_cdc_EP0_RxReady (void *pdev) uint8_t usbd_cdc_EP0_RxReady (void *pdev)
{ {
if (cdcCmd != NO_CMD) if (cdcCmd != NO_CMD)
{ {
@@ -615,6 +602,7 @@ static uint8_t usbd_cdc_EP0_RxReady (void *pdev)
return USBD_OK; return USBD_OK;
} }
/** /**
* @brief usbd_audio_DataIn * @brief usbd_audio_DataIn
* Data sent on non-control IN endpoint * Data sent on non-control IN endpoint
@@ -622,16 +610,16 @@ static uint8_t usbd_cdc_EP0_RxReady (void *pdev)
* @param epnum: endpoint number * @param epnum: endpoint number
* @retval status * @retval status
*/ */
static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum) uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum)
{ {
uint16_t USB_Tx_ptr; uint16_t USB_Tx_ptr;
uint16_t USB_Tx_length; uint16_t USB_Tx_length;
if (USB_Tx_State == 1) if (USB_Tx_State == USB_CDC_BUSY)
{ {
if (APP_Rx_length == 0) if (APP_Rx_length == 0)
{ {
USB_Tx_State = 0; USB_Tx_State = USB_CDC_IDLE;
} }
else else
{ {
@@ -649,6 +637,10 @@ static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum)
APP_Rx_ptr_out += APP_Rx_length; APP_Rx_ptr_out += APP_Rx_length;
APP_Rx_length = 0; APP_Rx_length = 0;
if(USB_Tx_length == CDC_DATA_IN_PACKET_SIZE)
{
USB_Tx_State = USB_CDC_ZLP;
}
} }
/* Prepare the available data buffer to be sent on IN endpoint */ /* Prepare the available data buffer to be sent on IN endpoint */
@@ -656,9 +648,21 @@ static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum)
CDC_IN_EP, CDC_IN_EP,
(uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr], (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr],
USB_Tx_length); USB_Tx_length);
return USBD_OK;
} }
} }
/* Avoid any asynchronous transfer during ZLP */
if (USB_Tx_State == USB_CDC_ZLP)
{
/*Send ZLP to indicate the end of the current transfer */
DCD_EP_Tx (pdev,
CDC_IN_EP,
NULL,
0);
USB_Tx_State = USB_CDC_IDLE;
}
return USBD_OK; return USBD_OK;
} }
@@ -669,7 +673,7 @@ static uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum)
* @param epnum: endpoint number * @param epnum: endpoint number
* @retval status * @retval status
*/ */
static uint8_t usbd_cdc_DataOut (void *pdev, uint8_t epnum) uint8_t usbd_cdc_DataOut (void *pdev, uint8_t epnum)
{ {
uint16_t USB_Rx_Cnt; uint16_t USB_Rx_Cnt;
@@ -696,7 +700,7 @@ static uint8_t usbd_cdc_DataOut (void *pdev, uint8_t epnum)
* @param epnum: endpoint number * @param epnum: endpoint number
* @retval status * @retval status
*/ */
static uint8_t usbd_cdc_SOF (void *pdev) uint8_t usbd_cdc_SOF (void *pdev)
{ {
static uint32_t FrameCount = 0; static uint32_t FrameCount = 0;
@@ -723,7 +727,7 @@ static void Handle_USBAsynchXfer (void *pdev)
uint16_t USB_Tx_ptr; uint16_t USB_Tx_ptr;
uint16_t USB_Tx_length; uint16_t USB_Tx_length;
if(USB_Tx_State != 1) if(USB_Tx_State == USB_CDC_IDLE)
{ {
if (APP_Rx_ptr_out == APP_RX_DATA_SIZE) if (APP_Rx_ptr_out == APP_RX_DATA_SIZE)
{ {
@@ -732,7 +736,7 @@ static void Handle_USBAsynchXfer (void *pdev)
if(APP_Rx_ptr_out == APP_Rx_ptr_in) if(APP_Rx_ptr_out == APP_Rx_ptr_in)
{ {
USB_Tx_State = 0; USB_Tx_State = USB_CDC_IDLE;
return; return;
} }
@@ -747,7 +751,7 @@ static void Handle_USBAsynchXfer (void *pdev)
} }
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
APP_Rx_length &= ~0x03; APP_Rx_length &= ~0x03;
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE) if (APP_Rx_length > CDC_DATA_IN_PACKET_SIZE)
@@ -757,6 +761,7 @@ static void Handle_USBAsynchXfer (void *pdev)
APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE; APP_Rx_ptr_out += CDC_DATA_IN_PACKET_SIZE;
APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE; APP_Rx_length -= CDC_DATA_IN_PACKET_SIZE;
USB_Tx_State = USB_CDC_BUSY;
} }
else else
{ {
@@ -765,15 +770,21 @@ static void Handle_USBAsynchXfer (void *pdev)
APP_Rx_ptr_out += APP_Rx_length; APP_Rx_ptr_out += APP_Rx_length;
APP_Rx_length = 0; APP_Rx_length = 0;
if(USB_Tx_length == CDC_DATA_IN_PACKET_SIZE)
{
USB_Tx_State = USB_CDC_ZLP;
}
else
{
USB_Tx_State = USB_CDC_BUSY;
}
} }
USB_Tx_State = 1;
DCD_EP_Tx (pdev, DCD_EP_Tx (pdev,
CDC_IN_EP, CDC_IN_EP,
(uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr], (uint8_t*)&APP_Rx_Buffer[USB_Tx_ptr],
USB_Tx_length); USB_Tx_length);
} }
} }
/** /**
@@ -783,14 +794,14 @@ static void Handle_USBAsynchXfer (void *pdev)
* @param length : pointer data length * @param length : pointer data length
* @retval pointer to descriptor buffer * @retval pointer to descriptor buffer
*/ */
static const uint8_t *USBD_cdc_GetCfgDesc (uint8_t speed, uint16_t *length) static const uint8_t * USBD_cdc_GetCfgDesc (uint8_t speed, uint16_t *length) // modified by OpenTX
{ {
*length = sizeof (usbd_cdc_CfgDesc); *length = sizeof (usbd_cdc_CfgDesc);
return usbd_cdc_CfgDesc; return usbd_cdc_CfgDesc;
} }
/** /**
* @brief USBD_cdc_GetCfgDesc * @brief USBD_cdc_GetOtherCfgDesc
* Return configuration descriptor * Return configuration descriptor
* @param speed : current device speed * @param speed : current device speed
* @param length : pointer data length * @param length : pointer data length
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_cdc_if_template.c * @file usbd_cdc_if_template.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Generic media access Layer. * @brief Generic media access Layer.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -67,7 +67,7 @@ CDC_IF_Prop_TypeDef TEMPLATE_fops =
* @brief TEMPLATE_Init * @brief TEMPLATE_Init
* Initializes the CDC media low layer * Initializes the CDC media low layer
* @param None * @param None
* @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/ */
static uint16_t TEMPLATE_Init(void) static uint16_t TEMPLATE_Init(void)
{ {
@@ -81,7 +81,7 @@ static uint16_t TEMPLATE_Init(void)
* @brief TEMPLATE_DeInit * @brief TEMPLATE_DeInit
* DeInitializes the CDC media low layer * DeInitializes the CDC media low layer
* @param None * @param None
* @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/ */
static uint16_t TEMPLATE_DeInit(void) static uint16_t TEMPLATE_DeInit(void)
{ {
@@ -98,7 +98,7 @@ static uint16_t TEMPLATE_DeInit(void)
* @param Cmd: Command code * @param Cmd: Command code
* @param Buf: Buffer containing command data (request parameters) * @param Buf: Buffer containing command data (request parameters)
* @param Len: Number of data to be sent (in bytes) * @param Len: Number of data to be sent (in bytes)
* @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/ */
static uint16_t TEMPLATE_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len) static uint16_t TEMPLATE_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len)
{ {
@@ -153,7 +153,7 @@ static uint16_t TEMPLATE_Ctrl (uint32_t Cmd, uint8_t* Buf, uint32_t Len)
* this function. * this function.
* @param Buf: Buffer of data to be sent * @param Buf: Buffer of data to be sent
* @param Len: Number of data to be sent (in bytes) * @param Len: Number of data to be sent (in bytes)
* @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
*/ */
static uint16_t TEMPLATE_DataTx (uint8_t* Buf, uint32_t Len) static uint16_t TEMPLATE_DataTx (uint8_t* Buf, uint32_t Len)
{ {
@@ -0,0 +1,129 @@
/**
******************************************************************************
* @file usbd_customhid_core.h
* @author MCD Application Team
* @version V1.2.0
* @date 09-November-2015
* @brief header file for the usbd_customhid_core.c file.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#ifndef __USB_CUSTOMHID_CORE_H_
#define __USB_CUSTOMHID_CORE_H_
#include "usbd_ioreq.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_CUSTOMHID
* @brief This file is the Header file for usbd_customhid_core.c
* @{
*/
/** @defgroup USBD_CUSTOMHID_Exported_Defines
* @{
*/
#define USBD_CUSTOM_HID_REPORT_DESC_SIZE 163
#define USB_CUSTOM_HID_CONFIG_DESC_SIZ 41
#define USB_CUSTOM_HID_DESC_SIZ 9
#define CUSTOM_HID_DESCRIPTOR_TYPE 0x21
#define CUSTOM_HID_REPORT_DESC 0x22
#define CUSTOM_HID_REQ_SET_PROTOCOL 0x0B
#define CUSTOM_HID_REQ_GET_PROTOCOL 0x03
#define CUSTOM_HID_REQ_SET_IDLE 0x0A
#define CUSTOM_HID_REQ_GET_IDLE 0x02
#define CUSTOM_HID_REQ_SET_REPORT 0x09
#define CUSTOM_HID_REQ_GET_REPORT 0x01
#define LED1_REPORT_ID 0x01
#define LED1_REPORT_COUNT 0x01
#define LED2_REPORT_ID 0x02
#define LED2_REPORT_COUNT 0x01
#define LED3_REPORT_ID 0x03
#define LED3_REPORT_COUNT 0x01
#define LED4_REPORT_ID 0x04
#define LED4_REPORT_COUNT 0x01
#define KEY_REPORT_ID 0x05
#define TAMPER_REPORT_ID 0x06
#define ADC_REPORT_ID 0x07
/**
* @}
*/
/** @defgroup USBD_CORE_Exported_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBD_CORE_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBD_CORE_Exported_Variables
* @{
*/
extern USBD_Class_cb_TypeDef USBD_CUSTOMHID_cb;
/**
* @}
*/
/** @defgroup USB_CORE_Exported_Functions
* @{
*/
uint8_t USBD_CUSTOM_HID_SendReport (USB_OTG_CORE_HANDLE *pdev,
uint8_t *report,
uint16_t len);
/**
* @}
*/
#endif /* __USB_CUSTOMHID_CORE_H_ */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
@@ -0,0 +1,718 @@
/**
******************************************************************************
* @file usbd_customhid_core.c
* @author MCD Application Team
* @version V1.2.0
* @date 09-November-2015
* @brief This file provides the CUSTOM_HID core functions.
*
* @verbatim
*
* ===================================================================
* CUSTOM_HID Class Description
* ===================================================================
* This module manages the HID class V1.11 following the "Device Class Definition
* for Human Interface Devices (CUSTOM_HID) Version 1.11 Jun 27, 2001".
* This driver implements the following aspects of the specification:
* - The Boot Interface Subclass
* - The Mouse protocol
* - Usage Page : Generic Desktop
* - Usage : Vendor
* - Collection : Application
*
* @note In HS mode and when the DMA is used, all variables and data structures
* dealing with the DMA during the transaction process should be 32-bit aligned.
*
*
* @endverbatim
*
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "usbd_customhid_core.h"
#include "usbd_desc.h"
#include "usbd_req.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_CUSTOM_HID
* @brief usbd core module
* @{
*/
/** @defgroup USBD_CUSTOM_HID_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBD_CUSTOM_HID_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup USBD_CUSTOM_HID_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBD_CUSTOM_HID_Private_FunctionPrototypes
* @{
*/
static uint8_t USBD_CUSTOM_HID_Init (void *pdev,
uint8_t cfgidx);
static uint8_t USBD_CUSTOM_HID_DeInit (void *pdev,
uint8_t cfgidx);
static uint8_t USBD_CUSTOM_HID_Setup (void *pdev,
USB_SETUP_REQ *req);
static uint8_t *USBD_CUSTOM_HID_GetCfgDesc (uint8_t speed, uint16_t *length);
static uint8_t USBD_CUSTOM_HID_DataIn (void *pdev, uint8_t epnum);
static uint8_t USBD_CUSTOM_HID_DataOut (void *pdev, uint8_t epnum);
static uint8_t USBD_CUSTOM_HID_EP0_RxReady (void *pdev);
/**
* @}
*/
/** @defgroup USBD_HID_Private_Variables
* @{
*/
USBD_Class_cb_TypeDef USBD_CUSTOMHID_cb =
{
USBD_CUSTOM_HID_Init,
USBD_CUSTOM_HID_DeInit,
USBD_CUSTOM_HID_Setup,
NULL, /*EP0_TxSent*/
USBD_CUSTOM_HID_EP0_RxReady, /*EP0_RxReady*/ /* STATUS STAGE IN */
USBD_CUSTOM_HID_DataIn, /*DataIn*/
USBD_CUSTOM_HID_DataOut,
NULL, /*SOF */
NULL,
NULL,
USBD_CUSTOM_HID_GetCfgDesc,
#ifdef USB_OTG_HS_CORE
USBD_CUSTOM_HID_GetCfgDesc, /* use same config as per FS */
#endif
};
uint8_t Report_buf[2];
uint8_t USBD_HID_Report_ID=0;
__IO uint32_t IsReportAvailable = 0;
extern uint8_t PrevXferDone;
#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 uint32_t USBD_HID_AltSet __ALIGN_END = 0;
#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 uint32_t USBD_HID_Protocol __ALIGN_END = 0;
#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 uint32_t USBD_HID_IdleState __ALIGN_END = 0;
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
#pragma data_alignment=4
#endif
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
/* USB HID device Configuration Descriptor */
__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END =
{
0x09, /* bLength: Configuration Descriptor size */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
USB_CUSTOM_HID_CONFIG_DESC_SIZ,
/* wTotalLength: Bytes returned */
0x00,
0x01, /*bNumInterfaces: 1 interface*/
0x01, /*bConfigurationValue: Configuration value*/
0x00, /*iConfiguration: Index of string descriptor describing
the configuration*/
0xC0, /*bmAttributes: bus powered and Support Remote Wake-up */
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
/************** Descriptor of Custom HID interface ****************/
/* 09 */
0x09, /*bLength: Interface Descriptor size*/
USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/
0x00, /*bInterfaceNumber: Number of Interface*/
0x00, /*bAlternateSetting: Alternate setting*/
0x02, /*bNumEndpoints*/
0x03, /*bInterfaceClass: HID*/
0x00, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
0x00, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
0, /*iInterface: Index of string descriptor*/
/******************** Descriptor of Custom HID ********************/
/* 18 */
0x09, /*bLength: HID Descriptor size*/
CUSTOM_HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
0x11, /*bcdHID: HID Class Spec release number*/
0x01,
0x00, /*bCountryCode: Hardware target country*/
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/
0x22, /*bDescriptorType*/
USBD_CUSTOM_HID_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
0x00,
/******************** Descriptor of Custom HID endpoints ***********/
/* 27 */
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
HID_IN_EP, /* bEndpointAddress: Endpoint Address (IN) */
0x03, /* bmAttributes: Interrupt endpoint */
HID_IN_PACKET, /* wMaxPacketSize: 2 Bytes max */
0x00,
0x20, /* bInterval: Polling Interval (32 ms) */
/* 34 */
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
/* Endpoint descriptor type */
HID_OUT_EP, /* bEndpointAddress: */
/* Endpoint Address (OUT) */
0x03, /* bmAttributes: Interrupt endpoint */
HID_OUT_PACKET, /* wMaxPacketSize: 2 Bytes max */
0x00,
0x20, /* bInterval: Polling Interval (20 ms) */
/* 41 */
} ;
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
#pragma data_alignment=4
#endif
#endif
__ALIGN_BEGIN static uint8_t CustomHID_ReportDesc[USBD_CUSTOM_HID_REPORT_DESC_SIZE] __ALIGN_END =
{
0x06, 0xFF, 0x00, /* USAGE_PAGE (Vendor Page: 0xFF00) */
0x09, 0x01, /* USAGE (Demo Kit) */
0xa1, 0x01, /* COLLECTION (Application) */
/* 6 */
/* Led 1 */
0x85, LED1_REPORT_ID, /* REPORT_ID (1) */
0x09, 0x01, /* USAGE (LED 1) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
0x75, 0x08, /* REPORT_SIZE (8) */
0x95, LED1_REPORT_COUNT, /* REPORT_COUNT (1) */
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
0x85, LED1_REPORT_ID, /* REPORT_ID (1) */
0x09, 0x01, /* USAGE (LED 1) */
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
/* 26 */
/* Led 2 */
0x85, LED2_REPORT_ID, /* REPORT_ID 2 */
0x09, 0x02, /* USAGE (LED 2) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
0x75, 0x08, /* REPORT_SIZE (8) */
0x95, LED2_REPORT_COUNT, /* REPORT_COUNT (1) */
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
0x85, LED2_REPORT_ID, /* REPORT_ID (2) */
0x09, 0x02, /* USAGE (LED 2) */
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
/* 46 */
/* Led 3 */
0x85, LED3_REPORT_ID, /* REPORT_ID (3) */
0x09, 0x03, /* USAGE (LED 3) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
0x75, 0x08, /* REPORT_SIZE (8) */
0x95, LED3_REPORT_COUNT, /* REPORT_COUNT (1) */
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
0x85, LED3_REPORT_ID, /* REPORT_ID (3) */
0x09, 0x03, /* USAGE (LED 3) */
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
/* 66 */
/* Led 4 */
0x85, LED4_REPORT_ID, /* REPORT_ID 4) */
0x09, 0x04, /* USAGE (LED 4) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
0x75, 0x08, /* REPORT_SIZE (8) */
0x95, LED4_REPORT_COUNT, /* REPORT_COUNT (1) */
0xB1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
0x85, LED4_REPORT_ID, /* REPORT_ID (4) */
0x09, 0x04, /* USAGE (LED 4) */
0x91, 0x82, /* OUTPUT (Data,Var,Abs,Vol) */
/* 86 */
/* key Push Button */
0x85, KEY_REPORT_ID, /* REPORT_ID (5) */
0x09, 0x05, /* USAGE (Push Button) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */
0x09, 0x05, /* USAGE (Push Button) */
0x75, 0x01, /* REPORT_SIZE (1) */
0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
0x75, 0x07, /* REPORT_SIZE (7) */
0x81, 0x83, /* INPUT (Cnst,Var,Abs,Vol) */
0x85, KEY_REPORT_ID, /* REPORT_ID (2) */
0x75, 0x07, /* REPORT_SIZE (7) */
0xb1, 0x83, /* FEATURE (Cnst,Var,Abs,Vol) */
/* 114 */
/* Tamper Push Button */
0x85, TAMPER_REPORT_ID,/* REPORT_ID (6) */
0x09, 0x06, /* USAGE (Tamper Push Button) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x25, 0x01, /* LOGICAL_MAXIMUM (1) */
0x75, 0x01, /* REPORT_SIZE (1) */
0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */
0x09, 0x06, /* USAGE (Tamper Push Button) */
0x75, 0x01, /* REPORT_SIZE (1) */
0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
0x75, 0x07, /* REPORT_SIZE (7) */
0x81, 0x83, /* INPUT (Cnst,Var,Abs,Vol) */
0x85, TAMPER_REPORT_ID,/* REPORT_ID (6) */
0x75, 0x07, /* REPORT_SIZE (7) */
0xb1, 0x83, /* FEATURE (Cnst,Var,Abs,Vol) */
/* 142 */
/* ADC IN */
0x85, ADC_REPORT_ID, /* REPORT_ID */
0x09, 0x07, /* USAGE (ADC IN) */
0x15, 0x00, /* LOGICAL_MINIMUM (0) */
0x26, 0xff, 0x00, /* LOGICAL_MAXIMUM (255) */
0x75, 0x08, /* REPORT_SIZE (8) */
0x81, 0x82, /* INPUT (Data,Var,Abs,Vol) */
0x85, ADC_REPORT_ID, /* REPORT_ID (7) */
0x09, 0x07, /* USAGE (ADC in) */
0xb1, 0x82, /* FEATURE (Data,Var,Abs,Vol) */
/* 161 */
0xc0 /* END_COLLECTION */
};
/**
* @}
*/
/** @defgroup USBD_HID_Private_Functions
* @{
*/
/**
* @brief USBD_HID_Init
* Initialize the HID interface
* @param pdev: device instance
* @param cfgidx: Configuration index
* @retval status
*/
static uint8_t USBD_CUSTOM_HID_Init (void *pdev,
uint8_t cfgidx)
{
/* Open EP IN */
DCD_EP_Open(pdev,
HID_IN_EP,
HID_IN_PACKET,
USB_OTG_EP_INT);
/* Open EP OUT */
DCD_EP_Open(pdev,
HID_OUT_EP,
HID_OUT_PACKET,
USB_OTG_EP_INT);
/*Receive Data*/
DCD_EP_PrepareRx(pdev,HID_OUT_EP,Report_buf,2);
return USBD_OK;
}
/**
* @brief USBD_HID_Init
* DeInitialize the HID layer
* @param pdev: device instance
* @param cfgidx: Configuration index
* @retval status
*/
static uint8_t USBD_CUSTOM_HID_DeInit (void *pdev,
uint8_t cfgidx)
{
/* Close HID EPs */
DCD_EP_Close (pdev , HID_IN_EP);
DCD_EP_Close (pdev , HID_OUT_EP);
return USBD_OK;
}
/**
* @brief USBD_HID_Setup
* Handle the HID specific requests
* @param pdev: instance
* @param req: usb requests
* @retval status
*/
static uint8_t USBD_CUSTOM_HID_Setup (void *pdev,
USB_SETUP_REQ *req)
{
uint8_t USBD_HID_Report_LENGTH=0;
uint16_t len = 0;
uint8_t *pbuf = NULL;
switch (req->bmRequest & USB_REQ_TYPE_MASK)
{
case USB_REQ_TYPE_CLASS :
switch (req->bRequest)
{
case CUSTOM_HID_REQ_SET_PROTOCOL:
USBD_HID_Protocol = (uint8_t)(req->wValue);
break;
case CUSTOM_HID_REQ_GET_PROTOCOL:
USBD_CtlSendData (pdev,
(uint8_t *)&USBD_HID_Protocol,
1);
break;
case CUSTOM_HID_REQ_SET_IDLE:
USBD_HID_IdleState = (uint8_t)(req->wValue >> 8);
break;
case CUSTOM_HID_REQ_GET_IDLE:
USBD_CtlSendData (pdev,
(uint8_t *)&USBD_HID_IdleState,
1);
break;
case CUSTOM_HID_REQ_SET_REPORT:
IsReportAvailable = 1;
USBD_HID_Report_ID = (uint8_t)(req->wValue);
USBD_HID_Report_LENGTH = (uint8_t)(req->wLength);
USBD_CtlPrepareRx (pdev, Report_buf, USBD_HID_Report_LENGTH);
break;
default:
USBD_CtlError (pdev, req);
return USBD_FAIL;
}
break;
case USB_REQ_TYPE_STANDARD:
switch (req->bRequest)
{
case USB_REQ_GET_DESCRIPTOR:
if( req->wValue >> 8 == CUSTOM_HID_REPORT_DESC)
{
len = MIN(USBD_CUSTOM_HID_REPORT_DESC_SIZE , req->wLength);
pbuf = (uint8_t*)CustomHID_ReportDesc;
}
else if( req->wValue >> 8 == CUSTOM_HID_DESCRIPTOR_TYPE)
{
pbuf = (uint8_t*)USBD_CUSTOM_HID_CfgDesc + 0x12;
len = MIN(USB_CUSTOM_HID_DESC_SIZ , req->wLength);
}
USBD_CtlSendData (pdev,
pbuf,
len);
break;
case USB_REQ_GET_INTERFACE :
USBD_CtlSendData (pdev,
(uint8_t *)&USBD_HID_AltSet,
1);
break;
case USB_REQ_SET_INTERFACE :
USBD_HID_AltSet = (uint8_t)(req->wValue);
break;
}
}
return USBD_OK;
}
/**
* @brief USBD_HID_SendReport
* Send HID Report
* @param pdev: device instance
* @param buff: pointer to report
* @retval status
*/
uint8_t USBD_CUSTOM_HID_SendReport (USB_OTG_CORE_HANDLE *pdev,
uint8_t *report,
uint16_t len)
{
if (pdev->dev.device_status == USB_OTG_CONFIGURED )
{
DCD_EP_Tx (pdev, HID_IN_EP, report, len);
}
return USBD_OK;
}
/**
* @brief USBD_HID_GetCfgDesc
* return configuration descriptor
* @param speed : current device speed
* @param length : pointer data length
* @retval pointer to descriptor buffer
*/
static uint8_t *USBD_CUSTOM_HID_GetCfgDesc (uint8_t speed, uint16_t *length)
{
*length = sizeof (USBD_CUSTOM_HID_CfgDesc);
return USBD_CUSTOM_HID_CfgDesc;
}
/**
* @brief USBD_HID_DataIn
* handle data IN Stage
* @param pdev: device instance
* @param epnum: endpoint index
* @retval status
*/
static uint8_t USBD_CUSTOM_HID_DataIn (void *pdev,
uint8_t epnum)
{
/* Ensure that the FIFO is empty before a new transfer, this condition could
be caused by a new transfer before the end of the previous transfer */
DCD_EP_Flush(pdev, HID_IN_EP);
if (epnum == 1) PrevXferDone = 1;
return USBD_OK;
}
/**
* @brief USBD_HID_DataOut
* handle data IN Stage
* @param pdev: device instance
* @param epnum: endpoint index
* @retval status
*/
uint8_t USBD_CUSTOM_HID_DataOut (void *pdev,
uint8_t epnum)
{
BitAction Led_State;
if (epnum == 1)
{
if (Report_buf[1] == 0)
{
Led_State = Bit_RESET;
}
else
{
Led_State = Bit_SET;
}
switch (Report_buf[0])
{
case 1: /* Led 1 */
if (Led_State != Bit_RESET)
{
STM_EVAL_LEDOn(LED1);
}
else
{
STM_EVAL_LEDOff(LED1);
}
break;
case 2: /* Led 2 */
if (Led_State != Bit_RESET)
{
STM_EVAL_LEDOn(LED2);
}
else
{
STM_EVAL_LEDOff(LED2);
}
break;
case 3: /* Led 3 */
if (Led_State != Bit_RESET)
{
STM_EVAL_LEDOn(LED3);
}
else
{
STM_EVAL_LEDOff(LED3);
}
break;
case 4: /* Led 4 */
if (Led_State != Bit_RESET)
{
STM_EVAL_LEDOn(LED4);
}
else
{
STM_EVAL_LEDOff(LED4);
}
break;
default:
STM_EVAL_LEDOff(LED1);
STM_EVAL_LEDOff(LED2);
STM_EVAL_LEDOff(LED3);
STM_EVAL_LEDOff(LED4);
break;
}
}
DCD_EP_PrepareRx(pdev,HID_IN_EP,Report_buf,2);
return USBD_OK;
}
/**
* @brief USBD_HID_EP0_RxReady
* Handles control request data.
* @param pdev: device instance
* @param epnum: endpoint index
* @retval status
*/
uint8_t USBD_CUSTOM_HID_EP0_RxReady(void *pdev)
{
BitAction Led_State;
if (IsReportAvailable == 1)
{
IsReportAvailable = 0;
if (Report_buf[1] == 0)
{
Led_State = Bit_RESET;
}
else
{
Led_State = Bit_SET;
}
switch (Report_buf[0])
{
case 1: /* Led 1 */
if (Led_State != Bit_RESET)
{
STM_EVAL_LEDOn(LED1);
}
else
{
STM_EVAL_LEDOff(LED1);
}
break;
case 2: /* Led 2 */
if (Led_State != Bit_RESET)
{
STM_EVAL_LEDOn(LED2);
}
else
{
STM_EVAL_LEDOff(LED2);
}
break;
case 3: /* Led 3 */
if (Led_State != Bit_RESET)
{
STM_EVAL_LEDOn(LED3);
}
else
{
STM_EVAL_LEDOff(LED3);
}
break;
case 4: /* Led 4 */
if (Led_State != Bit_RESET)
{
STM_EVAL_LEDOn(LED4);
}
else
{
STM_EVAL_LEDOff(LED4);
}
break;
default:
STM_EVAL_LEDOff(LED1);
STM_EVAL_LEDOff(LED2);
STM_EVAL_LEDOff(LED3);
STM_EVAL_LEDOff(LED4);
break;
}
}
return USBD_OK;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_dfu_core.h * @file usbd_dfu_core.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief header file for the usbd_dfu_core.c file. * @brief header file for the usbd_dfu_core.c file.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -181,7 +181,7 @@ extern USBD_Class_cb_TypeDef DFU_cb;
* @} * @}
*/ */
#endif // __USB_DFU_CORE_H_ #endif /* __USB_DFU_CORE_H_ */
/** /**
* @} * @}
*/ */
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_dfu_mal.h * @file usbd_dfu_mal.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Header for usbd_dfu_mal.c file. * @brief Header for usbd_dfu_mal.c file.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "usb_conf.h" #include "usb_conf.h"
#include "usbd_conf.h" #include "usbd_conf.h"
#include "usbd_dfu_core.h" #include "usbd_dfu_core.h"
@@ -54,7 +55,7 @@ DFU_MAL_Prop_TypeDef;
#define MAL_OK 0 #define MAL_OK 0
#define MAL_FAIL 1 #define MAL_FAIL 1
/* utils macro ---------------------------------------------------------------*/ /* useful macro ---------------------------------------------------------------*/
#define _1st_BYTE(x) (uint8_t)((x)&0xFF) /* 1st addressing cycle */ #define _1st_BYTE(x) (uint8_t)((x)&0xFF) /* 1st addressing cycle */
#define _2nd_BYTE(x) (uint8_t)(((x)&0xFF00)>>8) /* 2nd addressing cycle */ #define _2nd_BYTE(x) (uint8_t)(((x)&0xFF00)>>8) /* 2nd addressing cycle */
#define _3rd_BYTE(x) (uint8_t)(((x)&0xFF0000)>>16) /* 3rd addressing cycle */ #define _3rd_BYTE(x) (uint8_t)(((x)&0xFF0000)>>16) /* 3rd addressing cycle */
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_flash_if.h * @file usbd_flash_if.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Header for usbd_flash_if.c file. * @brief Header for usbd_flash_if.c file.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -39,9 +39,15 @@
#ifdef STM32F2XX #ifdef STM32F2XX
#define FLASH_END_ADD 0x08100000 #define FLASH_END_ADD 0x08100000
#define FLASH_IF_STRING "@Internal Flash /0x08000000/03*016Ka,01*016Kg,01*064Kg,07*128Kg" #define FLASH_IF_STRING "@Internal Flash /0x08000000/03*016Ka,01*016Kg,01*064Kg,07*128Kg"
#elif defined(STM32F4XX) #elif defined(STM32F40_41xxx)
#define FLASH_END_ADD 0x08100000 #define FLASH_END_ADD 0x08100000
#define FLASH_IF_STRING "@Internal Flash /0x08000000/03*016Ka,01*016Kg,01*064Kg,07*128Kg" #define FLASH_IF_STRING "@Internal Flash /0x08000000/03*016Ka,01*016Kg,01*064Kg,07*128Kg"
#elif defined(STM32F429_439xx)
#define FLASH_END_ADD 0x08200000
#define FLASH_IF_STRING "@Internal Flash /0x08000000/03*016Ka,01*016Kg,01*064Kg,07*128Kg,04*016Kg,01*064Kg,07*128Kg"
#elif defined(STM32F10X_CL) #elif defined(STM32F10X_CL)
#define FLASH_END_ADD 0x08040000 #define FLASH_END_ADD 0x08040000
#define FLASH_IF_STRING "@Internal Flash /0x08000000/06*002Ka,122*002Kg" #define FLASH_IF_STRING "@Internal Flash /0x08000000/06*002Ka,122*002Kg"
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_mem_if_template.h * @file usbd_mem_if_template.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Header for usbd_mem_if_template.c file. * @brief Header for usbd_mem_if_template.c file.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "usb_conf.h" #include "usb_conf.h"
#include "usbd_dfu_mal.h" #include "usbd_dfu_mal.h"
/* Exported types ------------------------------------------------------------*/ /* Exported types ------------------------------------------------------------*/
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_otp_if.h * @file usbd_otp_if.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Header for usbd_otp_if.c file. * @brief Header for usbd_otp_if.c file.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -2,8 +2,8 @@
****************************************************************************** ******************************************************************************
* @file usbd_dfu_core.c * @file usbd_dfu_core.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief This file provides the high layer firmware functions to manage the * @brief This file provides the high layer firmware functions to manage the
* following functionalities of the USB DFU Class: * following functionalities of the USB DFU Class:
* - Initialization and Configuration of high and low layer * - Initialization and Configuration of high and low layer
@@ -44,7 +44,7 @@
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -63,7 +63,6 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "usbd_dfu_core.h" #include "usbd_dfu_core.h"
#include "usbd_desc.h" #include "usbd_desc.h"
#include "usbd_req.h" #include "usbd_req.h"
#include "usb_bsp.h" #include "usb_bsp.h"
@@ -224,7 +223,7 @@ USBD_Class_cb_TypeDef DFU_cb =
/* USB DFU device Configuration Descriptor */ /* USB DFU device Configuration Descriptor */
__ALIGN_BEGIN uint8_t usbd_dfu_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END = __ALIGN_BEGIN uint8_t usbd_dfu_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END =
{ {
0x09, /* bLength: Configuation Descriptor size */ 0x09, /* bLength: Configuration Descriptor size */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */ USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
USB_DFU_CONFIG_DESC_SIZ, USB_DFU_CONFIG_DESC_SIZ,
/* wTotalLength: Bytes returned */ /* wTotalLength: Bytes returned */
@@ -232,7 +231,7 @@ __ALIGN_BEGIN uint8_t usbd_dfu_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END =
0x01, /*bNumInterfaces: 1 interface*/ 0x01, /*bNumInterfaces: 1 interface*/
0x01, /*bConfigurationValue: Configuration value*/ 0x01, /*bConfigurationValue: Configuration value*/
0x02, /*iConfiguration: Index of string descriptor describing the configuration*/ 0x02, /*iConfiguration: Index of string descriptor describing the configuration*/
0xC0, /*bmAttributes: bus powered and Supprts Remote Wakeup */ 0xC0, /*bmAttributes: bus powered and Supports Remote Wakeup */
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/ 0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
/* 09 */ /* 09 */
@@ -298,7 +297,7 @@ __ALIGN_BEGIN uint8_t usbd_dfu_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END =
__ALIGN_BEGIN uint8_t usbd_dfu_OtherCfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END = __ALIGN_BEGIN uint8_t usbd_dfu_OtherCfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END =
{ {
0x09, /* bLength: Configuation Descriptor size */ 0x09, /* bLength: Configuration Descriptor size */
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, /* bDescriptorType: Configuration */ USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, /* bDescriptorType: Configuration */
USB_DFU_CONFIG_DESC_SIZ, USB_DFU_CONFIG_DESC_SIZ,
/* wTotalLength: Bytes returned */ /* wTotalLength: Bytes returned */
@@ -306,7 +305,7 @@ __ALIGN_BEGIN uint8_t usbd_dfu_OtherCfgDesc[USB_DFU_CONFIG_DESC_SIZ] __ALIGN_END
0x01, /*bNumInterfaces: 1 interface*/ 0x01, /*bNumInterfaces: 1 interface*/
0x01, /*bConfigurationValue: Configuration value*/ 0x01, /*bConfigurationValue: Configuration value*/
0x02, /*iConfiguration: Index of string descriptor describing the configuration*/ 0x02, /*iConfiguration: Index of string descriptor describing the configuration*/
0xC0, /*bmAttributes: bus powered and Supprts Remote Wakeup */ 0xC0, /*bmAttributes: bus powered and Supports Remote Wakeup */
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/ 0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
/* 09 */ /* 09 */
@@ -590,7 +589,7 @@ static uint8_t EP0_TxSent (void *pdev)
/* Preform the write operation */ /* Preform the write operation */
MAL_Write(Addr, wlength); MAL_Write(Addr, wlength);
} }
/* Reset the global lenght and block number */ /* Reset the global length and block number */
wlength = 0; wlength = 0;
wBlockNum = 0; wBlockNum = 0;
@@ -737,7 +736,7 @@ static void DFU_Req_UPLOAD(void *pdev, USB_SETUP_REQ *req)
{ {
if ((DeviceState == STATE_dfuIDLE) || (DeviceState == STATE_dfuUPLOAD_IDLE)) if ((DeviceState == STATE_dfuIDLE) || (DeviceState == STATE_dfuUPLOAD_IDLE))
{ {
/* Update the global langth and block number */ /* Update the global length and block number */
wBlockNum = req->wValue; wBlockNum = req->wValue;
wlength = req->wLength; wlength = req->wLength;
@@ -1018,7 +1017,7 @@ static uint8_t *USBD_DFU_GetOtherCfgDesc (uint8_t speed, uint16_t *length)
* @brief USBD_DFU_GetUsrStringDesc * @brief USBD_DFU_GetUsrStringDesc
* Manages the transfer of memory interfaces string descriptors. * Manages the transfer of memory interfaces string descriptors.
* @param speed : current device speed * @param speed : current device speed
* @param index: desciptor index * @param index: descriptor index
* @param length : pointer data length * @param length : pointer data length
* @retval pointer to the descriptor table or NULL if the descriptor is not supported. * @retval pointer to the descriptor table or NULL if the descriptor is not supported.
*/ */
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_dfu_mal.c * @file usbd_dfu_mal.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Generic media access Layer. * @brief Generic media access Layer.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -90,7 +90,7 @@ static uint8_t MAL_CheckAdd (uint32_t Add);
* @brief MAL_Init * @brief MAL_Init
* Initializes the Media on the STM32 * Initializes the Media on the STM32
* @param None * @param None
* @retval Result of the opeartion (MAL_OK in all cases) * @retval Result of the operation (MAL_OK in all cases)
*/ */
uint16_t MAL_Init(void) uint16_t MAL_Init(void)
{ {
@@ -113,7 +113,7 @@ uint16_t MAL_Init(void)
* @brief MAL_DeInit * @brief MAL_DeInit
* DeInitializes the Media on the STM32 * DeInitializes the Media on the STM32
* @param None * @param None
* @retval Result of the opeartion (MAL_OK in all cases) * @retval Result of the operation (MAL_OK in all cases)
*/ */
uint16_t MAL_DeInit(void) uint16_t MAL_DeInit(void)
{ {
@@ -136,7 +136,7 @@ uint16_t MAL_DeInit(void)
* @brief MAL_Erase * @brief MAL_Erase
* Erase a sector of memory. * Erase a sector of memory.
* @param Add: Sector address/code * @param Add: Sector address/code
* @retval Result of the opeartion: MAL_OK if all operations are OK else MAL_FAIL * @retval Result of the operation: MAL_OK if all operations are OK else MAL_FAIL
*/ */
uint16_t MAL_Erase(uint32_t Add) uint16_t MAL_Erase(uint32_t Add)
{ {
@@ -171,7 +171,7 @@ uint16_t MAL_Erase(uint32_t Add)
* Write sectors of memory. * Write sectors of memory.
* @param Add: Sector address/code * @param Add: Sector address/code
* @param Len: Number of data to be written (in bytes) * @param Len: Number of data to be written (in bytes)
* @retval Result of the opeartion: MAL_OK if all operations are OK else MAL_FAIL * @retval Result of the operation: MAL_OK if all operations are OK else MAL_FAIL
*/ */
uint16_t MAL_Write (uint32_t Add, uint32_t Len) uint16_t MAL_Write (uint32_t Add, uint32_t Len)
{ {
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_flash_if.c * @file usbd_flash_if.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Specific media access Layer for internal flash. * @brief Specific media access Layer for internal flash.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -62,7 +62,7 @@ DFU_MAL_Prop_TypeDef DFU_Flash_cb =
* @brief FLASH_If_Init * @brief FLASH_If_Init
* Memory initialization routine. * Memory initialization routine.
* @param None * @param None
* @retval MAL_OK if operation is successeful, MAL_FAIL else. * @retval MAL_OK if operation is successful, MAL_FAIL else.
*/ */
uint16_t FLASH_If_Init(void) uint16_t FLASH_If_Init(void)
{ {
@@ -76,7 +76,7 @@ uint16_t FLASH_If_Init(void)
* @brief FLASH_If_DeInit * @brief FLASH_If_DeInit
* Memory deinitialization routine. * Memory deinitialization routine.
* @param None * @param None
* @retval MAL_OK if operation is successeful, MAL_FAIL else. * @retval MAL_OK if operation is successful, MAL_FAIL else.
*/ */
uint16_t FLASH_If_DeInit(void) uint16_t FLASH_If_DeInit(void)
{ {
@@ -95,7 +95,7 @@ uint16_t FLASH_If_DeInit(void)
*******************************************************************************/ *******************************************************************************/
uint16_t FLASH_If_Erase(uint32_t Add) uint16_t FLASH_If_Erase(uint32_t Add)
{ {
#if defined (STM32F2XX) || defined (STM32F4XX) #if !defined(STM32F10X_CL)
/* Check which sector has to be erased */ /* Check which sector has to be erased */
if (Add < 0x08004000) if (Add < 0x08004000)
{ {
@@ -149,10 +149,10 @@ uint16_t FLASH_If_Erase(uint32_t Add)
{ {
return MAL_FAIL; return MAL_FAIL;
} }
#elif defined(STM32F10X_CL) #else
/* Call the standard Flash erase function */ /* Call the standard Flash erase function */
FLASH_ErasePage(Add); FLASH_ErasePage(Add);
#endif /* STM32F2XX */ #endif /* STM32F10X_CL */
return MAL_OK; return MAL_OK;
} }
@@ -162,7 +162,7 @@ uint16_t FLASH_If_Erase(uint32_t Add)
* Memory write routine. * Memory write routine.
* @param Add: Address to be written to. * @param Add: Address to be written to.
* @param Len: Number of data to be written (in bytes). * @param Len: Number of data to be written (in bytes).
* @retval MAL_OK if operation is successeful, MAL_FAIL else. * @retval MAL_OK if operation is successful, MAL_FAIL else.
*/ */
uint16_t FLASH_If_Write(uint32_t Add, uint32_t Len) uint16_t FLASH_If_Write(uint32_t Add, uint32_t Len)
{ {
@@ -190,7 +190,7 @@ uint16_t FLASH_If_Write(uint32_t Add, uint32_t Len)
* Memory read routine. * Memory read routine.
* @param Add: Address to be read from. * @param Add: Address to be read from.
* @param Len: Number of data to be read (in bytes). * @param Len: Number of data to be read (in bytes).
* @retval Pointer to the phyisical address where data should be read. * @retval Pointer to the physical address where data should be read.
*/ */
uint8_t *FLASH_If_Read (uint32_t Add, uint32_t Len) uint8_t *FLASH_If_Read (uint32_t Add, uint32_t Len)
{ {
@@ -2,15 +2,15 @@
****************************************************************************** ******************************************************************************
* @file usbd_mem_if_template.c * @file usbd_mem_if_template.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Specific media access Layer for a template memory. This file is * @brief Specific media access Layer for a template memory. This file is
provided as template example showing how to implement a new memory provided as template example showing how to implement a new memory
interface based on pre-defined API. interface based on pre-defined API.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -64,7 +64,7 @@ DFU_MAL_Prop_TypeDef DFU_Mem_cb =
* @brief MEM_If_Init * @brief MEM_If_Init
* Memory initialization routine. * Memory initialization routine.
* @param None * @param None
* @retval MAL_OK if operation is successeful, MAL_FAIL else. * @retval MAL_OK if operation is successful, MAL_FAIL else.
*/ */
uint16_t MEM_If_Init(void) uint16_t MEM_If_Init(void)
{ {
@@ -75,7 +75,7 @@ uint16_t MEM_If_Init(void)
* @brief MEM_If_DeInit * @brief MEM_If_DeInit
* Memory deinitialization routine. * Memory deinitialization routine.
* @param None * @param None
* @retval MAL_OK if operation is successeful, MAL_FAIL else. * @retval MAL_OK if operation is successful, MAL_FAIL else.
*/ */
uint16_t MEM_If_DeInit(void) uint16_t MEM_If_DeInit(void)
{ {
@@ -86,7 +86,7 @@ uint16_t MEM_If_DeInit(void)
* @brief MEM_If_Erase * @brief MEM_If_Erase
* Erase sector. * Erase sector.
* @param Add: Address of sector to be erased. * @param Add: Address of sector to be erased.
* @retval MAL_OK if operation is successeful, MAL_FAIL else. * @retval MAL_OK if operation is successful, MAL_FAIL else.
*/ */
uint16_t MEM_If_Erase(uint32_t Add) uint16_t MEM_If_Erase(uint32_t Add)
{ {
@@ -98,7 +98,7 @@ uint16_t MEM_If_Erase(uint32_t Add)
* Memory write routine. * Memory write routine.
* @param Add: Address to be written to. * @param Add: Address to be written to.
* @param Len: Number of data to be written (in bytes). * @param Len: Number of data to be written (in bytes).
* @retval MAL_OK if operation is successeful, MAL_FAIL else. * @retval MAL_OK if operation is successful, MAL_FAIL else.
*/ */
uint16_t MEM_If_Write(uint32_t Add, uint32_t Len) uint16_t MEM_If_Write(uint32_t Add, uint32_t Len)
{ {
@@ -110,7 +110,7 @@ uint16_t MEM_If_Write(uint32_t Add, uint32_t Len)
* Memory read routine. * Memory read routine.
* @param Add: Address to be read from. * @param Add: Address to be read from.
* @param Len: Number of data to be read (in bytes). * @param Len: Number of data to be read (in bytes).
* @retval Pointer to the phyisical address where data should be read. * @retval Pointer to the physical address where data should be read.
*/ */
uint8_t *MEM_If_Read (uint32_t Add, uint32_t Len) uint8_t *MEM_If_Read (uint32_t Add, uint32_t Len)
{ {
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_otp_if.c * @file usbd_otp_if.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Specific media access Layer for OTP (One Time Programming) memory. * @brief Specific media access Layer for OTP (One Time Programming) memory.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -61,7 +61,7 @@ DFU_MAL_Prop_TypeDef DFU_Otp_cb =
* Memory write routine. * Memory write routine.
* @param Add: Address to be written to. * @param Add: Address to be written to.
* @param Len: Number of data to be written (in bytes). * @param Len: Number of data to be written (in bytes).
* @retval MAL_OK if operation is successeful, MAL_FAIL else. * @retval MAL_OK if operation is successful, MAL_FAIL else.
*/ */
uint16_t OTP_If_Write(uint32_t Add, uint32_t Len) uint16_t OTP_If_Write(uint32_t Add, uint32_t Len)
{ {
@@ -89,7 +89,7 @@ uint16_t OTP_If_Write(uint32_t Add, uint32_t Len)
* Memory read routine. * Memory read routine.
* @param Add: Address to be read from. * @param Add: Address to be read from.
* @param Len: Number of data to be read (in bytes). * @param Len: Number of data to be read (in bytes).
* @retval Pointer to the phyisical address where data should be read. * @retval Pointer to the physical address where data should be read.
*/ */
uint8_t *OTP_If_Read (uint32_t Add, uint32_t Len) uint8_t *OTP_If_Read (uint32_t Add, uint32_t Len)
{ {
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_hid_core.h * @file usbd_hid_core.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief header file for the usbd_hid_core.c file. * @brief header file for the usbd_hid_core.c file.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -52,6 +52,8 @@
#define HID_DESCRIPTOR_TYPE 0x21 #define HID_DESCRIPTOR_TYPE 0x21
#define HID_REPORT_DESC 0x22 #define HID_REPORT_DESC 0x22
#define HID_HS_BINTERVAL 0x07
#define HID_FS_BINTERVAL 0x0A
#define HID_REQ_SET_PROTOCOL 0x0B #define HID_REQ_SET_PROTOCOL 0x0B
#define HID_REQ_GET_PROTOCOL 0x03 #define HID_REQ_GET_PROTOCOL 0x03
@@ -89,7 +91,7 @@
* @{ * @{
*/ */
extern const USBD_Class_cb_TypeDef USBD_HID_cb; extern const USBD_Class_cb_TypeDef USBD_HID_cb; // modified by OpenTX
/** /**
* @} * @}
*/ */
@@ -100,11 +102,14 @@ extern const USBD_Class_cb_TypeDef USBD_HID_cb;
uint8_t USBD_HID_SendReport (USB_OTG_CORE_HANDLE *pdev, uint8_t USBD_HID_SendReport (USB_OTG_CORE_HANDLE *pdev,
uint8_t *report, uint8_t *report,
uint16_t len); uint16_t len);
uint32_t USBD_HID_GetPollingInterval (USB_OTG_CORE_HANDLE *pdev);
/** /**
* @} * @}
*/ */
#endif // __USB_HID_CORE_H_ #endif /* __USB_HID_CORE_H_ */
/** /**
* @} * @}
*/ */
@@ -2,8 +2,8 @@
****************************************************************************** ******************************************************************************
* @file usbd_hid_core.c * @file usbd_hid_core.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief This file provides the HID core functions. * @brief This file provides the HID core functions.
* *
* @verbatim * @verbatim
@@ -29,7 +29,7 @@
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -48,7 +48,6 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "usbd_hid_core.h" #include "usbd_hid_core.h"
#include "usbd_desc.h" #include "usbd_desc.h"
#include "usbd_req.h" #include "usbd_req.h"
@@ -95,18 +94,18 @@
*/ */
static uint8_t USBD_HID_Init (void *pdev, uint8_t USBD_HID_Init (void *pdev,
uint8_t cfgidx); uint8_t cfgidx);
static uint8_t USBD_HID_DeInit (void *pdev, uint8_t USBD_HID_DeInit (void *pdev,
uint8_t cfgidx); uint8_t cfgidx);
static uint8_t USBD_HID_Setup (void *pdev, uint8_t USBD_HID_Setup (void *pdev,
USB_SETUP_REQ *req); USB_SETUP_REQ *req);
static uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length); static uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length);
static uint8_t USBD_HID_DataIn (void *pdev, uint8_t epnum); uint8_t USBD_HID_DataIn (void *pdev, uint8_t epnum);
/** /**
* @} * @}
*/ */
@@ -205,7 +204,7 @@ __ALIGN_BEGIN static uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ] __ALIGN_E
0x03, /*bmAttributes: Interrupt endpoint*/ 0x03, /*bmAttributes: Interrupt endpoint*/
HID_IN_PACKET, /*wMaxPacketSize: 4 Byte max */ HID_IN_PACKET, /*wMaxPacketSize: 4 Byte max */
0x00, 0x00,
0x0A, /*bInterval: Polling Interval (10 ms)*/ HID_FS_BINTERVAL, /*bInterval: Polling Interval (10 ms)*/
/* 34 */ /* 34 */
} ; } ;
@@ -300,7 +299,7 @@ __ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __
* @param cfgidx: Configuration index * @param cfgidx: Configuration index
* @retval status * @retval status
*/ */
static uint8_t USBD_HID_Init (void *pdev, uint8_t USBD_HID_Init (void *pdev,
uint8_t cfgidx) uint8_t cfgidx)
{ {
@@ -310,12 +309,6 @@ static uint8_t USBD_HID_Init (void *pdev,
HID_IN_PACKET, HID_IN_PACKET,
USB_OTG_EP_INT); USB_OTG_EP_INT);
/* Open EP OUT */
DCD_EP_Open(pdev,
HID_OUT_EP,
HID_OUT_PACKET,
USB_OTG_EP_INT);
return USBD_OK; return USBD_OK;
} }
@@ -326,14 +319,11 @@ static uint8_t USBD_HID_Init (void *pdev,
* @param cfgidx: Configuration index * @param cfgidx: Configuration index
* @retval status * @retval status
*/ */
static uint8_t USBD_HID_DeInit (void *pdev, uint8_t USBD_HID_DeInit (void *pdev,
uint8_t cfgidx) uint8_t cfgidx)
{ {
/* Close HID EPs */ /* Close HID EPs */
DCD_EP_Close (pdev , HID_IN_EP); DCD_EP_Close (pdev , HID_IN_EP);
DCD_EP_Close (pdev , HID_OUT_EP);
return USBD_OK; return USBD_OK;
} }
@@ -344,7 +334,7 @@ static uint8_t USBD_HID_DeInit (void *pdev,
* @param req: usb requests * @param req: usb requests
* @retval status * @retval status
*/ */
static uint8_t USBD_HID_Setup (void *pdev, uint8_t USBD_HID_Setup (void *pdev,
USB_SETUP_REQ *req) USB_SETUP_REQ *req)
{ {
uint16_t len = 0; uint16_t len = 0;
@@ -355,8 +345,6 @@ static uint8_t USBD_HID_Setup (void *pdev,
case USB_REQ_TYPE_CLASS : case USB_REQ_TYPE_CLASS :
switch (req->bRequest) switch (req->bRequest)
{ {
case HID_REQ_SET_PROTOCOL: case HID_REQ_SET_PROTOCOL:
USBD_HID_Protocol = (uint8_t)(req->wValue); USBD_HID_Protocol = (uint8_t)(req->wValue);
break; break;
@@ -402,6 +390,10 @@ static uint8_t USBD_HID_Setup (void *pdev,
#endif #endif
len = MIN(USB_HID_DESC_SIZ , req->wLength); len = MIN(USB_HID_DESC_SIZ , req->wLength);
} }
else
{
/* Do Nothing */
}
USBD_CtlSendData (pdev, USBD_CtlSendData (pdev,
pbuf, pbuf,
@@ -418,7 +410,18 @@ static uint8_t USBD_HID_Setup (void *pdev,
case USB_REQ_SET_INTERFACE : case USB_REQ_SET_INTERFACE :
USBD_HID_AltSet = (uint8_t)(req->wValue); USBD_HID_AltSet = (uint8_t)(req->wValue);
break; break;
default:
USBD_HID_AltSet = (uint8_t)(req->wValue);
break;
} }
break;
default:
USBD_CtlSendData (pdev,
(uint8_t *)&USBD_HID_AltSet,
1);
break;
} }
return USBD_OK; return USBD_OK;
} }
@@ -461,7 +464,7 @@ static uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length)
* @param epnum: endpoint index * @param epnum: endpoint index
* @retval status * @retval status
*/ */
static uint8_t USBD_HID_DataIn (void *pdev, uint8_t USBD_HID_DataIn (void *pdev,
uint8_t epnum) uint8_t epnum)
{ {
@@ -471,6 +474,34 @@ static uint8_t USBD_HID_DataIn (void *pdev,
return USBD_OK; return USBD_OK;
} }
/**
* @brief USBD_HID_GetPollingInterval
* return polling interval from endpoint descriptor
* @param pdev: device instance
* @retval polling interval
*/
uint32_t USBD_HID_GetPollingInterval (USB_OTG_CORE_HANDLE *pdev)
{
uint32_t polling_interval = 0;
/* HIGH-speed endpoints */
if(pdev->cfg.speed == USB_OTG_SPEED_HIGH)
{
/* Sets the data transfer polling interval for high speed transfers.
Values between 1..16 are allowed. Values correspond to interval
of 2 ^ (bInterval-1). This option (8 ms, corresponds to HID_HS_BINTERVAL */
polling_interval = (((1 <<(HID_HS_BINTERVAL - 1)))/8);
}
else /* LOW and FULL-speed endpoints */
{
/* Sets the data transfer polling interval for low and full
speed transfers */
polling_interval = HID_FS_BINTERVAL;
}
return ((uint32_t)(polling_interval));
}
/** /**
* @} * @}
*/ */
@@ -0,0 +1,96 @@
/**
******************************************************************************
* @file usbd_hid_cdc_wrapper.h
* @author MCD Application Team
* @version V1.2.0
* @date 09-November-2015
* @brief header file for the usbd_hid_cdc_wrapper.c file.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#ifndef __USB_HID_CDC_WRAPPER_H_
#define __USB_HID_CDC_WRAPPER_H_
#include "usbd_ioreq.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_HID_CDC
* @brief This file is the Header file for usbd_msc_cdc_wrapper.c
* @{
*/
/** @defgroup USBD_HID_MSC_Exported_Defines
* @{
*/
/**
* @}
*/
/** @defgroup USBD_CORE_Exported_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBD_CORE_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBD_CORE_Exported_Variables
* @{
*/
extern USBD_Class_cb_TypeDef USBD_HID_CDC_cb;
/**
* @}
*/
/**
* @}
*/
#endif /* __USB_MSC_CDC_WRAPPER_H_ */
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
@@ -0,0 +1,461 @@
/**
******************************************************************************
* @file usbd_hid_cdc_wrapper.c
* @author MCD Application Team
* @version V1.2.0
* @date 09-November-2015
* @brief
*
* @verbatim
*
* ===================================================================
* composite HID_CDC
* ===================================================================
*
* @note In HS mode and when the DMA is used, all variables and data structures
* dealing with the DMA during the transaction process should be 32-bit aligned.
*
*
* @endverbatim
*
* @attention
*
* <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "usbd_hid_core.h"
#include "usbd_cdc_core.h"
#include "usbd_hid_cdc_wrapper.h"
#include "usbd_desc.h"
#include "usbd_req.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_MSC_VCP
* @brief usbd core module
* @{
*/
/** @defgroup USBD_MSC_VCP_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBD_MSC_VCP_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup USBD_MSC_VCP_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBD_MSC_VCP_Private_FunctionPrototypes
* @{
*/
/*********************************************
CDC Device library callbacks
*********************************************/
extern uint8_t usbd_cdc_Init (void *pdev, uint8_t cfgidx);
extern uint8_t usbd_cdc_DeInit (void *pdev, uint8_t cfgidx);
extern uint8_t usbd_cdc_Setup (void *pdev, USB_SETUP_REQ *req);
extern uint8_t usbd_cdc_EP0_RxReady (void *pdev);
extern uint8_t usbd_cdc_DataIn (void *pdev, uint8_t epnum);
extern uint8_t usbd_cdc_DataOut (void *pdev, uint8_t epnum);
extern uint8_t usbd_cdc_SOF (void *pdev);
extern uint8_t *USBD_cdc_GetCfgDesc (uint8_t speed, uint16_t *length);
#ifdef USE_USB_OTG_HS
extern uint8_t *USBD_cdc_GetOtherCfgDesc (uint8_t speed, uint16_t *length);
#endif
/*********************************************
MSC Device library callbacks
*********************************************/
extern uint8_t USBD_HID_Init (void *pdev, uint8_t cfgidx);
extern uint8_t USBD_HID_DeInit (void *pdev, uint8_t cfgidx);
extern uint8_t USBD_HID_Setup (void *pdev, USB_SETUP_REQ *req);
extern uint8_t USBD_HID_DataIn (void *pdev, uint8_t epnum);
extern uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length);
extern uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZ];
/**
* @}
*/
/** @defgroup USBD_MSC_CDC_Private_Variables
* @{
*/
static uint8_t USBD_HID_CDC_Init (void *pdev , uint8_t cfgidx);
static uint8_t USBD_HID_CDC_DeInit (void *pdev , uint8_t cfgidx);
/* Control Endpoints*/
static uint8_t USBD_HID_CDC_Setup (void *pdev , USB_SETUP_REQ *req);
static uint8_t USBD_HID_CDC_EP0_RxReady (void *pdev );
/* Class Specific Endpoints*/
static uint8_t USBD_HID_CDC_DataIn (void *pdev , uint8_t epnum);
static uint8_t USBD_HID_CDC_DataOut (void *pdev , uint8_t epnum);
static uint8_t USBD_HID_CDC_SOF (void *pdev);
static uint8_t* USBD_HID_CDC_GetConfigDescriptor( uint8_t speed , uint16_t *length);
#define USB_HID_CDC_CONFIG_DESC_SIZ (USB_HID_CONFIG_DESC_SIZ -9 + USB_CDC_CONFIG_DESC_SIZ + 8)
#define HID_INTERFACE 0x0
#define CDC_COM_INTERFACE 0x1
USBD_Class_cb_TypeDef USBD_HID_CDC_cb =
{
USBD_HID_CDC_Init,
USBD_HID_CDC_DeInit,
USBD_HID_CDC_Setup,
NULL,
USBD_HID_CDC_EP0_RxReady,
USBD_HID_CDC_DataIn,
USBD_HID_CDC_DataOut,
USBD_HID_CDC_SOF,
NULL,
NULL,
USBD_HID_CDC_GetConfigDescriptor,
};
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
#pragma data_alignment=4
#endif
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
/* USB MSC/CDC device Configuration Descriptor */
__ALIGN_BEGIN static uint8_t USBD_HID_CDC_CfgDesc[USB_HID_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
{
0x09, /* bLength: Configuration Descriptor size */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
USB_HID_CDC_CONFIG_DESC_SIZ,
/* wTotalLength: Bytes returned */
0x00,
0x03, /*bNumInterfaces: 3 interfaces (2 for CDC, 1 for MSC)*/
0x01, /*bConfigurationValue: Configuration value*/
0x00, /*iConfiguration: Index of string descriptor describing
the configuration*/
0xE0, /*bmAttributes: bus powered and Support Remote Wake-up */
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
/************** Descriptor of Joystick Mouse interface ****************/
/* 09 */
0x09, /*bLength: Interface Descriptor size*/
USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/
HID_INTERFACE, /*bInterfaceNumber: Number of Interface*/
0x00, /*bAlternateSetting: Alternate setting*/
0x01, /*bNumEndpoints*/
0x03, /*bInterfaceClass: HID*/
0x01, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
0x02, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
0, /*iInterface: Index of string descriptor*/
/******************** Descriptor of Joystick Mouse HID ********************/
/* 18 */
0x09, /*bLength: HID Descriptor size*/
HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
0x11, /*bcdHID: HID Class Spec release number*/
0x01,
0x00, /*bCountryCode: Hardware target country*/
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/
0x22, /*bDescriptorType*/
HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
0x00,
/******************** Descriptor of Mouse endpoint ********************/
/* 27 */
0x07, /*bLength: Endpoint Descriptor size*/
USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/
HID_IN_EP, /*bEndpointAddress: Endpoint Address (IN)*/
0x03, /*bmAttributes: Interrupt endpoint*/
HID_IN_PACKET, /*wMaxPacketSize: 4 Byte max */
0x00,
0x0A, /*bInterval: Polling Interval (10 ms)*/
/* 34 */
/******** /IAD should be positioned just before the CDC interfaces ******
IAD to associate the two CDC interfaces */
0x08, /* bLength */
0x0B, /* bDescriptorType */
0x01, /* bFirstInterface */
0x02, /* bInterfaceCount */
0x02, /* bFunctionClass */
0x02, /* bFunctionSubClass */
0x01, /* bFunctionProtocol */
0x00, /* iFunction (Index of string descriptor describing this function) */
/*Interface Descriptor */
0x09, /* bLength: Interface Descriptor size */
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: Interface */
/* Interface descriptor type */
CDC_COM_INTERFACE, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x01, /* bNumEndpoints: One endpoints used */
0x02, /* bInterfaceClass: Communication Interface Class */
0x02, /* bInterfaceSubClass: Abstract Control Model */
0x01, /* bInterfaceProtocol: Common AT commands */
0x01, /* iInterface: */
/*Header Functional Descriptor*/
0x05, /* bLength: Endpoint Descriptor size */
0x24, /* bDescriptorType: CS_INTERFACE */
0x00, /* bDescriptorSubtype: Header Func Desc */
0x10, /* bcdCDC: spec release number */
0x01,
/*Call Management Functional Descriptor*/
0x05, /* bFunctionLength */
0x24, /* bDescriptorType: CS_INTERFACE */
0x01, /* bDescriptorSubtype: Call Management Func Desc */
0x00, /* bmCapabilities: D0+D1 */
0x02, /* bDataInterface: 2 */
/*ACM Functional Descriptor*/
0x04, /* bFunctionLength */
0x24, /* bDescriptorType: CS_INTERFACE */
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
0x02, /* bmCapabilities */
/*Union Functional Descriptor*/
0x05, /* bFunctionLength */
0x24, /* bDescriptorType: CS_INTERFACE */
0x06, /* bDescriptorSubtype: Union func desc */
0x01, /* bMasterInterface: Communication class interface */
0x02, /* bSlaveInterface0: Data Class Interface */
/*Endpoint 2 Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
CDC_CMD_EP, /* bEndpointAddress */
0x03, /* bmAttributes: Interrupt */
LOBYTE(CDC_CMD_PACKET_SZE), /* wMaxPacketSize: */
HIBYTE(CDC_CMD_PACKET_SZE),
0xFF, /* bInterval: */
/*---------------------------------------------------------------------------*/
/*Data class interface descriptor*/
0x09, /* bLength: Endpoint Descriptor size */
USB_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType: */
0x02, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x02, /* bNumEndpoints: Two endpoints used */
0x0A, /* bInterfaceClass: CDC */
0x00, /* bInterfaceSubClass: */
0x00, /* bInterfaceProtocol: */
0x00, /* iInterface: */
/*Endpoint OUT Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
CDC_OUT_EP, /* bEndpointAddress */
0x02, /* bmAttributes: Bulk */
LOBYTE(CDC_DATA_MAX_PACKET_SIZE), /* wMaxPacketSize: */
HIBYTE(CDC_DATA_MAX_PACKET_SIZE),
0x00, /* bInterval: ignore for Bulk transfer */
/*Endpoint IN Descriptor*/
0x07, /* bLength: Endpoint Descriptor size */
USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: Endpoint */
CDC_IN_EP, /* bEndpointAddress */
0x02, /* bmAttributes: Bulk */
LOBYTE(CDC_DATA_MAX_PACKET_SIZE), /* wMaxPacketSize: */
HIBYTE(CDC_DATA_MAX_PACKET_SIZE),
0x00, /* bInterval */
} ;
/**
* @}
*/
/** @defgroup USBD_CDC_MSC_Private_Functions
* @{
*/
/**
* @brief USBD_MSC_CDC_Init
* Initialize the MSC & CDC interfaces
* @param pdev: device instance
* @param cfgidx: Configuration index
* @retval status
*/
static uint8_t USBD_HID_CDC_Init (void *pdev,
uint8_t cfgidx)
{
/* HID initialization */
USBD_HID_Init (pdev,cfgidx);
/* CDC initialization */
usbd_cdc_Init (pdev,cfgidx);
return USBD_OK;
}
/**
* @brief USBD_MSC_CDC_Init
* DeInitialize the MSC/CDC interfaces
* @param pdev: device instance
* @param cfgidx: Configuration index
* @retval status
*/
static uint8_t USBD_HID_CDC_DeInit (void *pdev,
uint8_t cfgidx)
{
/* MSC De-initialization */
USBD_HID_DeInit (pdev,cfgidx);
/* CDC De-initialization */
usbd_cdc_DeInit (pdev,cfgidx);
return USBD_OK;
}
/**
* @brief USBD_MSC_CDC_Setup
* Handle the MSC/CDC specific requests
* @param pdev: instance
* @param req: usb requests
* @retval status
*/
static uint8_t USBD_HID_CDC_Setup (void *pdev,
USB_SETUP_REQ *req)
{
switch (req->bmRequest & USB_REQ_RECIPIENT_MASK)
{
case USB_REQ_RECIPIENT_INTERFACE:
if (req->wIndex == HID_INTERFACE)
{
return (USBD_HID_Setup (pdev, req));
}
else
{
return (usbd_cdc_Setup(pdev, req));
}
case USB_REQ_RECIPIENT_ENDPOINT:
if (req->wIndex == HID_IN_EP)
{
return (USBD_HID_Setup (pdev, req));
}
else
{
return (usbd_cdc_Setup(pdev, req));
}
}
return USBD_OK;
}
/**
* @brief USBD_MSC_CDC_GetCfgDesc
* return configuration descriptor
* @param speed : current device speed
* @param length : pointer data length
* @retval pointer to descriptor buffer
*/
uint8_t *USBD_HID_CDC_GetConfigDescriptor (uint8_t speed, uint16_t *length)
{
*length = sizeof (USBD_HID_CDC_CfgDesc);
return USBD_HID_CDC_CfgDesc;
}
/**
* @brief USBD_MSC_CDC_DataIn
* handle data IN Stage
* @param pdev: device instance
* @param epnum: endpoint index
* @retval status
*/
static uint8_t USBD_HID_CDC_DataIn (void *pdev,
uint8_t epnum)
{
/*DataIN can be for CDC or MSC */
if (epnum == (CDC_IN_EP&~0x80) )
{
return (usbd_cdc_DataIn(pdev, epnum));
}
else
{
return (USBD_HID_DataIn(pdev, epnum));
}
}
uint8_t USBD_HID_CDC_DataOut(void *pdev , uint8_t epnum)
{
/*DataOut can be for CDC */
return (usbd_cdc_DataOut(pdev, epnum));
}
uint8_t USBD_HID_CDC_SOF (void *pdev)
{
/*SOF processing needed for CDC */
return (usbd_cdc_SOF(pdev));
}
uint8_t USBD_HID_CDC_EP0_RxReady (void *pdev )
{
/*RxReady processing needed for CDC only*/
return (usbd_cdc_EP0_RxReady(pdev));
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/
@@ -0,0 +1,100 @@
/**
******************************************************************************
* @file usbd_msc_hid_core.h
* @author MCD Application Team
* @version V1.2.0
* @date 09-November-2015
* @brief header file for the usbd_msc_hid_core.c file.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#ifndef __USB_MSC_HID_CORE_H_
#define __USB_MSC_HID_CORE_H_
#include "usbd_ioreq.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_HID
* @brief This file is the Header file for USBD_msc.c
* @{
*/
#define HID_INTERFACE 0x0
#define MSC_INTERFACE 0x1
/** @defgroup USBD_HID_Exported_Defines
* @{
*/
#define USB_MSC_HID_CONFIG_DESC_SIZ (USB_HID_CONFIG_DESC_SIZ -9 + USB_MSC_CONFIG_DESC_SIZ)
/**
* @}
*/
/** @defgroup USBD_CORE_Exported_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBD_CORE_Exported_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBD_CORE_Exported_Variables
* @{
*/
extern USBD_Class_cb_TypeDef USBD_MSC_HID_cb;
/**
* @}
*/
/** @defgroup USB_CORE_Exported_Functions
* @{
*/
/**
* @}
*/
#endif /* __USB_HID_CORE_H_ */
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
@@ -0,0 +1,378 @@
/**
******************************************************************************
* @file usbd_msc_hid_core.c
* @author MCD Application Team
* @version V1.2.0
* @date 09-November-2015
* @brief This file provides the HID core functions.
*
* @verbatim
*
* ===================================================================
* composite HID_MSC
* ===================================================================
*
* @note In HS mode and when the DMA is used, all variables and data structures
* dealing with the DMA during the transaction process should be 32-bit aligned.
*
*
* @endverbatim
*
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
*
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/software_license_agreement_liberty_v2
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "usbd_msc_hid_core.h"
#include "usbd_msc_core.h"
#include "usbd_hid_core.h"
#include "usbd_desc.h"
#include "usbd_req.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_HID
* @brief usbd core module
* @{
*/
/** @defgroup USBD_HID_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBD_HID_Private_Defines
* @{
*/
/**
* @}
*/
/** @defgroup USBD_HID_Private_Macros
* @{
*/
/**
* @}
*/
/** @defgroup USBD_HID_Private_FunctionPrototypes
* @{
*/
static uint8_t USBD_MSC_HID_Init (void *pdev,
uint8_t cfgidx);
static uint8_t USBD_MSC_HID_DeInit (void *pdev,
uint8_t cfgidx);
static uint8_t USBD_MSC_HID_Setup (void *pdev,
USB_SETUP_REQ *req);
static uint8_t *USBD_MSC_HID_GetCfgDesc (uint8_t speed, uint16_t *length);
static uint8_t USBD_MSC_HID_DataIn (void *pdev, uint8_t epnum);
static uint8_t USBD_MSC_HID_DataOut(void *pdev , uint8_t epnum);
/**
* @}
*/
/** @defgroup USBD_HID_Private_Variables
* @{
*/
USBD_Class_cb_TypeDef USBD_MSC_HID_cb =
{
USBD_MSC_HID_Init,
USBD_MSC_HID_DeInit,
USBD_MSC_HID_Setup,
NULL, /*EP0_TxSent*/
NULL, /*EP0_RxReady*/
USBD_MSC_HID_DataIn, /*DataIn*/
USBD_MSC_HID_DataOut, /*DataOut*/
NULL, /*SOF */
NULL,
NULL,
USBD_MSC_HID_GetCfgDesc,
#ifdef USB_OTG_HS_CORE
USBD_MSC_HID_GetCfgDesc, /* use same config as per FS */
#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 */
/* USB HID device Configuration Descriptor */
__ALIGN_BEGIN static uint8_t USBD_MSC_HID_CfgDesc[USB_MSC_HID_CONFIG_DESC_SIZ] __ALIGN_END =
{
0x09, /* bLength: Configuration Descriptor size */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
USB_MSC_HID_CONFIG_DESC_SIZ,
/* wTotalLength: Bytes returned */
0x00,
0x02, /*bNumInterfaces: 2 interface*/
0x01, /*bConfigurationValue: Configuration value*/
0x00, /*iConfiguration: Index of string descriptor describing
the configuration*/
0xE0, /*bmAttributes: bus powered and Support Remote Wake-up */
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
/************** Descriptor of Joystick Mouse interface ****************/
/* 09 */
0x09, /*bLength: Interface Descriptor size*/
USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/
HID_INTERFACE, /*bInterfaceNumber: Number of Interface*/
0x00, /*bAlternateSetting: Alternate setting*/
0x01, /*bNumEndpoints*/
0x03, /*bInterfaceClass: HID*/
0x01, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
0x02, /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
0, /*iInterface: Index of string descriptor*/
/******************** Descriptor of Joystick Mouse HID ********************/
/* 18 */
0x09, /*bLength: HID Descriptor size*/
HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
0x11, /*bcdHID: HID Class Spec release number*/
0x01,
0x00, /*bCountryCode: Hardware target country*/
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/
0x22, /*bDescriptorType*/
HID_MOUSE_REPORT_DESC_SIZE,/*wItemLength: Total length of Report descriptor*/
0x00,
/******************** Descriptor of Mouse endpoint ********************/
/* 27 */
0x07, /*bLength: Endpoint Descriptor size*/
USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/
HID_IN_EP, /*bEndpointAddress: Endpoint Address (IN)*/
0x03, /*bmAttributes: Interrupt endpoint*/
HID_IN_PACKET, /*wMaxPacketSize: 4 Byte max */
0x00,
0x0A, /*bInterval: Polling Interval (10 ms)*/
/* 34 */
/******************** Mass Storage interface ********************/
0x09, /* bLength: Interface Descriptor size */
0x04, /* bDescriptorType: */
MSC_INTERFACE, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x02, /* bNumEndpoints*/
0x08, /* bInterfaceClass: MSC Class */
0x06, /* bInterfaceSubClass : SCSI transparent*/
0x50, /* nInterfaceProtocol */
0x05, /* iInterface: */
/******************** Mass Storage Endpoints ********************/
0x07, /*Endpoint descriptor length = 7*/
0x05, /*Endpoint descriptor type */
MSC_IN_EP, /*Endpoint address (IN, address 1) */
0x02, /*Bulk endpoint type */
LOBYTE(MSC_MAX_PACKET),
HIBYTE(MSC_MAX_PACKET),
0x00, /*Polling interval in milliseconds */
0x07, /*Endpoint descriptor length = 7 */
0x05, /*Endpoint descriptor type */
MSC_OUT_EP, /*Endpoint address (OUT, address 1) */
0x02, /*Bulk endpoint type */
LOBYTE(MSC_MAX_PACKET),
HIBYTE(MSC_MAX_PACKET),
0x00 /*Polling interval in milliseconds*/
} ;
/* Private function prototypes -----------------------------------------------*/
/*********************************************
MSC Device library callbacks
*********************************************/
extern uint8_t USBD_MSC_Init (void *pdev, uint8_t cfgidx);
extern uint8_t USBD_MSC_DeInit (void *pdev, uint8_t cfgidx);
extern uint8_t USBD_MSC_Setup (void *pdev, USB_SETUP_REQ *req);
extern uint8_t USBD_MSC_DataIn (void *pdev, uint8_t epnum);
extern uint8_t USBD_MSC_DataOut (void *pdev, uint8_t epnum);
extern uint8_t *USBD_MSC_GetCfgDesc (uint8_t speed, uint16_t *length);
extern uint8_t USBD_MSC_CfgDesc[USB_MSC_CONFIG_DESC_SIZ];
/*********************************************
HID Device library callbacks
*********************************************/
extern uint8_t USBD_HID_Init (void *pdev, uint8_t cfgidx);
extern uint8_t USBD_HID_DeInit (void *pdev, uint8_t cfgidx);
extern uint8_t USBD_HID_Setup (void *pdev, USB_SETUP_REQ *req);
extern uint8_t *USBD_HID_GetCfgDesc (uint8_t speed, uint16_t *length);
extern uint8_t USBD_HID_DataIn (void *pdev, uint8_t epnum);
extern uint8_t USBD_HID_DataOut (void *pdev, uint8_t epnum);
/**
* @}
*/
/** @defgroup USBD_MSC_HID_Private_Functions
* @{
*/
/**
* @brief USBD_MSC_HID_Init
* Initialize the MSC-HID interface
* @param pdev: device instance
* @param cfgidx: Configuration index
* @retval status
*/
static uint8_t USBD_MSC_HID_Init (void *pdev,
uint8_t cfgidx)
{
/* HID initialization */
USBD_HID_Init (pdev,cfgidx);
/* MSC initialization */
USBD_MSC_Init (pdev,cfgidx);
return USBD_OK;
}
/**
* @brief USBD_MSC_HID_DeInit
* DeInitialize the MSC_HID layer
* @param pdev: device instance
* @param cfgidx: Configuration index
* @retval status
*/
static uint8_t USBD_MSC_HID_DeInit (void *pdev,
uint8_t cfgidx)
{
/* HID De-initialization */
USBD_HID_DeInit (pdev,cfgidx);
/* MSC De-initialization */
USBD_MSC_DeInit (pdev,cfgidx);
return USBD_OK;
}
/**
* @brief USBD_MSC_HID_Setup
* Handle the MSC_HID specific requests
* @param pdev: instance
* @param req: usb requests
* @retval status
*/
static uint8_t USBD_MSC_HID_Setup (void *pdev,
USB_SETUP_REQ *req)
{
switch (req->bmRequest & USB_REQ_RECIPIENT_MASK)
{
case USB_REQ_RECIPIENT_INTERFACE:
if (req->wIndex == HID_INTERFACE)
{
return (USBD_HID_Setup (pdev, req));
}
else
{
return (USBD_MSC_Setup(pdev, req));
}
case USB_REQ_RECIPIENT_ENDPOINT:
if (req->wIndex == HID_IN_EP)
{
return (USBD_HID_Setup (pdev, req));
}
else
{
return (USBD_MSC_Setup(pdev, req));
}
}
return USBD_OK;
}
/**
* @brief USBD_MSC_HID_GetCfgDesc
* return configuration descriptor
* @param speed : current device speed
* @param length : pointer data length
* @retval pointer to descriptor buffer
*/
static uint8_t *USBD_MSC_HID_GetCfgDesc (uint8_t speed, uint16_t *length)
{
*length = sizeof (USBD_MSC_HID_CfgDesc);
return USBD_MSC_HID_CfgDesc;
}
/**
* @brief USBD_MSC_HID_DataIn
* handle data IN Stage
* @param pdev: device instance
* @param epnum: endpoint index
* @retval status
*/
static uint8_t USBD_MSC_HID_DataIn (void *pdev,
uint8_t epnum)
{
/*DataIN can be for MSC or HID */
if (epnum == (MSC_IN_EP&~0x80) )
{
return (USBD_MSC_DataIn(pdev, epnum));
}
else
{
return (USBD_HID_DataIn(pdev, epnum));
}
}
/**
* @brief USBD_MSC_HID_DataOut
* handle data OUT Stage
* @param pdev: device instance
* @param epnum: endpoint index
* @retval status
*/
static uint8_t USBD_MSC_HID_DataOut(void *pdev , uint8_t epnum)
{
/*DataOut can be for MSC*/
return (USBD_MSC_DataOut(pdev, epnum));
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_msc_bot.h * @file usbd_msc_bot.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief header for the usbd_msc_bot.c file * @brief header for the usbd_msc_bot.c file
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_msc_core.h * @file usbd_msc_core.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief header for the usbd_msc_core.c file * @brief header for the usbd_msc_core.c file
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@
#ifndef _USB_MSC_CORE_H_ #ifndef _USB_MSC_CORE_H_
#define _USB_MSC_CORE_H_ #define _USB_MSC_CORE_H_
#include "../../../Core/inc/usbd_ioreq.h" #include "usbd_ioreq.h"
/** @addtogroup USBD_MSC_BOT /** @addtogroup USBD_MSC_BOT
* @{ * @{
@@ -69,7 +69,7 @@ extern USBD_Class_cb_TypeDef USBD_MSC_cb;
/** /**
* @} * @}
*/ */
#endif // _USB_MSC_CORE_H_ #endif /* _USB_MSC_CORE_H_ */
/** /**
* @} * @}
*/ */
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_msc_data.h * @file usbd_msc_data.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief header for the usbd_msc_data.c file * @brief header for the usbd_msc_data.c file
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -83,7 +83,7 @@ extern const uint8_t MSC_Mode_Sense10_data[] ;
* @} * @}
*/ */
/** @defgroup USBD_INFO_Exported_FunctionsPrototype /** @defgroup USBD_INFO_Exported_FunctionsPrototypes
* @{ * @{
*/ */
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_msc_mem.h * @file usbd_msc_mem.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief header for the STORAGE DISK file file * @brief header for the STORAGE DISK file file
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_msc_scsi.h * @file usbd_msc_scsi.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief header for the usbd_msc_scsi.c file * @brief header for the usbd_msc_scsi.c file
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_msc_bot.c * @file usbd_msc_bot.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief This file provides all the BOT protocol core functions. * @brief This file provides all the BOT protocol core functions.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -80,7 +80,7 @@ uint8_t MSC_BOT_Status;
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
#include "definitions.h" #include "definitions.h"
uint8_t MSC_BOT_Data[MSC_MEDIA_PACKET] __DMA; uint8_t MSC_BOT_Data[MSC_MEDIA_PACKET] __DMA; // modified by OpenTX
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
#if defined ( __ICCARM__ ) /*!< IAR Compiler */ #if defined ( __ICCARM__ ) /*!< IAR Compiler */
@@ -329,7 +329,7 @@ void MSC_BOT_SendCSW (USB_OTG_CORE_HANDLE *pdev,
(uint8_t *)&MSC_BOT_csw, (uint8_t *)&MSC_BOT_csw,
BOT_CSW_LENGTH); BOT_CSW_LENGTH);
/* Prapare EP to Receive next Cmd */ /* Prepare EP to Receive next Cmd */
DCD_EP_PrepareRx (pdev, DCD_EP_PrepareRx (pdev,
MSC_OUT_EP, MSC_OUT_EP,
(uint8_t *)&MSC_BOT_cbw, (uint8_t *)&MSC_BOT_cbw,
@@ -2,8 +2,8 @@
****************************************************************************** ******************************************************************************
* @file usbd_msc_core.c * @file usbd_msc_core.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief This file provides all the MSC core functions. * @brief This file provides all the MSC core functions.
* *
* @verbatim * @verbatim
@@ -23,7 +23,7 @@
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -102,7 +102,7 @@ uint8_t USBD_MSC_DataOut (void *pdev,
uint8_t epnum); uint8_t epnum);
const uint8_t *USBD_MSC_GetCfgDesc (uint8_t speed, const uint8_t *USBD_MSC_GetCfgDesc (uint8_t speed,
uint16_t *length); uint16_t *length); // modified by OpenTX
#ifdef USB_OTG_HS_CORE #ifdef USB_OTG_HS_CORE
uint8_t *USBD_MSC_GetOtherCfgDesc (uint8_t speed, uint8_t *USBD_MSC_GetOtherCfgDesc (uint8_t speed,
@@ -458,7 +458,7 @@ uint8_t USBD_MSC_DataOut (void *pdev,
* @param length : pointer data length * @param length : pointer data length
* @retval pointer to descriptor buffer * @retval pointer to descriptor buffer
*/ */
const uint8_t *USBD_MSC_GetCfgDesc (uint8_t speed, uint16_t *length) const uint8_t *USBD_MSC_GetCfgDesc (uint8_t speed, uint16_t *length) // modified by OpenTX
{ {
*length = sizeof (USBD_MSC_CfgDesc); *length = sizeof (USBD_MSC_CfgDesc);
return USBD_MSC_CfgDesc; return USBD_MSC_CfgDesc;
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_msc_data.c * @file usbd_msc_data.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief This file provides all the vital inquiry pages and sense data. * @brief This file provides all the vital inquiry pages and sense data.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_msc_scsi.c * @file usbd_msc_scsi.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief This file provides all the USBD SCSI layer functions. * @brief This file provides all the USBD SCSI layer functions.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -97,7 +97,7 @@ static int8_t SCSI_ReadFormatCapacity(uint8_t lun, uint8_t *params);
static int8_t SCSI_ReadCapacity10(uint8_t lun, uint8_t *params); static int8_t SCSI_ReadCapacity10(uint8_t lun, uint8_t *params);
static int8_t SCSI_RequestSense (uint8_t lun, uint8_t *params); static int8_t SCSI_RequestSense (uint8_t lun, uint8_t *params);
static int8_t SCSI_StartStopUnit(uint8_t lun, uint8_t *params); static int8_t SCSI_StartStopUnit(uint8_t lun, uint8_t *params);
static int8_t SCSI_AllowRemoval(uint8_t lun, uint8_t *params); static int8_t SCSI_AllowRemoval(uint8_t lun, uint8_t *params); // modified by OpenTX
static int8_t SCSI_ModeSense6 (uint8_t lun, uint8_t *params); static int8_t SCSI_ModeSense6 (uint8_t lun, uint8_t *params);
static int8_t SCSI_ModeSense10 (uint8_t lun, uint8_t *params); static int8_t SCSI_ModeSense10 (uint8_t lun, uint8_t *params);
static int8_t SCSI_Write10(uint8_t lun , uint8_t *params); static int8_t SCSI_Write10(uint8_t lun , uint8_t *params);
@@ -147,7 +147,7 @@ int8_t SCSI_ProcessCmd(USB_OTG_CORE_HANDLE *pdev,
return SCSI_StartStopUnit(lun, params); return SCSI_StartStopUnit(lun, params);
case SCSI_ALLOW_MEDIUM_REMOVAL: case SCSI_ALLOW_MEDIUM_REMOVAL:
return SCSI_AllowRemoval( lun, params); return SCSI_AllowRemoval( lun, params); // ST lib 2.2.0 uses SCSI_StartStopUnit which doesn't work // modified by OpenTX
case SCSI_MODE_SENSE6: case SCSI_MODE_SENSE6:
return SCSI_ModeSense6 (lun, params); return SCSI_ModeSense6 (lun, params);
@@ -434,13 +434,13 @@ void SCSI_SenseCode(uint8_t lun, uint8_t sKey, uint8_t ASC)
* @retval status * @retval status
*/ */
extern uint8_t lunReady[] ; extern uint8_t lunReady[]; // modified by OpenTX
static int8_t SCSI_StartStopUnit(uint8_t lun, uint8_t *params) static int8_t SCSI_StartStopUnit(uint8_t lun, uint8_t *params)
{ {
MSC_BOT_DataLen = 0; MSC_BOT_DataLen = 0;
#if defined(BOOT) #if defined(BOOT) // modified by OpenTX
if (lun < 2) if (lun < 2)
#else #else
if (lun < 1) if (lun < 1)
@@ -511,6 +511,7 @@ static int8_t SCSI_Read10(uint8_t lun , uint8_t *params)
} }
MSC_BOT_State = BOT_DATA_IN; MSC_BOT_State = BOT_DATA_IN;
// SCSI_blk_addr *= SCSI_blk_size; // modified by OpenTX
SCSI_blk_len *= SCSI_blk_size; SCSI_blk_len *= SCSI_blk_size;
/* cases 4,5 : Hi <> Dn */ /* cases 4,5 : Hi <> Dn */
@@ -582,6 +583,7 @@ static int8_t SCSI_Write10 (uint8_t lun , uint8_t *params)
return -1; /* error */ return -1; /* error */
} }
// SCSI_blk_addr *= SCSI_blk_size; // modified by OpenTX
SCSI_blk_len *= SCSI_blk_size; SCSI_blk_len *= SCSI_blk_size;
/* cases 3,11,13 : Hn,Ho <> D0 */ /* cases 3,11,13 : Hn,Ho <> D0 */
@@ -623,6 +625,13 @@ static int8_t SCSI_Verify10(uint8_t lun , uint8_t *params){
return -1; /* Error, Verify Mode Not supported*/ return -1; /* Error, Verify Mode Not supported*/
} }
SCSI_blk_addr = (params[2] << 24) | \
(params[3] << 16) | \
(params[4] << 8) | \
params[5];
SCSI_blk_len = (params[7] << 8) | \
params[8];
if(SCSI_CheckAddressRange(lun, SCSI_blk_addr, SCSI_blk_len) < 0) if(SCSI_CheckAddressRange(lun, SCSI_blk_addr, SCSI_blk_len) < 0)
{ {
return -1; /* error */ return -1; /* error */
@@ -641,7 +650,7 @@ static int8_t SCSI_Verify10(uint8_t lun , uint8_t *params){
*/ */
static int8_t SCSI_CheckAddressRange (uint8_t lun , uint32_t blk_offset , uint16_t blk_nbr) static int8_t SCSI_CheckAddressRange (uint8_t lun , uint32_t blk_offset , uint16_t blk_nbr)
{ {
if (USBD_STORAGE_fops->GetCapacity(lun, &SCSI_blk_nbr, &SCSI_blk_size) != 0) if (USBD_STORAGE_fops->GetCapacity(lun, &SCSI_blk_nbr, &SCSI_blk_size) != 0) // modified by OpenTX
{ {
SCSI_SenseCode(lun, NOT_READY, MEDIUM_NOT_PRESENT); SCSI_SenseCode(lun, NOT_READY, MEDIUM_NOT_PRESENT);
return -1; return -1;
@@ -670,7 +679,7 @@ static int8_t SCSI_ProcessRead (uint8_t lun)
if( USBD_STORAGE_fops->Read(lun , if( USBD_STORAGE_fops->Read(lun ,
MSC_BOT_Data, MSC_BOT_Data,
SCSI_blk_addr, SCSI_blk_addr, // modified by OpenTX
len / SCSI_blk_size) < 0) len / SCSI_blk_size) < 0)
{ {
@@ -685,7 +694,7 @@ static int8_t SCSI_ProcessRead (uint8_t lun)
len); len);
SCSI_blk_addr += len / SCSI_blk_size; SCSI_blk_addr += len / SCSI_blk_size; // modified by OpenTX
SCSI_blk_len -= len; SCSI_blk_len -= len;
/* case 6 : Hi = Di */ /* case 6 : Hi = Di */
@@ -713,7 +722,7 @@ static int8_t SCSI_ProcessWrite (uint8_t lun)
if(USBD_STORAGE_fops->Write(lun , if(USBD_STORAGE_fops->Write(lun ,
MSC_BOT_Data, MSC_BOT_Data,
SCSI_blk_addr, SCSI_blk_addr, // modified by OpenTX
len / SCSI_blk_size) < 0) len / SCSI_blk_size) < 0)
{ {
SCSI_SenseCode(lun, HARDWARE_ERROR, WRITE_FAULT); SCSI_SenseCode(lun, HARDWARE_ERROR, WRITE_FAULT);
@@ -721,7 +730,7 @@ static int8_t SCSI_ProcessWrite (uint8_t lun)
} }
SCSI_blk_addr += len / SCSI_blk_size; SCSI_blk_addr += len / SCSI_blk_size; // modified by OpenTX
SCSI_blk_len -= len; SCSI_blk_len -= len;
/* case 12 : Ho = Do */ /* case 12 : Ho = Do */
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_conf_template.h * @file usbd_conf_template.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 30-June-2015
* @brief usb device configuration template file * @brief usb device configuration template file
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_core.h * @file usbd_core.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Header file for usbd_core.c * @brief Header file for usbd_core.c
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -30,9 +30,9 @@
#define __USBD_CORE_H #define __USBD_CORE_H
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "usbd_conf.h" #include "usb_dcd.h"
#include "../../../STM32_USB_OTG_Driver/inc/usb_dcd.h"
#include "usbd_def.h" #include "usbd_def.h"
#include "usbd_conf.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{ * @{
@@ -92,7 +92,7 @@ void USBD_Init(USB_OTG_CORE_HANDLE *pdev,
USB_OTG_CORE_ID_TypeDef coreID, USB_OTG_CORE_ID_TypeDef coreID,
const USBD_DEVICE *pDevice, const USBD_DEVICE *pDevice,
const USBD_Class_cb_TypeDef *class_cb, const USBD_Class_cb_TypeDef *class_cb,
const USBD_Usr_cb_TypeDef *usr_cb); const USBD_Usr_cb_TypeDef *usr_cb); // modified by OpenTX
USBD_Status USBD_DeInit(USB_OTG_CORE_HANDLE *pdev); USBD_Status USBD_DeInit(USB_OTG_CORE_HANDLE *pdev);
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_def.h * @file usbd_def.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief general defines for the usb device library * @brief general defines for the usb device library
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -93,7 +93,7 @@
#define USB_DESC_TYPE_ENDPOINT 5 #define USB_DESC_TYPE_ENDPOINT 5
#define USB_DESC_TYPE_DEVICE_QUALIFIER 6 #define USB_DESC_TYPE_DEVICE_QUALIFIER 6
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7 #define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 7
#define USB_DESC_TYPE_BOS 0x0F
#define USB_CONFIG_REMOTE_WAKEUP 2 #define USB_CONFIG_REMOTE_WAKEUP 2
#define USB_CONFIG_SELF_POWERED 1 #define USB_CONFIG_SELF_POWERED 1
@@ -122,8 +122,8 @@
#define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \ #define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \
(((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8)) (((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8))
#define LOBYTE(x) ((uint8_t)(x & 0x00FF)) #define LOBYTE(x) ((uint8_t)((x) & 0x00FF))
#define HIBYTE(x) ((uint8_t)((x & 0xFF00) >>8)) #define HIBYTE(x) ((uint8_t)(((x) & 0xFF00) >>8))
/** /**
* @} * @}
*/ */
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_ioreq.h * @file usbd_ioreq.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief header file for the usbd_ioreq.c file * @brief header file for the usbd_ioreq.c file
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -84,7 +84,7 @@
USBD_Status USBD_CtlSendData (USB_OTG_CORE_HANDLE *pdev, USBD_Status USBD_CtlSendData (USB_OTG_CORE_HANDLE *pdev,
const uint8_t *buf, const uint8_t *buf,
uint16_t len); uint16_t len); // modified by OpenTX
USBD_Status USBD_CtlContinueSendData (USB_OTG_CORE_HANDLE *pdev, USBD_Status USBD_CtlContinueSendData (USB_OTG_CORE_HANDLE *pdev,
uint8_t *pbuf, uint8_t *pbuf,
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_req.h * @file usbd_req.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief header file for the usbd_req.c file * @brief header file for the usbd_req.c file
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -31,9 +31,9 @@
#define __USB_REQUEST_H_ #define __USB_REQUEST_H_
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "usbd_conf.h"
#include "usbd_def.h" #include "usbd_def.h"
#include "usbd_core.h" #include "usbd_core.h"
#include "usbd_conf.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_usr.h * @file usbd_usr.h
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Header file for usbd_usr.c * @brief Header file for usbd_usr.c
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@
#define __USBD_USR_H__ #define __USBD_USR_H__
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "usbd_core.h" #include "usbd_ioreq.h"
/** @addtogroup USBD_USER /** @addtogroup USBD_USER
@@ -51,9 +51,9 @@
* @{ * @{
*/ */
extern const USBD_Usr_cb_TypeDef USR_cb; extern const USBD_Usr_cb_TypeDef USR_cb; // modified by OpenTX
extern const USBD_Usr_cb_TypeDef USR_FS_cb; extern const USBD_Usr_cb_TypeDef USR_FS_cb; // modified by OpenTX
extern const USBD_Usr_cb_TypeDef USR_HS_cb; extern const USBD_Usr_cb_TypeDef USR_HS_cb; // modified by OpenTX
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_core.c * @file usbd_core.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief This file provides all the USBD core functions. * @brief This file provides all the USBD core functions.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -111,9 +111,9 @@ const USBD_DCD_INT_cb_TypeDef USBD_DCD_INT_cb =
USBD_DevConnected, USBD_DevConnected,
USBD_DevDisconnected, USBD_DevDisconnected,
#endif #endif
}; }; // modified by OpenTX
const USBD_DCD_INT_cb_TypeDef * const USBD_DCD_INT_fops = &USBD_DCD_INT_cb; const USBD_DCD_INT_cb_TypeDef * const USBD_DCD_INT_fops = &USBD_DCD_INT_cb; // modified by OpenTX
/** /**
* @} * @}
*/ */
@@ -124,7 +124,7 @@ const USBD_DCD_INT_cb_TypeDef * const USBD_DCD_INT_fops = &USBD_DCD_INT_cb;
/** /**
* @brief USBD_Init * @brief USBD_Init
* Initailizes the device stack and load the class driver * Initializes the device stack and load the class driver
* @param pdev: device instance * @param pdev: device instance
* @param core_address: USB OTG core ID * @param core_address: USB OTG core ID
* @param class_cb: Class callback structure address * @param class_cb: Class callback structure address
@@ -135,7 +135,7 @@ void USBD_Init(USB_OTG_CORE_HANDLE *pdev,
USB_OTG_CORE_ID_TypeDef coreID, USB_OTG_CORE_ID_TypeDef coreID,
const USBD_DEVICE *pDevice, const USBD_DEVICE *pDevice,
const USBD_Class_cb_TypeDef *class_cb, const USBD_Class_cb_TypeDef *class_cb,
const USBD_Usr_cb_TypeDef *usr_cb) const USBD_Usr_cb_TypeDef *usr_cb) // modified by OpenTX
{ {
/* Hardware Init */ /* Hardware Init */
USB_OTG_BSP_Init(pdev); USB_OTG_BSP_Init(pdev);
@@ -154,7 +154,8 @@ void USBD_Init(USB_OTG_CORE_HANDLE *pdev,
pdev->dev.usr_cb->Init(); pdev->dev.usr_cb->Init();
/* Force Device Mode*/ /* Force Device Mode*/
USB_OTG_SetCurrentMode(pdev, 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 */ /* Enable Interrupts */
USB_OTG_BSP_EnableInterrupt(pdev); USB_OTG_BSP_EnableInterrupt(pdev);
@@ -162,14 +163,14 @@ void USBD_Init(USB_OTG_CORE_HANDLE *pdev,
/** /**
* @brief USBD_DeInit * @brief USBD_DeInit
* Deinitialize USB device library * Re-Initialize the device library
* @param pdev: device instance * @param pdev: device instance
* @retval status: status * @retval status: status
*/ */
USBD_Status USBD_DeInit(USB_OTG_CORE_HANDLE *pdev) USBD_Status USBD_DeInit(USB_OTG_CORE_HANDLE *pdev)
{ {
/*Disable Interrupts*/ /*Disable Interrupts*/
USB_OTG_BSP_DisableInterrupt(pdev); USB_OTG_BSP_DisableInterrupt(pdev); // modified by OpenTX
USB_OTG_DisableGlobalInt(pdev); USB_OTG_DisableGlobalInt(pdev);
USB_OTG_BSP_Deinit(pdev); USB_OTG_BSP_Deinit(pdev);
return USBD_OK; return USBD_OK;
@@ -253,6 +254,11 @@ static uint8_t USBD_DataOutStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum)
{ {
pdev->dev.class_cb->DataOut(pdev, epnum); pdev->dev.class_cb->DataOut(pdev, epnum);
} }
else
{
/* Do Nothing */
}
return USBD_OK; return USBD_OK;
} }
@@ -283,6 +289,12 @@ static uint8_t USBD_DataInStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum)
USBD_CtlContinueSendData (pdev, USBD_CtlContinueSendData (pdev,
ep->xfer_buff, ep->xfer_buff,
ep->rem_data_len); ep->rem_data_len);
/* Start the transfer */
DCD_EP_PrepareRx (pdev,
0,
NULL,
0);
} }
else else
{ /* last packet is MPS multiple, so send ZLP packet */ { /* last packet is MPS multiple, so send ZLP packet */
@@ -293,6 +305,12 @@ static uint8_t USBD_DataInStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum)
USBD_CtlContinueSendData(pdev , NULL, 0); USBD_CtlContinueSendData(pdev , NULL, 0);
ep->ctl_data_len = 0; ep->ctl_data_len = 0;
/* Start the transfer */
DCD_EP_PrepareRx (pdev,
0,
NULL,
0);
} }
else else
{ {
@@ -316,6 +334,11 @@ static uint8_t USBD_DataInStage(USB_OTG_CORE_HANDLE *pdev , uint8_t epnum)
{ {
pdev->dev.class_cb->DataIn(pdev, epnum); pdev->dev.class_cb->DataIn(pdev, epnum);
} }
else
{
/* Do Nothing */
}
return USBD_OK; return USBD_OK;
} }
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_ioreq.c * @file usbd_ioreq.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief This file provides the IO requests APIs for control endpoints. * @brief This file provides the IO requests APIs for control endpoints.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -94,7 +94,7 @@
*/ */
USBD_Status USBD_CtlSendData (USB_OTG_CORE_HANDLE *pdev, USBD_Status USBD_CtlSendData (USB_OTG_CORE_HANDLE *pdev,
const uint8_t *pbuf, const uint8_t *pbuf,
uint16_t len) uint16_t len) // modified by OpenTX
{ {
USBD_Status ret = USBD_OK; USBD_Status ret = USBD_OK;
@@ -176,7 +176,7 @@ USBD_Status USBD_CtlContinueRx (USB_OTG_CORE_HANDLE *pdev,
} }
/** /**
* @brief USBD_CtlSendStatus * @brief USBD_CtlSendStatus
* send zero lzngth packet on the ctl pipe * send zero length packet on the ctl pipe
* @param pdev: USB OTG device instance * @param pdev: USB OTG device instance
* @retval status * @retval status
*/ */
@@ -196,7 +196,7 @@ USBD_Status USBD_CtlSendStatus (USB_OTG_CORE_HANDLE *pdev)
/** /**
* @brief USBD_CtlReceiveStatus * @brief USBD_CtlReceiveStatus
* receive zero lzngth packet on the ctl pipe * receive zero length packet on the ctl pipe
* @param pdev: USB OTG device instance * @param pdev: USB OTG device instance
* @retval status * @retval status
*/ */
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usbd_req.c * @file usbd_req.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief This file provides the standard USB requests following chapter 9. * @brief This file provides the standard USB requests following chapter 9.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -27,9 +27,8 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "usbd_req.h" #include "usbd_req.h"
#include "usbd_desc.h"
#include "usbd_ioreq.h" #include "usbd_ioreq.h"
#include "usbd_desc.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
@@ -84,7 +83,7 @@ __ALIGN_BEGIN uint32_t USBD_ep_status __ALIGN_END = 0;
#pragma data_alignment=4 #pragma data_alignment=4
#endif #endif
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
__ALIGN_BEGIN const uint32_t USBD_default_cfg __ALIGN_END = 0; __ALIGN_BEGIN const uint32_t USBD_default_cfg __ALIGN_END = 0; // modified by OpenTX
#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
#if defined ( __ICCARM__ ) /*!< IAR Compiler */ #if defined ( __ICCARM__ ) /*!< IAR Compiler */
@@ -93,12 +92,6 @@ __ALIGN_BEGIN const uint32_t USBD_default_cfg __ALIGN_END = 0;
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */ #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
__ALIGN_BEGIN uint32_t USBD_cfg_status __ALIGN_END = 0; __ALIGN_BEGIN uint32_t USBD_cfg_status __ALIGN_END = 0;
#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_StrDesc[USB_MAX_STR_DESC_SIZ] __ALIGN_END ;
/** /**
* @} * @}
*/ */
@@ -242,9 +235,15 @@ USBD_Status USBD_StdEPReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req)
ep_addr = LOBYTE(req->wIndex); ep_addr = LOBYTE(req->wIndex);
/* Check the class specific requests before going to standard request */
if ((req->bmRequest & USB_REQ_TYPE_MASK) == USB_REQ_TYPE_CLASS)
{
pdev->dev.class_cb->Setup (pdev, req);
return ret;
}
switch (req->bRequest) switch (req->bRequest)
{ {
case USB_REQ_SET_FEATURE : case USB_REQ_SET_FEATURE :
switch (pdev->dev.device_status) switch (pdev->dev.device_status)
@@ -341,6 +340,12 @@ USBD_Status USBD_StdEPReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req)
USBD_ep_status = 0x0000; USBD_ep_status = 0x0000;
} }
} }
else
{
/* Do Nothing */
}
USBD_CtlSendData (pdev, USBD_CtlSendData (pdev,
(uint8_t *)&USBD_ep_status, (uint8_t *)&USBD_ep_status,
2); 2);
@@ -369,16 +374,17 @@ static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE *pdev,
{ {
uint16_t len; uint16_t len;
uint8_t *pbuf; uint8_t *pbuf;
len = req->wLength ;
switch (req->wValue >> 8) switch (req->wValue >> 8)
{ {
#if (USBD_LPM_ENABLED == 1)
case USB_DESC_TYPE_BOS:
pbuf = pdev->pDesc->GetBOSDescriptor(pdev->dev_speed, &len);
break;
#endif
case USB_DESC_TYPE_DEVICE: case USB_DESC_TYPE_DEVICE:
pbuf = pdev->dev.usr_device->GetDeviceDescriptor(pdev->cfg.speed, &len); pbuf = pdev->dev.usr_device->GetDeviceDescriptor(pdev->cfg.speed, &len);
if ((req->wLength == 64) ||( pdev->dev.device_status == USB_OTG_DEFAULT))
{
len = 8;
}
break; break;
case USB_DESC_TYPE_CONFIGURATION: case USB_DESC_TYPE_CONFIGURATION:
@@ -428,7 +434,7 @@ static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE *pdev,
#else #else
USBD_CtlError(pdev , req); USBD_CtlError(pdev , req);
return; return;
#endif /* USBD_CtlError(pdev , req); */ #endif /* USBD_CtlError(pdev , req)*/
} }
break; break;
case USB_DESC_TYPE_DEVICE_QUALIFIER: case USB_DESC_TYPE_DEVICE_QUALIFIER:
@@ -474,8 +480,6 @@ static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE *pdev,
USBD_CtlError(pdev , req); USBD_CtlError(pdev , req);
return; return;
#endif #endif
default: default:
USBD_CtlError(pdev , req); USBD_CtlError(pdev , req);
return; return;
@@ -627,7 +631,7 @@ static void USBD_GetConfig(USB_OTG_CORE_HANDLE *pdev,
USBD_CtlSendData (pdev, USBD_CtlSendData (pdev,
(const uint8_t *)&USBD_default_cfg, (const uint8_t *)&USBD_default_cfg,
1); 1); // modified by OpenTX
break; break;
case USB_OTG_CONFIGURED: case USB_OTG_CONFIGURED:
@@ -713,31 +717,38 @@ static void USBD_SetFeature(USB_OTG_CORE_HANDLE *pdev,
test_mode = req->wIndex >> 8; test_mode = req->wIndex >> 8;
switch (test_mode) switch (test_mode)
{ {
case 1: // TEST_J case 1: /* TEST_J */
dctl.b.tstctl = 1; dctl.b.tstctl = 1;
break; break;
case 2: // TEST_K case 2: /* TEST_K */
dctl.b.tstctl = 2; dctl.b.tstctl = 2;
break; break;
case 3: // TEST_SE0_NAK case 3: /* TEST_SE0_NAK */
dctl.b.tstctl = 3; dctl.b.tstctl = 3;
break; break;
case 4: // TEST_PACKET case 4: /* TEST_PACKET */
dctl.b.tstctl = 4; dctl.b.tstctl = 4;
break; break;
case 5: // TEST_FORCE_ENABLE case 5: /* TEST_FORCE_ENABLE */
dctl.b.tstctl = 5; dctl.b.tstctl = 5;
break; break;
default :
dctl.b.tstctl = 1;
break;
} }
SET_TEST_MODE = dctl; SET_TEST_MODE = dctl;
pdev->dev.test_mode = 1; pdev->dev.test_mode = 1;
USBD_CtlSendStatus(pdev); USBD_CtlSendStatus(pdev);
} }
else
{
/* Do Nothing */
}
} }
@@ -1,5 +1,6 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head> <html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="File-List" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/filelist.xml"> <link rel="File-List" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/filelist.xml">
<link rel="Edit-Time-Data" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/editdata.mso"><!--[if !mso]> <link rel="Edit-Time-Data" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/editdata.mso"><!--[if !mso]>
@@ -9,11 +10,7 @@ o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);}
</style> </style>
<![endif]--> <![endif]--><title>Release Notes for STM32F105/7xx, STM32F2xx and STM32F4xx USB Device Library</title><!--[if gte mso 9]><xml>
<title>Release Notes for STM32F105/7xx, STM32F2xx and STM32F4xx USB Device Library</title><!--[if gte mso 9]><xml>
<o:DocumentProperties> <o:DocumentProperties>
<o:Author>STMicroelectronics</o:Author> <o:Author>STMicroelectronics</o:Author>
<o:LastAuthor>Raouf Hosni</o:LastAuthor> <o:LastAuthor>Raouf Hosni</o:LastAuthor>
@@ -30,7 +27,11 @@ w\:* {behavior:url(#default#VML);}
<o:CharactersWithSpaces>6508</o:CharactersWithSpaces> <o:CharactersWithSpaces>6508</o:CharactersWithSpaces>
<o:Version>12.00</o:Version> <o:Version>12.00</o:Version>
</o:DocumentProperties> </o:DocumentProperties>
</xml><![endif]--><link rel="themeData" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/themedata.thmx"> </xml><![endif]-->
<link rel="themeData" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/themedata.thmx">
<link rel="colorSchemeMapping" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/colorschememapping.xml"><!--[if gte mso 9]><xml> <link rel="colorSchemeMapping" href="Release_Notes_for_STM32F2xx_StdPeriph_Driver_files/colorschememapping.xml"><!--[if gte mso 9]><xml>
<w:WordDocument> <w:WordDocument>
<w:Zoom>110</w:Zoom> <w:Zoom>110</w:Zoom>
@@ -877,8 +878,7 @@ ul
</xml><![endif]--><!--[if gte mso 9]><xml> </xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit"> <o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1"/> <o:idmap v:ext="edit" data="1"/>
</o:shapelayout></xml><![endif]--><meta content="MCD Application Team" name="author"></head> </o:shapelayout></xml><![endif]--><meta content="MCD Application Team" name="author"></head><body style="" link="blue" vlink="blue">
<body style="" link="blue" vlink="blue">
<div class="WordSection1"> <div class="WordSection1">
@@ -899,28 +899,49 @@ ul
<td style="padding: 1.5pt;"> <td style="padding: 1.5pt;">
<h1 style="margin-bottom: 0.25in; text-align: center;" align="center"><span style="font-size: 20pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: rgb(51, 102, 255);">Release Notes for STM32F105/7xx, STM32F2xx and STM32F4xx&nbsp;USB Device Library</span><span style="font-size: 20pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"><o:p></o:p></span></h1> <h1 style="margin-bottom: 0.25in; text-align: center;" align="center"><span style="font-size: 20pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: rgb(51, 102, 255);">Release Notes for STM32F105/7xx, STM32F2xx and STM32F4xx&nbsp;USB Device Library</span><span style="font-size: 20pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"><o:p></o:p></span></h1>
<p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; color: black;">Copyright <p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; color: black;">Copyright
2012 STMicroelectronics</span><span style="color: black;"><u1:p></u1:p><o:p></o:p></span></p> 2015 STMicroelectronics</span><span style="color: black;"><u1:p></u1:p><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; color: black;"><img style="border: 0px solid ; width: 86px; height: 65px;" alt="" id="_x0000_i1026" src="../../_htmresc/logo.bmp"></span><span style="font-size: 10pt;"><o:p></o:p></span></p> <p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; color: black;"><img style="border: 0px solid ; width: 86px; height: 65px;" alt="" id="_x0000_i1026" src="../../_htmresc/logo.bmp"></span><span style="font-size: 10pt;"><o:p></o:p></span></p>
</td> </td>
</tr> </tr>
</tbody></table> </tbody></table>
<p class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; display: none;"><o:p>&nbsp;</o:p></span></p> <p class="MsoNormal"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;; display: none;"><o:p>&nbsp;</o:p></span></p>
<table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" width="900"> <table style="width: 675pt;" class="MsoNormalTable" border="0" cellpadding="0" width="900">
<tbody><tr style=""> <tbody><tr style="">
<td style="padding: 0in;" valign="top"> <td style="padding: 0in;" valign="top">
<h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><span style="font-size: 12pt; color: white;">Contents<o:p></o:p></span></h2>
<ol style="margin-top: 0in;" start="1" type="1">
<li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"><a href="#History">Update History</a><o:p></o:p></span></li> <h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><a name="History"></a><span style="font-size: 12pt; color: white;">Update History</span></h2><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 200px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.2.0 / 09-November-2015</span></h3><p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
<li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"><a href="#License">License</a><o:p></o:p></span></li> Changes</span></u></b><u><span style="font-size: 10pt; font-family: Verdana; color: black;"><o:p></o:p></span></u></p>
</ol>
<h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><a name="History"></a><span style="font-size: 12pt; color: white;">Update History</span></h2><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 200px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.1.0 / 19-March-2012<o:p></o:p></span></h3>
<ul style="margin-top: 0cm;" type="square"><li style="font-weight: bold;"><span style="font-size: 10pt; font-family: Verdana;">Add composite class</span></li>
<li><span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;">Core Driver</span></li>
<ul style="list-style-type: circle;"><li><span style="font-size: 10pt; font-family: Verdana;">usbd_core.c:
Fix bug of unsupported premature Host Out stage during data In stage
(ie. when endpoint 0 maximum data size is 8 and Host requests
GetDeviceDescriptor for the first time)</span></li><li><span style="font-size: 10pt; font-family: Verdana;">usbd_req.c:&nbsp;</span></li><ul><li><span style="font-size: 10pt; font-family: Verdana;">Fix bug of unsupported Endpoint Class requests (ie. Audio SetCurrent request for endpoint sampling rate setting)</span></li><li><span style="font-size: 10pt; font-family: Verdana;">Initialize </span><span style="font-size: 10pt; font-family: Verdana;">the <span style="font-style: italic;">len</span> </span><span style="font-size: 10pt; font-family: Verdana;">variable before the switch case in <span style="font-style: italic;">USBD_GetDescriptor</span> function<br></span></li></ul></ul><li><span style="font-size: 10pt; font-family: Verdana;">HID Class</span></li><ul><li><span style="font-size: 10pt; font-family: Verdana;">Add Polling time API <span style="font-style: italic;">USBD_HID_GetPollingInterval()</span> to query this period for HS and FS</span></li></ul><li><span style="font-size: 10pt; font-family: Verdana;">CDC Class</span></li><ul><li><span style="font-size: 10pt; font-family: Verdana;">usbd_cdc.core.c:&nbsp;</span></li><ul><li><span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;">Fix bug for not handling the ZLP (zero length packet). A new state to handle the ZLP case are added</span></li><li><span style="font-size: 10pt; font-family: Verdana;">Remove <span style="font-style: italic;">USB_REQ_GET_DESCRIPTOR</span> case Handling from CDC-specific SETUP requests</span></li><li><span style="font-size: 10pt; font-family: Verdana;">Call </span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic;">USBD_CtlSendData() </span></span><span style="font-size: 10pt; font-family: Verdana;">inside the if block in the&nbsp; <span style="font-style: italic;">USB_REQ_GET_DESCRIPTOR</span> case<br></span></li></ul></ul></ul><ul style="margin-top: 0cm;" type="square"><li><span style="font-size: 10pt; font-family: Verdana;">MSC Class</span></li><ul><li><span style="font-size: 10pt; font-family: Verdana;">usbd_msc_scsi.c:&nbsp;</span></li><ul><li><span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;">Define values for <span style="font-style: italic;">SCSI_blk_addr</span>, <span style="font-style: italic;">SCSI_blk_len</span> variables.</span></li></ul></ul></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 200px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.1.0 / 19-March-2012<o:p></o:p></span></h3>
<p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main <p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
Changes<o:p></o:p></span></u></b></p> Changes<o:p></o:p></span></u></b></p>
<ul style="margin-top: 0cm;" type="square"><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Official support of </span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-weight: bold; font-style: italic;">STM32F4xx</span> devices</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">All source files: license disclaimer text update and add link to the License file on ST Internet.<br></span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Handle test mode in the set feature request</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Handle dynamically the USB SELF POWERED feature</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Handle correctly the USBD_CtlError process to take into account error during Control OUT stage</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Miscellaneous bug fix</span></li></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial; margin-right: 500pt; width: 171px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.0.0 / 22-July-2011<o:p></o:p></span></h3><p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main <ul style="margin-top: 0cm;" type="square"><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Official support of </span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-weight: bold; font-style: italic;">STM32F4xx</span> devices</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">All source files: license disclaimer text update and add link to the License file on ST Internet.<br></span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Handle test mode in the set feature request</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Handle dynamically the USB SELF POWERED feature</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Handle correctly the USBD_CtlError process to take into account error during Control OUT stage</span></li><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">Miscellaneous bug fix</span></li></ul><h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 171px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.0.0 / 22-July-2011<o:p></o:p></span></h3><p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
Changes<o:p></o:p></span></u></b></p> Changes<o:p></o:p></span></u></b></p>
<ul style="margin-top: 0cm;" type="square"><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">First official version for <span style="font-weight: bold; font-style: italic;">STM32F105/7xx</span> and <span style="font-weight: bold; font-style: italic;">STM32F2xx</span> devices</span></li></ul><span style="font-size: 10pt; font-family: Verdana;"></span><br><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span> <ul style="margin-top: 0cm;" type="square"><li class="MsoNormal" style="color: black; margin-top: 4.5pt; margin-bottom: 4.5pt;"><span style="font-size: 10pt; font-family: Verdana;">First official version for <span style="font-weight: bold; font-style: italic;">STM32F105/7xx</span> and <span style="font-weight: bold; font-style: italic;">STM32F2xx</span> devices</span></li></ul><span style="font-size: 10pt; font-family: Verdana;"></span><br><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span>
<h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: initial; -moz-background-origin: initial; -moz-background-inline-policy: initial;"><a name="License"></a><span style="font-size: 12pt; color: white;">License<o:p></o:p></span></h2> <h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><a name="License"></a><span style="font-size: 12pt; color: white;">License<o:p></o:p></span></h2>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); You may not use this&nbsp;</span><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">package</span><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"> except in compliance with the License. You may obtain a copy of the License at:<br><br></span></p><div style="text-align: center;"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a target="_blank" href="http://www.st.com/software_license_agreement_liberty_v2">http://www.st.com/software_license_agreement_liberty_v2</a></span><br><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"></span></div><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"><br>Unless <p class="MsoNormal"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); You may not use this&nbsp;</span><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">package</span><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"> except in compliance with the License. You may obtain a copy of the License at:<br><br></span></p><div style="text-align: center;"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a target="_blank" href="http://www.st.com/software_license_agreement_liberty_v2">http://www.st.com/software_license_agreement_liberty_v2</a></span><br><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"></span></div><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"><br>Unless
required by applicable law or agreed to in writing, software required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, <br>WITHOUT distributed under the License is distributed on an "AS IS" BASIS, <br>WITHOUT
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_bsp.h * @file usb_bsp.h
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Specific api's relative to the used hardware platform * @brief Specific api's relative to the used hardware platform
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -78,20 +78,24 @@
void BSP_Init(void); void BSP_Init(void);
void USB_OTG_BSP_Init (USB_OTG_CORE_HANDLE *pdev); void USB_OTG_BSP_Init (USB_OTG_CORE_HANDLE *pdev);
void USB_OTG_BSP_Deinit(USB_OTG_CORE_HANDLE *pdev); void USB_OTG_BSP_Deinit(USB_OTG_CORE_HANDLE *pdev); // modified by OpenTX
void USB_OTG_BSP_uDelay (const uint32_t usec); void USB_OTG_BSP_uDelay (const uint32_t usec);
void USB_OTG_BSP_mDelay (const uint32_t msec); void USB_OTG_BSP_mDelay (const uint32_t msec);
void USB_OTG_BSP_EnableInterrupt (USB_OTG_CORE_HANDLE *pdev); void USB_OTG_BSP_EnableInterrupt (USB_OTG_CORE_HANDLE *pdev);
void USB_OTG_BSP_DisableInterrupt (USB_OTG_CORE_HANDLE *pdev); void USB_OTG_BSP_TimerIRQ (void);
void USB_OTG_BSP_DisableInterrupt (USB_OTG_CORE_HANDLE *pdev); // modified by OpenTX
#ifdef USE_HOST_MODE #ifdef USE_HOST_MODE
void USB_OTG_BSP_ConfigVBUS(USB_OTG_CORE_HANDLE *pdev); void USB_OTG_BSP_ConfigVBUS(USB_OTG_CORE_HANDLE *pdev);
void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE *pdev,uint8_t state); void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE *pdev,uint8_t state);
#endif void USB_OTG_BSP_Resume(USB_OTG_CORE_HANDLE *pdev) ;
void USB_OTG_BSP_Suspend(USB_OTG_CORE_HANDLE *pdev);
#endif /* USE_HOST_MODE */
/** /**
* @} * @}
*/ */
#endif //__USB_BSP__H__ #endif /* __USB_BSP__H__ */
/** /**
* @} * @}
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_conf.h * @file usb_conf.h
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief General low level driver configuration * @brief General low level driver configuration
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_core.h * @file usb_core.h
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Header of the Core Layer * @brief Header of the Core Layer
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -195,17 +195,11 @@ typedef struct _Device_TypeDef
uint8_t *(*GetSerialStrDescriptor)( uint8_t speed , uint16_t *length); uint8_t *(*GetSerialStrDescriptor)( uint8_t speed , uint16_t *length);
uint8_t *(*GetConfigurationStrDescriptor)( uint8_t speed , uint16_t *length); uint8_t *(*GetConfigurationStrDescriptor)( uint8_t speed , uint16_t *length);
uint8_t *(*GetInterfaceStrDescriptor)( uint8_t speed , uint16_t *length); uint8_t *(*GetInterfaceStrDescriptor)( uint8_t speed , uint16_t *length);
} USBD_DEVICE, *pUSBD_DEVICE;
//typedef struct USB_OTG_hPort #if (USBD_LPM_ENABLED == 1)
//{ uint8_t *(*GetBOSDescriptor)( uint8_t speed , uint16_t *length);
// void (*Disconnect) (void *phost); #endif
// void (*Connect) (void *phost); } USBD_DEVICE, *pUSBD_DEVICE;
// uint8_t ConnStatus;
// uint8_t DisconnStatus;
// uint8_t ConnHandled;
// uint8_t DisconnHandled;
//} USB_OTG_hPort_TypeDef;
typedef struct _Device_cb typedef struct _Device_cb
{ {
@@ -222,9 +216,9 @@ typedef struct _Device_cb
uint8_t (*IsoINIncomplete) (void *pdev); uint8_t (*IsoINIncomplete) (void *pdev);
uint8_t (*IsoOUTIncomplete) (void *pdev); uint8_t (*IsoOUTIncomplete) (void *pdev);
const uint8_t *(*GetConfigDescriptor)( uint8_t speed , uint16_t *length); const uint8_t *(*GetConfigDescriptor)( uint8_t speed , uint16_t *length); // modified by OpenTX
#ifdef USB_OTG_HS_CORE #ifdef USB_OTG_HS_CORE
const uint8_t *(*GetOtherConfigDescriptor)( uint8_t speed , uint16_t *length); const uint8_t *(*GetOtherConfigDescriptor)( uint8_t speed , uint16_t *length); // modified by OpenTX
#endif #endif
#ifdef USB_SUPPORT_USER_STRING_DESC #ifdef USB_SUPPORT_USER_STRING_DESC
@@ -267,20 +261,20 @@ typedef struct _DCD
const USBD_DEVICE *usr_device; const USBD_DEVICE *usr_device;
uint8_t *pConfig_descriptor; uint8_t *pConfig_descriptor;
} }
DCD_DEV , *DCD_PDEV; DCD_DEV , *DCD_PDEV; // modified by OpenTX
typedef struct _HCD typedef struct _HCD
{ {
uint8_t Rx_Buffer [MAX_DATA_LENGTH]; uint8_t Rx_Buffer [MAX_DATA_LENGTH];
__IO uint32_t ConnSts; __IO uint32_t ConnSts;
__IO uint32_t PortEnabled;
__IO uint32_t ErrCnt[USB_OTG_MAX_TX_FIFOS]; __IO uint32_t ErrCnt[USB_OTG_MAX_TX_FIFOS];
__IO uint32_t XferCnt[USB_OTG_MAX_TX_FIFOS]; __IO uint32_t XferCnt[USB_OTG_MAX_TX_FIFOS];
__IO HC_STATUS HC_Status[USB_OTG_MAX_TX_FIFOS]; __IO HC_STATUS HC_Status[USB_OTG_MAX_TX_FIFOS];
__IO URB_STATE URB_State[USB_OTG_MAX_TX_FIFOS]; __IO URB_STATE URB_State[USB_OTG_MAX_TX_FIFOS];
USB_OTG_HC hc [USB_OTG_MAX_TX_FIFOS]; USB_OTG_HC hc [USB_OTG_MAX_TX_FIFOS];
uint16_t channel [USB_OTG_MAX_TX_FIFOS]; uint16_t channel [USB_OTG_MAX_TX_FIFOS];
// USB_OTG_hPort_TypeDef *port_cb;
} }
HCD_DEV , *USB_OTG_USBH_PDEV; HCD_DEV , *USB_OTG_USBH_PDEV;
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_dcd.h * @file usb_dcd.h
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Peripheral Driver Header file * @brief Peripheral Driver Header file
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "usb_core.h" #include "usb_core.h"
/** @addtogroup USB_OTG_DRIVER /** @addtogroup USB_OTG_DRIVER
* @{ * @{
*/ */
@@ -128,7 +129,7 @@ uint32_t DCD_EP_PrepareRx ( USB_OTG_CORE_HANDLE *pdev,
uint32_t DCD_EP_Tx (USB_OTG_CORE_HANDLE *pdev, uint32_t DCD_EP_Tx (USB_OTG_CORE_HANDLE *pdev,
uint8_t ep_addr, uint8_t ep_addr,
const uint8_t *pbuf, const uint8_t *pbuf,
uint32_t buf_len); uint32_t buf_len); // modified by OpenTX
uint32_t DCD_EP_Stall (USB_OTG_CORE_HANDLE *pdev, uint32_t DCD_EP_Stall (USB_OTG_CORE_HANDLE *pdev,
uint8_t epnum); uint8_t epnum);
uint32_t DCD_EP_ClrStall (USB_OTG_CORE_HANDLE *pdev, uint32_t DCD_EP_ClrStall (USB_OTG_CORE_HANDLE *pdev,
@@ -149,7 +150,7 @@ void DCD_SetEPStatus (USB_OTG_CORE_HANDLE *pdev ,
*/ */
#endif //__DCD_H__ #endif /* __DCD_H__ */
/** /**
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_dcd_int.h * @file usb_dcd_int.h
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Peripheral Device Interface Layer * @brief Peripheral Device Interface Layer
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -65,7 +65,7 @@ typedef struct _USBD_DCD_INT
}USBD_DCD_INT_cb_TypeDef; }USBD_DCD_INT_cb_TypeDef;
extern const USBD_DCD_INT_cb_TypeDef * const USBD_DCD_INT_fops; extern const USBD_DCD_INT_cb_TypeDef * const USBD_DCD_INT_fops; // modified by OpenTX
/** /**
* @} * @}
*/ */
@@ -90,7 +90,7 @@ extern const USBD_DCD_INT_cb_TypeDef * const USBD_DCD_INT_fops;
#define CLEAR_OUT_EP_INTR(epnum,intr) \ #define CLEAR_OUT_EP_INTR(epnum,intr) \
doepint.d32=0; \ doepint.d32=0; \
doepint.b.intr = 1; \ doepint.b.intr = 1; \
USB_OTG_WRITE_REG32(&pdev->regs.OUTEP_REGS[epnum]->DOEPINT,doepint.d32); USB_OTG_WRITE_REG32(&pdev->regs.OUTEP_REGS[(epnum)]->DOEPINT,doepint.d32);
/** /**
* @} * @}
@@ -108,13 +108,14 @@ extern const USBD_DCD_INT_cb_TypeDef * const USBD_DCD_INT_fops;
*/ */
uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev); uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev);
uint32_t USBD_OTG_EP1OUT_ISR_Handler (USB_OTG_CORE_HANDLE *pdev);
uint32_t USBD_OTG_EP1IN_ISR_Handler (USB_OTG_CORE_HANDLE *pdev);
/** /**
* @} * @}
*/ */
#endif // USB_DCD_INT_H__ #endif /* USB_DCD_INT_H__ */
/** /**
* @} * @}
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_defines.h * @file usb_defines.h
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Header of the Core Layer * @brief Header of the Core Layer
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -220,10 +220,10 @@ typedef enum
/** @defgroup Internal_Macro's /** @defgroup Internal_Macro's
* @{ * @{
*/ */
#define USB_OTG_READ_REG32(reg) (*(__IO uint32_t *)reg) #define USB_OTG_READ_REG32(reg) (*(__IO uint32_t *)(reg))
#define USB_OTG_WRITE_REG32(reg,value) (*(__IO uint32_t *)reg = value) #define USB_OTG_WRITE_REG32(reg,value) (*(__IO uint32_t *)(reg) = (value))
#define USB_OTG_MODIFY_REG32(reg,clear_mask,set_mask) \ #define USB_OTG_MODIFY_REG32(reg,clear_mask,set_mask) \
USB_OTG_WRITE_REG32(reg, (((USB_OTG_READ_REG32(reg)) & ~clear_mask) | set_mask ) ) USB_OTG_WRITE_REG32((reg), (((USB_OTG_READ_REG32(reg)) & ~(clear_mask)) | (set_mask)) )
/******************************************************************************** /********************************************************************************
ENUMERATION TYPE ENUMERATION TYPE
@@ -235,7 +235,7 @@ enum USB_OTG_SPEED {
USB_SPEED_HIGH USB_SPEED_HIGH
}; };
#endif //__USB_DEFINES__H__ #endif /* __USB_DEFINES__H__ */
/** /**
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_hcd.h * @file usb_hcd.h
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Host layer Header file * @brief Host layer Header file
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -86,6 +86,8 @@ uint32_t HCD_SubmitRequest (USB_OTG_CORE_HANDLE *pdev ,
uint32_t HCD_GetCurrentSpeed (USB_OTG_CORE_HANDLE *pdev); uint32_t HCD_GetCurrentSpeed (USB_OTG_CORE_HANDLE *pdev);
uint32_t HCD_ResetPort (USB_OTG_CORE_HANDLE *pdev); uint32_t HCD_ResetPort (USB_OTG_CORE_HANDLE *pdev);
uint32_t HCD_IsDeviceConnected (USB_OTG_CORE_HANDLE *pdev); uint32_t HCD_IsDeviceConnected (USB_OTG_CORE_HANDLE *pdev);
uint32_t HCD_IsPortEnabled (USB_OTG_CORE_HANDLE *pdev);
uint32_t HCD_GetCurrentFrame (USB_OTG_CORE_HANDLE *pdev) ; uint32_t HCD_GetCurrentFrame (USB_OTG_CORE_HANDLE *pdev) ;
URB_STATE HCD_GetURB_State (USB_OTG_CORE_HANDLE *pdev, uint8_t ch_num); URB_STATE HCD_GetURB_State (USB_OTG_CORE_HANDLE *pdev, uint8_t ch_num);
uint32_t HCD_GetXferCnt (USB_OTG_CORE_HANDLE *pdev, uint8_t ch_num); uint32_t HCD_GetXferCnt (USB_OTG_CORE_HANDLE *pdev, uint8_t ch_num);
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_hcd_int.h * @file usb_hcd_int.h
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Peripheral Device Interface Layer * @brief Peripheral Device Interface Layer
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -60,6 +60,8 @@ typedef struct _USBH_HCD_INT
uint8_t (* SOF) (USB_OTG_CORE_HANDLE *pdev); uint8_t (* SOF) (USB_OTG_CORE_HANDLE *pdev);
uint8_t (* DevConnected) (USB_OTG_CORE_HANDLE *pdev); uint8_t (* DevConnected) (USB_OTG_CORE_HANDLE *pdev);
uint8_t (* DevDisconnected) (USB_OTG_CORE_HANDLE *pdev); uint8_t (* DevDisconnected) (USB_OTG_CORE_HANDLE *pdev);
uint8_t (* DevPortEnabled) (USB_OTG_CORE_HANDLE *pdev);
uint8_t (* DevPortDisabled) (USB_OTG_CORE_HANDLE *pdev);
}USBH_HCD_INT_cb_TypeDef; }USBH_HCD_INT_cb_TypeDef;
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_otg.h * @file usb_otg.h
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief OTG Core Header * @brief OTG Core Header
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_regs.h * @file usb_regs.h
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief hardware registers * @brief hardware registers
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -80,7 +80,7 @@
/** @defgroup __USB_OTG_Core_register /** @defgroup __USB_OTG_Core_register
* @{ * @{
*/ */
typedef struct _USB_OTG_GREGS //000h typedef struct _USB_OTG_GREGS /* 000h */
{ {
__IO uint32_t GOTGCTL; /* USB_OTG Control and Status Register 000h*/ __IO uint32_t GOTGCTL; /* USB_OTG Control and Status Register 000h*/
__IO uint32_t GOTGINT; /* USB_OTG Interrupt Register 004h*/ __IO uint32_t GOTGINT; /* USB_OTG Interrupt Register 004h*/
@@ -110,7 +110,7 @@ USB_OTG_GREGS;
/** @defgroup __device_Registers /** @defgroup __device_Registers
* @{ * @{
*/ */
typedef struct _USB_OTG_DREGS // 800h typedef struct _USB_OTG_DREGS /* 800h */
{ {
__IO uint32_t DCFG; /* dev Configuration Register 800h*/ __IO uint32_t DCFG; /* dev Configuration Register 800h*/
__IO uint32_t DCTL; /* dev Control Register 804h*/ __IO uint32_t DCTL; /* dev Control Register 804h*/
@@ -219,7 +219,7 @@ USB_OTG_HC_REGS;
/** @defgroup __otg_Core_registers /** @defgroup __otg_Core_registers
* @{ * @{
*/ */
typedef struct USB_OTG_core_regs //000h typedef struct USB_OTG_core_regs /* 000h */
{ {
USB_OTG_GREGS *GREGS; USB_OTG_GREGS *GREGS;
USB_OTG_DREGS *DREGS; USB_OTG_DREGS *DREGS;
@@ -866,12 +866,13 @@ uint32_t xfersize :
uint32_t Reserved7_18 : uint32_t Reserved7_18 :
12; 12;
uint32_t pktcnt : uint32_t pktcnt :
2; 1;
uint32_t Reserved20_28 : uint32_t Reserved20_28 :
9; 9;
uint32_t supcnt : uint32_t supcnt :
2; 2;
uint32_t Reserved31; uint32_t Reserved31 :
1;
} }
b; b;
} USB_OTG_DEP0XFRSIZ_TypeDef ; } USB_OTG_DEP0XFRSIZ_TypeDef ;
@@ -1174,7 +1175,7 @@ uint32_t Reserved5_31 :
*/ */
#endif //__USB_OTG_REGS_H__ #endif /* __USB_OTG_REGS_H__ */
/** /**
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_core.c * @file usb_core.c
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief USB-OTG Core Layer * @brief USB-OTG Core Layer
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -178,9 +178,10 @@ USB_OTG_STS USB_OTG_WritePacket(USB_OTG_CORE_HANDLE *pdev,
count32b = (len + 3) / 4; count32b = (len + 3) / 4;
fifo = pdev->regs.DFIFO[ch_ep_num]; fifo = pdev->regs.DFIFO[ch_ep_num];
for (i = 0; i < count32b; i++, src+=4) for (i = 0; i < count32b; i++)
{ {
USB_OTG_WRITE_REG32( fifo, *((__packed uint32_t *)src) ); USB_OTG_WRITE_REG32( fifo, *((__packed uint32_t *)src) );
src+=4;
} }
} }
return status; return status;
@@ -203,10 +204,10 @@ void *USB_OTG_ReadPacket(USB_OTG_CORE_HANDLE *pdev,
__IO uint32_t *fifo = pdev->regs.DFIFO[0]; __IO uint32_t *fifo = pdev->regs.DFIFO[0];
for ( i = 0; i < count32b; i++, dest += 4 ) for( i = 0; i < count32b; i++)
{ {
*(__packed uint32_t *)dest = USB_OTG_READ_REG32(fifo); *(__packed uint32_t *)dest = USB_OTG_READ_REG32(fifo);
dest += 4 ;
} }
return ((void *)dest); return ((void *)dest);
} }
@@ -278,6 +279,11 @@ USB_OTG_STS USB_OTG_SelectCore(USB_OTG_CORE_HANDLE *pdev,
} }
else
{
/* Do Nothing */
}
pdev->regs.GREGS = (USB_OTG_GREGS *)(baseAddress + \ pdev->regs.GREGS = (USB_OTG_GREGS *)(baseAddress + \
USB_OTG_CORE_GLOBAL_REGS_OFFSET); USB_OTG_CORE_GLOBAL_REGS_OFFSET);
pdev->regs.DREGS = (USB_OTG_DREGS *) (baseAddress + \ pdev->regs.DREGS = (USB_OTG_DREGS *) (baseAddress + \
@@ -326,13 +332,13 @@ USB_OTG_STS USB_OTG_CoreInit(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_GUSBCFG_TypeDef usbcfg; USB_OTG_GUSBCFG_TypeDef usbcfg;
USB_OTG_GCCFG_TypeDef gccfg; USB_OTG_GCCFG_TypeDef gccfg;
USB_OTG_GAHBCFG_TypeDef ahbcfg; USB_OTG_GAHBCFG_TypeDef ahbcfg;
#if defined (STM32F446xx) || defined (STM32F469_479xx)
USB_OTG_DCTL_TypeDef dctl;
#endif
usbcfg.d32 = 0; usbcfg.d32 = 0;
gccfg.d32 = 0; gccfg.d32 = 0;
ahbcfg.d32 = 0; ahbcfg.d32 = 0;
if (pdev->cfg.phy_itface == USB_OTG_ULPI_PHY) if (pdev->cfg.phy_itface == USB_OTG_ULPI_PHY)
{ {
gccfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GCCFG); gccfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GCCFG);
@@ -385,9 +391,9 @@ USB_OTG_STS USB_OTG_CoreInit(USB_OTG_CORE_HANDLE *pdev)
/* Deactivate the power down*/ /* Deactivate the power down*/
gccfg.d32 = 0; gccfg.d32 = 0;
gccfg.b.pwdn = 1; gccfg.b.pwdn = 1;
gccfg.b.vbussensingA = 1 ; gccfg.b.vbussensingA = 1 ;
gccfg.b.vbussensingB = 1 ; gccfg.b.vbussensingB = 1 ;
#ifndef VBUS_SENSING_ENABLED #ifndef VBUS_SENSING_ENABLED
gccfg.b.disablevbussensing = 1; gccfg.b.disablevbussensing = 1;
#endif #endif
@@ -418,6 +424,20 @@ USB_OTG_STS USB_OTG_CoreInit(USB_OTG_CORE_HANDLE *pdev)
USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, usbcfg.d32); USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, usbcfg.d32);
USB_OTG_EnableCommonInt(pdev); USB_OTG_EnableCommonInt(pdev);
#endif #endif
#if defined (STM32F446xx) || defined (STM32F469_479xx)
usbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GUSBCFG);
usbcfg.b.srpcap = 1;
/*clear sdis bit in dctl */
dctl.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DCTL);
/* Connect device */
dctl.b.sftdiscon = 0;
USB_OTG_WRITE_REG32(&pdev->regs.DREGS->DCTL, dctl.d32);
dctl.d32 = USB_OTG_READ_REG32(&pdev->regs.DREGS->DCTL);
USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, usbcfg.d32);
USB_OTG_EnableCommonInt(pdev);
#endif
return status; return status;
} }
/** /**
@@ -540,6 +560,11 @@ USB_OTG_STS USB_OTG_SetCurrentMode(USB_OTG_CORE_HANDLE *pdev , uint8_t mode)
usbcfg.b.force_dev = 1; usbcfg.b.force_dev = 1;
} }
else
{
/* Do Nothing */
}
USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, usbcfg.d32); USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, usbcfg.d32);
USB_OTG_BSP_mDelay(50); USB_OTG_BSP_mDelay(50);
return status; return status;
@@ -771,12 +796,19 @@ USB_OTG_STS USB_OTG_EnableHostInt(USB_OTG_CORE_HANDLE *pdev)
{ {
intmsk.b.rxstsqlvl = 1; intmsk.b.rxstsqlvl = 1;
} }
intmsk.b.portintr = 1;
intmsk.b.hcintr = 1;
intmsk.b.disconnect = 1;
intmsk.b.sofintr = 1;
intmsk.b.incomplisoout = 1; intmsk.b.incomplisoout = 1;
intmsk.b.hcintr = 1;
intmsk.b.portintr = 1;
USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GINTMSK, intmsk.d32, intmsk.d32); USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GINTMSK, intmsk.d32, intmsk.d32);
intmsk.d32 = 0;
intmsk.b.disconnect = 1;
intmsk.b.sofintr = 1;
USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GINTMSK, intmsk.d32, 0);
return status; return status;
} }
@@ -840,7 +872,7 @@ uint32_t USB_OTG_ResetPort(USB_OTG_CORE_HANDLE *pdev)
hprt0.d32 = USB_OTG_ReadHPRT0(pdev); hprt0.d32 = USB_OTG_ReadHPRT0(pdev);
hprt0.b.prtrst = 1; hprt0.b.prtrst = 1;
USB_OTG_WRITE_REG32(pdev->regs.HPRT0, hprt0.d32); USB_OTG_WRITE_REG32(pdev->regs.HPRT0, hprt0.d32);
USB_OTG_BSP_mDelay (10); /* See Note #1 */ USB_OTG_BSP_mDelay (100); /* See Note #1 */
hprt0.b.prtrst = 0; hprt0.b.prtrst = 0;
USB_OTG_WRITE_REG32(pdev->regs.HPRT0, hprt0.d32); USB_OTG_WRITE_REG32(pdev->regs.HPRT0, hprt0.d32);
USB_OTG_BSP_mDelay (20); USB_OTG_BSP_mDelay (20);
@@ -1091,7 +1123,7 @@ USB_OTG_STS USB_OTG_HC_Halt(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
nptxsts.d32 = 0; nptxsts.d32 = 0;
hptxsts.d32 = 0; hptxsts.d32 = 0;
hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR); hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR);
hcchar.b.chen = 1;
hcchar.b.chdis = 1; hcchar.b.chdis = 1;
/* Check for space in the request queue to issue the halt. */ /* Check for space in the request queue to issue the halt. */
@@ -1101,6 +1133,7 @@ USB_OTG_STS USB_OTG_HC_Halt(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
if (nptxsts.b.nptxqspcavail == 0) if (nptxsts.b.nptxqspcavail == 0)
{ {
hcchar.b.chen = 0; hcchar.b.chen = 0;
USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR, hcchar.d32);
} }
} }
else else
@@ -1109,8 +1142,10 @@ USB_OTG_STS USB_OTG_HC_Halt(USB_OTG_CORE_HANDLE *pdev , uint8_t hc_num)
if (hptxsts.b.ptxqspcavail == 0) if (hptxsts.b.ptxqspcavail == 0)
{ {
hcchar.b.chen = 0; hcchar.b.chen = 0;
USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR, hcchar.d32);
} }
} }
hcchar.b.chen = 1;
USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR, hcchar.d32); USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCCHAR, hcchar.d32);
return status; return status;
} }
@@ -1435,10 +1470,14 @@ enum USB_OTG_SPEED USB_OTG_GetDeviceSpeed (USB_OTG_CORE_HANDLE *pdev)
case DSTS_ENUMSPD_LS_PHY_6MHZ: case DSTS_ENUMSPD_LS_PHY_6MHZ:
speed = USB_SPEED_LOW; speed = USB_SPEED_LOW;
break; break;
default:
speed = USB_SPEED_FULL;
break;
} }
return speed; return speed;
} }
/** /**
* @brief enables EP0 OUT to receive SETUP packets and configures EP0 * @brief enables EP0 OUT to receive SETUP packets and configures EP0
* for transmitting packets * for transmitting packets
@@ -1467,6 +1506,9 @@ USB_OTG_STS USB_OTG_EP0Activate(USB_OTG_CORE_HANDLE *pdev)
case DSTS_ENUMSPD_LS_PHY_6MHZ: case DSTS_ENUMSPD_LS_PHY_6MHZ:
diepctl.b.mps = DEP0CTL_MPS_8; diepctl.b.mps = DEP0CTL_MPS_8;
break; break;
default:
diepctl.b.mps = DEP0CTL_MPS_64;
break;
} }
USB_OTG_WRITE_REG32(&pdev->regs.INEP_REGS[0]->DIEPCTL, diepctl.d32); USB_OTG_WRITE_REG32(&pdev->regs.INEP_REGS[0]->DIEPCTL, diepctl.d32);
dctl.b.cgnpinnak = 1; dctl.b.cgnpinnak = 1;
@@ -1671,6 +1713,7 @@ USB_OTG_STS USB_OTG_EPStartXfer(USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep)
{ {
deptsiz.b.pktcnt = (ep->xfer_len + (ep->maxpacket - 1)) / ep->maxpacket; deptsiz.b.pktcnt = (ep->xfer_len + (ep->maxpacket - 1)) / ep->maxpacket;
deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket; deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
ep->xfer_len = deptsiz.b.xfersize ;
} }
USB_OTG_WRITE_REG32(&pdev->regs.OUTEP_REGS[ep->num]->DOEPTSIZ, deptsiz.d32); USB_OTG_WRITE_REG32(&pdev->regs.OUTEP_REGS[ep->num]->DOEPTSIZ, deptsiz.d32);
@@ -2051,23 +2094,34 @@ uint32_t USB_OTG_GetEPStatus(USB_OTG_CORE_HANDLE *pdev ,USB_OTG_EP *ep)
depctl.d32 = USB_OTG_READ_REG32(depctl_addr); depctl.d32 = USB_OTG_READ_REG32(depctl_addr);
if (depctl.b.stall == 1) if (depctl.b.stall == 1)
{
Status = USB_OTG_EP_TX_STALL; Status = USB_OTG_EP_TX_STALL;
}
else if (depctl.b.naksts == 1) else if (depctl.b.naksts == 1)
{
Status = USB_OTG_EP_TX_NAK; Status = USB_OTG_EP_TX_NAK;
}
else else
{
Status = USB_OTG_EP_TX_VALID; Status = USB_OTG_EP_TX_VALID;
}
} }
else else
{ {
depctl_addr = &(pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL); depctl_addr = &(pdev->regs.OUTEP_REGS[ep->num]->DOEPCTL);
depctl.d32 = USB_OTG_READ_REG32(depctl_addr); depctl.d32 = USB_OTG_READ_REG32(depctl_addr);
if (depctl.b.stall == 1) if (depctl.b.stall == 1)
{
Status = USB_OTG_EP_RX_STALL; Status = USB_OTG_EP_RX_STALL;
}
else if (depctl.b.naksts == 1) else if (depctl.b.naksts == 1)
{
Status = USB_OTG_EP_RX_NAK; Status = USB_OTG_EP_RX_NAK;
}
else else
{
Status = USB_OTG_EP_RX_VALID; Status = USB_OTG_EP_RX_VALID;
}
} }
/* Return the current status */ /* Return the current status */
@@ -2099,7 +2153,9 @@ void USB_OTG_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep , uint32_t
USB_OTG_EPSetStall(pdev, ep); return; USB_OTG_EPSetStall(pdev, ep); return;
} }
else if (Status == USB_OTG_EP_TX_NAK) else if (Status == USB_OTG_EP_TX_NAK)
{
depctl.b.snak = 1; depctl.b.snak = 1;
}
else if (Status == USB_OTG_EP_TX_VALID) else if (Status == USB_OTG_EP_TX_VALID)
{ {
if (depctl.b.stall == 1) if (depctl.b.stall == 1)
@@ -2113,7 +2169,14 @@ void USB_OTG_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep , uint32_t
depctl.b.epena = 1; depctl.b.epena = 1;
} }
else if (Status == USB_OTG_EP_TX_DIS) else if (Status == USB_OTG_EP_TX_DIS)
{
depctl.b.usbactep = 0; depctl.b.usbactep = 0;
}
else
{
/* Do Nothing */
}
} }
else /* Process for OUT endpoint */ else /* Process for OUT endpoint */
{ {
@@ -2124,7 +2187,9 @@ void USB_OTG_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep , uint32_t
depctl.b.stall = 1; depctl.b.stall = 1;
} }
else if (Status == USB_OTG_EP_RX_NAK) else if (Status == USB_OTG_EP_RX_NAK)
{
depctl.b.snak = 1; depctl.b.snak = 1;
}
else if (Status == USB_OTG_EP_RX_VALID) else if (Status == USB_OTG_EP_RX_VALID)
{ {
if (depctl.b.stall == 1) if (depctl.b.stall == 1)
@@ -2141,6 +2206,11 @@ void USB_OTG_SetEPStatus (USB_OTG_CORE_HANDLE *pdev , USB_OTG_EP *ep , uint32_t
{ {
depctl.b.usbactep = 0; depctl.b.usbactep = 0;
} }
else
{
/* Do Nothing */
}
} }
USB_OTG_WRITE_REG32(depctl_addr, depctl.d32); USB_OTG_WRITE_REG32(depctl_addr, depctl.d32);
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_dcd.c * @file usb_dcd.c
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Peripheral Device Interface Layer * @brief Peripheral Device Interface Layer
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -107,7 +107,7 @@ void DCD_Init(USB_OTG_CORE_HANDLE *pdev ,
ep->is_in = 1; ep->is_in = 1;
ep->num = i; ep->num = i;
ep->tx_fifo_num = i; ep->tx_fifo_num = i;
/* Control until ep is actvated */ /* Control until ep is activated */
ep->type = EP_TYPE_CTRL; ep->type = EP_TYPE_CTRL;
ep->maxpacket = USB_OTG_MAX_EP0_SIZE; ep->maxpacket = USB_OTG_MAX_EP0_SIZE;
ep->xfer_buff = 0; ep->xfer_buff = 0;
@@ -130,17 +130,27 @@ void DCD_Init(USB_OTG_CORE_HANDLE *pdev ,
USB_OTG_DisableGlobalInt(pdev); USB_OTG_DisableGlobalInt(pdev);
/*Init the Core (common init.) */ #if defined (STM32F446xx) || defined (STM32F469_479xx)
USB_OTG_CoreInit(pdev);
/* Force Device Mode*/ /* Force Device Mode*/
USB_OTG_SetCurrentMode(pdev, DEVICE_MODE); USB_OTG_SetCurrentMode(pdev, DEVICE_MODE);
/*Init the Core (common init.) */
USB_OTG_CoreInit(pdev);
#else
/*Init the Core (common init.) */
USB_OTG_CoreInit(pdev);
/* Force Device Mode*/
USB_OTG_SetCurrentMode(pdev, DEVICE_MODE);
#endif
/* Init Device */ /* Init Device */
USB_OTG_CoreInitDev(pdev); USB_OTG_CoreInitDev(pdev);
/* Enable USB Global interrupt */ /* Enable USB Global interrupt */
USB_OTG_EnableGlobalInt(pdev); USB_OTG_EnableGlobalInt(pdev);
} }
@@ -261,7 +271,7 @@ uint32_t DCD_EP_PrepareRx( USB_OTG_CORE_HANDLE *pdev,
uint32_t DCD_EP_Tx ( USB_OTG_CORE_HANDLE *pdev, uint32_t DCD_EP_Tx ( USB_OTG_CORE_HANDLE *pdev,
uint8_t ep_addr, uint8_t ep_addr,
const uint8_t *pbuf, const uint8_t *pbuf,
uint32_t buf_len) uint32_t buf_len) // modified by OpenTX
{ {
USB_OTG_EP *ep; USB_OTG_EP *ep;
@@ -270,7 +280,7 @@ uint32_t DCD_EP_Tx ( USB_OTG_CORE_HANDLE *pdev,
/* Setup and start the Transfer */ /* Setup and start the Transfer */
ep->is_in = 1; ep->is_in = 1;
ep->num = ep_addr & 0x7F; ep->num = ep_addr & 0x7F;
ep->xfer_buff = (uint8_t*)pbuf; //remove const qualifier, safe to do because we are sending ep->xfer_buff = (uint8_t*)pbuf; //remove const qualifier, safe to do because we are sending // modified by OpenTX
ep->dma_addr = (uint32_t)pbuf; ep->dma_addr = (uint32_t)pbuf;
ep->xfer_count = 0; ep->xfer_count = 0;
ep->xfer_len = buf_len; ep->xfer_len = buf_len;
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_dcd_int.c * @file usb_dcd_int.c
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Peripheral Device interrupt subroutines * @brief Peripheral Device interrupt subroutines
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -27,6 +27,8 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "usb_dcd_int.h" #include "usb_dcd_int.h"
#include "board.h" // modified by OpenTX
/** @addtogroup USB_OTG_DRIVER /** @addtogroup USB_OTG_DRIVER
* @{ * @{
*/ */
@@ -130,8 +132,7 @@ uint32_t USBD_OTG_EP1OUT_ISR_Handler (USB_OTG_CORE_HANDLE *pdev)
if (pdev->cfg.dma_enable == 1) if (pdev->cfg.dma_enable == 1)
{ {
deptsiz.d32 = USB_OTG_READ_REG32(&(pdev->regs.OUTEP_REGS[1]->DOEPTSIZ)); deptsiz.d32 = USB_OTG_READ_REG32(&(pdev->regs.OUTEP_REGS[1]->DOEPTSIZ));
/*ToDo : handle more than one single MPS size packet */ pdev->dev.out_ep[1].xfer_count = pdev->dev.out_ep[1].xfer_len- \
pdev->dev.out_ep[1].xfer_count = pdev->dev.out_ep[1].maxpacket - \
deptsiz.b.xfersize; deptsiz.b.xfersize;
} }
/* Inform upper layer: data ready */ /* Inform upper layer: data ready */
@@ -194,13 +195,6 @@ uint32_t USBD_OTG_EP1IN_ISR_Handler (USB_OTG_CORE_HANDLE *pdev)
if (diepint.b.emptyintr) if (diepint.b.emptyintr)
{ {
DCD_WriteEmptyTxFifo(pdev , 1); DCD_WriteEmptyTxFifo(pdev , 1);
CLEAR_IN_EP_INTR(1, emptyintr);
/*
Notice: this probabbly needs the same fix as DCD_HandleInEP_ISR(), but
leaving this out, we don't use this part of code
fifoemptymsk = 0x1 << 1;
USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPEMPMSK, fifoemptymsk, 0);
*/
} }
return 1; return 1;
} }
@@ -438,7 +432,7 @@ static uint32_t DCD_HandleInEP_ISR(USB_OTG_CORE_HANDLE *pdev)
while ( ep_intr ) while ( ep_intr )
{ {
if (ep_intr&0x1) /* In ITR */ if ((ep_intr & 0x1) == 0x01) /* In ITR */
{ {
diepint.d32 = DCD_ReadDevInEP(pdev , epnum); /* Get In ITR status */ diepint.d32 = DCD_ReadDevInEP(pdev , epnum); /* Get In ITR status */
if ( diepint.b.xfercompl ) if ( diepint.b.xfercompl )
@@ -476,40 +470,7 @@ static uint32_t DCD_HandleInEP_ISR(USB_OTG_CORE_HANDLE *pdev)
} }
if (diepint.b.emptyintr) if (diepint.b.emptyintr)
{ {
/*===============ADDED SECTION ==============================*/
/*
This only applies to INTERRUPT transfer mode.
diepint.b.emptyintr interrupt can't be reset by writing 1 to
DIEPINT register. According to reference manual, this bit
is read-only.
The CLEAR_IN_EP_INTR(epnum, emptyintr) does not work!
The only way to stop this interrupt is to disable it using
mask register DIEPEMPMSK.
Original code gets here, is unsuccessful at interrupt flag reset
and when interrupt handler returns, another one is fired again,
robbing CPU time, which is then spent only in interrupt handlers
(this one and all other that have higher priority)
This only happens in HID mode (when interrupt in endpoint is
used) and when host is not actively polling device (us) for
update. This is situation on Linux when no program is using
joystick. The kernel/joystick driver stops polling device.
*/
if ( pdev->dev.in_ep[epnum].type == USB_OTG_EP_INT ) {
fifoemptymsk = 0x1 << epnum;
USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPEMPMSK, fifoemptymsk, 0);
}
/*===============END OF ADDED SECTION ==============================*/
DCD_WriteEmptyTxFifo(pdev , epnum); DCD_WriteEmptyTxFifo(pdev , epnum);
CLEAR_IN_EP_INTR(epnum, emptyintr);
} }
} }
epnum++; epnum++;
@@ -678,6 +639,7 @@ static uint32_t DCD_WriteEmptyTxFifo(USB_OTG_CORE_HANDLE *pdev, uint32_t epnum)
uint32_t len = 0; uint32_t len = 0;
uint32_t len32b; uint32_t len32b;
txstatus.d32 = 0; txstatus.d32 = 0;
uint32_t fifoemptymsk;
ep = &pdev->dev.in_ep[epnum]; ep = &pdev->dev.in_ep[epnum];
@@ -691,8 +653,6 @@ static uint32_t DCD_WriteEmptyTxFifo(USB_OTG_CORE_HANDLE *pdev, uint32_t epnum)
len32b = (len + 3) / 4; len32b = (len + 3) / 4;
txstatus.d32 = USB_OTG_READ_REG32( &pdev->regs.INEP_REGS[epnum]->DTXFSTS); txstatus.d32 = USB_OTG_READ_REG32( &pdev->regs.INEP_REGS[epnum]->DTXFSTS);
while (txstatus.b.txfspcavail > len32b && while (txstatus.b.txfspcavail > len32b &&
ep->xfer_count < ep->xfer_len && ep->xfer_count < ep->xfer_len &&
ep->xfer_len != 0) ep->xfer_len != 0)
@@ -712,6 +672,14 @@ static uint32_t DCD_WriteEmptyTxFifo(USB_OTG_CORE_HANDLE *pdev, uint32_t epnum)
ep->xfer_count += len; ep->xfer_count += len;
txstatus.d32 = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[epnum]->DTXFSTS); txstatus.d32 = USB_OTG_READ_REG32(&pdev->regs.INEP_REGS[epnum]->DTXFSTS);
/* Mask the TxFIFOEmpty interrupt */
if (ep->xfer_len == ep->xfer_count)
{
fifoemptymsk = 0x1 << ep->num;
USB_OTG_MODIFY_REG32(&pdev->regs.DREGS->DIEPEMPMSK,
fifoemptymsk, 0);
}
} }
return 1; return 1;
@@ -800,26 +768,100 @@ static uint32_t DCD_HandleUsbReset_ISR(USB_OTG_CORE_HANDLE *pdev)
*/ */
static uint32_t DCD_HandleEnumDone_ISR(USB_OTG_CORE_HANDLE *pdev) static uint32_t DCD_HandleEnumDone_ISR(USB_OTG_CORE_HANDLE *pdev)
{ {
uint32_t hclk = 168000000;
USB_OTG_GINTSTS_TypeDef gintsts; USB_OTG_GINTSTS_TypeDef gintsts;
USB_OTG_GUSBCFG_TypeDef gusbcfg; USB_OTG_GUSBCFG_TypeDef gusbcfg;
RCC_ClocksTypeDef RCC_Clocks;
USB_OTG_EP0Activate(pdev); USB_OTG_EP0Activate(pdev);
/* Set USB turn-around time based on device speed and PHY interface. */ /* Get HCLK frequency */
RCC_GetClocksFreq(&RCC_Clocks);
hclk = RCC_Clocks.HCLK_Frequency;
/* Clear default TRDT value and Set USB turn-around time based on device speed and PHY interface. */
gusbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GUSBCFG); gusbcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.GREGS->GUSBCFG);
gusbcfg.b.usbtrdtim = 0;
USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, gusbcfg.d32);
/* Full or High speed */ /* Full or High speed */
if ( USB_OTG_GetDeviceSpeed(pdev) == USB_SPEED_HIGH) if ( USB_OTG_GetDeviceSpeed(pdev) == USB_SPEED_HIGH)
{ {
pdev->cfg.speed = USB_OTG_SPEED_HIGH; pdev->cfg.speed = USB_OTG_SPEED_HIGH;
pdev->cfg.mps = USB_OTG_HS_MAX_PACKET_SIZE ; pdev->cfg.mps = USB_OTG_HS_MAX_PACKET_SIZE ;
/*USBTRD min For HS device*/
gusbcfg.b.usbtrdtim = 9; gusbcfg.b.usbtrdtim = 9;
} }
else else
{ {
pdev->cfg.speed = USB_OTG_SPEED_FULL; pdev->cfg.speed = USB_OTG_SPEED_FULL;
pdev->cfg.mps = USB_OTG_FS_MAX_PACKET_SIZE ; pdev->cfg.mps = USB_OTG_FS_MAX_PACKET_SIZE ;
gusbcfg.b.usbtrdtim = 5;
/* The USBTRD is configured according to the tables below, depending on AHB frequency
used by application. In the low AHB frequency range it is used to stretch enough the USB response
time to IN tokens, the USB turnaround time, so to compensate for the longer AHB read access
latency to the Data FIFO */
if((hclk >= 15000000)&&(hclk < 16000000))
{
/* hclk Clock Range between 15-16 MHz */
gusbcfg.b.usbtrdtim = 0xE;
}
else if((hclk >= 16000000)&&(hclk < 17100000))
{
/* hclk Clock Range between 16-17.1 MHz */
gusbcfg.b.usbtrdtim = 0xD;
}
else if((hclk >= 17100000)&&(hclk < 18400000))
{
/* hclk Clock Range between 17-18.4 MHz */
gusbcfg.b.usbtrdtim = 0xC;
}
else if((hclk >= 18400000)&&(hclk < 20000000))
{
/* hclk Clock Range between 18.4-20 MHz */
gusbcfg.b.usbtrdtim = 0xB;
}
else if((hclk >= 20000000)&&(hclk < 21800000))
{
/* hclk Clock Range between 20-21.8 MHz */
gusbcfg.b.usbtrdtim = 0xA;
}
else if((hclk >= 21800000)&&(hclk < 24000000))
{
/* hclk Clock Range between 21.8-24 MHz */
gusbcfg.b.usbtrdtim = 0x9;
}
else if((hclk >= 24000000)&&(hclk < 26600000))
{
/* hclk Clock Range between 24-26.6 MHz */
gusbcfg.b.usbtrdtim = 0x8;
}
else if((hclk >= 26600000)&&(hclk < 30000000))
{
/* hclk Clock Range between 26.6-30 MHz */
gusbcfg.b.usbtrdtim = 0x7;
}
else if((hclk >= 30000000)&&(hclk < 34300000))
{
/* hclk Clock Range between 30-34.3 MHz */
gusbcfg.b.usbtrdtim= 0x6;
}
else /* if(hclk >= 34300000) */
{
/* hclk Clock Range between 34.3-168 MHz */
gusbcfg.b.usbtrdtim = 0x5;
}
} }
USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, gusbcfg.d32); USB_OTG_WRITE_REG32(&pdev->regs.GREGS->GUSBCFG, gusbcfg.d32);
@@ -888,8 +930,6 @@ static uint32_t DCD_ReadDevInEP (USB_OTG_CORE_HANDLE *pdev, uint8_t epnum)
return v; return v;
} }
/** /**
* @} * @}
*/ */
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_hcd.c * @file usb_hcd.c
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Host Interface Layer * @brief Host Interface Layer
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "usb_core.h" #include "usb_core.h"
#include "usb_hcd.h" #include "usb_hcd.h"
#include "usb_conf.h" #include "usb_conf.h"
#include "usb_bsp.h" #include "usb_bsp.h"
@@ -170,6 +169,19 @@ uint32_t HCD_IsDeviceConnected(USB_OTG_CORE_HANDLE *pdev)
return (pdev->host.ConnSts); return (pdev->host.ConnSts);
} }
/**
* @brief HCD_IsPortEnabled
* This function checks if port is enabled
* @param pdev : Selected device
* @retval Frame number
*
*/
uint32_t HCD_IsPortEnabled(USB_OTG_CORE_HANDLE *pdev)
{
return (pdev->host.PortEnabled);
}
/** /**
* @brief HCD_GetCurrentFrame * @brief HCD_GetCurrentFrame
* This function returns the frame number for sof packet * This function returns the frame number for sof packet
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_hcd_int.c * @file usb_hcd_int.c
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief Host driver interrupt subroutines * @brief Host driver interrupt subroutines
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.
@@ -365,9 +365,10 @@ static uint32_t USB_OTG_USBH_handle_port_ISR (USB_OTG_CORE_HANDLE *pdev)
USB_OTG_HPRT0_TypeDef hprt0; USB_OTG_HPRT0_TypeDef hprt0;
USB_OTG_HPRT0_TypeDef hprt0_dup; USB_OTG_HPRT0_TypeDef hprt0_dup;
USB_OTG_HCFG_TypeDef hcfg; USB_OTG_HCFG_TypeDef hcfg;
uint32_t do_reset = 0;
uint32_t retval = 0; uint32_t retval = 0;
USB_OTG_GINTMSK_TypeDef intmsk;
intmsk.d32 = 0;
hcfg.d32 = 0; hcfg.d32 = 0;
hprt0.d32 = 0; hprt0.d32 = 0;
hprt0_dup.d32 = 0; hprt0_dup.d32 = 0;
@@ -385,7 +386,6 @@ static uint32_t USB_OTG_USBH_handle_port_ISR (USB_OTG_CORE_HANDLE *pdev)
/* Port Connect Detected */ /* Port Connect Detected */
if (hprt0.b.prtconndet) if (hprt0.b.prtconndet)
{ {
hprt0_dup.b.prtconndet = 1; hprt0_dup.b.prtconndet = 1;
USBH_HCD_INT_fops->DevConnected(pdev); USBH_HCD_INT_fops->DevConnected(pdev);
retval |= 1; retval |= 1;
@@ -398,13 +398,9 @@ static uint32_t USB_OTG_USBH_handle_port_ISR (USB_OTG_CORE_HANDLE *pdev)
if (hprt0.b.prtena == 1) if (hprt0.b.prtena == 1)
{ {
USBH_HCD_INT_fops->DevConnected(pdev);
if ((hprt0.b.prtspd == HPRT0_PRTSPD_LOW_SPEED) || if ((hprt0.b.prtspd == HPRT0_PRTSPD_LOW_SPEED) ||
(hprt0.b.prtspd == HPRT0_PRTSPD_FULL_SPEED)) (hprt0.b.prtspd == HPRT0_PRTSPD_FULL_SPEED))
{ {
hcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.HREGS->HCFG); hcfg.d32 = USB_OTG_READ_REG32(&pdev->regs.HREGS->HCFG);
if (hprt0.b.prtspd == HPRT0_PRTSPD_LOW_SPEED) if (hprt0.b.prtspd == HPRT0_PRTSPD_LOW_SPEED)
@@ -414,38 +410,42 @@ static uint32_t USB_OTG_USBH_handle_port_ISR (USB_OTG_CORE_HANDLE *pdev)
{ {
if(pdev->cfg.phy_itface == USB_OTG_EMBEDDED_PHY) if(pdev->cfg.phy_itface == USB_OTG_EMBEDDED_PHY)
{ {
USB_OTG_InitFSLSPClkSel(pdev ,HCFG_6_MHZ ); USB_OTG_InitFSLSPClkSel(pdev , HCFG_6_MHZ);
} }
do_reset = 1;
}
}
else
{
USB_OTG_WRITE_REG32(&pdev->regs.HREGS->HFIR, 48000 ); else
if (hcfg.b.fslspclksel != HCFG_48_MHZ) {
{ USB_OTG_WRITE_REG32(&pdev->regs.HREGS->HFIR, 48000 );
USB_OTG_InitFSLSPClkSel(pdev ,HCFG_48_MHZ ); if (hcfg.b.fslspclksel != HCFG_48_MHZ)
do_reset = 1; {
USB_OTG_InitFSLSPClkSel(pdev ,HCFG_48_MHZ );
}
}
} }
} }
} }
else
{ USBH_HCD_INT_fops->DevPortEnabled(pdev);
do_reset = 1;
} /*unmask disconnect interrupt */
intmsk.d32 = 0;
intmsk.b.disconnect = 1;
USB_OTG_MODIFY_REG32(&pdev->regs.GREGS->GINTMSK, intmsk.d32, intmsk.d32);
}
else
{
USBH_HCD_INT_fops->DevPortDisabled(pdev);
} }
} }
/* Overcurrent Change Interrupt */ /* Overcurrent Change Interrupt */
if (hprt0.b.prtovrcurrchng) if (hprt0.b.prtovrcurrchng)
{ {
hprt0_dup.b.prtovrcurrchng = 1; hprt0_dup.b.prtovrcurrchng = 1;
retval |= 1; retval |= 1;
} }
if (do_reset)
{
USB_OTG_ResetPort(pdev);
}
/* Clear Port Interrupts */ /* Clear Port Interrupts */
USB_OTG_WRITE_REG32(pdev->regs.HPRT0, hprt0_dup.d32); USB_OTG_WRITE_REG32(pdev->regs.HPRT0, hprt0_dup.d32);
@@ -512,7 +512,10 @@ uint32_t USB_OTG_USBH_handle_hc_n_Out_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t
{ {
pdev->host.ErrCnt[num] = 0; pdev->host.ErrCnt[num] = 0;
UNMASK_HOST_INT_CHH (num); UNMASK_HOST_INT_CHH (num);
USB_OTG_HC_Halt(pdev, num); if (pdev->cfg.dma_enable == 0)
{
USB_OTG_HC_Halt(pdev, num);
}
CLEAR_HC_INT(hcreg , nak); CLEAR_HC_INT(hcreg , nak);
pdev->host.HC_Status[num] = HC_NAK; pdev->host.HC_Status[num] = HC_NAK;
} }
@@ -521,7 +524,6 @@ uint32_t USB_OTG_USBH_handle_hc_n_Out_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t
{ {
UNMASK_HOST_INT_CHH (num); UNMASK_HOST_INT_CHH (num);
USB_OTG_HC_Halt(pdev, num); USB_OTG_HC_Halt(pdev, num);
pdev->host.ErrCnt[num] ++;
pdev->host.HC_Status[num] = HC_XACTERR; pdev->host.HC_Status[num] = HC_XACTERR;
CLEAR_HC_INT(hcreg , xacterr); CLEAR_HC_INT(hcreg , xacterr);
} }
@@ -529,13 +531,15 @@ uint32_t USB_OTG_USBH_handle_hc_n_Out_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t
{ {
pdev->host.ErrCnt[num] = 0; pdev->host.ErrCnt[num] = 0;
UNMASK_HOST_INT_CHH (num); UNMASK_HOST_INT_CHH (num);
USB_OTG_HC_Halt(pdev, num); if (pdev->cfg.dma_enable == 0)
{
USB_OTG_HC_Halt(pdev, num);
}
CLEAR_HC_INT(hcreg , nyet); CLEAR_HC_INT(hcreg , nyet);
pdev->host.HC_Status[num] = HC_NYET; pdev->host.HC_Status[num] = HC_NYET;
} }
else if (hcint.b.datatglerr) else if (hcint.b.datatglerr)
{ {
UNMASK_HOST_INT_CHH (num); UNMASK_HOST_INT_CHH (num);
USB_OTG_HC_Halt(pdev, num); USB_OTG_HC_Halt(pdev, num);
CLEAR_HC_INT(hcreg , nak); CLEAR_HC_INT(hcreg , nak);
@@ -574,10 +578,8 @@ uint32_t USB_OTG_USBH_handle_hc_n_Out_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t
} }
else if(pdev->host.HC_Status[num] == HC_XACTERR) else if(pdev->host.HC_Status[num] == HC_XACTERR)
{ {
if (pdev->host.ErrCnt[num] == 3)
{ {
pdev->host.URB_State[num] = URB_ERROR; pdev->host.URB_State[num] = URB_ERROR;
pdev->host.ErrCnt[num] = 0;
} }
} }
CLEAR_HC_INT(hcreg , chhltd); CLEAR_HC_INT(hcreg , chhltd);
@@ -604,7 +606,6 @@ uint32_t USB_OTG_USBH_handle_hc_n_In_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t n
USB_OTG_HCTSIZn_TypeDef hctsiz; USB_OTG_HCTSIZn_TypeDef hctsiz;
USB_OTG_HC_REGS *hcreg; USB_OTG_HC_REGS *hcreg;
hcreg = pdev->regs.HC_REGS[num]; hcreg = pdev->regs.HC_REGS[num];
hcint.d32 = USB_OTG_READ_REG32(&hcreg->HCINT); hcint.d32 = USB_OTG_READ_REG32(&hcreg->HCINT);
hcintmsk.d32 = USB_OTG_READ_REG32(&hcreg->HCINTMSK); hcintmsk.d32 = USB_OTG_READ_REG32(&hcreg->HCINTMSK);
@@ -612,7 +613,6 @@ uint32_t USB_OTG_USBH_handle_hc_n_In_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t n
hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[num]->HCCHAR); hcchar.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[num]->HCCHAR);
hcintmsk.d32 = 0; hcintmsk.d32 = 0;
if (hcint.b.ahberr) if (hcint.b.ahberr)
{ {
CLEAR_HC_INT(hcreg ,ahberr); CLEAR_HC_INT(hcreg ,ahberr);
@@ -636,7 +636,6 @@ uint32_t USB_OTG_USBH_handle_hc_n_In_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t n
} }
else if (hcint.b.datatglerr) else if (hcint.b.datatglerr)
{ {
UNMASK_HOST_INT_CHH (num); UNMASK_HOST_INT_CHH (num);
USB_OTG_HC_Halt(pdev, num); USB_OTG_HC_Halt(pdev, num);
CLEAR_HC_INT(hcreg , nak); CLEAR_HC_INT(hcreg , nak);
@@ -653,7 +652,6 @@ uint32_t USB_OTG_USBH_handle_hc_n_In_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t n
else if (hcint.b.xfercompl) else if (hcint.b.xfercompl)
{ {
if (pdev->cfg.dma_enable == 1) if (pdev->cfg.dma_enable == 1)
{ {
hctsiz.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[num]->HCTSIZ); hctsiz.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[num]->HCTSIZ);
@@ -679,7 +677,6 @@ uint32_t USB_OTG_USBH_handle_hc_n_In_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t n
USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[num]->HCCHAR, hcchar.d32); USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[num]->HCCHAR, hcchar.d32);
pdev->host.URB_State[num] = URB_DONE; pdev->host.URB_State[num] = URB_DONE;
} }
} }
else if (hcint.b.chhltd) else if (hcint.b.chhltd)
{ {
@@ -713,20 +710,25 @@ uint32_t USB_OTG_USBH_handle_hc_n_In_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t n
else if (hcint.b.xacterr) else if (hcint.b.xacterr)
{ {
UNMASK_HOST_INT_CHH (num); UNMASK_HOST_INT_CHH (num);
pdev->host.ErrCnt[num] ++;
pdev->host.HC_Status[num] = HC_XACTERR; pdev->host.HC_Status[num] = HC_XACTERR;
USB_OTG_HC_Halt(pdev, num); USB_OTG_HC_Halt(pdev, num);
CLEAR_HC_INT(hcreg , xacterr); CLEAR_HC_INT(hcreg , xacterr);
} }
else if (hcint.b.nak) else if (hcint.b.nak)
{ {
if(hcchar.b.eptype == EP_TYPE_INTR) if(hcchar.b.eptype == EP_TYPE_INTR)
{ {
UNMASK_HOST_INT_CHH (num); UNMASK_HOST_INT_CHH (num);
USB_OTG_HC_Halt(pdev, num); if (pdev->cfg.dma_enable == 0)
{
USB_OTG_HC_Halt(pdev, num);
}
} }
else if ((hcchar.b.eptype == EP_TYPE_CTRL)||
pdev->host.HC_Status[num] = HC_NAK;
CLEAR_HC_INT(hcreg , nak);
if ((hcchar.b.eptype == EP_TYPE_CTRL)||
(hcchar.b.eptype == EP_TYPE_BULK)) (hcchar.b.eptype == EP_TYPE_BULK))
{ {
/* re-activate the channel */ /* re-activate the channel */
@@ -734,8 +736,6 @@ uint32_t USB_OTG_USBH_handle_hc_n_In_ISR (USB_OTG_CORE_HANDLE *pdev , uint32_t n
hcchar.b.chdis = 0; hcchar.b.chdis = 0;
USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[num]->HCCHAR, hcchar.d32); USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[num]->HCCHAR, hcchar.d32);
} }
pdev->host.HC_Status[num] = HC_NAK;
CLEAR_HC_INT(hcreg , nak);
} }
@@ -2,13 +2,13 @@
****************************************************************************** ******************************************************************************
* @file usb_otg.c * @file usb_otg.c
* @author MCD Application Team * @author MCD Application Team
* @version V2.1.0 * @version V2.2.0
* @date 19-March-2012 * @date 09-November-2015
* @brief OTG Core Layer * @brief OTG Core Layer
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
* *
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
* You may not use this file except in compliance with the License. * You may not use this file except in compliance with the License.