现在想只读取sd卡到电脑端,按照原子哥读取单磁盘sd卡
http://www.openedv.com/thread-42578-1-1.html 改了STORAGE_LUN_NBR 和case里的数字,但是还是读不到sd卡 过一会电脑显示无法识别usb设备。请问有人知道该怎么修改吗?
[mw_shl_code=c,true]#include "usbd_msc_mem.h"
#include "usb_conf.h"
#include "w25qxx.h"
#include "sdio_sdcard.h"
#include "nand.h"
#include "ftl.h"
//////////////////////////////////////////////////////////////////////////////////
//±¾3ìDòÖ»1©Ñ§Ï°ê1óã¬Î′¾-×÷ÕßDí¿é£¬2»μÃóÃóúÆäËüèÎoÎóÃí¾
//ALIENTEK STM32¿a·¢°å
//USB¶á¿¨Æ÷ Çy¶ˉ′úÂë
//ÕyμãÔ-×ó@ALIENTEK
//¼¼êõÂÛì3:
www.openedv.com
//′′½¨èÕÆú:2016/1/21
//°æ±¾£oV1.0
//°æè¨ËùóD£¬μá°æ±Ø¾¿¡£
//Copyright(C) 1ãÖYêDDÇòíμç×ó¿Æ¼¼óDÏT1«Ë¾ 2009-2019
//All rights reserved
//*******************************************************************************
//DT¸ÄDÅÏ¢
//ÎT
//////////////////////////////////////////////////////////////////////////////////
//×î′óÖ§3ÖμÄé豸êy,3¸ö
#define STORAGE_LUN_NBR 0
////////////////////////////×Ô¼o¶¨òåμÄò»¸ö±ê¼ÇUSB×′ì¬μļÄ′æÆ÷///////////////////
//bit0:±íê¾μçÄÔÕyÔúÏòSD¿¨D′èëêy¾Y
//bit1:±íê¾μçÄÔÕy′óSD¿¨¶á3öêy¾Y
//bit2:SD¿¨D′êy¾Y′íÎó±ê־λ
//bit3:SD¿¨¶áêy¾Y′íÎó±ê־λ
//bit4:1,±íê¾μçÄÔóDÂÖÑˉ2ù×÷(±íÃ÷ᬽó»1±£3Ö×Å)
vu8 USB_STATUS_REG=0;
////////////////////////////////////////////////////////////////////////////////
//USB Mass storage ±ê×¼2éÑˉêy¾Y(ÿ¸ölunÕ¼36×Ö½ú)
const int8_t STORAGE_Inquirydata[] = {
/* LUN 0 */
0x00,
0x80,
0x02,
0x02,
(USBD_STD_INQUIRY_LENGTH - 4),
0x00,
0x00,
0x00,
/* Vendor Identification */
'A', 'L', 'I', 'E', 'N', 'T', 'E', 'K', ' ',//9×Ö½ú
/* Product Identification */
'S', 'P', 'I', ' ', 'F', 'l', 'a', 's', 'h',//15×Ö½ú
' ','D', 'i', 's', 'k', ' ',
/* Product Revision Level */
'1', '.', '0', ' ', //4×Ö½ú
/* LUN 1 */
0x00,
0x80,
0x02,
0x02,
(USBD_STD_INQUIRY_LENGTH - 4),
0x00,
0x00,
0x00,
/* Vendor Identification */
'A', 'L', 'I', 'E', 'N', 'T', 'E', 'K',' ', //9×Ö½ú
/* Product Identification */
'N', 'A', 'N', 'D', ' ', 'F', 'l', 'a', 's', 'h',//15×Ö½ú
' ','D', 'i', 's', 'k',
/* Product Revision Level */
'1', '.', '0' ,' ', //4×Ö½ú
/* LUN 2 */
0x00,
0x80,
0x02,
0x02,
(USBD_STD_INQUIRY_LENGTH - 4),
0x00,
0x00,
0x00,
/* Vendor Identification */
'A', 'L', 'I', 'E', 'N', 'T', 'E', 'K',' ', //9×Ö½ú
/* Product Identification */
'S', 'D', ' ', 'F', 'l', 'a', 's', 'h', ' ',//15×Ö½ú
'D', 'i', 's', 'k', ' ', ' ',
/* Product Revision Level */
'1', '.', '0' ,' ', //4×Ö½ú
};
int8_t STORAGE_Init (uint8_t lun);
int8_t STORAGE_GetCapacity (uint8_t lun,uint32_t *block_num,uint32_t *block_size);
int8_t STORAGE_IsReady (uint8_t lun);
int8_t STORAGE_IsWriteProtected (uint8_t lun);
int8_t STORAGE_Read (uint8_t lun,uint8_t *buf,uint32_t blk_addr,uint16_t blk_len);
int8_t STORAGE_Write (uint8_t lun,uint8_t *buf,uint32_t blk_addr,uint16_t blk_len);
int8_t STORAGE_GetMaxLun (void);
//USB Device óû§»Øμ÷oˉêy½ó¿ú
USBD_STORAGE_cb_TypeDef USBD_MICRO_SDIO_fops =
{
STORAGE_Init,
STORAGE_GetCapacity,
STORAGE_IsReady,
STORAGE_IsWriteProtected,
STORAGE_Read,
STORAGE_Write,
STORAGE_GetMaxLun,
(int8_t *)STORAGE_Inquirydata,
};
USBD_STORAGE_cb_TypeDef *USBD_STORAGE_fops=&USBD_MICRO_SDIO_fops;//Ö¸ÏòUSBD_MICRO_SDIO_fops½á11ìå.
//3õê¼»ˉ′æ′¢é豸
//lun:Âß¼-μ¥Ôa±àoÅ,0,SD¿¨;1,SPI FLASH
//·μ»ØÖμ:0,3é1|;
// ÆäËû,′íÎó′úÂë
int8_t STORAGE_Init (uint8_t lun)
{
u8 res=0;
switch(lun)
{
case 2://SPI FLASH
W25QXX_Init();
break;
case 1://NAND FLASH
res=FTL_Init();
break;
case 0://SD¿¨
res=SD_Init();
break;
}
return res;
}
//»ñè¡′æ′¢é豸μÄèYá¿oí¿é′óD¡
//lun:Âß¼-μ¥Ôa±àoÅ,0,SD¿¨;1,SPI FLASH
//block_num:¿éêyá¿(éèÇøêy)
//block_size:¿é′óD¡(éèÇø′óD¡)
//·μ»ØÖμ:0,3é1|;
// ÆäËû,′íÎó′úÂë
int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_size)
{
switch(lun)
{
case 2://SPI FLASH
*block_size=512;
*block_num=1024*1024*25/512; //SPI FLASHμÄÇ°Ãæ25M×Ö½ú,ÎļtÏμí3óÃ
break;
case 1://NAND FLASH
*block_size=512;
*block_num=nand_dev.valid_blocknum*nand_dev.block_pagenum*nand_dev.page_mainsize/512;
break;
case 0://SD¿¨
*block_size=512;
*block_num=SDCardInfo.CardCapacity/512;
break;
}
return 0;
}
//2é¿′′æ′¢é豸êÇ·ñ¾íD÷
//lun:Âß¼-μ¥Ôa±àoÅ,0,SD¿¨;1,SPI FLASH
//·μ»ØÖμ:0,¾íD÷;
// ÆäËû,Î′¾íD÷
int8_t STORAGE_IsReady (uint8_t lun)
{
USB_STATUS_REG|=0X10;//±ê¼ÇÂÖÑˉ
return 0;
}
//2é¿′′æ′¢é豸êÇ·ñD′±£»¤
//lun:Âß¼-μ¥Ôa±àoÅ,0,SD¿¨;1,SPI FLASH
//·μ»ØÖμ:0,ûóDD′±£»¤;
// ÆäËû,D′±£»¤(Ö»¶á)
int8_t STORAGE_IsWriteProtected (uint8_t lun)
{
return 0;
}
//′ó′æ′¢é豸¶áè¡êy¾Y
//lun:Âß¼-μ¥Ôa±àoÅ,0,SD¿¨;1,SPI FLASH
//buf:êy¾Y′æ′¢Çøê×μØÖ·Ö¸Õë
//blk_addr:òa¶áè¡μÄμØÖ·(éèÇøμØÖ·)
//blk_len:òa¶áè¡μÄ¿éêy(éèÇøêy)
//·μ»ØÖμ:0,3é1|;
// ÆäËû,′íÎó′úÂë
int8_t STORAGE_Read (uint8_t lun,uint8_t *buf,uint32_t blk_addr,uint16_t blk_len)
{
int8_t res=0;
USB_STATUS_REG|=0X02;//±ê¼ÇÕyÔú¶áêy¾Y
switch(lun)
{
case 2://SPI FLASH
W25QXX_Read(buf,blk_addr*512,blk_len*512);
break;
case 1://NAND FLASH
res=FTL_ReadSectors(buf,blk_addr,512,blk_len);
break;
case 0://SD¿¨
res=SD_ReadDisk(buf,blk_addr,blk_len);
break;
}
if(res)
{
USB_STATUS_REG|=0X08;//¶á′íÎó!
}
return res;
}
//Ïò′æ′¢é豸D′êy¾Y
//lun:Âß¼-μ¥Ôa±àoÅ,0,SD¿¨;1,SPI FLASH
//buf:êy¾Y′æ′¢Çøê×μØÖ·Ö¸Õë
//blk_addr:òaD′èëμÄμØÖ·(éèÇøμØÖ·)
//blk_len:òaD′èëμÄ¿éêy(éèÇøêy)
//·μ»ØÖμ:0,3é1|;
// ÆäËû,′íÎó′úÂë
int8_t STORAGE_Write (uint8_t lun,uint8_t *buf,uint32_t blk_addr,uint16_t blk_len)
{
int8_t res=0;
USB_STATUS_REG|=0X01;//±ê¼ÇÕyÔúD′êy¾Y
switch(lun)
{
case 2://SPI FLASH
W25QXX_Write(buf,blk_addr*512,blk_len*512);
break;
case 1://NAND FLASH
res=FTL_WriteSectors(buf,blk_addr,512,blk_len);
break;
case 0://SD¿¨
res=SD_WriteDisk(buf,blk_addr,blk_len);
break;
}
if(res)
{
USB_STATUS_REG|=0X04;//D′′íÎó!
}
return res;
}
//»ñè¡Ö§3ÖμÄ×î′óÂß¼-μ¥Ôa¸öêy
//·μ»ØÖμ:Ö§3ÖμÄÂß¼-μ¥Ôa¸öêy-1
int8_t STORAGE_GetMaxLun (void)
{
if(SDCardInfo.CardCapacity)return STORAGE_LUN_NBR-1;
else return STORAGE_LUN_NBR-2;
}[/mw_shl_code]
一周热门 更多>