Merge pull request #2496 from betaflight/fix-usb-disconnect

Fix usb disconnect (f1/f3/f4/f7)
This commit is contained in:
Martin Budden 2017-02-26 14:25:26 +00:00 committed by GitHub
commit a51e91d24d
21 changed files with 20 additions and 132 deletions

View File

@ -786,13 +786,15 @@ VCP_SRC = \
vcpf4/usbd_desc.c \ vcpf4/usbd_desc.c \
vcpf4/usbd_usr.c \ vcpf4/usbd_usr.c \
vcpf4/usbd_cdc_vcp.c \ vcpf4/usbd_cdc_vcp.c \
drivers/serial_usb_vcp.c drivers/serial_usb_vcp.c \
drivers/usb_io.c
else ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS))) else ifeq ($(TARGET),$(filter $(TARGET),$(F7_TARGETS)))
VCP_SRC = \ VCP_SRC = \
vcp_hal/usbd_desc.c \ vcp_hal/usbd_desc.c \
vcp_hal/usbd_conf.c \ vcp_hal/usbd_conf.c \
vcp_hal/usbd_cdc_interface.c \ vcp_hal/usbd_cdc_interface.c \
drivers/serial_usb_vcp.c drivers/serial_usb_vcp.c \
drivers/usb_io.c
else else
VCP_SRC = \ VCP_SRC = \
vcp/hw_config.c \ vcp/hw_config.c \

View File

@ -28,8 +28,10 @@
#if defined(STM32F4) #if defined(STM32F4)
#include "usb_core.h" #include "usb_core.h"
#include "usbd_cdc_vcp.h" #include "usbd_cdc_vcp.h"
#include "usb_io.h"
#elif defined(STM32F7) #elif defined(STM32F7)
#include "vcp_hal/usbd_cdc_interface.h" #include "vcp_hal/usbd_cdc_interface.h"
#include "usb_io.h"
USBD_HandleTypeDef USBD_Device; USBD_HandleTypeDef USBD_Device;
#else #else
#include "usb_core.h" #include "usb_core.h"
@ -184,10 +186,14 @@ serialPort_t *usbVcpOpen(void)
vcpPort_t *s; vcpPort_t *s;
#if defined(STM32F4) #if defined(STM32F4)
usbGenerateDisconnectPulse();
IOInit(IOGetByTag(IO_TAG(PA11)), OWNER_USB, 0); IOInit(IOGetByTag(IO_TAG(PA11)), OWNER_USB, 0);
IOInit(IOGetByTag(IO_TAG(PA12)), OWNER_USB, 0); IOInit(IOGetByTag(IO_TAG(PA12)), OWNER_USB, 0);
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb); USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb);
#elif defined(STM32F7) #elif defined(STM32F7)
usbGenerateDisconnectPulse();
IOInit(IOGetByTag(IO_TAG(PA11)), OWNER_USB, 0); IOInit(IOGetByTag(IO_TAG(PA11)), OWNER_USB, 0);
IOInit(IOGetByTag(IO_TAG(PA12)), OWNER_USB, 0); IOInit(IOGetByTag(IO_TAG(PA12)), OWNER_USB, 0);
/* Init Device Library */ /* Init Device Library */

View File

@ -1,55 +0,0 @@
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight 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.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdint.h>
#include "platform.h"
#include "io.h"
#include "system.h"
static IO_t usbDetectPin = IO_NONE;
void usbCableDetectDeinit(void)
{
#ifdef USB_DETECT_PIN
IOInit(usbDetectPin, OWNER_FREE, 0);
IOConfigGPIO(usbDetectPin, IOCFG_IN_FLOATING);
usbDetectPin = IO_NONE;
#endif
}
void usbCableDetectInit(void)
{
#ifdef USB_DETECT_PIN
usbDetectPin = IOGetByTag(IO_TAG(USB_DETECT_PIN));
IOInit(usbDetectPin, OWNER_USB_DETECT, 0);
IOConfigGPIO(usbDetectPin, IOCFG_OUT_PP);
#endif
}
bool usbCableIsInserted(void)
{
bool result = false;
#ifdef USB_DETECT_PIN
result = IORead(usbDetectPin) != 0;
#endif
return result;
}

View File

@ -1,22 +0,0 @@
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight 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.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
void usbCableDetectDeinit(void);
void usbCableDetectInit(void);
bool usbCableIsInserted(void);

View File

@ -20,7 +20,7 @@
#include "platform.h" #include "platform.h"
#ifdef USB_IO #ifdef USE_VCP
#include "io.h" #include "io.h"
#include "system.h" #include "system.h"
@ -28,7 +28,6 @@
#include "sdcard.h" #include "sdcard.h"
#ifdef USB_DETECT_PIN #ifdef USB_DETECT_PIN
static IO_t usbDetectPin = IO_NONE; static IO_t usbDetectPin = IO_NONE;
#endif #endif
@ -75,5 +74,4 @@ void usbGenerateDisconnectPulse(void)
IOLo(usbPin); IOLo(usbPin);
} }
#endif #endif

View File

@ -488,7 +488,7 @@ void init(void)
} }
#endif #endif
#ifdef USB_CABLE_DETECTION #ifdef USB_DETECT_PIN
usbCableDetectInit(); usbCableDetectInit();
#endif #endif

View File

@ -49,8 +49,6 @@
#define REMAP_TIM16_DMA #define REMAP_TIM16_DMA
#define REMAP_TIM17_DMA #define REMAP_TIM17_DMA
#define USB_IO
#define USE_VCP #define USE_VCP
#define USE_UART1 #define USE_UART1
#define USE_UART2 #define USE_UART2

View File

@ -75,8 +75,6 @@
#define USE_MAG_AK8963 #define USE_MAG_AK8963
#define USE_MAG_AK8975 #define USE_MAG_AK8975
#define USB_IO
#define USE_VCP #define USE_VCP
#define USE_UART1 #define USE_UART1
#define USE_UART2 #define USE_UART2

View File

@ -91,7 +91,6 @@
#define USE_BARO_BMP280 #define USE_BARO_BMP280
#define USE_BARO_SPI_BMP280 #define USE_BARO_SPI_BMP280
#define USB_IO
#define USE_VCP #define USE_VCP
#define USE_UART1 #define USE_UART1
#define USE_UART2 #define USE_UART2

View File

@ -108,8 +108,6 @@
// Performance logging for SD card operations: // Performance logging for SD card operations:
// #define AFATFS_USE_INTROSPECTIVE_LOGGING // #define AFATFS_USE_INTROSPECTIVE_LOGGING
#define USB_IO
#define USE_VCP #define USE_VCP
#define USE_UART1 #define USE_UART1
#define USE_UART2 #define USE_UART2

View File

@ -27,8 +27,6 @@
#define USABLE_TIMER_CHANNEL_COUNT 8 #define USABLE_TIMER_CHANNEL_COUNT 8
#define USB_IO
#define USE_EXTI #define USE_EXTI
#define MPU_INT_EXTI PC13 #define MPU_INT_EXTI PC13
#define EXTI15_10_CALLBACK_HANDLER_COUNT 1 #define EXTI15_10_CALLBACK_HANDLER_COUNT 1

View File

@ -113,8 +113,6 @@
#define ACC_MPU6500_ALIGN CW270_DEG #define ACC_MPU6500_ALIGN CW270_DEG
#endif #endif
#define USB_IO
#define USE_VCP #define USE_VCP
#define USE_UART1 #define USE_UART1
#define USE_UART2 #define USE_UART2

View File

@ -60,8 +60,12 @@
#define USB_IO #define USB_IO
#define USB_CABLE_DETECTION #define USB_CABLE_DETECTION
#define USB_DETECT_PIN PB5 #define USB_DETECT_PIN PB5
#undef GPS
#define USE_VCP #define USE_VCP
#define USE_UART1 #define USE_UART1
#define USE_UART2 #define USE_UART2

View File

@ -58,8 +58,6 @@
#define SONAR_TRIGGER_PIN PA6 // RC_CH7 (PB0) - only 3.3v ( add a 1K Ohms resistor ) #define SONAR_TRIGGER_PIN PA6 // RC_CH7 (PB0) - only 3.3v ( add a 1K Ohms resistor )
#define SONAR_ECHO_PIN PB1 // RC_CH8 (PB1) - only 3.3v ( add a 1K Ohms resistor ) #define SONAR_ECHO_PIN PB1 // RC_CH8 (PB1) - only 3.3v ( add a 1K Ohms resistor )
#define USB_IO
#define USE_VCP #define USE_VCP
#define USE_UART1 #define USE_UART1
#define USE_UART2 #define USE_UART2

View File

@ -78,8 +78,6 @@
#define SDCARD_DMA_CHANNEL_TX_COMPLETE_FLAG DMA1_FLAG_TC3 #define SDCARD_DMA_CHANNEL_TX_COMPLETE_FLAG DMA1_FLAG_TC3
#define ENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT #define ENABLE_BLACKBOX_LOGGING_ON_SDCARD_BY_DEFAULT
#define USB_IO
#define USE_VCP #define USE_VCP
#define USE_UART1 #define USE_UART1
#define USE_UART2 #define USE_UART2

View File

@ -53,8 +53,6 @@
#define MPU6500_CS_PIN PA4 #define MPU6500_CS_PIN PA4
#define MPU6500_SPI_INSTANCE SPI1 #define MPU6500_SPI_INSTANCE SPI1
#define USB_IO
#define USE_VCP #define USE_VCP
#define USE_UART1 #define USE_UART1
#define USE_UART2 #define USE_UART2

View File

@ -65,8 +65,6 @@
//#define SONAR //#define SONAR
#define USB_IO
#define USE_VCP #define USE_VCP
#define USE_UART1 #define USE_UART1
#define USE_UART2 #define USE_UART2

View File

@ -78,8 +78,6 @@
#define BRUSHED_ESC_AUTODETECT #define BRUSHED_ESC_AUTODETECT
#define USB_IO
#define USE_VCP #define USE_VCP
#define USE_UART1 #define USE_UART1
#define USE_UART2 #define USE_UART2
@ -107,12 +105,13 @@
#define UART3_TX_PIN PB10 // PB10 (AF7) #define UART3_TX_PIN PB10 // PB10 (AF7)
#define UART3_RX_PIN PB11 // PB11 (AF7) #define UART3_RX_PIN PB11 // PB11 (AF7)
#ifndef TINYBEEF3 #ifndef TINYBEEF3
#define SOFTSERIAL1_RX_PIN PA0 // PA0 / PAD3 #define SOFTSERIAL1_RX_PIN PA0 // PA0 / PAD3
#define SOFTSERIAL1_TX_PIN PA1 // PA1 / PAD4 #define SOFTSERIAL1_TX_PIN PA1 // PA1 / PAD4
#endif #endif
#define USB_DETECT_PIN PB5
#define SONAR_SOFTSERIAL1_EXCLUSIVE #define SONAR_SOFTSERIAL1_EXCLUSIVE
#define USE_SPI #define USE_SPI

View File

@ -53,8 +53,6 @@
#define USE_MAG_AK8975 #define USE_MAG_AK8975
#define USE_MAG_HMC5883 #define USE_MAG_HMC5883
#define USB_IO
#define USE_VCP #define USE_VCP
#define USE_UART1 #define USE_UART1
#define USE_UART2 #define USE_UART2

View File

@ -46,7 +46,6 @@
#if USB_VCP_ENABLED #if USB_VCP_ENABLED
#define USE_VCP #define USE_VCP
#define USB_IO
#define USBD_PRODUCT_STRING "tinyFISH" #define USBD_PRODUCT_STRING "tinyFISH"
#define SERIAL_PORT_COUNT 6 #define SERIAL_PORT_COUNT 6
#else #else

View File

@ -37,6 +37,7 @@
#include <stdbool.h> #include <stdbool.h>
#include "drivers/system.h" #include "drivers/system.h"
#include "drivers/usb_io.h"
#include "drivers/nvic.h" #include "drivers/nvic.h"
#include "common/utils.h" #include "common/utils.h"
@ -85,30 +86,7 @@ void Set_System(void)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
#endif /* STM32L1XX_XD */ #endif /* STM32L1XX_XD */
/*Pull down PA12 to create USB Disconnect Pulse*/ // HJI usbGenerateDisconnectPulse();
#if defined(STM32F303xC) // HJI
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); // HJI
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; // HJI
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // HJI
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; // HJI
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; // HJI
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // HJI
#else
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // HJI
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;// HJI
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;// HJI
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;// HJI
#endif
GPIO_Init(GPIOA, &GPIO_InitStructure); // HJI
GPIO_ResetBits(GPIOA, GPIO_Pin_12); // HJI
delay(200); // HJI
GPIO_SetBits(GPIOA, GPIO_Pin_12); // HJI
#if defined(STM32F37X) || defined(STM32F303xC) #if defined(STM32F37X) || defined(STM32F303xC)