mirror of
https://github.com/opentx/opentx.git
synced 2025-07-20 14:55:13 +03:00
Merge pull request #1298 from ChrisNisbet01/mass_storage_in_firmware
CN - Adds support for a mass storage USB device in the main firmware.
This commit is contained in:
commit
a191543ee3
9 changed files with 132 additions and 42 deletions
|
@ -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)
|
||||
|
|
|
@ -2492,7 +2492,7 @@ void opentxClose()
|
|||
#endif
|
||||
|
||||
|
||||
#if defined(PCBTARANIS) && !defined(SIMU)
|
||||
#if defined(USB_JOYSTICK) && defined(PCBTARANIS) && !defined(SIMU)
|
||||
extern USB_OTG_CORE_HANDLE USB_OTG_dev;
|
||||
|
||||
/*
|
||||
|
@ -2526,7 +2526,7 @@ void usbJoystickUpdate(void)
|
|||
USBD_HID_SendReport (&USB_OTG_dev, HID_Buffer, HID_IN_PACKET );
|
||||
}
|
||||
|
||||
#endif //#if defined(PCBTARANIS) && !defined(SIMU)
|
||||
#endif //#if defined(USB_JOYSTICK) && defined(PCBTARANIS) && !defined(SIMU)
|
||||
|
||||
|
||||
void perMain()
|
||||
|
@ -2683,10 +2683,17 @@ void perMain()
|
|||
#if defined(PCBTARANIS) && !defined(SIMU)
|
||||
static bool usbStarted = false;
|
||||
if (!usbStarted && usbPlugged()) {
|
||||
#if defined(USB_MASS_STORAGE)
|
||||
opentxClose();
|
||||
#endif
|
||||
usbStart();
|
||||
#if defined(USB_MASS_STORAGE)
|
||||
usbPluggedIn();
|
||||
#endif
|
||||
usbStarted = true;
|
||||
}
|
||||
|
||||
#if defined(USB_JOYTICK)
|
||||
if (usbStarted) {
|
||||
if (!usbPlugged()) {
|
||||
//disable USB
|
||||
|
@ -2697,6 +2704,8 @@ void perMain()
|
|||
usbJoystickUpdate();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //#if defined(PCBTARANIS) && !defined(SIMU)
|
||||
|
||||
#if defined(NAVIGATION_STICKS)
|
||||
|
@ -2763,6 +2772,14 @@ void perMain()
|
|||
StickScrollAllowed = 1 ;
|
||||
#endif
|
||||
|
||||
#if defined(USB_MASS_STORAGE)
|
||||
if (usbPlugged()) {
|
||||
lcd_clear();
|
||||
menuMainView(0);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
const char *warn = s_warning;
|
||||
uint8_t menu = s_menu_count;
|
||||
|
||||
|
@ -2787,6 +2804,7 @@ void perMain()
|
|||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
drawStatusLine();
|
||||
lcdRefresh();
|
||||
|
|
|
@ -1700,4 +1700,8 @@ void varioWakeup();
|
|||
extern const pm_uchar logo_taranis[];
|
||||
#endif
|
||||
|
||||
#if defined(USB_MASS_STORAGE)
|
||||
extern void usbPluggedIn();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -440,7 +440,12 @@ static int8_t SCSI_StartStopUnit(uint8_t lun, uint8_t *params)
|
|||
{
|
||||
MSC_BOT_DataLen = 0;
|
||||
|
||||
if (lun < 2) {
|
||||
#if defined(BOOT)
|
||||
if (lun < 2)
|
||||
#else
|
||||
if (lun < 1)
|
||||
#endif
|
||||
{
|
||||
if (params[4] & 1) {
|
||||
// lun to be active
|
||||
lunReady[lun] = 1 ;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -68,10 +68,17 @@
|
|||
#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 =
|
||||
|
|
|
@ -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****/
|
||||
|
|
|
@ -119,6 +119,9 @@ void USBD_USR_DeviceConnected (void)
|
|||
*/
|
||||
void USBD_USR_DeviceDisconnected (void)
|
||||
{
|
||||
#if !defined(BOOT) && defined(USB_MASS_STORAGE)
|
||||
NVIC_SystemReset();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue