IAR环境stm32f030 IAP升级:
IAP核心代码:
#if(FLASH_PAGE_SIZE == 0X400U) #define FLASH_SIZE (256 * FLASH_PAGE_SIZE) #define BOOT_AREA_SIZE (12 * FLASH_PAGE_SIZE) #define TAG_AREA_SIZE (2 * FLASH_PAGE_SIZE) #define APP1_AREA_SIZE ((FLASH_SIZE -BOOT_AREA_SIZE-TAG_AREA_SIZE)/2) // must mod == 0 #define APP2_AREA_SIZE APP1_AREA_SIZE #endif #if(FLASH_PAGE_SIZE == 0x800U) #define FLASH_SIZE (128 * FLASH_PAGE_SIZE) #define BOOT_AREA_SIZE (7 * FLASH_PAGE_SIZE) #define TAG_AREA_SIZE (1 * FLASH_PAGE_SIZE) #define APP1_AREA_SIZE ((FLASH_SIZE -BOOT_AREA_SIZE-TAG_AREA_SIZE)/2) // must mod == 0 #define APP2_AREA_SIZE APP1_AREA_SIZE #endif #define BASE_ADDRESS 0x08000000 #define TAG_ADDRESS (BOOT_AREA_SIZE + APP1_AREA_SIZE + APP2_AREA_SIZE + BASE_ADDRESS) #define APP1_IMG_BEG_ADDRESS (BOOT_AREA_SIZE + BASE_ADDRESS) #define APP2_IMG_BEG_ADDRESS (BOOT_AREA_SIZE + APP1_AREA_SIZE + BASE_ADDRESS) typedef void ( *jump ) ( void ); void Restart ( void ) { jump reboot; __set_MSP ( * ( volatile uint32_t * ) 0x08000000 ); reboot = ( jump ) * ( volatile uint32_t * ) 0x08000004; reboot(); } void AppJump ( void ) { jump appjump; __set_MSP ( * ( volatile uint32_t* ) APP1_IMG_BEG_ADDRESS ); appjump = ( jump ) * ( volatile uint32_t * ) ( APP1_IMG_BEG_ADDRESS + 4 ); appjump(); }
工程配置按照正常工程配置即可;
APP端核心代码:
#if(FLASH_PAGE_SIZE == 0X400U) #define FLASH_SIZE (256 * FLASH_PAGE_SIZE) // only support even page #define BOOT_AREA_SIZE (12 * FLASH_PAGE_SIZE) // only support even page #define TAG_AREA_SIZE (2 * FLASH_PAGE_SIZE) // only support even page #define APP1_AREA_SIZE ((FLASH_SIZE -BOOT_AREA_SIZE-TAG_AREA_SIZE)/2) // must mod == 0 #define APP2_AREA_SIZE APP1_AREA_SIZE #endif #if(FLASH_PAGE_SIZE == 0x800U) #define FLASH_SIZE (128 * FLASH_PAGE_SIZE) #define BOOT_AREA_SIZE (7 * FLASH_PAGE_SIZE) #define TAG_AREA_SIZE (1 * FLASH_PAGE_SIZE) #define APP1_AREA_SIZE ((FLASH_SIZE -BOOT_AREA_SIZE-TAG_AREA_SIZE)/2) // must mod == 0 #define APP2_AREA_SIZE APP1_AREA_SIZE #endif #define BASE_ADDRESS 0x08000000 #define TAG_ADDRESS (BOOT_AREA_SIZE + APP1_AREA_SIZE + APP2_AREA_SIZE + BASE_ADDRESS) #define APP1_IMG_BEG_ADDRESS (BOOT_AREA_SIZE + BASE_ADDRESS) #define APP2_IMG_BEG_ADDRESS (BOOT_AREA_SIZE + APP1_AREA_SIZE + BASE_ADDRESS) #if (defined ( __CC_ARM )) volatile uint32_t VectorTable[48] __attribute__ ( ( at ( 0x20000000 ) ) ); #elif (defined (__ICCARM__)) #pragma location = 0x20000000 __no_init volatile uint32_t VectorTable[48]; #elif defined ( __GNUC__ ) volatile uint32_t VectorTable[48] __attribute__ ( ( section ( ".RAMVectorTable" ) ) ); #elif defined ( __TASKING__ ) volatile uint32_t VectorTable[48] __at ( 0x20000000 ); #endif void VectorTableRemap ( void ) { uint32_t i = 0; /* Relocate by software the vector table to the internal SRAM at 0x20000000 ***/ /* Copy the vector table from the Flash (mapped at the base of the application load address APP_IMAG_LOCATION) to the base address of the SRAM at 0x20000000. */ for ( i = 0; i < 48; i++ ) { VectorTable[i] = * ( volatile uint32_t* ) ( APP1_IMG_BEG_ADDRESS + ( i << 2 ) ); // VectorTable[i] = * ( volatile uint32_t* ) ( 0x08000000 + ( i << 2 ) ); } /* Enable the SYSCFG peripheral clock*/ __HAL_RCC_SYSCFG_CLK_ENABLE(); /* Remap SRAM at 0x00000000 */ __HAL_SYSCFG_REMAPMEMORY_SRAM(); }
将此函数放到main函数最开头即可,然后将中断向量表起始地址改为APP1_IMG_BEG_ADDRESS ,ram起始地址改为0x200000C0,如下图所示:
至此,IAP功能便配置成功,详细原理可以参考如下链接: