我用STM8S208MB来做升级,在RAM里运行对flash的擦写工作,结果,前面写都是正确的,到了一定地址就写不正确了,不知道是怎么回事,已经弄了2周了,还没有弄好。请各位帮我看看,不然就不用STM8做了,这个项目就正式完蛋了。
传输协议都是自己定制协议,然后调用ST的库函数里的INRAM的那三个函数。
IN_RAM(void FLASH_EraseBlock(uint16_t BlockNum, FLASH_MemType_TypeDef FLASH_MemType));
IN_RAM(void FLASH_ProgramBlock(uint16_t BlockNum, FLASH_MemType_TypeDef FLASH_MemType,
FLASH_ProgramMode_TypeDef FLASH_ProgMode, uint8_t *Buffer));
IN_RAM(FLASH_Status_TypeDef FLASH_WaitForLastOperation(FLASH_MemType_TypeDef FLASH_MemType));
在操作过程中,我具体步骤如下:
解锁Flash,并COPY到RAM中:disableInterrupts();
unlock_PROG();
unlock_DATA();
_fctcpy('F');
MCUUpdateCodeProc();
写Flash的动作:
for(i=0;i<128;i++)
{
FlashBuf = DataBuffer[6+i];
}
FLASH_EraseBlock(blockcnt,FLASH_MEMTYPE_PROG);
FLASH_ProgramBlock(blockcnt,FLASH_MEMTYPE_PROG,FLASH_PROGRAMMODE_STANDARD,FlashBuf);
FLASH_WaitForLastOperation(FLASH_MEMTYPE_PROG);Blockcnt++;
写完以后的动作:
/* Lock program memory */
FLASH->IAPSR = ~0x02;
/* Lock data memory */
FLASH->IAPSR = ~0x08;
跳转到起始位置,相当于重启:
//reset stack pointer (lower byte - because compiler decreases SP with some bytes)
_asm("LDW X, SP ");
_asm("LD A, $FF");
_asm("LD XL, A ");
_asm("LDW SP, X ");
一周热门 更多>