如题,固件库是3.5的
程序很庞大,我就不全贴出来了
但我处理flash存储的程序是这样的void SaveFlashData()
{
unsigned char FunctionStatusReturn;
unsigned char ReSaveTimes=0;
do
{
ReSaveTimes++;
FunctionStatusReturn=0;
delay_ms(2);
__disable_irq();
UnlockFlash();
FLASH_ErasePage(_USER_MSG_PAGE_ADDr);
FunctionStatusReturn+=SaveFlashChar(pID, pID_Flash_ADDr, 22);
FunctionStatusReturn+=SaveFlashChar(pPass, pPass_Flash_ADDr, 16);
FunctionStatusReturn+=SaveFlashChar(pURL, pURL_Flash_ADDr, pURLlen[0]);
FunctionStatusReturn+=SaveFlashshort(pPort, pPort_Flash_ADDr, 1);
FunctionStatusReturn+=SaveFlashshort(pWeek0, pWeek0_Flash_ADDr, 7);
FunctionStatusReturn+=SaveFlashshort(pWeek1, pWeek1_Flash_ADDr, 7);
FunctionStatusReturn+=SaveFlashshort(pSTimer, pSTimer_Flash_ADDr, 1);
FunctionStatusReturn+=SaveFlashChar(pSwitch, pSwitch_Flash_ADDr, 1);
FunctionStatusReturn+=SaveFlashChar(pWeek0Action, pWeek0Action_Flash_ADDr, 1);
FunctionStatusReturn+=SaveFlashChar(pWeek1Action, pWeek1Action_Flash_ADDr, 1);
FunctionStatusReturn+=SaveFlashChar(pSTimerAction, pSTimerAction_Flash_ADDr, 1);
FunctionStatusReturn+=SaveFlashChar(pURLlen, pURLlen_Flash_ADDr, 1);
FunctionStatusReturn+=SaveFlashChar(&ulSmartConfigSatus, ulSmartConfigSatus_Flash_ADDr, 1);
LockFlash();
__enable_irq();
}while( FunctionStatusReturn!=0 && ReSaveTimes<=3 );
if(ReSaveTimes>3)
{
#ifdef DEBUG_WU
UartSendPacket("SAVE Fail\r\n",11);
UartSendPacketInt(ReSaveTimes,"ReSaveTimes");
#endif
}else
{
#ifdef DEBUG_WU
UartSendPacket("-->SAVE DONE\r\n",11);
#endif
}
}
其中,编程成功则返回0
因为每次重新编程会要先擦出,所以只能批量重写,按理来说编写3次都写不正确这几率也太小了,但我在调试程序的时候,在程序的特定位置出错几率特别高
(也就是软件自动复位,置标志位,然后再main函数中判断flash编程是否完成,在判断复位标志位是否置起,这样便重启系统,就是在这里进行flash编程很容易出错)
if(!(FLASHOperatStatus&FLASH_UPDATA_SAVE))
{
__disable_irq();
//__enable_irq();
NVIC_GenerateSystemReset();
while(1);
}
|