Merge pull request #11198 from SteveCEvans/sce_rc2
[betaflight.git] / src / main / drivers / usb_msc_f7xx.c
blob9fbf62c8ee15897752db0fcd0406af70e67826aa
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
22 * Author: Chris Hockuba (https://github.com/conkerkh)
26 #include <stdint.h>
27 #include <stdbool.h>
28 #include <string.h>
30 #include "platform.h"
32 #if defined(USE_USB_MSC)
34 #include "build/build_config.h"
36 #include "common/utils.h"
38 #include "blackbox/blackbox.h"
39 #include "drivers/io.h"
40 #include "drivers/nvic.h"
41 #include "drivers/serial_usb_vcp.h"
42 #include "drivers/system.h"
43 #include "drivers/time.h"
44 #include "drivers/usb_msc.h"
46 #include "msc/usbd_storage.h"
48 #include "pg/sdcard.h"
49 #include "pg/usb.h"
51 #include "vcp_hal/usbd_cdc_interface.h"
53 #include "usb_io.h"
54 #include "usbd_msc.h"
56 uint8_t mscStart(void)
58 //Start USB
59 usbGenerateDisconnectPulse();
61 IOInit(IOGetByTag(IO_TAG(PA11)), OWNER_USB, 0);
62 IOInit(IOGetByTag(IO_TAG(PA12)), OWNER_USB, 0);
64 USBD_Init(&USBD_Device, &VCP_Desc, 0);
66 /** Regsiter class */
67 USBD_RegisterClass(&USBD_Device, USBD_MSC_CLASS);
69 /** Register interface callbacks */
70 switch (blackboxConfig()->device) {
71 #ifdef USE_SDCARD
72 case BLACKBOX_DEVICE_SDCARD:
73 switch (sdcardConfig()->mode) {
74 #ifdef USE_SDCARD_SDIO
75 case SDCARD_MODE_SDIO:
76 USBD_MSC_RegisterStorage(&USBD_Device, &USBD_MSC_MICRO_SDIO_fops);
77 break;
78 #endif
79 #ifdef USE_SDCARD_SPI
80 case SDCARD_MODE_SPI:
81 USBD_MSC_RegisterStorage(&USBD_Device, &USBD_MSC_MICRO_SD_SPI_fops);
82 break;
83 #endif
84 default:
85 return 1;
87 break;
88 #endif
90 #ifdef USE_FLASHFS
91 case BLACKBOX_DEVICE_FLASH:
92 USBD_MSC_RegisterStorage(&USBD_Device, &USBD_MSC_EMFAT_fops);
93 break;
94 #endif
96 default:
97 return 1;
100 USBD_Start(&USBD_Device);
102 // NVIC configuration for SYSTick
103 NVIC_DisableIRQ(SysTick_IRQn);
104 NVIC_SetPriority(SysTick_IRQn, NVIC_BUILD_PRIORITY(0, 0));
105 NVIC_EnableIRQ(SysTick_IRQn);
107 return 0;
110 #endif