91 lines
2.1 KiB
C
91 lines
2.1 KiB
C
|
#include "main.h"
|
||
|
|
||
|
#include "usart.h"
|
||
|
#include "dma.h"
|
||
|
#include "tim.h"
|
||
|
#include "custom_flash.h"
|
||
|
#include "gpio.h"
|
||
|
#include "can.h"
|
||
|
#include "sdio.h"
|
||
|
#include "fatfs.h"
|
||
|
|
||
|
|
||
|
// KEY defines
|
||
|
#define BOOTLOADER_KEY_ADR (uint32_t)0x08009800
|
||
|
#define BOOTLOADER_KEY_PAGE 20
|
||
|
#define BL_KEY_APP_WRITTEN 0xAAAA5555
|
||
|
|
||
|
// MAIN APP defines
|
||
|
#define MAIN_APP_START_ADR (uint32_t)0x0800C000
|
||
|
#define MAIN_APP_PAGE 21
|
||
|
#define MAIN_APP_NUM_OF_PAGE 250-MAIN_APP_PAGE
|
||
|
|
||
|
// ERROR DEFINES
|
||
|
|
||
|
|
||
|
|
||
|
struct flag
|
||
|
{
|
||
|
unsigned reInitMCU:1; // флаг перепрошивки (очишает память перед прошивкой новой)
|
||
|
unsigned InitOrWait:1; // флаг активной прошивки (1) или ожидания комманды UART/CAN (0)
|
||
|
unsigned StartInit:1; // флаг что необходимо начать прием прошивки/прошивку
|
||
|
unsigned InitBootPeriph:1;// флаг старта инициализации перифирии для прошивки
|
||
|
unsigned BootloaderCMD:3; // комманда: интерфейс для прошивки
|
||
|
unsigned InitMCUReady:1; // окончание прошивки
|
||
|
unsigned HalfOfWrite:1; // какая половина из dma буфера не записана
|
||
|
|
||
|
|
||
|
unsigned SDCardIn:1;
|
||
|
};
|
||
|
|
||
|
|
||
|
|
||
|
struct Bootloader_Errors
|
||
|
{
|
||
|
unsigned FLASH_ERASE:1;
|
||
|
unsigned FLASH_WRITE:1;
|
||
|
|
||
|
unsigned CMD_INVALID:1;
|
||
|
unsigned USART_RECEIVE:1;
|
||
|
|
||
|
|
||
|
#ifdef __CAN_H__
|
||
|
unsigned CAN:1;
|
||
|
#endif
|
||
|
|
||
|
#ifdef __SDIO_H__
|
||
|
unsigned SD_CARD_NOT_INSERTED:1;
|
||
|
unsigned SD_CARD_READ:1;
|
||
|
#endif
|
||
|
};
|
||
|
|
||
|
|
||
|
|
||
|
struct Bootloader_Errors_Counters
|
||
|
{
|
||
|
unsigned FLASH_ERASE;
|
||
|
unsigned FLASH_WRITE;
|
||
|
|
||
|
unsigned CMD_INVALID;
|
||
|
unsigned USART_RECEIVE;
|
||
|
|
||
|
#ifdef __CAN_H__
|
||
|
unsigned CAN_RECEIVE;
|
||
|
#endif
|
||
|
#ifdef __SDIO_H__
|
||
|
unsigned SD_CARD_NOT_INSERTED;
|
||
|
unsigned SD_CARD_READ;
|
||
|
#endif
|
||
|
|
||
|
};
|
||
|
|
||
|
void Bootloader_main(void);
|
||
|
|
||
|
void SD_Programming(FRESULT *res_fresult, HAL_StatusTypeDef *res_hal);
|
||
|
void Bootloader_TIM_Handler(void); // handler for "WD" Timer
|
||
|
void Check_CMD_USART(uint8_t *DataUART);
|
||
|
void SetKey(void);
|
||
|
uint32_t ReadKey(void);
|
||
|
void ResetKey(void);
|
||
|
void Boot_SystemClock_Config(void);
|