不含stm32 底层的代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
MyStm32Code/libraries/usbmsc_port.c

108 lines
3.1 KiB

#include <stdio.h>
#include "stm32f4xx.h"
#include "main.h"
#include "elog.h"
#include "bsp_driver_sd.h"
#include "fatfs.h"
#include "usbd_storage_if.h"
static void FILE_MGT_USB_CHECK_TASK(const void *arg) ;
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
void OTG_FS_IRQHandler(void)
{
// log_i(" OTG_FS_IRQHandler ...");
HAL_PCD_IRQHandler(&hpcd_USB_OTG_FS);
FILE_MGT_USB_CHECK_TASK(NULL); // 自定义的函数
// #ifdef USE_STM32F4_VCP
// HAL_PCD_IRQHandler(&hpcd_USB_OTG_VCP);
// #endif /* USE_STM32F4_VCP */
// #ifdef USE_STM32F4_DEVICE_HID
// HAL_PCD_IRQHandler(&hpcd_USB_OTG_HID);
// #endif
// #ifdef USE_STM32F4_HOST_MSC
// HAL_HCD_IRQHandler(&hhcd_USB_OTG_FS);
// #endif
// #ifdef USE_STM32F4_HOST_HID
// HAL_HCD_IRQHandler(&hhcd_USB_OTG_FS);
// #endif
}
// // USB连接状态检测
static void FILE_MGT_USB_CHECK_TASK(const void *arg) {
uint8_t dev_state = 0;
osEvent event;
// FatFs_Check();
// 等待信号量 acquire , 判断FATFA是否在使用SD 卡; umount 文件系统
// 执行下面操作完成后释放信号量?
// for (;;) {
// event = osMessageGet(usbStateQueueHandle, osWaitForever);
// if (event.status == osEventMessage) {
// osMutexWait(sdFreeMutexHandle, osWaitForever);
// printf("hUsbDeviceFS:%d\n", (uint8_t) event.value.v);
// if ((uint8_t) event.value.v == USBD_STATE_ADDRESSED) {
// dev_state = USBD_STATE_ADDRESSED;
// } else if ((dev_state == USBD_STATE_ADDRESSED)
// && ((uint8_t) event.value.v == USBD_STATE_CONFIGURED)) {
// Set_SD_WriteOrRead(0);
// printf("usb connect\n");
// } else {
// dev_state = 0;
// Set_SD_WriteOrRead(1);
// printf("usb disconnect\n");
// }
// osMutexRelease(sdFreeMutexHandle);
// }
// }
}
// // 文件操作测试
// static void FILE_MGT_SD_TEST_TASK(const void *arg) {
// osDelay(500);
// for (;;) {
// osDelay(500);
// osMutexWait(sdFreeMutexHandle, osWaitForever);
// if (SDCard_EN) {
// FatFs_FileTest();
// } else {
// printf("禁止使用SD卡\n");
// }
// osMutexRelease(sdFreeMutexHandle);
// }
// }
// // 使能/禁止SD卡读写 1允许 0禁止
// static void Set_SD_WriteOrRead(uint8_t en) {
// if (en == 1) {
// SD_Create_Queue();
// SDCard_EN = 1;
// } else {
// SD_Delet_Queue();
// SDCard_EN = 0;
// }
// }
// void SD_Delet_Queue(void) {
// osMessageDelete(SDQueueID);
// }
// void SD_Create_Queue(void) {
// osMessageQDef(SD_Queue, QUEUE_SIZE, uint16_t);
// SDQueueID = osMessageCreate(osMessageQ(SD_Queue), NULL);
// }