今天升级完发现跳转不了,然后用JLINK读取发现APP区域前1K也就是0X400的空间是空的,而后面的都能和正常APP大小对应,所以看是哪里多擦了一块
FLASH_Status CAN_BOOT_ErasePage(uint32_t StartPageAddr,uint32_t EndPageAddr)
{
uint32_t i;
FLASH_Status FLASHStatus = FLASH_COMPLETE;
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
for(i = StartPageAddr;i <= EndPageAddr;i += PAGE_SIZE){
FLASHStatus = FLASH_ErasePage(i);
if(FLASHStatus!=FLASH_COMPLETE){
FLASH_Lock();
return FLASHStatus;
}
}
FLASH_Lock();
return FLASHStatus;
}
#if defined (STM32F10X_MD) || defined (STM32F10X_MD_VL)
#define PAGE_SIZE (0x400) /* 1 Kbyte */
#define FLASH_SIZE (0x20000) /* 128 KBytes */
#elif defined STM32F10X_CL
#define PAGE_SIZE (0x800) /* 2 Kbytes */
#define FLASH_SIZE (0x40000) /* 256 KBytes */
#elif defined STM32F10X_HD
#define PAGE_SIZE (0x800) /* 2 Kbytes */
#define FLASH_SIZE (0x80000) /* 512 KBytes */
#elif defined STM32F10X_XL
#define PAGE_SIZE (0x800) /* 2 Kbytes */
#define FLASH_SIZE (0x100000) /* 1 MByte */
#else
#error "Please select first the STM32 device to be used (in stm32f10x.h)"
#endif
结果发现芯片与前芯片不一样,之前页大小是1KB,现在是2KB,而自定义的校验空间只有1KB,所以擦校验空间FLASH多擦了1KB,于是扩大校验地址到2KB,APP区域后移1KB就好了