我用的平台是STM32F103,有FATFS8.3 U盘先插上 然后对CH375B 进行如下操作: RESET_ALL 正常 CHECK_EXIST 正常 GET_IC_VER 55 正常 SET_USB_MODE 先是7模式,然后是6模式 正常 TEST_CONNECT 正常,返回中断状态为已连接,但未初始化 DISK_INIT 正常,返回中断状态初始化成功 DISK_READY 正常,返回状态U盘准备好 DISK_SIZE 正常,成功获取U盘扇区大小为512B,和扇区数量 GET_MAX_LUN 正常,成功获取U盘逻辑单元数,只有一个逻辑单元 下面从U盘扇区LBA=0x0开始读取1个扇区时,出现问题了 DISK_READ命令 然后发送了LBA地址0x00000000和扇区数0x01 然后等待第一个64B取回中断时,CH375一直没有中断请求,不知道为什么 是不是还有没有什么命令没设置啊,求帮助
确保前面命令都正确通过,中断状态返回正确。DISK_READY之后就直接可以调用DISK_READ命令。具体流程可以参考一下:CH375EVT\MCS51C\MISCELL里面的例子
前面命令都正确通过的,不知道为啥读扇区命令没有中断请求
检查一下此时中断脚有没有被拉低?读扇区的流程可以参考下面的函数: UINT8 mReadSector( UINT32 iLbaStart, UINT8 iSectorCount, UINT8X *oDataBuffer ) { /* 从U盘读取数据块到缓冲区 */ /* iLbaStart 起始扇区号, iSectorCount 扇区数, oDataBuffer 缓冲区起址 */ UINT16 mBlockCount; UINT8 c; CH375_WR_CMD_PORT( CMD_DISK_READ ); /* 从USB存储器读数据块 */ CH375_WR_DAT_PORT( (UINT8)iLbaStart ); /* LBA的最低8位 */ CH375_WR_DAT_PORT( (UINT8)( iLbaStart >> 8 ) ); CH375_WR_DAT_PORT( (UINT8)( iLbaStart >> 16 ) ); CH375_WR_DAT_PORT( (UINT8)( iLbaStart >> 24 ) ); /* LBA的最高8位 */ CH375_WR_DAT_PORT( iSectorCount ); /* 扇区数 */ for ( mBlockCount = iSectorCount * 8; mBlockCount != 0; mBlockCount -- ) { /* 数据块计数 */ c = mWaitInterrupt( ); /* 等待中断并获取状态 */ if ( c == USB_INT_DISK_READ ) { /* 等待中断并获取状态,USB存储器读数据块,请求数据读出 */ CH375_WR_CMD_PORT( CMD_RD_USB_DATA ); /* 从CH375缓冲区读取数据块 */ c = CH375_RD_DAT_PORT( ); /* 后续数据的长度 */ while ( c -- ) *oDataBuffer++ = CH375_RD_DAT_PORT( ); /* 根据长度读取数据并保存 */ CH375_WR_CMD_PORT( CMD_DISK_RD_GO ); /* 继续执行USB存储器的读操作 */ } else break; /* 返回错误状态 */ } if ( mBlockCount == 0 ) { c = mWaitInterrupt( ); /* 等待中断并获取状态 */ if ( c== USB_INT_SUCCESS ) return( 0 ); /* 操作成功 */ } return( c ); /* 操作失败 */ }
中断引脚没有被拉低,我是用while 查询的,就一直停在while这个地方 u8 USB_ReadDisk(u8 *pBuffer,u32 ReadAddr, u16 NumByteToRead) { u8 tmp; CH375_SentCMD(DISK_READ); //·¢ËͶÁÅÌÃüÁî delay_ms(10); CH375_SentData((u8)(ReadAddr&0x000000FF)); //·¢ËÍÆðʼLBAµØÖ· delay_ms(20); CH375_SentData((u8)((ReadAddr&0x0000FF00)>>8)); delay_ms(20); CH375_SentData((u8)((ReadAddr&0x00FF0000)>>16)); delay_ms(20); CH375_SentData((u8)((ReadAddr&0xFF000000)>>24)); delay_ms(20); CH375_SentData((u8)NumByteToRead); //·¢ËÍÒª¶ÁµÄÉÈÇøÊý delay_ms(100); while(1) { while(INTER); CH375_SentCMD(GET_STATUS); delay_ms(200); tmp = CH375_ReadData(); if(tmp == USB_INT_DISK_READ) { CH375_SentCMD(RD_USB_DATA); tmp = CH375_ReadData(); if(tmp) for(;tmp>0;tmp--) { *pBuffer = CH375_ReadData(); pBuffer++; } else return 1; CH375_SentCMD(DISK_RD_GO); }else if(tmp == USB_INT_SUCCESS) break; else if(tmp == USB_INT_DISK_ERR) return 1; } return 0; }
那说明你中断没有产生,有可能是你中断配置问题或者是发送的数据有问题。那你测试一下写会不会产生中断?
我没有用单片机的中断输入,就是IO口查询,CH375就没有向单片机请求中断,INT引脚没有拉低,不知道为啥,函数发送的数据LBA起始地址为0x00000000,数据长度为0x01,这个应该不会错吧,怎么就无法读取扇区呢。DISK_SIZE命令都能正确获取扇区数和扇区大小,说明CH375基本通信正常的嘛,这是我的程序你帮我看看
void CH375_SentCMD(u8 cmd) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = DATAPIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); A0 = 1; DATAout(cmd); WR = 0; delay_ms(1); WR = 1; return ; }
void CH375_SentData(u8 data) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = DATAPIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOC, &GPIO_InitStructure); A0 = 0; DATAout(data); WR = 0; delay_ms(1); WR = 1; return ; }
u8 CH375_ReadData() { u8 tmp; GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = DATAPIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOC, &GPIO_InitStructure); A0 = 0; RD = 0; delay_ms(1); tmp = DATAin; RD = 1; return tmp; }
u8 USB_ReadDisk(u8 *pBuffer,u32 ReadAddr, u16 NumByteToRead) { u8 tmp; CH375_SentCMD(DISK_READ); //·¢ËͶÁÅÌÃüÁî delay_ms(10); CH375_SentData((u8)(ReadAddr)); //·¢ËÍÆðʼLBAµØÖ· delay_ms(20); CH375_SentData((u8)(ReadAddr>>8)); delay_ms(20); CH375_SentData((u8)(ReadAddr>>16)); delay_ms(20); CH375_SentData((u8)(ReadAddr>>24)); delay_ms(20); CH375_SentData((u8)NumByteToRead); //·¢ËÍÒª¶ÁµÄÉÈÇøÊý delay_ms(100); while(1) { while(INTER); CH375_SentCMD(GET_STATUS); delay_ms(200); tmp = CH375_ReadData(); if(tmp == USB_INT_DISK_READ) { CH375_SentCMD(RD_USB_DATA); tmp = CH375_ReadData(); if(tmp) for(;tmp>0;tmp--) { *pBuffer = CH375_ReadData(); pBuffer++; } else return 1; CH375_SentCMD(DISK_RD_GO); }else if(tmp == USB_INT_SUCCESS) break; else if(tmp == USB_INT_DISK_ERR) return 1; } return 0; }
unsigned long int sectors; u16 sectorsize; u8 USB() { u8 state,res; u16 tmp; CH375_GPIOInit(); CS = 1; A0 = 1; WR = 1; RD = 1; CS = 0; CH375_SentCMD(RESET_ALL);//RESET ALL delay_ms(40); CH375_SentCMD(CHECK_EXIST);//CHECK_EXIST delay_ms(5); CH375_SentData(0xF0); delay_ms(5); tmp = CH375_ReadData(); if(tmp == 0x0F) printf("CH375 works!\r\n"); else printf("CH375 failed,back data is%d\r\n",tmp); CH375_SentCMD(GET_IC_VER); //GET_IC_VER delay_ms(5); tmp = CH375_ReadData(); printf("IC VER IS:%d\r\n",tmp&0x3F); CH375_SentCMD(SET_USB_MODE); delay_ms(5); CH375_SentData(0x07); delay_ms(5); tmp = CH375_ReadData(); if(tmp == CMD_RET_SUCCESS) printf("USB mode set successfully!\r\n"); else if(tmp == CMD_RET_ABORT) printf("USB mode set failed!\r\n"); //if((tmp == 0x15)||(tmp == 0x16)) CH375_SentCMD(SET_USB_MODE); delay_ms(5); CH375_SentData(0x06); delay_ms(5); tmp = CH375_ReadData(); if(tmp == CMD_RET_SUCCESS) printf("USB mode set successfully!\r\n"); else printf("USB mode set failed!\r\n"); CH375_SentCMD(TEST_CONNECT); delay_ms(5); tmp = CH375_ReadData(); if(tmp == 0x15) printf("USB device has connected,but not init\r\n"); else if(tmp == 0x16) printf("USB device has disconnected\r\n"); else printf("USB device is ready\r\n"); CH375_SentCMD(DISK_INIT);//³õʼ»¯USBÉ豸 delay_ms(5); while(INTER); CH375_SentCMD(GET_STATUS); delay_ms(100); tmp = CH375_ReadData(); // delay_ms(20); if(tmp == USB_INT_SUCCESS) { printf("USB device Initialize Successfully!\r\n"); res = 0; } else if((tmp == USB_INT_DISK_ERR)||(tmp == USB_INT_BUF_OVER)) { printf("Unknown USB device\r\n"); res = 1; } else if(tmp == USB_INT_DISCONNECT) { printf("USB device has been disconnected\r\n"); res = 1; } else if(tmp == USB_INT_CONNECT) printf("USB device has been connected\r\n"); else { printf("USB Initialize Failed,bakc code is %d\r\n",tmp); res = 1; } if(!INTER) printf("中断请求未消除\r\n"); CH375_SentCMD(DISK_READY); delay_ms(5); while(INTER); CH375_SentCMD(GET_STATUS); delay_ms(400); tmp = CH375_ReadData(); if(tmp == USB_INT_SUCCESS) printf("USB Disk is ready!\r\n"); else{ printf("USB Disk is not ready!\r\n"); } delay_ms(500); CH375_SentCMD(DISK_SIZE); delay_ms(5); while(INTER); CH375_SentCMD(GET_STATUS); // delay_ms(5); tmp = CH375_ReadData(); if(tmp == USB_INT_SUCCESS) { CH375_SentCMD(RD_USB_DATA); tmp = CH375_ReadData(); printf("data lenth is %d\r\n",tmp); if(tmp) { for(tmp = 0;tmp<4;tmp++) { sectors <<= 8; sectors |= CH375_ReadData(); } printf("扇区数为%d\r\n",sectors); for(tmp = 0; tmp<4; tmp++) { sectorsize <<= 8; sectorsize |= CH375_ReadData(); } printf("扇区大小为%d\r\n",sectorsize); printf("Total Disk Size is %lu MBytes\r\n",(sectors>>20)*512); } } CH375_SentCMD(GET_MAX_LUN);//»ñÈ¡UÅ̵ÄÂß¼µ¥ÔªÊý CH375_SentData(0x38); delay_ms(10); tmp = CH375_ReadData(); printf("The USB disk has %d logic unit\r\n",tmp+1); return res; }
由于没有CH375文件级子程序库,再加上也不会用库,我用的FATFS8.3, 需要调用读扇区的函数
看了你的程序,流程上读扇区和获取扇区大小都是发一个命令然后等中断,如果能够正常获取扇区数和扇区大小,读扇区操作也一样的。 你的U盘是不是比较特殊,是不是写保护了?我们支持FAT12/16/32的文件系统。你用的FATFS8.3是什么格式文件系统?
就是普通的U盘,我用了两个U盘来试,第一个U盘有两个逻辑单元,GET_MAX_LUN 命令,CH375能正确检测到两个逻辑单元,第二个U盘只有一个逻辑单元,CH375也正常识别,但是两个U盘用CH375读扇区都没反应,没有中断请求。因为我的应用设备上有SPIFLASH,SD卡存储设备,所以用的FATFS来做文件系统。FATFS8.3支持FAT16和FAT32, 配置为支持FAT32,是这样的,FATFS先要mount挂载驱动器,要做一系列检查,其中有一项要检查驱动器的文件系统是不是能够被支持,先要读取一个扇区来检查是否是FAT-VBR,DEBUG发现读取的是第一个扇区的内容,于是FATFS调用了需要自己编写的底层读扇区函数,就是u8 USB_ReadDisk(u8 *pBuffer,u32 ReadAddr, u16 NumByteToRead)这个函数,但是这个函数一直在等待CH375给出中断请求,两个U盘都是这样,读扇区内容CH375一直不请求中断
第一个U盘有状态指示灯,如果主机在读内容的时候U盘的呼吸灯会闪烁,但是我发现调用u8 USB_ReadDisk(u8 *pBuffer,u32 ReadAddr, u16 NumByteToRead)这个函数让CH375读扇区的时候U盘状态灯都没闪
CH375读U盘的流程是不是这样的:(假设U盘已经插上去了) MCU先RESET_ALL 复位CH375 然后CHECK_EXIST //检查CH375是否正常工作 然后GET_IC_VER //获取CH375芯片号(可以不要?) 然后SET_USB_MODE 先是7模式,然后是6模式,设置成6模式后,CH375是不是会自动完成与U盘的握手枚举,为U盘分配USB地址? TEST_CONNECT ,检查U盘是不是连上 DISK_INIT ,这步是对U盘初始化,这个初始化是完成哪些步骤? DISK_READY 查询U盘是否就绪,如果就绪了就可以进行下面的步骤 DISK_SIZE 获取U盘扇区数和扇区大小 GET_MAX_LUN 获取U盘的逻辑单元数 然后就可以DISK_READ进行读取扇区操作了 是不是这个流程?
你们的那个库函数就只是实现文件系统的功能吗
我们提供ARM单片机的库函数,主要实现文件系统的功能。 关于操作步骤版本号是可以不要,设置模式只是设置CH375的工作模式。DISK_INIT里面做了获取设备描述符、配置描述符、设置地址,设置配置、获取U盘逻辑单元、获取磁盘特性。然后DISK_READY 查询U盘是否就绪,这一步做完之后就可以进行扇区读写了。 你的操作还没有到分析文件系统那一层,只是对U盘扇区进行读写。
FATFS需要先读0号扇区来检查是否是FAT-VBR,后续的操作会进行文件系统分析 这是将U盘挂载到文件系统之前对U盘进行检查的函数 static FRESULT chk_mounted ( /* FR_OK(0): successful, !=0: any error occurred */ const TCHAR **path, /* Pointer to pointer to the path name (drive number) */ FATFS **rfs, /* Pointer to pointer to the found file system object */ BYTE wmode /* !=0: Check write protection for write access */ ) { BYTE fmt, b, pi, *tbl; UINT vol; DSTATUS stat; DWORD bsect, fasize, tsect, sysect, nclst, szbfat; WORD nrsv; const TCHAR *p = *path; FATFS *fs;
/* Get logical drive number from the path name */ vol = p[0] - '0'; /* Is there a drive number? */ if (vol <= 9 && p[1] == ':') { /* Found a drive number, get and strip it */ p += 2; *path = p; /* Return pointer to the path name */ } else { /* No drive number is given */ #if _FS_RPATH vol = CurrVol; /* Use current drive */ #else vol = 0; /* Use drive 0 */ #endif }
/* Check if the file system object is valid or not */ *rfs = 0; if (vol >= _VOLUMES) /* Is the drive number valid? */ return FR_INVALID_DRIVE; fs = FatFs[vol]; /* Get corresponding file system object */ if (!fs) return FR_NOT_ENABLED; /* Is the file system object available? */
ENTER_FF(fs); /* Lock file system */
*rfs = fs; /* Return pointer to the corresponding file system object */ if (fs->fs_type) { /* If the volume has been mounted */ stat = disk_status(fs->drv); if (!(stat & STA_NOINIT)) { /* and the physical drive is kept initialized (has not been changed), */ if (!_FS_READONLY && wmode && (stat & STA_PROTECT)) /* Check write protection if needed */ return FR_WRITE_PROTECTED; return FR_OK; /* The file system object is valid */ } }
/* The file system object is not valid. */ /* Following code attempts to mount the volume. (analyze BPB and initialize the fs object) */
fs->fs_type = 0; /* Clear the file system object */ fs->drv = LD2PD(vol); /* Bind the logical drive and a physical drive */ stat = disk_initialize(fs->drv); /* Initialize the physical drive */ if (stat & STA_NOINIT) /* Check if the initialization succeeded */ return FR_NOT_READY; /* Failed to initialize due to no medium or hard error */ if (!_FS_READONLY && wmode && (stat & STA_PROTECT)) /* Check disk write protection if needed */ return FR_WRITE_PROTECTED; #if _MAX_SS != 512 /* Get disk sector size (variable sector size cfg only) */ if (disk_ioctl(fs->drv, GET_SECTOR_SIZE, &fs->ssize) != RES_OK) return FR_DISK_ERR; #endif /* Search FAT partition on the drive. Supports only generic partitions, FDISK and SFD. */ fmt = check_fs(fs, bsect = 0);这一步就是检查0号扇区的内容 /* Load sector 0 and check if it is an FAT-VBR (in SFD) */ if (LD2PT(vol) && !fmt) fmt = 1; /* Force non-SFD if the volume is forced partition */ if (fmt == 1) { /* Not an FAT-VBR, the physical drive can be partitioned */ /* Check the partition listed in the partition table */ pi = LD2PT(vol); if (pi) pi--; tbl = &fs->win[MBR_Table + pi * SZ_PTE];/* Partition table */ if (tbl[4]) { /* Is the partition existing? */ bsect = LD_DWORD(&tbl[8]); /* Partition offset in LBA */ fmt = check_fs(fs, bsect); /* Check the partition */ } } if (fmt == 3) return FR_DISK_ERR; if (fmt) return FR_NO_FILESYSTEM; /* No FAT volume is found */
/* An FAT volume is found. Following code initializes the file system object */
if (LD_WORD(fs->win+BPB_BytsPerSec) != SS(fs)) /* (BPB_BytsPerSec must be equal to the physical sector size) */ return FR_NO_FILESYSTEM;
fasize = LD_WORD(fs->win+BPB_FATSz16); /* Number of sectors per FAT */ if (!fasize) fasize = LD_DWORD(fs->win+BPB_FATSz32); fs->fsize = fasize;
fs->n_fats = b = fs->win[BPB_NumFATs]; /* Number of FAT copies */ if (b != 1 && b != 2) return FR_NO_FILESYSTEM; /* (Must be 1 or 2) */ fasize *= b; /* Number of sectors for FAT area */
fs->csize = b = fs->win[BPB_SecPerClus]; /* Number of sectors per cluster */ if (!b || (b & (b - 1))) return FR_NO_FILESYSTEM; /* (Must be power of 2) */
fs->n_rootdir = LD_WORD(fs->win+BPB_RootEntCnt); /* Number of root directory entries */ if (fs->n_rootdir % (SS(fs) / SZ_DIR)) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must be sector aligned) */
tsect = LD_WORD(fs->win+BPB_TotSec16); /* Number of sectors on the volume */ if (!tsect) tsect = LD_DWORD(fs->win+BPB_TotSec32);
nrsv = LD_WORD(fs->win+BPB_RsvdSecCnt); /* Number of reserved sectors */ if (!nrsv) return FR_NO_FILESYSTEM; /* (BPB_RsvdSecCnt must not be 0) */
/* Determine the FAT sub type */ sysect = nrsv + fasize + fs->n_rootdir / (SS(fs) / SZ_DIR); /* RSV+FAT+DIR */ if (tsect < sysect) return FR_NO_FILESYSTEM; /* (Invalid volume size) */ nclst = (tsect - sysect) / fs->csize; /* Number of clusters */ if (!nclst) return FR_NO_FILESYSTEM; /* (Invalid volume size) */ fmt = FS_FAT12; if (nclst >= MIN_FAT16) fmt = FS_FAT16; if (nclst >= MIN_FAT32) fmt = FS_FAT32;
/* Boundaries and Limits */ fs->n_fatent = nclst + 2; /* Number of FAT entries */ fs->database = bsect + sysect; /* Data start sector */ fs->fatbase = bsect + nrsv; /* FAT start sector */ if (fmt == FS_FAT32) { if (fs->n_rootdir) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must be 0) */ fs->dirbase = LD_DWORD(fs->win+BPB_RootClus); /* Root directory start cluster */ szbfat = fs->n_fatent * 4; /* (Required FAT size) */ } else { if (!fs->n_rootdir) return FR_NO_FILESYSTEM; /* (BPB_RootEntCnt must not be 0) */ fs->dirbase = fs->fatbase + fasize; /* Root directory start sector */ szbfat = (fmt == FS_FAT16) ? /* (Required FAT size) */ fs->n_fatent * 2 : fs->n_fatent * 3 / 2 + (fs->n_fatent & 1); } if (fs->fsize < (szbfat + (SS(fs) - 1)) / SS(fs)) /* (BPB_FATSz must not be less than required) */ return FR_NO_FILESYSTEM;
#if !_FS_READONLY /* Initialize cluster allocation information */ fs->free_clust = 0xFFFFFFFF; fs->last_clust = 0;
/* Get fsinfo if available */ if (fmt == FS_FAT32) { fs->fsi_flag = 0; fs->fsi_sector = bsect + LD_WORD(fs->win+BPB_FSInfo); if (disk_read(fs->drv, fs->win, fs->fsi_sector, 1) == RES_OK && LD_WORD(fs->win+BS_55AA) == 0xAA55 && LD_DWORD(fs->win+FSI_LeadSig) == 0x41615252 && LD_DWORD(fs->win+FSI_StrucSig) == 0x61417272) { fs->last_clust = LD_DWORD(fs->win+FSI_Nxt_Free); fs->free_clust = LD_DWORD(fs->win+FSI_Free_Count); } } #endif fs->fs_type = fmt; /* FAT sub-type */ fs->id = ++Fsid; /* File system mount ID */ fs->winsect = 0; /* Invalidate sector cache */ fs->wflag = 0; #if _FS_RPATH fs->cdir = 0; /* Current directory (root dir) */ #endif #if _FS_LOCK /* Clear file lock semaphores */ clear_lock(fs); #endif
return FR_OK; }
/*-----------------------------------------------------------------------*/ /* Load a sector and check if it is an FAT Volume Boot Record */ /*-----------------------------------------------------------------------*/
static BYTE check_fs ( /* 0:FAT-VBR, 1:Any BR but not FAT, 2:Not a BR, 3:Disk error */ FATFS *fs, /* File system object */ DWORD sect /* Sector# (lba) to check if it is an FAT boot record or not */ ) { if (disk_read(fs->drv, fs->win, sect, 1) != RES_OK) 这一步就用到了自己编写的读扇区函数 /* Load boot record */ return 3; if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature (always placed at offset 510 even if the sector size is >512) */ return 2;
if ((LD_DWORD(&fs->win[BS_FilSysType]) & 0xFFFFFF) == 0x544146) /* Check "FAT" string */ return 0; if ((LD_DWORD(&fs->win[BS_FilSysType32]) & 0xFFFFFF) == 0x544146) return 0;
return 1; }
//读扇区 //drv:磁盘编号0~9 //*buff:数据接收缓冲首地址 //sector:扇区地址 //count:要读的扇区数 DRESULT disk_read ( BYTE drv, /* Physical drive nmuber (0..) */ BYTE *buff, /* Data buffer to store read data */ DWORD sector, /* Sector address (LBA) */ BYTE count /* Number of sectors to read (1..255) */ ) { u8 res=0; if (!count)return RES_PARERR;//count²»ÄܵÈÓÚ0£¬·ñÔò·µ»Ø²ÎÊý´íÎó switch(drv) { case SD_CARD://SD卡的 res=SD_ReadDisk(buff,sector,count); if(res) { SD_SPI_SpeedLow(); SD_SPI_ReadWriteByte(0xff); SD_SPI_SpeedHigh(); } break; case EX_FLASH://SPI FLASH的 for(;count>0;count--) { SPI_Flash_Read(buff,sector*FLASH_SECTOR_SIZE,FLASH_SECTOR_SIZE); sector++; buff+=FLASH_SECTOR_SIZE; } res=0; break; case USB_DISK: res = USB_ReadDisk(buff,sector,count); //U盘的读扇区函数 default: res=1; } //处理返回值 if(res==0x00)return RES_OK; else return RES_ERROR; }
你的操作应该是先读取到扇区0的数据之后,才能对U盘进行检查,最后才是挂载文件系统。关键还是要能够正确进行扇区读取。12楼对相关流程已做说明。 如还有疑问,你也可以发邮件到我的邮箱或者直接来电咨询。
对的,你说得没错,就是需要先读扇区0的数据,现在就是连扇区0都没法读,CH375不给中断请求,函数就一直在while那里等待