STM32 USB-Host-Device_Lib_V2.1.0 SPIflash 无法格式化问题

折腾了几天,终于搞定了无法格式化的问题,原来是blk_len快数量的问题,

int8_t STORAGE_Write (uint8_t lun, //逻辑单元号
                  uint8_t *buf, //指向缓冲区
                  uint32_t blk_addr,//块地址
                  uint16_t blk_len)//块数量

这里的块地址和数量都是以字节为单位的。

block_size =  4096;XP下不能格式化,但可以快速格式化,win8下都可以
block_size =  512;都可以格式化了

 

usbd_storage_msd.c

/**
  * @brief  return medium capacity and block size
  * @param  lun : logical unit number
  * @param  block_num :  number of physical block
  * @param  block_size : size of a physical block
  * @retval Status
  */
int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_size)
{
  *block_size =  512;  //块大小
  *block_num =  4096;  //快数量
  return (0);
}

/**
  * @brief  check whether the medium is ready
  * @param  lun : logical unit number
  * @retval Status
  */
int8_t  STORAGE_IsReady (uint8_t lun)
{
  return (0);
}

/**
  * @brief  check whether the medium is write-protected
  * @param  lun : logical unit number
  * @retval Status
  */
//写保护
int8_t  STORAGE_IsWriteProtected (uint8_t lun)
{
  return  0;
}

/**
  * @brief  Read data from the medium
  * @param  lun : logical unit number
  * @param  buf : Pointer to the buffer to save data
  * @param  blk_addr :  address of 1st block to be read
  * @param  blk_len : nmber of blocks to be read
  * @retval Status
  */
int8_t STORAGE_Read (uint8_t lun, 
                 uint8_t *buf, 
                 uint32_t blk_addr,                       
                 uint16_t blk_len)
{
  
  SPI_Flash_Read((u8*)buf, blk_addr* 512, blk_len* 512);
  //DebugPrintf("读取地址\r\n",4,(u8 *)&blk_addr);
  //DebugPrintf("读取数据\r\n",blk_len,buf);
  return 0;
}
/**
  * @brief  Write data to the medium
  * @param  lun : logical unit number
  * @param  buf : Pointer to the buffer to write from
  * @param  blk_addr :  address of 1st block to be written
  * @param  blk_len : nmber of blocks to be read
  * @retval Status
  */
int8_t STORAGE_Write (uint8_t lun, //逻辑单元号
                  uint8_t *buf, //指向缓冲区
                  uint32_t blk_addr,//块地址
                  uint16_t blk_len)
{
  SPI_Flash_Write((u8*)buf, blk_addr* 512, blk_len* 512);
  //DebugPrintf("写入地址\r\n",4,(u8 *)blk_addr);
  //DebugPrintf("写入数据\r\n",blk_len,buf);
  return (0);
}

/**
  * @brief  Return number of supported logical unit
  * @param  None
  * @retval number of logical unit
  */

int8_t STORAGE_GetMaxLun (void)
{
  return (STORAGE_LUN_NBR - 1);
}

 

posted @ 2014-01-15 13:47  阿林阿林  阅读(1034)  评论(0)    收藏  举报