@@香水城
这个写Flash,只有擦除后第一次可以写(就是能把初始值成功写入),后面在程序里调用就失败,帮忙看看怎么解决?谢谢
u8bit write_para_to_flash(u16bit wVal, u8bit bType)
{
FLASH_Status temp_stat;
u32bit temp_addr = BASE_ADD;
FLASH_Unlock(); // Flash½âËø£¬ÔÊÐí²Ù×÷Ïà¹ØµÄ¼Ä´æÆ÷
temp_addr = temp_addr + (bType << 4);
temp_stat = FLASH_ProgramHalfWord(temp_addr,wVal);
FLASH_Lock();
if(temp_stat != FLASH_COMPLETE)
return FALSE;
else
{
wParaArray[bType] = wVal;
return TRUE;
}
}
void mem_init(void)
{
u8bit bIndex;
for(bIndex = 0; bIndex < MAX_PARA_NUM; bIndex++)
{
wParaArray[bIndex] = get_para_from_flash(bIndex);
}
if(wParaArray[MEM_WRITTEN] != WRITE_VAL)
{
wParaArray[BaudOffset] = DEFAULT_BAUD;
wParaArray[NEG_Offset] = DEFAULT_NEG_VAL;
wParaArray[POS_Offset] = DEFAULT_POS_VAL;
wParaArray[MEM_WRITTEN] = WRITE_VAL;
for(bIndex = 0; bIndex < MAX_PARA_NUM; bIndex++)
{
write_para_to_flash(wParaArray[bIndex], bIndex);
}
}
}
|