資源簡介
1.什么是IAP?
英文名:in-application programming。
中文名:應用程序內編程。
作用:對于大多數基于閃存的系統,一個重要的要求是能夠在最終產品中安裝固件時進行更新。
? ? ? ? ? ?STM32微控制器可以運行用戶特定的固件來對微控制器中嵌入的閃存執行IAP。
接口:此功能支持的任何通信接口。
由于不限制通信接口協議等,只要能通過任意通信接口拿到新版固件包數據(bin文件),就能自己升級固件。
這就能做到添加? 外部無線模塊(4G模塊、wifi)做到OTA升級。
也可以使用U盤或TF卡等外部存儲設備做到OTG升級。U盤升級的IAP官方有模板程

代碼片段和文件信息
/*
?*?flash_if.c
?*
?*??Created?on:?Aug?12?2020
?*??????Author:?Sudaroot
?*/
/**?@addtogroup?STM32F4xx_IAP_Main
??*?@{
??*/
/*?Includes?------------------------------------------------------------------*/
#include?“flash_if.h“
/*?Private?typedef?-----------------------------------------------------------*/
/*?Private?define?------------------------------------------------------------*/
/*?Private?macro?-------------------------------------------------------------*/
/*?Private?variables?---------------------------------------------------------*/
/*?Private?function?prototypes?-----------------------------------------------*/
static?uint32_t?GetSector(uint32_t?Address);
/*?Private?functions?---------------------------------------------------------*/
/**
??*?@brief??Unlocks?Flash?for?write?access
??*?@param??None
??*?@retval?None
??*/
void?FLASH_If_Init(void)
{
??HAL_FLASH_Unlock();
??/*?Clear?pending?flags?(if?any)?*/
??__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP?|?FLASH_FLAG_OPERR?|?FLASH_FLAG_WRPERR?|
?????????????????????????FLASH_FLAG_PGAERR?|?FLASH_FLAG_PGPERR?|?FLASH_FLAG_PGSERR);
}
/**
??*?@brief??This?function?does?an?erase?of?all?user?flash?area
??*?@param??StartSector:?start?of?user?flash?area
??*?@retval?0:?user?flash?area?successfully?erased
??*?????????1:?error?occurred
??*/
uint32_t?FLASH_If_Erase(uint32_t?StartSector)
{
??uint32_t?UserStartSector;
??uint32_t?SectorError;
??FLASH_EraseInitTypeDef?pEraseInit;
??/*?Unlock?the?Flash?to?enable?the?flash?control?register?access?*************/
??FLASH_If_Init();
??/*?Get?the?sector?where?start?the?user?flash?area?*/
??UserStartSector?=?GetSector(APPLICATION_ADDRESS);
??pEraseInit.TypeErase?=?TYPEERASE_SECTORS;
??pEraseInit.Sector?=?UserStartSector;
??pEraseInit.NbSectors?=?10;
??pEraseInit.VoltageRange?=?VOLTAGE_RANGE_3;
??if?(HAL_FLASHEx_Erase(&pEraseInit?&SectorError)?!=?HAL_OK)
??{
?????/*?Error?occurred?while?page?erase?*/
?????return?(1);
??}
??return?(0);
}
/**
??*?@brief??This?function?writes?a?data?buffer?in?flash?(data?are?32-bit?aligned).
??*?@note???After?writing?data?buffer?the?flash?content?is?checked.
??*?@param??FlashAddress:?start?address?for?writing?data?buffer
??*?@param??Data:?pointer?on?data?buffer
??*?@param??DataLength:?length?of?data?buffer?(unit?is?32-bit?word)
??*?@retval?0:?Data?successfully?written?to?Flash?memory
??*?????????1:?Error?occurred?while?writing?data?in?Flash?memory
??*?????????2:?Written?Data?in?flash?memory?is?different?from?expected?one
??*/
uint32_t?FLASH_If_Write(uint32_t?FlashAddress?uint32_t*?Data?uint32_t?DataLength)
{
??uint32_t?i?=?0;
??for?(i?=?0;?(i???{
????/*?Device?voltage?range?supposed?to?be?[2.7V?to?3.6V]?the?operation?will
???????be?done?by?word?*/
????if?(HAL_FLASH_Program(TYPEPROGRAM_WORD?FlashAddress?*(uint32_t*)(Data+i))?==?HAL_OK)
????{
?????/*?Check?the?wri
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????26008??2020-08-16?21:52??IAP?Bootloader\.cproject
?????文件???????6889??2020-08-16?21:52??IAP?Bootloader\.mxproject
?????文件???????1387??2020-08-16?21:46??IAP?Bootloader\.project
?????文件???????2372??2020-08-20?23:31??IAP?Bootloader\.settings\language.settings.xm
?????文件???????2495??2020-08-12?14:35??IAP?Bootloader\Core\Inc\flash_if.h
?????文件???????2181??2020-08-16?21:52??IAP?Bootloader\Core\Inc\main.h
?????文件??????20065??2020-08-16?21:52??IAP?Bootloader\Core\Inc\stm32f4xx_hal_conf.h
?????文件???????2106??2020-08-16?21:52??IAP?Bootloader\Core\Inc\stm32f4xx_it.h
?????文件???????6962??2020-08-13?11:11??IAP?Bootloader\Core\Src\flash_if.c
?????文件???????9497??2020-08-16?22:05??IAP?Bootloader\Core\Src\main.c
?????文件???????4096??2020-08-16?21:52??IAP?Bootloader\Core\Src\stm32f4xx_hal_msp.c
?????文件???????5566??2020-08-16?21:52??IAP?Bootloader\Core\Src\stm32f4xx_it.c
?????文件???????2675??2020-08-12?10:44??IAP?Bootloader\Core\Src\syscalls.c
?????文件???????1468??2020-08-12?10:44??IAP?Bootloader\Core\Src\sysmem.c
?????文件??????26457??2020-07-13?23:42??IAP?Bootloader\Core\Src\system_stm32f4xx.c
?????文件??????24986??2020-07-13?23:42??IAP?Bootloader\Core\Startup\startup_stm32f429igtx.s
?????文件????1480591??2020-07-13?23:42??IAP?Bootloader\Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f429xx.h
?????文件???????9485??2020-07-13?23:42??IAP?Bootloader\Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f4xx.h
?????文件???????3796??2020-07-13?23:42??IAP?Bootloader\Drivers\CMSIS\Device\ST\STM32F4xx\Include\system_stm32f4xx.h
?????文件??????28208??2020-07-13?23:43??IAP?Bootloader\Drivers\CMSIS\Include\cmsis_armcc.h
?????文件??????56497??2020-07-13?23:43??IAP?Bootloader\Drivers\CMSIS\Include\cmsis_armclang.h
?????文件???????9014??2020-07-13?23:43??IAP?Bootloader\Drivers\CMSIS\Include\cmsis_compiler.h
?????文件??????62344??2020-07-13?23:43??IAP?Bootloader\Drivers\CMSIS\Include\cmsis_gcc.h
?????文件??????28414??2020-07-13?23:43??IAP?Bootloader\Drivers\CMSIS\Include\cmsis_iccarm.h
?????文件???????1716??2020-07-13?23:43??IAP?Bootloader\Drivers\CMSIS\Include\cmsis_version.h
?????文件??????97995??2020-07-13?23:43??IAP?Bootloader\Drivers\CMSIS\Include\core_armv8mbl.h
?????文件?????168914??2020-07-13?23:43??IAP?Bootloader\Drivers\CMSIS\Include\core_armv8mml.h
?????文件??????42208??2020-07-13?23:43??IAP?Bootloader\Drivers\CMSIS\Include\core_cm0.h
?????文件??????50464??2020-07-13?23:43??IAP?Bootloader\Drivers\CMSIS\Include\core_cm0plus.h
?????文件??????43456??2020-07-13?23:43??IAP?Bootloader\Drivers\CMSIS\Include\core_cm1.h
............此處省略171個文件信息
評論
共有 條評論