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-19 16:57:17 +12:00
parent b83f95ed1a
commit 07b4be8f45
9 changed files with 3955 additions and 3865 deletions
+18 -1
View File
@@ -272,6 +272,12 @@ LUA = NO
# Values = NO, READONLY, NOMENUS
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 ---------------------------
# 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_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/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_dcd.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
EXTRABOARDSRC += targets/taranis/usbd_usr.cpp
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)
ifeq ($(LUA), YES)
+3503 -3485
View File
File diff suppressed because it is too large Load Diff
+4
View File
@@ -1699,4 +1699,8 @@ void varioWakeup();
extern const pm_uchar logo_taranis[];
#endif
#if defined(USB_MASS_STORAGE)
extern void usbPluggedIn();
#endif
#endif
@@ -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_RequestSense (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_ModeSense10 (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);
case SCSI_ALLOW_MEDIUM_REMOVAL:
return SCSI_AllowRemoval( lun, params);
return SCSI_AllowRemoval( lun, params);
case SCSI_MODE_SENSE6:
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
* @retval status
*/
extern uint8_t lunReady[] ;
extern uint8_t lunReady[] ;
static int8_t SCSI_StartStopUnit(uint8_t lun, uint8_t *params)
{
MSC_BOT_DataLen = 0;
if (lun < 2) {
if (params[4] & 1) {
// lun to be active
lunReady[lun] = 1 ;
}
else {
// lun to be ejected
lunReady[lun] = 0 ;
}
}
#if defined(BOOT)
if (lun < 2)
#else
if (lun < 1)
#endif
{
if (params[4] & 1) {
// lun to be active
lunReady[lun] = 1 ;
}
else {
// lun to be ejected
lunReady[lun] = 0 ;
}
}
return 0;
}
@@ -224,7 +224,9 @@ void turnBacklightOff(void);
int usbPlugged(void);
void usbInit(void);
void usbStart(void);
#if defined(USB_JOYSTICK)
void usbStop(void);
#endif
#ifdef __cplusplus
}
+9 -1
View File
@@ -43,6 +43,7 @@ int usbPlugged(void)
//debounce
static uint8_t debounced_state = 0;
static uint8_t last_state = 0;
if ( GPIO_ReadInputDataBit(GPIOA, PIN_FS_VBUS) ) {
if (last_state) debounced_state = 1;
last_state = 1;
@@ -69,16 +70,23 @@ void usbInit(void)
void usbStart(void)
{
#if !defined(BOOT)
#if defined(USB_JOYSTICK)
//intialize USB as HID device
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
//intialize USB as MSC device
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_MSC_cb, &USR_cb);
#endif //!defined(BOOT)
}
#if defined(USB_JOYSTICK)
void usbStop(void)
{
USBD_DeInit(&USB_OTG_dev);
}
#endif
+236 -229
View File
@@ -1,229 +1,236 @@
/**
******************************************************************************
* @file usbd_desc.c
* @author MCD Application Team
* @version V1.1.0
* @date 19-March-2012
* @brief This file provides the USBD descriptors and string formating method.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2012 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_core.h"
#include "usbd_desc.h"
#include "usbd_req.h"
#include "usbd_conf.h"
#include "usb_regs.h"
#include "board_taranis.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_DESC
* @brief USBD descriptors module
* @{
*/
/** @defgroup USBD_DESC_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBD_DESC_Private_Defines
* @{
*/
#define USBD_VID 0x0483
#define USBD_LANGID_STRING 0x409
#define USBD_MANUFACTURER_STRING "FrSky"
#define USBD_SERIALNUMBER_FS_STRING "00000000001B"
#if defined(BOOT)
#define USBD_PID 0x5720
#define USBD_PRODUCT_FS_STRING "FrSky Taranis Bootloader"
#define USBD_CONFIGURATION_FS_STRING "MSC Config"
#define USBD_INTERFACE_FS_STRING "MSC Interface"
#else
#define USBD_PID 0x5710
#define USBD_PRODUCT_FS_STRING "FrSky Taranis Joystick"
#define USBD_CONFIGURATION_FS_STRING "HID Config"
#define USBD_INTERFACE_FS_STRING "HID Interface"
#endif
USBD_DEVICE USR_desc =
{
USBD_USR_DeviceDescriptor,
USBD_USR_LangIDStrDescriptor,
USBD_USR_ManufacturerStrDescriptor,
USBD_USR_ProductStrDescriptor,
USBD_USR_SerialStrDescriptor,
USBD_USR_ConfigStrDescriptor,
USBD_USR_InterfaceStrDescriptor,
};
/* USB Standard Device Descriptor */
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END =
{
0x12, /*bLength */
USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
0x00, /*bcdUSB */
0x02,
0x00, /*bDeviceClass*/
0x00, /*bDeviceSubClass*/
0x00, /*bDeviceProtocol*/
USB_OTG_MAX_EP0_SIZE, /*bMaxPacketSize*/
LOBYTE(USBD_VID), /*idVendor*/
HIBYTE(USBD_VID), /*idVendor*/
LOBYTE(USBD_PID), /*idVendor*/
HIBYTE(USBD_PID), /*idVendor*/
0x00, /*bcdDevice rel. 2.00*/
0x02,
USBD_IDX_MFC_STR, /*Index of manufacturer string*/
USBD_IDX_PRODUCT_STR, /*Index of product string*/
USBD_IDX_SERIAL_STR, /*Index of serial number string*/
USBD_CFG_MAX_NUM /*bNumConfigurations*/
} ; /* USB_DeviceDescriptor */
/* USB Standard Device Descriptor */
__ALIGN_BEGIN uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
{
USB_LEN_DEV_QUALIFIER_DESC,
USB_DESC_TYPE_DEVICE_QUALIFIER,
0x00,
0x02,
0x00,
0x00,
0x00,
0x40,
0x01,
0x00,
};
/* USB Standard Device Descriptor */
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END =
{
USB_SIZ_STRING_LANGID,
USB_DESC_TYPE_STRING,
LOBYTE(USBD_LANGID_STRING),
HIBYTE(USBD_LANGID_STRING),
};
/*
* @brief USBD_USR_DeviceDescriptor
* return the device descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length)
{
*length = sizeof(USBD_DeviceDesc);
return USBD_DeviceDesc;
}
/**
* @brief USBD_USR_LangIDStrDescriptor
* return the LangID string descriptor
* @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)
{
*length = sizeof(USBD_LangIDDesc);
return USBD_LangIDDesc;
}
/**
* @brief USBD_USR_ProductStrDescriptor
* return the product string descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length)
{
USBD_GetString ((uint8_t*)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
}
/**
* @brief USBD_USR_ManufacturerStrDescriptor
* return the manufacturer string descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length)
{
USBD_GetString ((uint8_t*)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
}
/**
* @brief USBD_USR_SerialStrDescriptor
* return the serial number string descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length)
{
USBD_GetString ((uint8_t*)USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
}
/**
* @brief USBD_USR_ConfigStrDescriptor
* return the configuration string descriptor
* @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)
{
USBD_GetString ((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
}
/**
* @brief USBD_USR_InterfaceStrDescriptor
* return the interface string descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
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****/
/**
******************************************************************************
* @file usbd_desc.c
* @author MCD Application Team
* @version V1.1.0
* @date 19-March-2012
* @brief This file provides the USBD descriptors and string formating method.
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2012 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_core.h"
#include "usbd_desc.h"
#include "usbd_req.h"
#include "usbd_conf.h"
#include "usb_regs.h"
#include "board_taranis.h"
/** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
* @{
*/
/** @defgroup USBD_DESC
* @brief USBD descriptors module
* @{
*/
/** @defgroup USBD_DESC_Private_TypesDefinitions
* @{
*/
/**
* @}
*/
/** @defgroup USBD_DESC_Private_Defines
* @{
*/
#define USBD_VID 0x0483
#define USBD_LANGID_STRING 0x409
#define USBD_MANUFACTURER_STRING "FrSky"
#define USBD_SERIALNUMBER_FS_STRING "00000000001B"
#if defined(BOOT)
#define USBD_PID 0x5720
#define USBD_PRODUCT_FS_STRING "FrSky Taranis Bootloader"
#define USBD_CONFIGURATION_FS_STRING "MSC Config"
#define USBD_INTERFACE_FS_STRING "MSC Interface"
#else
#if defined(USB_JOYSTICK)
#define USBD_PID 0x5710
#define USBD_PRODUCT_FS_STRING "FrSky Taranis Joystick"
#define USBD_CONFIGURATION_FS_STRING "HID Config"
#define USBD_INTERFACE_FS_STRING "HID Interface"
#elif defined(USB_MASS_STORAGE)
#define USBD_PID 0x5720
#define USBD_PRODUCT_FS_STRING "FrSky Taranis Mass Storage"
#define USBD_CONFIGURATION_FS_STRING "MSC Config"
#define USBD_INTERFACE_FS_STRING "MSC Interface"
#endif
#endif
USBD_DEVICE USR_desc =
{
USBD_USR_DeviceDescriptor,
USBD_USR_LangIDStrDescriptor,
USBD_USR_ManufacturerStrDescriptor,
USBD_USR_ProductStrDescriptor,
USBD_USR_SerialStrDescriptor,
USBD_USR_ConfigStrDescriptor,
USBD_USR_InterfaceStrDescriptor,
};
/* USB Standard Device Descriptor */
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_SIZ_DEVICE_DESC] __ALIGN_END =
{
0x12, /*bLength */
USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
0x00, /*bcdUSB */
0x02,
0x00, /*bDeviceClass*/
0x00, /*bDeviceSubClass*/
0x00, /*bDeviceProtocol*/
USB_OTG_MAX_EP0_SIZE, /*bMaxPacketSize*/
LOBYTE(USBD_VID), /*idVendor*/
HIBYTE(USBD_VID), /*idVendor*/
LOBYTE(USBD_PID), /*idVendor*/
HIBYTE(USBD_PID), /*idVendor*/
0x00, /*bcdDevice rel. 2.00*/
0x02,
USBD_IDX_MFC_STR, /*Index of manufacturer string*/
USBD_IDX_PRODUCT_STR, /*Index of product string*/
USBD_IDX_SERIAL_STR, /*Index of serial number string*/
USBD_CFG_MAX_NUM /*bNumConfigurations*/
} ; /* USB_DeviceDescriptor */
/* USB Standard Device Descriptor */
__ALIGN_BEGIN uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
{
USB_LEN_DEV_QUALIFIER_DESC,
USB_DESC_TYPE_DEVICE_QUALIFIER,
0x00,
0x02,
0x00,
0x00,
0x00,
0x40,
0x01,
0x00,
};
/* USB Standard Device Descriptor */
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID] __ALIGN_END =
{
USB_SIZ_STRING_LANGID,
USB_DESC_TYPE_STRING,
LOBYTE(USBD_LANGID_STRING),
HIBYTE(USBD_LANGID_STRING),
};
/*
* @brief USBD_USR_DeviceDescriptor
* return the device descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length)
{
*length = sizeof(USBD_DeviceDesc);
return USBD_DeviceDesc;
}
/**
* @brief USBD_USR_LangIDStrDescriptor
* return the LangID string descriptor
* @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)
{
*length = sizeof(USBD_LangIDDesc);
return USBD_LangIDDesc;
}
/**
* @brief USBD_USR_ProductStrDescriptor
* return the product string descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_ProductStrDescriptor( uint8_t speed , uint16_t *length)
{
USBD_GetString ((uint8_t*)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
}
/**
* @brief USBD_USR_ManufacturerStrDescriptor
* return the manufacturer string descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_ManufacturerStrDescriptor( uint8_t speed , uint16_t *length)
{
USBD_GetString ((uint8_t*)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
}
/**
* @brief USBD_USR_SerialStrDescriptor
* return the serial number string descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length)
{
USBD_GetString ((uint8_t*)USBD_SERIALNUMBER_FS_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
}
/**
* @brief USBD_USR_ConfigStrDescriptor
* return the configuration string descriptor
* @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)
{
USBD_GetString ((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
return USBD_StrDesc;
}
/**
* @brief USBD_USR_InterfaceStrDescriptor
* return the interface string descriptor
* @param speed : current device speed
* @param length : pointer to data length variable
* @retval pointer to descriptor buffer
*/
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****/
+34 -8
View File
@@ -35,7 +35,12 @@ extern "C" {
#include "usbd_msc_mem.h"
#include "usb_conf.h"
#if defined(BOOT)
#define STORAGE_LUN_NBR 2
#else
/* SD card only when not running bootloader */
#define STORAGE_LUN_NBR 1
#endif
#define BLOCKSIZE 512
/* 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 */
'R', 'a', 'd', 'i', 'o', ' ', ' ', ' ',
'1', '.', '0', '0', /* Version : 4 Bytes */
#if defined(BOOT)
/* LUN 1 */
0x00,
0x80,
@@ -67,10 +73,13 @@ const unsigned char STORAGE_Inquirydata[] = {//36
'T', 'a', 'r', 'a', 'n', 'i', 's', ' ', /* Product : 16 Bytes */
'R', 'a', 'd', 'i', 'o', ' ', ' ', ' ',
'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 fat12Read( uint8_t *buffer, uint16_t sector, uint16_t count ) ;
#endif
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)
{
#if defined(BOOT)
if (lun == 1) {
*block_size = BLOCKSIZE;
*block_num = 3 + EESIZE/BLOCKSIZE + FLASHSIZE/BLOCKSIZE;
}
else {
else
#endif
{
if (!SD_CARD_PRESENT())
return -1;
@@ -161,17 +173,22 @@ int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_si
return 0;
}
#if defined(BOOT)
uint8_t lunReady[2] ;
#else
uint8_t lunReady[1] ;
#endif
void usbPluggedIn()
{
if (lunReady[0] == 0) {
lunReady[0] = 1;
}
#if defined(BOOT)
if (lunReady[1] == 0) {
lunReady[1] = 1;
}
#endif
}
/**
@@ -181,13 +198,16 @@ void usbPluggedIn()
*/
int8_t STORAGE_IsReady (uint8_t lun)
{
#if defined(BOOT)
if (lun == 1) {
if (lunReady[1] == 0) {
return -1 ;
}
return 0 ;
}
else {
else
#endif
{
if (lunReady[0] == 0) {
return -1 ;
}
@@ -221,11 +241,14 @@ int8_t STORAGE_Read (uint8_t lun,
uint32_t blk_addr,
uint16_t blk_len)
{
#if defined(BOOT)
if (lun == 1) {
if (fat12Read(buf, blk_addr, blk_len) != 0)
return -1;
}
else {
else
#endif
{
if (SD_ReadSectors(buf, blk_addr, blk_len) != 0) {
return -1;
}
@@ -249,11 +272,14 @@ int8_t STORAGE_Write (uint8_t lun,
uint32_t blk_addr,
uint16_t blk_len)
{
#if defined(BOOT)
if (lun == 1) {
if (fat12Write(buf, blk_addr, blk_len) != 0)
return -1;
}
else {
else
#endif
{
if (SD_WriteSectors(buf, blk_addr, blk_len) != 0)
return -1;
}
@@ -269,10 +295,10 @@ int8_t STORAGE_Write (uint8_t lun,
int8_t STORAGE_GetMaxLun (void)
{
return (STORAGE_LUN_NBR - 1);
return STORAGE_LUN_NBR - 1;
}
#if defined(BOOT)
//------------------------------------------------------------------------------
/**
* FAT12 boot sector partition.
@@ -766,5 +792,5 @@ int32_t fat12Write(const uint8_t *buffer, uint16_t sector, uint32_t count )
}
return 0 ;
}
#endif
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+128 -125
View File
@@ -1,125 +1,128 @@
/**
******************************************************************************
* @file usbd_usr.c
* @author MCD Application Team
* @version V1.1.0
* @date 19-March-2012
* @brief This file includes the user application layer
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2012 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 "../../opentx.h"
extern "C" {
#include "usbd_usr.h"
/* Points to the DEVICE_PROP structure of current device */
/* The purpose of this register is to speed up the execution */
USBD_Usr_cb_TypeDef USR_cb =
{
USBD_USR_Init,
USBD_USR_DeviceReset,
USBD_USR_DeviceConfigured,
USBD_USR_DeviceSuspended,
USBD_USR_DeviceResumed,
USBD_USR_DeviceConnected,
USBD_USR_DeviceDisconnected,
};
}
/**
* @brief Whatever the user application needs to do when USB is initialised
* @param None
* @retval None
*/
void USBD_USR_Init(void)
{
}
/**
* @brief Displays the message on LCD on device reset event
* @param speed : device speed
* @retval None
*/
void USBD_USR_DeviceReset (uint8_t speed)
{
}
/**
* @brief Displays the message on LCD on device config event
* @param None
* @retval Staus
*/
void USBD_USR_DeviceConfigured (void)
{
}
/**
* @brief Displays the message on LCD on device suspend event
* @param None
* @retval None
*/
void USBD_USR_DeviceSuspended(void)
{
}
/**
* @brief Displays the message on LCD on device resume event
* @param None
* @retval None
*/
void USBD_USR_DeviceResumed(void)
{
}
/**
* @brief USBD_USR_DeviceConnected
* Displays the message on LCD on device connection Event
* @param None
* @retval Staus
*/
void USBD_USR_DeviceConnected (void)
{
}
/**
* @brief USBD_USR_DeviceDisonnected
* Displays the message on LCD on device disconnection Event
* @param None
* @retval Staus
*/
void USBD_USR_DeviceDisconnected (void)
{
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
/**
******************************************************************************
* @file usbd_usr.c
* @author MCD Application Team
* @version V1.1.0
* @date 19-March-2012
* @brief This file includes the user application layer
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2012 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 "../../opentx.h"
extern "C" {
#include "usbd_usr.h"
/* Points to the DEVICE_PROP structure of current device */
/* The purpose of this register is to speed up the execution */
USBD_Usr_cb_TypeDef USR_cb =
{
USBD_USR_Init,
USBD_USR_DeviceReset,
USBD_USR_DeviceConfigured,
USBD_USR_DeviceSuspended,
USBD_USR_DeviceResumed,
USBD_USR_DeviceConnected,
USBD_USR_DeviceDisconnected,
};
}
/**
* @brief Whatever the user application needs to do when USB is initialised
* @param None
* @retval None
*/
void USBD_USR_Init(void)
{
}
/**
* @brief Displays the message on LCD on device reset event
* @param speed : device speed
* @retval None
*/
void USBD_USR_DeviceReset (uint8_t speed)
{
}
/**
* @brief Displays the message on LCD on device config event
* @param None
* @retval Staus
*/
void USBD_USR_DeviceConfigured (void)
{
}
/**
* @brief Displays the message on LCD on device suspend event
* @param None
* @retval None
*/
void USBD_USR_DeviceSuspended(void)
{
}
/**
* @brief Displays the message on LCD on device resume event
* @param None
* @retval None
*/
void USBD_USR_DeviceResumed(void)
{
}
/**
* @brief USBD_USR_DeviceConnected
* Displays the message on LCD on device connection Event
* @param None
* @retval Staus
*/
void USBD_USR_DeviceConnected (void)
{
}
/**
* @brief USBD_USR_DeviceDisonnected
* Displays the message on LCD on device disconnection Event
* @param None
* @retval Staus
*/
void USBD_USR_DeviceDisconnected (void)
{
#if !defined(BOOT) && defined(USB_MASS_STORAGE)
NVIC_SystemReset();
#endif
}
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/