1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-24 00:35:18 +03:00

CN - Adds support for a mass storage USB device in the main firmware.

By default, the firmware includes the USB joystick device, but it is possible to replace this code with a mass storage device that allows access to the SD card when running the main firmware.
To include the mass storage device and remove the joystick device, add "USB=MASS" to the command line args when making the firmware.
This commit is contained in:
Chris Nisbet 2014-06-17 15:10:20 +12:00
parent b83f95ed1a
commit 07b4be8f45
9 changed files with 3955 additions and 3865 deletions

View file

@ -272,6 +272,12 @@ LUA = NO
# Values = NO, READONLY, NOMENUS # Values = NO, READONLY, NOMENUS
MENUS_LOCK = NO MENUS_LOCK = NO
# USB options in the main image
# Values = JOYSTICK, DRIVES
# JOYSTICK: The TX will appear as a joystick
# MASS: The TX will appear as a drive (as occurred pre-V2.0)
USB = JOYSTICK
#------- END BUILD OPTIONS --------------------------- #------- END BUILD OPTIONS ---------------------------
# Define programs and commands. # Define programs and commands.
@ -673,7 +679,7 @@ ifeq ($(PCB), TARANIS)
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_pwr.c SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_pwr.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_usart.c SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/stm32f2xx_usart.c
SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc_ride7/startup_stm32f2xx.s SRC += targets/taranis/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Source/Templates/gcc_ride7/startup_stm32f2xx.s
SRC += targets/taranis/usb_bsp.c targets/taranis/usbd_desc.c targets/taranis/usbd_hid_joystick.c SRC += targets/taranis/usb_bsp.c targets/taranis/usbd_desc.c
SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_core.c SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_core.c
SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_dcd.c SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_dcd.c
SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_dcd_int.c SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_OTG_Driver/src/usb_dcd_int.c
@ -682,6 +688,17 @@ ifeq ($(PCB), TARANIS)
SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/src/usbd_req.c SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Core/src/usbd_req.c
EXTRABOARDSRC += targets/taranis/usbd_usr.cpp EXTRABOARDSRC += targets/taranis/usbd_usr.cpp
SRC += targets/sky9x/syscalls.c SRC += targets/sky9x/syscalls.c
ifeq ($(USB), JOYSTICK)
CPPDEFS += -DUSB_JOYSTICK
SRC += targets/taranis/usbd_hid_joystick.c
else
CPPDEFS += -DUSB_MASS_STORAGE
SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_data.c
SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_scsi.c
SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_bot.c
SRC += targets/taranis/STM32_USB-Host-Device_Lib_V2.1.0/Libraries/STM32_USB_Device_Library/Class/msc/src/usbd_msc_core.c
EXTRABOARDSRC += targets/taranis/usbd_storage_msd.cpp
endif
ifneq ($(LUA), NO) ifneq ($(LUA), NO)
ifeq ($(LUA), YES) ifeq ($(LUA), YES)

File diff suppressed because it is too large Load diff

View file

@ -1699,4 +1699,8 @@ void varioWakeup();
extern const pm_uchar logo_taranis[]; extern const pm_uchar logo_taranis[];
#endif #endif
#if defined(USB_MASS_STORAGE)
extern void usbPluggedIn();
#endif
#endif #endif

View file

@ -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);
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);
case SCSI_MODE_SENSE6: case SCSI_MODE_SENSE6:
return SCSI_ModeSense6 (lun, params); return SCSI_ModeSense6 (lun, params);
@ -433,24 +433,29 @@ void SCSI_SenseCode(uint8_t lun, uint8_t sKey, uint8_t ASC)
* @param params: Command parameters * @param params: Command parameters
* @retval status * @retval status
*/ */
extern uint8_t lunReady[] ; extern uint8_t lunReady[] ;
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 (lun < 2) { #if defined(BOOT)
if (params[4] & 1) { if (lun < 2)
// lun to be active #else
lunReady[lun] = 1 ; if (lun < 1)
} #endif
else { {
// lun to be ejected if (params[4] & 1) {
lunReady[lun] = 0 ; // lun to be active
} lunReady[lun] = 1 ;
} }
else {
// lun to be ejected
lunReady[lun] = 0 ;
}
}
return 0; return 0;
} }

View file

@ -224,7 +224,9 @@ void turnBacklightOff(void);
int usbPlugged(void); int usbPlugged(void);
void usbInit(void); void usbInit(void);
void usbStart(void); void usbStart(void);
#if defined(USB_JOYSTICK)
void usbStop(void); void usbStop(void);
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -43,6 +43,7 @@ int usbPlugged(void)
//debounce //debounce
static uint8_t debounced_state = 0; static uint8_t debounced_state = 0;
static uint8_t last_state = 0; static uint8_t last_state = 0;
if ( GPIO_ReadInputDataBit(GPIOA, PIN_FS_VBUS) ) { if ( GPIO_ReadInputDataBit(GPIOA, PIN_FS_VBUS) ) {
if (last_state) debounced_state = 1; if (last_state) debounced_state = 1;
last_state = 1; last_state = 1;
@ -69,16 +70,23 @@ void usbInit(void)
void usbStart(void) void usbStart(void)
{ {
#if !defined(BOOT) #if !defined(BOOT)
#if defined(USB_JOYSTICK)
//intialize USB as HID device //intialize USB as HID device
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_HID_cb, &USR_cb); USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_HID_cb, &USR_cb);
#elif defined(USB_MASS_STORAGE)
//intialize USB as MSC device
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_MSC_cb, &USR_cb);
#endif
#else #else
//intialize USB as MSC device //intialize USB as MSC device
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_MSC_cb, &USR_cb); USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_MSC_cb, &USR_cb);
#endif //!defined(BOOT) #endif //!defined(BOOT)
} }
#if defined(USB_JOYSTICK)
void usbStop(void) void usbStop(void)
{ {
USBD_DeInit(&USB_OTG_dev); USBD_DeInit(&USB_OTG_dev);
} }
#endif

View file

@ -1,229 +1,236 @@
/** /**
****************************************************************************** ******************************************************************************
* @file usbd_desc.c * @file usbd_desc.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.1.0
* @date 19-March-2012 * @date 19-March-2012
* @brief This file provides the USBD descriptors and string formating method. * @brief This file provides the USBD descriptors and string formating method.
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2012 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.
* You may obtain a copy of the License at: * You may obtain a copy of the License at:
* *
* http://www.st.com/software_license_agreement_liberty_v2 * http://www.st.com/software_license_agreement_liberty_v2
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
****************************************************************************** ******************************************************************************
*/ */
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "usbd_core.h" #include "usbd_core.h"
#include "usbd_desc.h" #include "usbd_desc.h"
#include "usbd_req.h" #include "usbd_req.h"
#include "usbd_conf.h" #include "usbd_conf.h"
#include "usb_regs.h" #include "usb_regs.h"
#include "board_taranis.h" #include "board_taranis.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{ * @{
*/ */
/** @defgroup USBD_DESC /** @defgroup USBD_DESC
* @brief USBD descriptors module * @brief USBD descriptors module
* @{ * @{
*/ */
/** @defgroup USBD_DESC_Private_TypesDefinitions /** @defgroup USBD_DESC_Private_TypesDefinitions
* @{ * @{
*/ */
/** /**
* @} * @}
*/ */
/** @defgroup USBD_DESC_Private_Defines /** @defgroup USBD_DESC_Private_Defines
* @{ * @{
*/ */
#define USBD_VID 0x0483 #define USBD_VID 0x0483
#define USBD_LANGID_STRING 0x409 #define USBD_LANGID_STRING 0x409
#define USBD_MANUFACTURER_STRING "FrSky" #define USBD_MANUFACTURER_STRING "FrSky"
#define USBD_SERIALNUMBER_FS_STRING "00000000001B" #define USBD_SERIALNUMBER_FS_STRING "00000000001B"
#if defined(BOOT) #if defined(BOOT)
#define USBD_PID 0x5720 #define USBD_PID 0x5720
#define USBD_PRODUCT_FS_STRING "FrSky Taranis Bootloader" #define USBD_PRODUCT_FS_STRING "FrSky Taranis Bootloader"
#define USBD_CONFIGURATION_FS_STRING "MSC Config" #define USBD_CONFIGURATION_FS_STRING "MSC Config"
#define USBD_INTERFACE_FS_STRING "MSC Interface" #define USBD_INTERFACE_FS_STRING "MSC Interface"
#else #else
#define USBD_PID 0x5710 #if defined(USB_JOYSTICK)
#define USBD_PRODUCT_FS_STRING "FrSky Taranis Joystick" #define USBD_PID 0x5710
#define USBD_CONFIGURATION_FS_STRING "HID Config" #define USBD_PRODUCT_FS_STRING "FrSky Taranis Joystick"
#define USBD_INTERFACE_FS_STRING "HID Interface" #define USBD_CONFIGURATION_FS_STRING "HID Config"
#endif #define USBD_INTERFACE_FS_STRING "HID Interface"
#elif defined(USB_MASS_STORAGE)
USBD_DEVICE USR_desc = #define USBD_PID 0x5720
{ #define USBD_PRODUCT_FS_STRING "FrSky Taranis Mass Storage"
USBD_USR_DeviceDescriptor, #define USBD_CONFIGURATION_FS_STRING "MSC Config"
USBD_USR_LangIDStrDescriptor, #define USBD_INTERFACE_FS_STRING "MSC Interface"
USBD_USR_ManufacturerStrDescriptor, #endif
USBD_USR_ProductStrDescriptor, #endif
USBD_USR_SerialStrDescriptor,
USBD_USR_ConfigStrDescriptor, USBD_DEVICE USR_desc =
USBD_USR_InterfaceStrDescriptor, {
}; USBD_USR_DeviceDescriptor,
USBD_USR_LangIDStrDescriptor,
/* USB Standard Device Descriptor */ USBD_USR_ManufacturerStrDescriptor,
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END = USBD_USR_ProductStrDescriptor,
{ USBD_USR_SerialStrDescriptor,
0x12, /*bLength */ USBD_USR_ConfigStrDescriptor,
USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/ USBD_USR_InterfaceStrDescriptor,
0x00, /*bcdUSB */ };
0x02,
0x00, /*bDeviceClass*/ /* USB Standard Device Descriptor */
0x00, /*bDeviceSubClass*/ __ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END =
0x00, /*bDeviceProtocol*/ {
USB_OTG_MAX_EP0_SIZE, /*bMaxPacketSize*/ 0x12, /*bLength */
LOBYTE(USBD_VID), /*idVendor*/ USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
HIBYTE(USBD_VID), /*idVendor*/ 0x00, /*bcdUSB */
LOBYTE(USBD_PID), /*idVendor*/ 0x02,
HIBYTE(USBD_PID), /*idVendor*/ 0x00, /*bDeviceClass*/
0x00, /*bcdDevice rel. 2.00*/ 0x00, /*bDeviceSubClass*/
0x02, 0x00, /*bDeviceProtocol*/
USBD_IDX_MFC_STR, /*Index of manufacturer string*/ USB_OTG_MAX_EP0_SIZE, /*bMaxPacketSize*/
USBD_IDX_PRODUCT_STR, /*Index of product string*/ LOBYTE(USBD_VID), /*idVendor*/
USBD_IDX_SERIAL_STR, /*Index of serial number string*/ HIBYTE(USBD_VID), /*idVendor*/
USBD_CFG_MAX_NUM /*bNumConfigurations*/ LOBYTE(USBD_PID), /*idVendor*/
} ; /* USB_DeviceDescriptor */ HIBYTE(USBD_PID), /*idVendor*/
0x00, /*bcdDevice rel. 2.00*/
/* USB Standard Device Descriptor */ 0x02,
__ALIGN_BEGIN uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = USBD_IDX_MFC_STR, /*Index of manufacturer string*/
{ USBD_IDX_PRODUCT_STR, /*Index of product string*/
USB_LEN_DEV_QUALIFIER_DESC, USBD_IDX_SERIAL_STR, /*Index of serial number string*/
USB_DESC_TYPE_DEVICE_QUALIFIER, USBD_CFG_MAX_NUM /*bNumConfigurations*/
0x00, } ; /* USB_DeviceDescriptor */
0x02,
0x00, /* USB Standard Device Descriptor */
0x00, __ALIGN_BEGIN uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
0x00, {
0x40, USB_LEN_DEV_QUALIFIER_DESC,
0x01, USB_DESC_TYPE_DEVICE_QUALIFIER,
0x00, 0x00,
}; 0x02,
0x00,
/* USB Standard Device Descriptor */ 0x00,
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END = 0x00,
{ 0x40,
USB_SIZ_STRING_LANGID, 0x01,
USB_DESC_TYPE_STRING, 0x00,
LOBYTE(USBD_LANGID_STRING), };
HIBYTE(USBD_LANGID_STRING),
}; /* USB Standard Device Descriptor */
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END =
/* {
* @brief USBD_USR_DeviceDescriptor USB_SIZ_STRING_LANGID,
* return the device descriptor USB_DESC_TYPE_STRING,
* @param speed : current device speed LOBYTE(USBD_LANGID_STRING),
* @param length : pointer to data length variable HIBYTE(USBD_LANGID_STRING),
* @retval pointer to descriptor buffer };
*/
uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length) /*
{ * @brief USBD_USR_DeviceDescriptor
*length = sizeof(USBD_DeviceDesc); * return the device descriptor
return USBD_DeviceDesc; * @param speed : current device speed
} * @param length : pointer to data length variable
* @retval pointer to descriptor buffer
/** */
* @brief USBD_USR_LangIDStrDescriptor uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length)
* return the LangID string descriptor {
* @param speed : current device speed *length = sizeof(USBD_DeviceDesc);
* @param length : pointer to data length variable return USBD_DeviceDesc;
* @retval pointer to descriptor buffer }
*/
uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length) /**
{ * @brief USBD_USR_LangIDStrDescriptor
*length = sizeof(USBD_LangIDDesc); * return the LangID string descriptor
return USBD_LangIDDesc; * @param speed : current device speed
} * @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
/** uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length)
* @brief USBD_USR_ProductStrDescriptor {
* return the product string descriptor *length = sizeof(USBD_LangIDDesc);
* @param speed : current device speed return USBD_LangIDDesc;
* @param length : pointer to data length variable }
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length) /**
{ * @brief USBD_USR_ProductStrDescriptor
USBD_GetString ((uint8_t*)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length); * return the product string descriptor
return USBD_StrDesc; * @param speed : current device speed
} * @param length : pointer to data length variable
* @retval pointer to descriptor buffer
/** */
* @brief USBD_USR_ManufacturerStrDescriptor uint8_t * USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length)
* return the manufacturer string descriptor {
* @param speed : current device speed USBD_GetString ((uint8_t*)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
* @param length : pointer to data length variable return USBD_StrDesc;
* @retval pointer to descriptor buffer }
*/
uint8_t * USBD_USR_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length) /**
{ * @brief USBD_USR_ManufacturerStrDescriptor
USBD_GetString ((uint8_t*)USBD_MANUFACTURER_STRING, USBD_StrDesc, length); * return the manufacturer string descriptor
return USBD_StrDesc; * @param speed : current device speed
} * @param length : pointer to data length variable
* @retval pointer to descriptor buffer
/** */
* @brief USBD_USR_SerialStrDescriptor uint8_t * USBD_USR_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length)
* return the serial number string descriptor {
* @param speed : current device speed USBD_GetString ((uint8_t*)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
* @param length : pointer to data length variable return USBD_StrDesc;
* @retval pointer to descriptor buffer }
*/
uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length) /**
{ * @brief USBD_USR_SerialStrDescriptor
USBD_GetString ((uint8_t*)USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length); * return the serial number string descriptor
return USBD_StrDesc; * @param speed : current device speed
} * @param length : pointer to data length variable
* @retval pointer to descriptor buffer
/** */
* @brief USBD_USR_ConfigStrDescriptor uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length)
* return the configuration string descriptor {
* @param speed : current device speed USBD_GetString ((uint8_t*)USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length);
* @param length : pointer to data length variable return USBD_StrDesc;
* @retval pointer to descriptor buffer }
*/
uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length) /**
{ * @brief USBD_USR_ConfigStrDescriptor
USBD_GetString ((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length); * return the configuration string descriptor
return USBD_StrDesc; * @param speed : current device speed
} * @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
/** uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length)
* @brief USBD_USR_InterfaceStrDescriptor {
* return the interface string descriptor USBD_GetString ((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
* @param speed : current device speed return USBD_StrDesc;
* @param length : pointer to data length variable }
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length) /**
{ * @brief USBD_USR_InterfaceStrDescriptor
USBD_GetString ((uint8_t*)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length); * return the interface string descriptor
return USBD_StrDesc; * @param speed : current device speed
} * @param length : pointer to data length variable
* @retval pointer to descriptor buffer
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ */
uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length)
{
USBD_GetString ((uint8_t*)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -35,7 +35,12 @@ extern "C" {
#include "usbd_msc_mem.h" #include "usbd_msc_mem.h"
#include "usb_conf.h" #include "usb_conf.h"
#if defined(BOOT)
#define STORAGE_LUN_NBR 2 #define STORAGE_LUN_NBR 2
#else
/* SD card only when not running bootloader */
#define STORAGE_LUN_NBR 1
#endif
#define BLOCKSIZE 512 #define BLOCKSIZE 512
/* USB Mass storage Standard Inquiry Data */ /* USB Mass storage Standard Inquiry Data */
@ -54,6 +59,7 @@ const unsigned char STORAGE_Inquirydata[] = {//36
'T', 'a', 'r', 'a', 'n', 'i', 's', ' ', /* Product : 16 Bytes */ 'T', 'a', 'r', 'a', 'n', 'i', 's', ' ', /* Product : 16 Bytes */
'R', 'a', 'd', 'i', 'o', ' ', ' ', ' ', 'R', 'a', 'd', 'i', 'o', ' ', ' ', ' ',
'1', '.', '0', '0', /* Version : 4 Bytes */ '1', '.', '0', '0', /* Version : 4 Bytes */
#if defined(BOOT)
/* LUN 1 */ /* LUN 1 */
0x00, 0x00,
0x80, 0x80,
@ -67,10 +73,13 @@ const unsigned char STORAGE_Inquirydata[] = {//36
'T', 'a', 'r', 'a', 'n', 'i', 's', ' ', /* Product : 16 Bytes */ 'T', 'a', 'r', 'a', 'n', 'i', 's', ' ', /* Product : 16 Bytes */
'R', 'a', 'd', 'i', 'o', ' ', ' ', ' ', 'R', 'a', 'd', 'i', 'o', ' ', ' ', ' ',
'1', '.', '0' ,'0', /* Version : 4 Bytes */ '1', '.', '0' ,'0', /* Version : 4 Bytes */
#endif
}; };
#if defined(BOOT)
int32_t fat12Write( const uint8_t *buffer, uint16_t sector, uint32_t count ) ; int32_t fat12Write( const uint8_t *buffer, uint16_t sector, uint32_t count ) ;
int32_t fat12Read( uint8_t *buffer, uint16_t sector, uint16_t count ) ; int32_t fat12Read( uint8_t *buffer, uint16_t sector, uint16_t count ) ;
#endif
int8_t STORAGE_Init (uint8_t lun); int8_t STORAGE_Init (uint8_t lun);
@ -137,11 +146,14 @@ int8_t STORAGE_Init (uint8_t lun)
*/ */
int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_size) int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_size)
{ {
#if defined(BOOT)
if (lun == 1) { if (lun == 1) {
*block_size = BLOCKSIZE; *block_size = BLOCKSIZE;
*block_num = 3 + EESIZE/BLOCKSIZE + FLASHSIZE/BLOCKSIZE; *block_num = 3 + EESIZE/BLOCKSIZE + FLASHSIZE/BLOCKSIZE;
} }
else { else
#endif
{
if (!SD_CARD_PRESENT()) if (!SD_CARD_PRESENT())
return -1; return -1;
@ -161,17 +173,22 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_si
return 0; return 0;
} }
#if defined(BOOT)
uint8_t lunReady[2] ; uint8_t lunReady[2] ;
#else
uint8_t lunReady[1] ;
#endif
void usbPluggedIn() void usbPluggedIn()
{ {
if (lunReady[0] == 0) { if (lunReady[0] == 0) {
lunReady[0] = 1; lunReady[0] = 1;
} }
#if defined(BOOT)
if (lunReady[1] == 0) { if (lunReady[1] == 0) {
lunReady[1] = 1; lunReady[1] = 1;
} }
#endif
} }
/** /**
@ -181,13 +198,16 @@ void usbPluggedIn()
*/ */
int8_t STORAGE_IsReady (uint8_t lun) int8_t STORAGE_IsReady (uint8_t lun)
{ {
#if defined(BOOT)
if (lun == 1) { if (lun == 1) {
if (lunReady[1] == 0) { if (lunReady[1] == 0) {
return -1 ; return -1 ;
} }
return 0 ; return 0 ;
} }
else { else
#endif
{
if (lunReady[0] == 0) { if (lunReady[0] == 0) {
return -1 ; return -1 ;
} }
@ -221,11 +241,14 @@ int8_t STORAGE_Read (uint8_t lun,
uint32_t blk_addr, uint32_t blk_addr,
uint16_t blk_len) uint16_t blk_len)
{ {
#if defined(BOOT)
if (lun == 1) { if (lun == 1) {
if (fat12Read(buf, blk_addr, blk_len) != 0) if (fat12Read(buf, blk_addr, blk_len) != 0)
return -1; return -1;
} }
else { else
#endif
{
if (SD_ReadSectors(buf, blk_addr, blk_len) != 0) { if (SD_ReadSectors(buf, blk_addr, blk_len) != 0) {
return -1; return -1;
} }
@ -249,11 +272,14 @@ int8_t STORAGE_Write (uint8_t lun,
uint32_t blk_addr, uint32_t blk_addr,
uint16_t blk_len) uint16_t blk_len)
{ {
#if defined(BOOT)
if (lun == 1) { if (lun == 1) {
if (fat12Write(buf, blk_addr, blk_len) != 0) if (fat12Write(buf, blk_addr, blk_len) != 0)
return -1; return -1;
} }
else { else
#endif
{
if (SD_WriteSectors(buf, blk_addr, blk_len) != 0) if (SD_WriteSectors(buf, blk_addr, blk_len) != 0)
return -1; return -1;
} }
@ -269,10 +295,10 @@ int8_t STORAGE_Write (uint8_t lun,
int8_t STORAGE_GetMaxLun (void) int8_t STORAGE_GetMaxLun (void)
{ {
return (STORAGE_LUN_NBR - 1); return STORAGE_LUN_NBR - 1;
} }
#if defined(BOOT)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/** /**
* FAT12 boot sector partition. * FAT12 boot sector partition.
@ -766,5 +792,5 @@ int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint32_t count )
} }
return 0 ; return 0 ;
} }
#endif
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View file

@ -1,125 +1,128 @@
/** /**
****************************************************************************** ******************************************************************************
* @file usbd_usr.c * @file usbd_usr.c
* @author MCD Application Team * @author MCD Application Team
* @version V1.1.0 * @version V1.1.0
* @date 19-March-2012 * @date 19-March-2012
* @brief This file includes the user application layer * @brief This file includes the user application layer
****************************************************************************** ******************************************************************************
* @attention * @attention
* *
* <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2> * <h2><center>&copy; COPYRIGHT 2012 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.
* You may obtain a copy of the License at: * You may obtain a copy of the License at:
* *
* http://www.st.com/software_license_agreement_liberty_v2 * http://www.st.com/software_license_agreement_liberty_v2
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
****************************************************************************** ******************************************************************************
*/ */
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "../../opentx.h" #include "../../opentx.h"
extern "C" { extern "C" {
#include "usbd_usr.h" #include "usbd_usr.h"
/* Points to the DEVICE_PROP structure of current device */ /* Points to the DEVICE_PROP structure of current device */
/* The purpose of this register is to speed up the execution */ /* The purpose of this register is to speed up the execution */
USBD_Usr_cb_TypeDef USR_cb = USBD_Usr_cb_TypeDef USR_cb =
{ {
USBD_USR_Init, USBD_USR_Init,
USBD_USR_DeviceReset, USBD_USR_DeviceReset,
USBD_USR_DeviceConfigured, USBD_USR_DeviceConfigured,
USBD_USR_DeviceSuspended, USBD_USR_DeviceSuspended,
USBD_USR_DeviceResumed, USBD_USR_DeviceResumed,
USBD_USR_DeviceConnected, USBD_USR_DeviceConnected,
USBD_USR_DeviceDisconnected, USBD_USR_DeviceDisconnected,
}; };
} }
/** /**
* @brief Whatever the user application needs to do when USB is initialised * @brief Whatever the user application needs to do when USB is initialised
* @param None * @param None
* @retval None * @retval None
*/ */
void USBD_USR_Init(void) void USBD_USR_Init(void)
{ {
} }
/** /**
* @brief Displays the message on LCD on device reset event * @brief Displays the message on LCD on device reset event
* @param speed : device speed * @param speed : device speed
* @retval None * @retval None
*/ */
void USBD_USR_DeviceReset (uint8_t speed) void USBD_USR_DeviceReset (uint8_t speed)
{ {
} }
/** /**
* @brief Displays the message on LCD on device config event * @brief Displays the message on LCD on device config event
* @param None * @param None
* @retval Staus * @retval Staus
*/ */
void USBD_USR_DeviceConfigured (void) void USBD_USR_DeviceConfigured (void)
{ {
} }
/** /**
* @brief Displays the message on LCD on device suspend event * @brief Displays the message on LCD on device suspend event
* @param None * @param None
* @retval None * @retval None
*/ */
void USBD_USR_DeviceSuspended(void) void USBD_USR_DeviceSuspended(void)
{ {
} }
/** /**
* @brief Displays the message on LCD on device resume event * @brief Displays the message on LCD on device resume event
* @param None * @param None
* @retval None * @retval None
*/ */
void USBD_USR_DeviceResumed(void) void USBD_USR_DeviceResumed(void)
{ {
} }
/** /**
* @brief USBD_USR_DeviceConnected * @brief USBD_USR_DeviceConnected
* Displays the message on LCD on device connection Event * Displays the message on LCD on device connection Event
* @param None * @param None
* @retval Staus * @retval Staus
*/ */
void USBD_USR_DeviceConnected (void) void USBD_USR_DeviceConnected (void)
{ {
} }
/** /**
* @brief USBD_USR_DeviceDisonnected * @brief USBD_USR_DeviceDisonnected
* Displays the message on LCD on device disconnection Event * Displays the message on LCD on device disconnection Event
* @param None * @param None
* @retval Staus * @retval Staus
*/ */
void USBD_USR_DeviceDisconnected (void) void USBD_USR_DeviceDisconnected (void)
{ {
} #if !defined(BOOT) && defined(USB_MASS_STORAGE)
NVIC_SystemReset();
#endif
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ }
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/