/*---------------------------------------------------------------
1k=0x400
10k=0x2800
不同容量的CPU对应的EndAddr
64k:EndAddr=0x08010000
128k:EndAddr=0x08020000
256k:EndAddr=0x08040000
512k:EndAddr=0x08080000
u32 vw_p[10]= {1,3,5,7,9,2,4,6,8,10};
u32 StartAddr=((u32)EndAddr-UserFlashSize);
int i;
Flash_write(vw_p,10);
for (i=0;i<10;i++)
{
USART_OUT(USART1,"%d",Flash_Read(i)); //读取方法
}
*/
u32 Address=0;
volatile FLASH_Status FLASHStatus;
/*****************************写Flash函数*****************************
src :待写入的数据起始地址
size:数据长度
*/
void Flash_write(unsigned int *src,u32 size)
{
u32 i=0;
RCC_HSICmd(ENABLE);
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
FLASHStatus = FLASH_ErasePage(StartAddr);
Address = StartAddr;
if(FLASHStatus == FLASH_COMPLETE)
{
while(i<size)
{
FLASHStatus = FLASH_ProgramWord(Address, *(src+i));
Address+=4;
i++;
}
}
FLASH_Lock();
}
/*****************************读Flash函数*****************************
rdadr :数据偏移地址
*/
u8 Flash_Read(u32 rdadr)
{
return(*(u8*)(StartAddr + rdadr*4));
}