Update struct and working for FLASH

This commit is contained in:
Valentin Dabstep 2025-05-15 17:38:59 +03:00
parent 2e88044e07
commit a0800410e0
3 changed files with 99 additions and 78 deletions

View file

@ -4,22 +4,24 @@
#include <stdio.h>
#include <stdlib.h>
/* for addr in FLASH */
/* no padding for this struct, beacuse storing 8 bytes*/
typedef struct{
uint8_t data_id; // data_id = id register of can
uint8_t value;
uint8_t data_type; //float or uint8_t if 4 - float 1 - uint8_t
uint16_t crc;
uint32_t value;
// uint32_t write_ptr_now;
}FLASH_RECORD;
enum {
addr_id = 0,
foc_id = 1,
angl = 2,
vel = 3,
pid_p = 4,
pid_p,
pid_i,
pid_d
pid_d,
foc_id,
angl,
vel
};
#define FLASH_RECORD_SIZE sizeof(FLASH_RECORD) //size flash struct
@ -54,7 +56,7 @@ enum {
// Flash status flags
#define FLASH_BUSY (FLASH->SR & FLASH_SR_BSY)
#define FLASH_ERROR (FLASH->SR & (FLASH_SR_WRPERR | FLASH_SR_PGAERR | FLASH_SR_PGPERR | FLASH_SR_PGSERR))
static uint32_t write_ptr = SECTOR_6;
//for bootloader
typedef void(*pFunction)(void);
@ -64,11 +66,13 @@ void flash_lock(void);
void erase_sector(uint8_t sector);
void flash_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);
uint16_t validate_crc16(uint8_t *data,uint32_t length);
void flash_write(uint32_t addr, FLASH_RECORD* record);
bool validaate_crc(FLASH_RECORD* crc);
void write_param(uint8_t param_id,uint32_t val);
#endif /* FLASH_H_ */