本帖最后由 kxing91 于 2017-2-17 16:33 编辑
第一步:设置flash地址,我分了三个区,BOOT区(8000-8FFF),APP区(9000-C7FF),COPY区(C800-FFFF)在lnkstm8l052c6.icf文件中修改
define region NearFuncCode = [from 0x9000 to 0xC7FF];
define region FarFuncCode = [from 0x9000 to 0xC7FF];
define region HugeFuncCode = [from 0x9000 to 0xC7FF];
第二步:中断向量表重定向
__root const long reintvec[]@".intvec"= //中断向量表重定向
{ 0x82008080,0x82009004,0x82009008,0x8200900c, //当应用程序地址不是0x9000时则要相应改掉除第一个0x82008080以外的数值
0x82009010,0x82009014,0x82009018,0x8200901c,
0x82009020,0x82009024,0x82009028,0x8200902c,
0x82009030,0x82009034,0x82009038,0x8200903c,
0x82009040,0x82009044,0x82009048,0x8200904c,
0x82009050,0x82009054,0x82009058,0x8200905c,
0x82009060,0x82009064,0x82009068,0x8200906c,
0x82009070,0x82009074,0x82009078,0x8200907c,
};
第三步:flash的擦写:
void FLASH_WriteDat_OnePage(u8 *GBuffer, u8 Page)
{
FLASH_Unlock(FLASH_MemType_Program);
while (FLASH_GetFlagStatus(FLASH_FLAG_PUL) == RESET);
FLASH_EraseBlock(Page, FLASH_MemType_Program);
while (FLASH_GetFlagStatus(FLASH_FLAG_HVOFF) == RESET);
FLASH_ProgramBlock(Page, FLASH_MemType_Program, FLASH_ProgramMode_Standard, GBuffer);
while (FLASH_GetFlagStatus(FLASH_FLAG_HVOFF) == RESET);
FLASH_Lock(FLASH_MemType_Program);
}
升级流程:收到主机升级指令-->判断是否升级(版本号)-->获取升级包大小-->在APP中将升级包存储到COPY区-->计算判断CRC-->复位进入BOOT-->将COPY区的数据复制到APP区-->跳转。
|