野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 16507|回复: 1

F429 SD卡模拟U盘失败 求助

[复制链接]
发表于 2019-6-7 18:31:40 | 显示全部楼层 |阅读模式
本帖最后由 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);
}



回复

使用道具 举报

发表于 2019-6-9 16:10:37 | 显示全部楼层
帮顶
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2025-12-7 05:41 , Processed in 0.045188 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表