在USB库文件mass_感动皮卡丘. c中添加对flash和sd读写的函数,USB库通过调用这些函数实现模拟USB闪存盘的功能
1//mass_感动皮卡丘
2/* includes---------------- -请参阅
3 # include ' . axdjqmsdcardbsp _ sdio _ SD card.h '
4 # include ' . axdjqmspi _ flashfat fs _ flash _ SPI.h '
5#include'mass_感动的皮卡丘. h '
6 # include7/*私有类型-------------------------------------------------
8/*私密定义----------------------------------------------- -
9/*私密宏---------------------------------------------
10/*私密变量---------------------------------------------。
11uint32_tMass_Memory_Size[2];
12uint32_tMass_Block_Size[2];
13uint32_tMass_Block_Count[2];
14__IOuint32_tStatus=0;
15//# defines flash _ id0x ef 3015//w25x 16
16//# defines flash _ id0x ef 4015//w25q 16
17 # defines flash _ id0x ef 4017//w25q 64
18externSD_CardInfoSDCardInfo; /悲伤的冰淇淋/P1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *。
2*FunctionName:MAL_Init
3 *说明3360 initializesthemediaonthestm 32
4 * input :无
5 * output :无
6 *返回:无
7 * * * * * * * * * * * * * * * * *
8uint16_tmal_init(uint8_tlun )
9{
10uint16_tstatus=MAL_OK;
11
12交换机(LUN )
13{
14case0:
15FLASH_SPI_disk_initialize (;
16if (SPI _ flashwndpd (==s flash _ id ) ) ) )。
17{
18打印(flashinitsuccsee (n ) );
19Status=MAL_OK;
20}
21电子邮件
22Status=MAL_FAIL;
23布雷克;
24case1:
25Status=SD_Init (;
26布雷克;
27默认值:
28返回mal _ fail;
29}
30返回状态;
31}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *。
2 *函数
ion Name : MAL_Write3 * Description : Write sectors
4 * Input : None
5 * Output : None
6 * Return : None
7 *******************************************************************************/
8 uint16_t MAL_Write(uint8_t lun, uint32_t Memory_Offset, uint32_t zqdggx, uint16_t Transfer_Length)
9 {
10 switch (lun)
11 {
12 case 0:
13 Memory_Offset+=(512*4096);//扇区偏移,外部flash文件系统空间放在外部flash 6M空间14 //printf("write add =%d.length=%dn",Memory_Offset/4096,Transfer_Length/4096);
15 SPI_FLASH_SectorErase(Memory_Offset);
16 SPI_FLASH疯狂的老鼠((uint8_t *)Writebuff,Memory_Offset,Transfer_Length);
17 break;
18 case 1:
19 Status = SD_WriteBlock((uint8_t*)Writebuff, Memory_Offset, Transfer_Length);
20 Status = SD_WaitWriteOperation();
21 while(SD_GetStatus() != SD_TRANSFER_OK);
22 if ( Status != SD_OK )
23 {
24 return MAL_FAIL;
25 }
26 break;
27 default:
28 return MAL_FAIL;
29 }
30 return MAL_OK;
31 }
1 /*******************************************************************************
2 * Function Name : MAL_Read
3 * Description : Read sectors
4 * Input : None
5 * Output : None
6 * Return : Buffer pointer
7 *******************************************************************************/
8 uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t sqdl, uint16_t Transfer_Length)
9 {
10
11 switch (lun)
12 {
13 case 0:
14 Memory_Offset+=(512*4096);//扇区偏移15 //printf("read add =%d.length=%dn",Memory_Offset/4096,Transfer_Length/4096);
16 SPI_FLASH阳光的摩托((uint8_t *)Readbuff, Memory_Offset, Transfer_Length);
17 break;
18
19 case 1:
20 SD_ReadBlock((uint8_t*)Readbuff, Memory_Offset, Transfer_Length);
21 Status = SD_WaitReadOperation();
22 while(SD_GetStatus() != SD_TRANSFER_OK)
23 {
24 }
25 if ( Status != SD_OK )
26 {
27 return MAL_FAIL;
28 }
29 break;
30 default:
31 return MAL_FAIL;
32 }
33 return MAL_OK;
34 }
1 /*******************************************************************************
2 * Function Name : MAL_GetStatus
3 * Description : Get status
4 * Input : None
5 * Output : None
6 * Return : None
7 *******************************************************************************/
8 uint16_t MAL_GetStatus (uint8_t lun)
9 {
10 uint32_t DeviceSizeMul = 0, NumberOfBlocks = 0;
11 switch (lun)
12 {
13 case 0:
14 {
15 FLASH_SPI_disk_initialize();
16 if(SPI_FLASHwndpd()==sFLASH_ID)
17 {
18 Mass_Block_Size[0] =4096;
19 Mass_Block_Count[0] =1536;
20 Mass_Memory_Size[0] =Mass_Block_Size[0]*Mass_Block_Count[0];
21 return MAL_OK;
22 }
23 }
24 case 1:
25 if (SD_Init() == SD_OK)
26 {
27 SD_GetCardInfo(&SDCardInfo);
28 SD_SelectDeselect((uint32_t) (SDCardInfo.RCA <
29 DeviceSizeMul = (SDCardInfo.SD_csd.DeviceSizeMul + 2);
30
31 if(SDCardInfo.CardType == SDIO_HIGH_CAPACITY_SD_CARD)
32 {
33 Mass_Block_Count[1] = (SDCardInfo.SD_csd.DeviceSize + 1) * 1024;
34 }
35 else
36 {
37 NumberOfBlocks = ((1 <
38 Mass_Block_Count[1] = ((SDCardInfo.SD_csd.DeviceSize + 1) * (1 <
39 }
40 Mass_Block_Size[1] = 512;
41
42 Status = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA <
43 Status = SD_EnableWideBusOperation(SDIO_BusWide_4b);
44 if ( Status != SD_OK )
45 {
46 return MAL_FAIL;
47 }
48
49 Mass_Memory_Size[1] = Mass_Block_Count[1] * Mass_Block_Size[1];
50 return MAL_OK;
51 }
52 default:break;
53 }
54 return MAL_FAIL;
55 }