Algoritm for save flash(while non-work)
This commit is contained in:
parent
5dbd56f200
commit
b5ff05bed6
4 changed files with 52 additions and 30 deletions
|
@ -7,14 +7,20 @@
|
|||
|
||||
/* for addr in FLASH */
|
||||
typedef struct{
|
||||
uint8_t data_id;
|
||||
uint8_t data_id; // data_id = id register of can
|
||||
uint8_t value;
|
||||
uint16_t crc;
|
||||
}FLASH_RECORD;
|
||||
enum {
|
||||
addr_id = 0,
|
||||
foc_id = 1,
|
||||
kp_id = 2,
|
||||
ki_id = 3,
|
||||
kd_id = 4
|
||||
};
|
||||
|
||||
static uint32_t write_ptr;
|
||||
#define FLASH_RECORD_SIZE sizeof(FLASH_RECORD) //size flash struct
|
||||
#define PARAM_COUNT 4 // count data in flash
|
||||
#define PARAM_COUNT 3 // count data in flash
|
||||
|
||||
// Flash sectors for STM32F407
|
||||
|
||||
|
@ -32,7 +38,8 @@ static uint32_t write_ptr;
|
|||
|
||||
//FLASH SET ONE PROGRAMM WORD
|
||||
#define FLASH_8BYTE FLASH->CR &= ~FLASH_CR_PSIZE & ~FLASH_CR_PSIZE_1
|
||||
#define FLASH_32BYTE FLASH->CR |= FLASH_CR_PSIZE | FLASH_CR_PSIZE_0
|
||||
#define FLASH_32BYTE \
|
||||
FLASH->CR = (FLASH->CR & ~FLASH_CR_PSIZE) | (0x2 << FLASH_CR_PSIZE_Pos)
|
||||
|
||||
// Flash command bits
|
||||
#define FLASH_LOCK FLASH->CR |= FLASH_CR_LOCK
|
||||
|
@ -52,7 +59,11 @@ void flash_lock(void);
|
|||
void erase_sector(uint8_t sector);
|
||||
void program_word(uint32_t address, uint32_t data,uint32_t byte_len);
|
||||
uint8_t flash_read_word(uint32_t address);
|
||||
|
||||
|
||||
void write_param(uint8_t param_id, uint8_t val);
|
||||
FLASH_RECORD* load_params();
|
||||
void compact_page();
|
||||
void flash_read(uint32_t addr,FLASH_RECORD* ptr);
|
||||
bool validate_crc(FLASH_RECORD* crc);
|
||||
void flash_write(uint32_t addr, FLASH_RECORD* record);
|
||||
|
||||
#endif /* FLASH_H_ */
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define REG_CAH_H_
|
||||
|
||||
#define APP_ADDR 0x0800400 // 16KB - Application
|
||||
#define ADDR_VAR 0x8050000
|
||||
#define ADDR_VAR 0x8040000
|
||||
#define ADDR_VAR_ID ADDR_VAR
|
||||
#define ADDR_VAR_P (ADDR_VAR + 1)
|
||||
#define ADDR_VAR_I (ADDR_VAR + 2)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue