Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / drivers / usb_msc_f4xx.c
blob66b0fcf43d2c0cdf8350acc4bf2d0eb495dc1d5a
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"
40 #include "drivers/io.h"
41 #include "drivers/nvic.h"
42 #include "drivers/sdmmc_sdio.h"
43 #include "drivers/system.h"
44 #include "drivers/time.h"
45 #include "drivers/usb_msc.h"
47 #include "msc/usbd_storage.h"
49 #include "pg/sdcard.h"
50 #include "pg/usb.h"
52 #include "usb_core.h"
53 #include "usbd_cdc_vcp.h"
54 #include "usb_io.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 switch (blackboxConfig()->device) {
65 #ifdef USE_SDCARD
66 case BLACKBOX_DEVICE_SDCARD:
67 switch (sdcardConfig()->mode) {
68 #ifdef USE_SDCARD_SDIO
69 case SDCARD_MODE_SDIO:
70 USBD_STORAGE_fops = &USBD_MSC_MICRO_SDIO_fops;
71 break;
72 #endif
73 #ifdef USE_SDCARD_SPI
74 case SDCARD_MODE_SPI:
75 USBD_STORAGE_fops = &USBD_MSC_MICRO_SD_SPI_fops;
76 break;
77 #endif
78 default:
79 return 1;
81 break;
82 #endif
84 #ifdef USE_FLASHFS
85 case BLACKBOX_DEVICE_FLASH:
86 USBD_STORAGE_fops = &USBD_MSC_EMFAT_fops;
87 break;
88 #endif
89 default:
90 return 1;
93 USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &MSC_desc, &USBD_MSC_cb, &USR_cb);
95 // NVIC configuration for SYSTick
96 NVIC_DisableIRQ(SysTick_IRQn);
97 NVIC_SetPriority(SysTick_IRQn, NVIC_BUILD_PRIORITY(0, 0));
98 NVIC_EnableIRQ(SysTick_IRQn);
100 return 0;
103 #endif