2023-09-25 13:12:41 +03:00
|
|
|
|
/*
|
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
|
|
|
2023-10-24 16:48:53 +03:00
|
|
|
|
//<2F> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD> <20><> 128<32>, <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|
|
|
|
|
|
|
|
|
static FLASH_EraseInitTypeDef FlashEraseInitPar; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
static FLASH_EraseInitTypeDef FlashEraseInitCor; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
2023-10-11 17:28:58 +03:00
|
|
|
|
__IO extern UserData_TypeDef currentData;
|
2023-09-25 13:12:41 +03:00
|
|
|
|
|
2023-10-24 16:48:53 +03:00
|
|
|
|
__IO extern uint16_t correctedKu[13]; // <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 13:12:41 +03:00
|
|
|
|
__IO uint16_t COUNT_EXT = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MX_FLASH_Init(void)
|
|
|
|
|
{
|
|
|
|
|
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
|
|
|
|
|
2023-10-24 16:48:53 +03:00
|
|
|
|
FlashEraseInitPar.TypeErase = FLASH_TYPEERASE_SECTORS;
|
|
|
|
|
FlashEraseInitPar.Banks = FLASH_BANK_1;
|
|
|
|
|
FlashEraseInitPar.Sector = FLASH_SECTOR_7;
|
|
|
|
|
FlashEraseInitPar.NbSectors = 1;
|
|
|
|
|
FlashEraseInitPar.VoltageRange = FLASH_VOLTAGE_RANGE_3;
|
|
|
|
|
|
|
|
|
|
FlashEraseInitCor.TypeErase = FLASH_TYPEERASE_SECTORS;
|
|
|
|
|
FlashEraseInitCor.Banks = FLASH_BANK_1;
|
|
|
|
|
FlashEraseInitCor.Sector = FLASH_SECTOR_6;
|
|
|
|
|
FlashEraseInitCor.NbSectors = 1;
|
|
|
|
|
FlashEraseInitCor.VoltageRange = FLASH_VOLTAGE_RANGE_3;
|
2023-09-25 13:12:41 +03:00
|
|
|
|
|
|
|
|
|
rdPar();
|
2023-10-24 16:48:53 +03:00
|
|
|
|
rdCor();
|
2023-09-25 13:12:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-10-24 16:48:53 +03:00
|
|
|
|
|
2023-09-25 13:12:41 +03:00
|
|
|
|
void wrPar(void)
|
|
|
|
|
{
|
|
|
|
|
__IO uint32_t Address, lenpar, i;
|
|
|
|
|
__IO uint32_t *pData;
|
|
|
|
|
uint32_t SECTORError = 0;
|
|
|
|
|
|
|
|
|
|
lenpar = sizeof(UserData_TypeDef);
|
2023-10-24 16:48:53 +03:00
|
|
|
|
while(lenpar % 4) { //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 4
|
2023-09-25 13:12:41 +03:00
|
|
|
|
lenpar++;
|
|
|
|
|
}
|
2023-10-24 16:48:53 +03:00
|
|
|
|
lenpar >>= 2; //<2F><><EFBFBD><EFBFBD><EFBFBD> <20><> 4
|
2023-09-25 13:12:41 +03:00
|
|
|
|
|
2023-10-24 16:48:53 +03:00
|
|
|
|
HAL_FLASH_Unlock(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(HAL_FLASHEx_Erase(&FlashEraseInitPar, &SECTORError) == HAL_OK) //
|
2023-09-25 13:12:41 +03:00
|
|
|
|
{
|
2023-10-24 16:48:53 +03:00
|
|
|
|
Address = USERPAGEPAR;
|
2023-10-11 17:28:58 +03:00
|
|
|
|
pData = (uint32_t *) ¤tData;
|
2023-09-25 13:12:41 +03:00
|
|
|
|
for(i = 0; i < lenpar; i++)
|
|
|
|
|
{
|
|
|
|
|
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, *pData++);
|
|
|
|
|
Address += 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
HAL_FLASH_Lock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-10-24 16:48:53 +03:00
|
|
|
|
void wrCor(void) ///<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
__IO uint32_t Address, lenpar, i;
|
|
|
|
|
__IO uint32_t *pData;
|
|
|
|
|
uint32_t SECTORError = 0;
|
|
|
|
|
|
|
|
|
|
lenpar = sizeof(correctedKu); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
while(lenpar % 4) { //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 4
|
|
|
|
|
lenpar++;
|
|
|
|
|
}
|
|
|
|
|
lenpar >>= 2; //<2F><><EFBFBD><EFBFBD><EFBFBD> <20><> 4
|
|
|
|
|
|
|
|
|
|
HAL_FLASH_Unlock(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(HAL_FLASHEx_Erase(&FlashEraseInitCor, &SECTORError) == HAL_OK) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
Address = USERPAGECOR;
|
|
|
|
|
pData = (uint32_t *) &correctedKu;
|
|
|
|
|
for(i = 0; i < lenpar; i++)
|
|
|
|
|
{
|
|
|
|
|
HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, Address, *pData++);
|
|
|
|
|
Address += 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
HAL_FLASH_Lock();
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-25 13:12:41 +03:00
|
|
|
|
|
|
|
|
|
void rdPar(void)
|
|
|
|
|
{
|
2023-11-24 14:41:27 +03:00
|
|
|
|
//uint8_t i;
|
2023-09-25 13:12:41 +03:00
|
|
|
|
uint32_t lenpar;
|
|
|
|
|
volatile bool rewrite = false;
|
|
|
|
|
|
|
|
|
|
lenpar = sizeof(UserData_TypeDef);
|
2023-10-24 16:48:53 +03:00
|
|
|
|
memcpy((void *) ¤tData, (void *) USERPAGEPAR, lenpar);
|
2023-09-25 13:12:41 +03:00
|
|
|
|
|
2023-10-24 16:48:53 +03:00
|
|
|
|
//pardata.OWN = 0xffff;//todo //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if(currentData.OWN == 0xffff) //<2F><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
2023-09-25 13:12:41 +03:00
|
|
|
|
{
|
2023-10-24 16:48:53 +03:00
|
|
|
|
currentData.OWN = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2023-10-11 17:28:58 +03:00
|
|
|
|
currentData.BAUD = 5;
|
|
|
|
|
currentData.INFB = 1;
|
|
|
|
|
|
|
|
|
|
currentData.IIN = CHARGE;
|
2023-10-24 16:48:53 +03:00
|
|
|
|
currentData.IFV = Hp0_2;
|
2023-10-11 17:28:58 +03:00
|
|
|
|
currentData.IFN = Lp100000;
|
|
|
|
|
currentData.IKU = Ku1;
|
|
|
|
|
currentData.IK0 = 1;
|
|
|
|
|
currentData.IK1 = 0;
|
2023-10-24 16:48:53 +03:00
|
|
|
|
currentData.IK2 = '~';
|
2023-10-11 17:28:58 +03:00
|
|
|
|
currentData.IK3 = 0;
|
|
|
|
|
currentData.IK4 = 0;
|
2023-10-24 16:48:53 +03:00
|
|
|
|
currentData.IK5 = 0;
|
2023-10-11 17:28:58 +03:00
|
|
|
|
currentData.IPZ =0;
|
|
|
|
|
|
2023-10-24 16:48:53 +03:00
|
|
|
|
|
2023-10-11 17:28:58 +03:00
|
|
|
|
currentData.KCOND = 1.0f;
|
|
|
|
|
currentData.SENS = 1.0f;
|
2023-09-25 13:12:41 +03:00
|
|
|
|
|
2023-10-24 16:48:53 +03:00
|
|
|
|
currentData.UNIT =MS2;
|
|
|
|
|
|
2023-09-25 13:12:41 +03:00
|
|
|
|
rewrite = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////
|
|
|
|
|
if(rewrite)
|
|
|
|
|
{
|
|
|
|
|
rewrite = false;
|
|
|
|
|
wrPar();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-10-24 16:48:53 +03:00
|
|
|
|
void rdCor(void)
|
|
|
|
|
{
|
2023-11-24 14:41:27 +03:00
|
|
|
|
//uint8_t i;
|
2023-10-24 16:48:53 +03:00
|
|
|
|
uint32_t lenpar;
|
|
|
|
|
volatile bool rewrite = false;
|
|
|
|
|
|
|
|
|
|
lenpar = sizeof(correctedKu);
|
|
|
|
|
memcpy((void *) &correctedKu, (void *) USERPAGECOR, lenpar);
|
|
|
|
|
|
|
|
|
|
//pardata.OWN = 0xffff;//todo //<2F><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 4095 <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 4095
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
if(currentData.OWN == 0xffff) //<2F><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
currentData.OWN = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
currentData.BAUD = 5;
|
|
|
|
|
currentData.INFB = 1;
|
|
|
|
|
|
|
|
|
|
currentData.IIN = CHARGE;
|
|
|
|
|
currentData.IFV = Hp0_2;
|
|
|
|
|
currentData.IFN = Lp100000;
|
|
|
|
|
currentData.IKU = Ku1;
|
|
|
|
|
currentData.IK0 = 1;
|
|
|
|
|
currentData.IK1 = 0;
|
|
|
|
|
currentData.IK2 = '~';
|
|
|
|
|
currentData.IK3 = 0;
|
|
|
|
|
currentData.IK4 = 0;
|
|
|
|
|
currentData.IK5 = 0;
|
|
|
|
|
currentData.IPZ =0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
currentData.KCOND = 1.0f;
|
|
|
|
|
currentData.SENS = 1.0f;
|
|
|
|
|
|
|
|
|
|
currentData.UNIT =MS2;
|
|
|
|
|
|
|
|
|
|
rewrite = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////
|
|
|
|
|
if(rewrite)
|
|
|
|
|
{
|
|
|
|
|
rewrite = false;
|
|
|
|
|
wrCor();
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
2023-09-25 13:12:41 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|