void FLASH_Configuration()
{
u16 i;
u16 *p=(u16 *)0x08000000+0x400*(SECTOR-1);
RCC_HSICmd(ENABLE);
FLASH_ClearFlag(FLASH_FLAG_BSY|FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR);
FLASH_Unlock();
while(FLASH_WaitForLastOperation(5)==FLASH_BUSY);
FLASH_ClearFlag(FLASH_FLAG_BSY|FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR);
FLASH_ITConfig(FLASH_IT_ERROR,ENABLE);
while(FLASH_WaitForLastOperation(5)==FLASH_BUSY);
FLASH_ClearFlag(FLASH_FLAG_BSY|FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR);
printf("%d ",FLASH_ErasePage(0x08000000+0x400*(SECTOR-1)));
while(FLASH_WaitForLastOperation(200)==FLASH_BUSY);
FLASH_ClearFlag(FLASH_FLAG_BSY|FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR);
for(i=0;i<LARGE;i++)
{
printf("%d ",FLASH_ProgramHalfWord(0x08000000+0x400*(SECTOR-1)+i*2,i+1));
while(FLASH_WaitForLastOperation(200)==FLASH_BUSY);
FLASH_ClearFlag(FLASH_FLAG_BSY|FLASH_FLAG_EOP|FLASH_FLAG_PGERR|FLASH_FLAG_WRPRTERR);
printf("%d ",*(u16 *)(p+i*2));
}
FLASH_Lock();
}
经过本函数的初始化之后(其中SECTOR=10),flash里面的数值没有改变,依旧是0xffff。如果数据写进flash的代码区里,却会报错。求告知怎么回事? |