/*
* flash.c
*
* Created on: 4 <EFBFBD><EFBFBD><EFBFBD>. 2021 <EFBFBD>.
* Author: Toporov
*/
#include "my.h"
#include "flash.h"
#include "stm32f4xx_hal_flash.h"
#include "stm32f4xx_hal_flash_ex.h"
static FLASH_EraseInitTypeDef FlashEraseInit;
__IO extern UserData_TypeDef currentData;
__IO uint16_t COUNT_EXT = 0;
void MX_FLASH_Init(void)
{
__HAL_RCC_SYSCFG_CLK_ENABLE();
FlashEraseInit.TypeErase = FLASH_TYPEERASE_SECTORS;
FlashEraseInit.Banks = FLASH_BANK_1;
FlashEraseInit.Sector = FLASH_SECTOR_7;
FlashEraseInit.NbSectors = 1;
FlashEraseInit.VoltageRange = FLASH_VOLTAGE_RANGE_3;
rdPar();
}
void wrPar(void)
__IO uint32_t Address, lenpar, i;
__IO uint32_t *pData;
uint32_t SECTORError = 0;
lenpar = sizeof(UserData_TypeDef);
while(lenpar % 4) {
lenpar++;
lenpar >>= 2;
HAL_FLASH_Unlock();
if(HAL_FLASHEx_Erase(&FlashEraseInit, &SECTORError) == HAL_OK)
Address = USERPAGE;
pData = (uint32_t *) ¤tData;
for(i = 0; i < lenpar; i++)
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, *pData++);
Address += 4;
HAL_FLASH_Lock();
void rdPar(void)
uint8_t i;
uint32_t lenpar;
volatile bool rewrite = false;
memcpy((void *) ¤tData, (void *) USERPAGE, lenpar);
//pardata.OWN = 0xffff;//todo
if(currentData.OWN == 0xffff)
currentData.OWN = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
currentData.BAUD = 5;
currentData.INFB = 1;
currentData.IIN = CHARGE;
currentData.IFV = Hp0_1;
currentData.IFN = Lp100000;
currentData.IKU = Ku1;
currentData.IK0 = 1;
currentData.IK1 = 0;
currentData.IK2 = 0;
currentData.IK3 = 0;
currentData.IK4 = 0;
currentData.IPZ =0;
currentData.KCOND = 1.0f;
currentData.SENS = 1.0f;
rewrite = true;
////////////////////
if(rewrite)
rewrite = false;
wrPar();