- UID
- 1029342
- 性别
- 男
|
*******************************************************************************void I2C_EE_BufferWrite(u8 DeviceType,u8SlaveAddr,u16 RomAddr,u16 NumByteToWrite,u8 *pRomData)
{
uint32_tparam_flashbase;
uint32_t tempaddress;
uint32_t startaddress;
uint32_t FlashAddress;
uint32_t datasource;
u8 buf1[PAGE_SIZE];
u8 buf2[PAGE_SIZE];
u32 pagenumber = 0x0;
u32 EraseCounter = 0x0;
u32 i = 0;
FLASH_Status FLASHStatus =FLASH_COMPLETE;
param_flashbase= 0x8000000+(300+20)*1024;
startaddress=tempaddress =param_flashbase+RomAddr;
/*********************起始指针不在Flash页的开始端*********************
if( (tempaddress%PAGE_SIZE) != 0)
{ printf("startptr not in Page head \r\n");
if( ((startaddress%PAGE_SIZE)+NumByteToWrite)> PAGE_SIZE ) /*超出一页范围
{
I2C_EE_BufferRead(0,0,(tempaddress-(tempaddress %PAGE_SIZE)),PAGE_SIZE,buf1); /*把起始地址所在页的内容读到内存buf1中
memcpy(buf1+(tempaddress% PAGE_SIZE),pRomData,PAGE_SIZE-(tempaddress %PAGE_SIZE)); /*把需要写入的数据覆盖到buf1中
while( FLASHStatus ==FLASH_ErasePage(tempaddress) ) /*buf1写入到Flash
{
i=PAGE_SIZE/4;
datasource = (uint32_t)buf1;
FlashAddress = tempaddress-(tempaddress %PAGE_SIZE);
while(i-->0)
{
FLASH_ProgramWord(FlashAddress,*(uint32_t*)datasource);
if(*(uint32_t*)FlashAddress !=*(uint32_t*)datasource)
{
printf("I2C_EE_BufferWrite error!\r\n");
return ;
}
datasource += 4;
FlashAddress +=4;
}
break;
} |
|