学前班
最后登录1970-1-1
在线时间 小时
注册时间2019-6-6
|
本帖最后由 rt_sye 于 2019-6-7 18:31 编辑
在野火F429例程---外部FLASH模拟U盘的基础上,将usbd_storage_msd.c文件中的底层驱动从外部FLASH替换成SD卡,但一直不被电脑识别,不知道有没有大侠遇到过类似问题,望指点一二,不胜感激!说明:
1、SD卡的底层驱动是从野火F429例程---SDIO-SD卡读写测试中拷贝过来的;
2、烧写野火F429例程---SDIO-SD卡读写测试后,初始化、擦除和测试全部成功;
附上usbd_storage_msd.c文件代码如下:
const int8_t STORAGE_Inquirydata[] = {//36
/* LUN 0 */
0x00,
0x80,
0x02,
0x02,
(USBD_STD_INQUIRY_LENGTH - 5),
0x00,
0x00,
0x00,
'W', 'F', ' ', ' ', ' ', ' ', ' ', ' ', /* Manufacturer : 8 bytes */
'S', 'P', 'I', ' ', 'F', 'l', 'a', 's', /* Product : 16 Bytes */
'h', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
'1', '.', '0' ,'0', /* Version : 4 Bytes */
};
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);
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;
extern SD_CardInfo SDCardInfo;
__IO uint32_t count = 0;
int8_t STORAGE_Init (uint8_t lun)
{
return SD_Init();//SPI_FLASH_Init();
}
int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_size)
{
*block_size=512;
*block_num=SDCardInfo.CardCapacity/512;
return (0);
}
int8_t STORAGE_IsReady (uint8_t lun)
{
return 0;//GET_SPIFLASH_STATE();
}
/**
* @brief check whether the medium is write-protected
* @param lun : logical unit number
* @retval Status
*/
int8_t STORAGE_IsWriteProtected (uint8_t lun)
{
return 0;
}
int8_t STORAGE_Read (uint8_t lun,
uint8_t *buf,
uint32_t blk_addr,
uint16_t blk_len)
{
if( SD_ReadMultiBlocks (buf,
blk_addr * 512,
512,
blk_len) != 0)
{
return -1;
}
#ifndef USE_STM3210C_EVAL
SD_WaitReadOperation();
while (SD_GetStatus() != SD_TRANSFER_OK);
#endif
return 0;
}
int8_t STORAGE_Write (uint8_t lun,
uint8_t *buf,
uint32_t blk_addr,
uint16_t blk_len)
{
if( SD_WriteMultiBlocks (buf,
blk_addr * 512,
512,
blk_len) != 0)
{
return -1;
}
#ifndef USE_STM3210C_EVAL
SD_WaitWriteOperation();
while (SD_GetStatus() != SD_TRANSFER_OK);
#endif
return (0);
}
int8_t STORAGE_GetMaxLun (void)
{
return (STORAGE_LUN_NBR - 1);
}
|
|