#ifndef  _SOFT_FLASH_
#define  _SOFT_FLASH_

#include "stdbool.h"
#include "stm32f4xx_hal.h"



/*内存分配
  stm32f405rgt6 12个扇区  4个16kb,1个64kb,7个128kb  一页2kb
  bootloader: 0 - 32kb 0x8000000 - 0x80008000
  升级标志位： 32kb 0x80008000
  参数信息: 48kb - 64kb 0x800C0000 - 0x80100000
  APP：    64kb - 1024kb 0x80100000 - 0x81000000    128kb 地址 0x8020000  //给EFT测试 更改3处
*/

//升级标志位
#define FLASH_UPDATE_ADDR (uint32_t)0x8008000
//参数信息
#define FLASH_PAR_ADDR (uint32_t)0x800C000
//APP
#define FLASH_APP_ADDR (uint32_t)0x8020000
//STM32F405 芯片ID地址
#define FLASH_ID_ADDR (uint32_t)0x1FFF7A10

#define PAR_FALG  0xABCD

extern bool write_flash_flag;

#pragma pack(1)
typedef struct 
{
    uint16_t flash_flag;

    int pmu_serial; //PMU序列号
    int uavtype;    //机型
    int abnormal_outage_flag; //异常断电标志
    int voltage;    //电压校准
    int chip_passid;    //芯片ID加密码
}flash_data;
#pragma pack()
extern flash_data stor_par;
extern flash_data cur_par;

extern bool Check_Chip_Verified;
void ReadFlashNBtye(uint32_t ReadAddress, uint8_t *pdata, uint16_t size);

HAL_StatusTypeDef WriteFlashNBtye(uint32_t ReadAddress, uint8_t *pdata, uint16_t size);

void write_flash_function(void);
void flash_init(void);
int GetSectorFromAddress(uint32_t address);
#endif
