用的官方例程SRAM模拟U盘,官方的每次插拔不会掉格式,我改的外部flash,不清楚为什么每次插拔都要重新格式化,但是格式化后又能正常往里面放文件,读文件都是正常的
#define STORAGE_BLK_NBR 512
#define STORAGE_BLK_SIZ 4096
static int8_t STORAGE_Read (uint8_t Lun,
uint8_t *buf,
uint32_t BlkAddr,
uint16_t BlkLen)
{
spi_flash_buffer_read(buf,BlkAddr*STORAGE_BLK_SIZ,BlkLen*STORAGE_BLK_SIZ);
return 0;
}
/*!
\brief write data to the medium
\param[in] Lun: logical unit number
\param[in] buf: pointer to the buffer to write
\param[in] BlkAddr: address of 1st block to be written
\param[in] BlkLen: number of blocks to be write
\param[out] none
\retval status
*/
static int8_t STORAGE_Write (uint8_t Lun,
uint8_t *buf,
uint32_t BlkAddr,
uint16_t BlkLen)
{
//spi_flash_sector_erase(BlkAddr*STORAGE_BLK_SIZ);
W25QXX_Write(buf, BlkAddr*STORAGE_BLK_SIZ, BlkLen*STORAGE_BLK_SIZ);
return 0;
}
并且我给2M,格式化前2M,格式化后变1.98了
|