初始版本

This commit is contained in:
2026-04-23 13:49:53 +08:00
parent c1d6ebd38c
commit ac718a463a
257 changed files with 265681 additions and 0 deletions
+144
View File
@@ -0,0 +1,144 @@
#include "dev_boot.h"
static uint32_t pdwCrc32Tbl[256]={0};
static void InitCrc32Table(void)
{
for (int wCnt = 0; wCnt != 256; wCnt++)
{
uint32_t dwCrc = wCnt;
for (int ucCnt = 0; ucCnt != 8; ucCnt++)
{
if (dwCrc & 1)
{
dwCrc = (dwCrc >> 1) ^ 0xEDB88320;
}
else
{
dwCrc >>= 1;
}
}
pdwCrc32Tbl[wCnt] = dwCrc;
}
}
void dev_boot_read_param(boot_para_t *pParam)
{
hdl_flash_read_data(FLASH_BINFO_BASE,(uint8_t *)pParam,sizeof(boot_para_t));
}
int dev_boot_write_param(boot_para_t Param)
{
int res = LL_OK;
int wLen;
uint32_t *pData;
pData= (uint32_t *)&Param;
wLen = sizeof(boot_para_t);
hdl_flash_unlock();
/* Erase sector. */
res = hdl_flash_erase_sector(FLASH_BINFO_BASE,FLASH_BINFO_SIZE);
if(res == LL_OK){
res = hdl_flash_write_data (FLASH_BINFO_BASE, (uint8_t *)pData, wLen);
}
hdl_flash_lock();
return res;
}
void dev_boot_erase_app(void)
{
hdl_flash_unlock();
for(int Addr = FLASH_APP_BASE; Addr < FLASH_APP_SIZE; Addr += FLASH_SECTOR_SIZE) {
EFM_SectorErase(Addr);
SWDT_FeedDog();
}
/* Lock EFM. */
hdl_flash_lock();
}
void dev_boot_write_app(uint32_t AddrOffset, uint8_t* wData, int wLen)
{
hdl_flash_unlock();
hdl_flash_write_data (FLASH_APP_BASE + AddrOffset, (uint8_t *)wData, wLen);
hdl_flash_lock();
}
uint8_t dev_boot_check_app(void)
{
uint32_t AppAddr =FLASH_APP_BASE;
uint32_t u32StackTop = *((__IO uint32_t*)AppAddr);
if ((u32StackTop > SRAM_BASE) && (u32StackTop <= (SRAM_BASE + SRAM_SIZE)))
{
return 1;
}
return 0;
}
void dev_boot_run_app(void)
{
volatile uint32_t JumpAddress;
func_ptr_t JumpToApplication;
uint32_t AppAddr =FLASH_APP_BASE;
uint32_t u32StackTop = *((__IO uint32_t*)AppAddr);
if ((u32StackTop > SRAM_BASE) && (u32StackTop <= (SRAM_BASE + SRAM_SIZE)))
{
JumpAddress = *(__IO uint32_t*)(AppAddr + 4);
JumpToApplication = (func_ptr_t)JumpAddress;
__disable_fiq();
__set_MSP(*(__IO uint32_t*)AppAddr);
JumpToApplication();
}
}
uint32_t dev_boot_get_app_crc32(int dwLen)
{
if(dwLen >= 0xFFFFFFFF)
return 0;
InitCrc32Table();
uint32_t Data;
uint32_t dwCrc32Data = 0xFFFFFFFF;
for (int dwCnt = 0; dwCnt != dwLen; ++dwCnt)
{
Data = *((volatile uint8_t*)(FLASH_APP_BASE + dwCnt));
uint32_t dwTbl = (dwCrc32Data ^ Data) & 0xFF;
dwCrc32Data = ((dwCrc32Data >> 8) & 0xFFFFFF) ^ pdwCrc32Tbl[dwTbl];
}
return ~dwCrc32Data;
}
+54
View File
@@ -0,0 +1,54 @@
#ifndef _DEV_BOOT_
#define _DEV_BOOT_
#include "hdl_flash.h"
#define APP_START_FLAG 0x55AA5A5A
#define APP_UPDATE_FLAG 0xA5A5AA55
#define BOOT_BASE (FLASH_BASE)
#define BOOT_SIZE (4*FLASH_SECTOR_SIZE)
#define APP_ADDRESS (BOOT_BASE + BOOT_SIZE)
#define APP_SIZE (58*FLASH_SECTOR_SIZE)
#define BOOT_PARA_ADDRESS (APP_ADDRESS + APP_SIZE)
#define BOOT_PARA_SIZE (FLASH_SECTOR_SIZE)
#define APP_START_FLAG 0x55AA5A5A
#define APP_UPDATE_FLAG 0xA5A5AA55
typedef struct {
uint32_t AppFlag;
uint32_t DevType;
uint32_t DevAddr;
uint32_t UpdateFlag;
uint32_t PackageNum;
uint32_t AppSize;
uint32_t Crc32Check;
}boot_para_t;
void dev_boot_read_param(boot_para_t *pParam);
int dev_boot_write_param(boot_para_t Param);
void dev_boot_erase_app(void);
void dev_boot_write_app(uint32_t AddrOffset, uint8_t* wData, int wLen);
uint8_t dev_boot_check_app(void);
uint32_t dev_boot_get_app_crc32(int dwLen);
void dev_boot_run_app(void);
#endif
+67
View File
@@ -0,0 +1,67 @@
#include "dev_rs485.h"
#include "hdl_led.h"
static void rs485_rxpin_init(void)
{
LL_PERIPH_WE(LL_PERIPH_GPIO);
stc_gpio_init_t stcGpioInit={0};
GPIO_StructInit(&stcGpioInit);
stcGpioInit.u16PinDir = PIN_DIR_OUT;
stcGpioInit.u16PinDrv = PIN_HIGH_DRV;
stcGpioInit.u16PullUp = PIN_PU_ON;
stcGpioInit.u16PinAttr = PIN_ATTR_DIGITAL;
(void)GPIO_Init(RS485_CTRL_PORT, RS485_CTRL_PIN, &stcGpioInit);
LL_PERIPH_WP(LL_PERIPH_GPIO);
}
static void rs485_rxpin_enable(void)
{
GPIO_ResetPins(RS485_CTRL_PORT,RS485_CTRL_PIN);
}
static void rs485_rxpin_disable(void)
{
GPIO_SetPins(RS485_CTRL_PORT,RS485_CTRL_PIN);
}
int dev_rs485_init(void)
{
hdl_com_uart_init();
rs485_rxpin_init();
rs485_rxpin_enable();
return 0;
}
int dev_rs485_rx_register(dev_rs485_cb_t fnCallback)
{
hdl_com_uart_rx_register((com_rx_callback)fnCallback);
return 0;
}
void dev_rs485_send(uint8_t* buf, int len)
{
rs485_rxpin_disable();
hdl_com_uart_send(buf, len);
rs485_rxpin_enable();
}
int dev_rs485_deinit(void)
{
return 0;
}
+22
View File
@@ -0,0 +1,22 @@
#ifndef _DEV_RS485_H_
#define _DEV_RS485_H_
#include "hdl_usart.h"
#define RS485_CTRL_PORT (GPIO_PORT_C)
#define RS485_CTRL_PIN (GPIO_PIN_07)
typedef void (*dev_rs485_cb_t)(uint8_t dat);
extern int dev_rs485_init(void);
extern void dev_rs485_send(uint8_t *buf, int len);
extern int dev_rs485_read(uint8_t *buf, int len);
extern int dev_rs485_rx_register(dev_rs485_cb_t fnCallback);
extern int dev_rs485_deinit(void);
#endif