optical/NxFuncs/stiap/stiap.h
2025-09-04 09:45:08 +08:00

117 lines
3.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef __STIAP_H__
#define __STIAP_H__
#include "config.h"
#include "stflash.h"
#include "stapp.h"
#if (APP_SAVE_TO == APP_SAVE_NORFLASH)
#include "norflash.h"
#elif (APP_SAVE_TO == APP_SAVE_EXRAM)
#include "corefmc.h"
#endif
//-------------------------------------------------------------------------------
/*
iap 控制程序
通过 bootloader 编程 app 区域
支持 接收升级数据到 norflash exram st-flash 然后写入app区域
*/
#if (APP_SAVE_TO == APP_SAVE_NORFLASH)
#define NOR_SAVE_BASE (SNF_UPDATE_BEGIN) // NORflash中存放IAP数据的基地址 = 32MB-512KB
#define NOR_SAVE_SIZE (SNF_UPDATE_SIZE) // NORflash中存放IAP数据区域大小
#define NOR_SAVE_END (NOR_SAVE_BASE+NOR_SAVE_SIZE)
#define NOR_MARK_ADDR (NOR_SAVE_BASE) // NORflash中存放升级标志地址长度1K
#define NOR_APP_ADDR (NOR_SAVE_BASE+STM32_BOOT_SIZE) // 存放在NORflash中应用程序起始地址
#define MASK_BUF_LEN 0x80
#define APP_SAVE_BASE NOR_SAVE_BASE
#define APP_ADDR_BEG NOR_APP_ADDR
#define APP_MARK_ADDR NOR_MARK_ADDR
#elif (APP_SAVE_TO == APP_SAVE_EXRAM)
#define EXRAM_SAVE_BASE CORE_SDRAM2_ADDR_BEG //
#define EXRAM_APP_ADDR (EXRAM_SAVE_BASE + STM32_BOOT_SIZE) // APP 数据起始地址
#define TMP_SEC_ADDR EXRAM_SAVE_BASE // 临时数据存储地址
#define MAX_TMP_SIZE (STM32_BOOT_SIZE) // STM32_BOOT_SIZE
#define EXRAM_MARK_ADDR TMP_SEC_ADDR
#define MASK_BUF_LEN 0x80
#define APP_SAVE_BASE EXRAM_SAVE_BASE
#define APP_ADDR_BEG EXRAM_APP_ADDR
#define APP_MARK_ADDR EXRAM_MARK_ADDR
#elif (APP_SAVE_TO == APP_SAVE_INFLASH)
#define INFLASH_SAVE_BASE STF_UPDATE_BEGIN
#define INFLASH_MARK_ADDR INFLASH_SAVE_BASE
#define INFLASH_APP_ADDR (INFLASH_SAVE_BASE+MARK_SIZE)
#define MASK_BUF_LEN 0x80
#define APP_SAVE_BASE INFLASH_SAVE_BASE
#define APP_ADDR_BEG INFLASH_APP_ADDR
#define APP_MARK_ADDR INFLASH_MARK_ADDR
#else
#define MASK_BUF_LEN 0x80
#define APP_SAVE_BASE 0
#define APP_ADDR_BEG 0
#define APP_MARK_ADDR 0
#endif
//--------------------------------------------------------------------
#define IAPHEAD_LEN (1*1024)
//--------------------------------------------------------------------
#define STM32_MARK "APP_CAN_UPDATE" // 关键字
#define APP_RIGHT "APP_FILE_RIGHT"
typedef struct
{
char upmask[MASK_BUF_LEN];
u32 rdaddr; // 数据读取偏移地址
u32 wraddr; // 数据写入偏移地址
u32 size; // 数据长度(字节数)
u32 wsize; // 写入长度
u32 appcheck; // app 数据的校验字
u8 rev[IAPHEAD_LEN - MASK_BUF_LEN - 4*5 - 4];
u32 checkcrc; // 校验
} __attribute__ ((packed)) IapHead;
//--------------------------------------------------------------------
//bootloader 接口函数
int UpdateApp(void); // 升级主控文件
int JumpToApp(void); // 执行flash里面的app程序
//主控 接口函数
void IAPCleanUpdateArea(void); // 擦除升级区域norflash的块
void IapWritePara(u32 rdAddr, u32 wrAddr, u32 len, u32 wlen, u32 check); // 写入升级起始地址和长度和升级标志
void IapRestartMcu(void); // STM32软件复位
void CloseAllPeripheral(void);
//--------------------------------------------------------------------
//--------------------------------------------------------------------
#endif