大学生
最后登录1970-1-1
在线时间 小时
注册时间2018-1-8
|
小弟在用STM32F429IGT6核心板内部flash模拟U盘,在官方例程“USB—外部FLASH模拟U盘”基础上修改,部分修改的代码如下,请各位大神指点下,谢谢!!!代码只是修改了“usbd_storage_msd.c”文件下的部分,是不是其他文件也有要修改的,我没修改啊???
#include "usbd_msc_mem.h"
#include "usb_conf.h"
#include "./bsp/flash/bsp_spi_flash.h"
#define FLASH_START_ADDR 0x08020000 // Flash start address
#define FLASH_SIZE 7 //7个扇区
#define FLASH_PAGE_SIZE 0x20000 // 128Kbytes每个扇区
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,
uint32_t blk_len);
int8_t STORAGE_Write (uint8_t lun,
uint8_t *buf,
uint32_t blk_addr,
uint32_t blk_len);
int8_t STORAGE_GetMaxLun (void);
int8_t STORAGE_Init (uint8_t lun)
{
//return SPI_FLASH_Init();
FLASH_Unlock();
return 0;
}
int8_t STORAGE_GetCapacity (uint8_t lun, uint32_t *block_num, uint32_t *block_size)
{
*block_size = 0x20000; //flashÿ¸öéèÇø128Kbytes
*block_num = 7; //×ü127¸öéèÇø
return (0);
}
int8_t STORAGE_Read (uint8_t lun,
uint8_t *buf,
uint32_t blk_addr,
uint32_t blk_len)
{
uint32_t i;
if(lun==0)
{
for(i=0;i<blk_len;i+=4)
{
buf=*((vu32*)(FLASH_START_ADDR + blk_addr));
buf[i+1]=(*((vu32*)(FLASH_START_ADDR + blk_addr)))>>8;
buf[i+2]=(*((vu32*)(FLASH_START_ADDR + blk_addr)))>>16;
buf[i+3]=(*((vu32*)(FLASH_START_ADDR + blk_addr)))>>24;
}
return 0;
}
return 1;
//blk_addr+=1536;
//SPI_FLASH_BufferRead((uint8_t *)buf, blk_addr<<12, blk_len<<12);
}
int8_t STORAGE_Write (uint8_t lun,
uint8_t *buf,
uint32_t blk_addr,
uint32_t blk_len)
{
uint32_t i;
uint32_t pbuff;
if(lun==0)
{
for(i=0; i<blk_len;i+=FLASH_PAGE_SIZE)
{
if(FLASH_WaitForLastOperation()==FLASH_COMPLETE)
{
FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR);
}
FLASH_EraseSector(FLASH_START_ADDR + blk_addr + i,VoltageRange_3);
}
for(i=0;i<blk_len;i+=4)
{
if(FLASH_WaitForLastOperation()==FLASH_COMPLETE)
{
FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR);
}
pbuff=((uint32_t)buf[i+3]<<24)+((uint32_t)buf[i+2]<<16)+((uint32_t)buf[i+1]<<8)+((uint32_t)buf[i+1]);
FLASH_ProgramWord(FLASH_START_ADDR + blk_addr + i, pbuff);
}
return (0);
}
return 1;
//blk_addr+=1536;
//SPI_FLASH_SectorErase(blk_addr<<12);
//SPI_FLASH_BufferWrite((uint8_t *)buf,blk_addr<< 12,blk_len<<12);
}
|
|