IAP之boot实现
生活随笔
收集整理的這篇文章主要介紹了
IAP之boot实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
flash基本規劃
為實現IAP升級,一般將flash規劃成如上區域。
bootloader: 系統引導
app: 主程序運行的地方
update: 新的主程序固件存放的地方
這里給bootloader預留16K的空間,所以APP所在地址是0x08004000,編譯APP時,要注意將中斷向量表的偏移地址設置為0x4000
bootloader要完成的功能
根據以上描述,bootloader應有以下功能
bootloader實現
根據上節分析,實現bootloader要有如下工作:
- 根據ST官方例程實現的flash操作接口:
擦除操作
寫flash
#define UPDATE_APP_ADDRESS (uint32_t)0x0802C000 /* ADDR_FLASH_PAGE_88 */ #define APP_ADDRESS (uint32_t)0x08004000 uint32_t FLASH_If_Write(uint32_t destination, uint32_t *p_source, uint32_t length) {uint32_t i = 0;/* Unlock the Flash to enable the flash control register access *************/HAL_FLASH_Unlock();for (i = 0; (i < length) && (destination <= (USER_FLASH_END_ADDRESS-4)); i++){/* Device voltage range supposed to be [2.7V to 3.6V], the operation willbe done by word */ if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, destination, *(uint32_t*)(p_source+i)) == HAL_OK) {/* Check the written value */if (*(uint32_t*)destination != *(uint32_t*)(p_source+i)){/* Flash content doesn't match SRAM content */return(FLASHIF_WRITINGCTRL_ERROR);}/* Increment FLASH destination address */destination += 4;}else{/* Error occurred while writing data in Flash memory */return (FLASHIF_WRITING_ERROR);}}/* Lock the Flash to disable the flash control register access (recommendedto protect the FLASH memory against possible unwanted operation) *********/HAL_FLASH_Lock();return (FLASHIF_OK); }- 固件轉移
- 程序跳轉
- main.c
bool就完成了 IAP參考這里
總結
以上是生活随笔為你收集整理的IAP之boot实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 山东大学项目实训(二十七)—— 微信小程
- 下一篇: 小米笔试题 风口的猪-中国牛市