With bootloader
This commit is contained in:
parent
b5ff05bed6
commit
023026987c
8 changed files with 312 additions and 141 deletions
|
@ -1,31 +1,52 @@
|
|||
#ifndef FLASH_H_
|
||||
#define FLASH_H_
|
||||
#include "stm32f446xx.h"
|
||||
#include "hal_conf_extra.h"
|
||||
/* for addr in FLASH */
|
||||
typedef struct{
|
||||
uint32_t write_ptr_now;
|
||||
uint16_t crc;
|
||||
uint8_t value;
|
||||
uint8_t data_id; // data_id = id register of can
|
||||
}FLASH_RECORD;
|
||||
enum {
|
||||
addr_id = 0
|
||||
};
|
||||
|
||||
#define FLASH_RECORD_SIZE sizeof(FLASH_RECORD) //size flash struct
|
||||
#define PARAM_COUNT 1 // count data in flash
|
||||
|
||||
|
||||
|
||||
#define FLAG_BOOT 0x08060000 // Адрес хранения флага для обновления прошивки
|
||||
#define UPDATE_FLAG 0xDEADBEEF // Уникальное 32-битное значение
|
||||
#define APP_ADDRESS 0x08004000 // Адрес основной прошивки
|
||||
#define BOOT_CAN_ID 0x721 // CAN ID бутлоадера
|
||||
#define BOOT_CAN_END 0x722 // CAN ID завершения передачи
|
||||
#define DATA_CAN_ID 0x730 // CAN ID данных
|
||||
#define MAX_FW_SIZE 0x3FFF // Макс. размер прошивки (256KB)
|
||||
|
||||
|
||||
|
||||
// Flash sectors for STM32F407
|
||||
#define BOOT 0x08000000 // 16KB - Bootloader
|
||||
#define APP_ADDR 0x08004000 // 16KB - Application
|
||||
#define SECTOR_2 0x08008000 // 16KB
|
||||
#define SECTOR_3 0x0800C000 // 16KB
|
||||
#define SECTOR_4 0x08010000 // 64KB
|
||||
#define SECTOR_5 0x08020000 // 128KB
|
||||
#define SECTOR_6 0x08040000 // 128KB
|
||||
#define SECTOR_7 0x08060000 // 128KB
|
||||
|
||||
#define SECTOR_2 0x08008000 // 16KB
|
||||
#define SECTOR_3 0x0800C000 // 16KB
|
||||
#define SECTOR_4 0x08010000 // 64KB
|
||||
#define SECTOR_5 0x08020000 // 128KB
|
||||
#define SECTOR_6 0x08040000 // 128KB
|
||||
#define SECTOR_6_END (SECTOR_6 + 128 * 1024) // sector 6 end
|
||||
|
||||
#define SECTOR_7 0x08060000
|
||||
|
||||
|
||||
#define FLAG_BOOT (0x08040000 + 4)
|
||||
// Flash keys for unlocking flash memory
|
||||
#define FLASH_KEY1 0x45670123
|
||||
#define FLASH_KEY2 0xCDEF89AB
|
||||
|
||||
|
||||
//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
|
||||
|
||||
// Flash command bits
|
||||
#define FLASH_LOCK FLASH->CR |= FLASH_CR_LOCK
|
||||
#define FLASH_UNLOCK FLASH->KEYR = FLASH_KEY1; FLASH->KEYR = FLASH_KEY2
|
||||
|
||||
#define FLASH_32BYTE \
|
||||
FLASH->CR = (FLASH->CR & ~FLASH_CR_PSIZE) | (0x2 << FLASH_CR_PSIZE_Pos)
|
||||
|
||||
// Flash status flags
|
||||
#define FLASH_BUSY (FLASH->SR & FLASH_SR_BSY)
|
||||
|
@ -37,10 +58,14 @@ typedef void(*pFunction)(void);
|
|||
// Function prototypes
|
||||
void flash_unlock(void);
|
||||
void flash_lock(void);
|
||||
void flash_erase_sector(uint8_t sector);
|
||||
void flash_program_word(uint32_t address, uint32_t data,uint32_t byte_len);
|
||||
void erase_sector(uint8_t sector);
|
||||
void flash_program_word(uint32_t address,uint32_t data,uint32_t byte_len);
|
||||
void write_flash_page(const uint8_t *data, uint16_t len);
|
||||
void flash_read(uint32_t addr,FLASH_RECORD* ptr);
|
||||
bool validate_crc(FLASH_RECORD* crc);
|
||||
uint8_t flash_read_word(uint32_t address);
|
||||
|
||||
|
||||
void flash_write(uint32_t addr, FLASH_RECORD* record);
|
||||
FLASH_RECORD load_params();
|
||||
//bool write_flash_page(const uint8_t* data, uint16_t len);
|
||||
|
||||
#endif /* FLASH_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue