1、startup.s汇编文件的的中断重定向改为ifdef,通过切换app_debug和app_boot判断是否编译

2、Sx1276Type_t 结构体给定固定值
3、lora通道选择取消,通过修改频率来修改通道
4、增加了修改lora参数的函数
5、将USE_BOOTLOADER的宏定义更改到工程预编译define
6、将BootPara_t结构体定义到bsp.h文件下
7、在bsp.h文件下增加了LoraPara_r,RS485Para_t结构体并声明
8、串口带波特率参数初始化
9、增加了MAIN_DBG_LOG和DATA_DBG_LOG调试打印
10、Update.h的boot参数定义在bsp.h获取
11、当工程是app_boot时调试口为Lpuart0,当工程是app_debug时调试口为uart0
12、设备Mac从bootloader中固定地址0x00002800获取,设备类型、通讯方式、设备标志和设备序号从获取到的mac地址解析
13、debug文件增加了调试指令
This commit is contained in:
2026-05-20 13:41:07 +08:00
parent cd594e3d69
commit 2efab2862f
16 changed files with 1239 additions and 223 deletions
+2 -2
View File
@@ -4,7 +4,7 @@
#define __SGCP_H
#include "bsp.h"
#define WORK_MODE 1//工作模式选择,0、本机为查询模式,1、本机为上报模式(低功耗)
#define WORK_MODE 1 //工作模式选择,0、本机为查询模式,1、本机为上报模式(低功耗)
#define SGCP_SELECT 1 //协议选择,0、本机为单个主设备接多个子设备,1、本机为单个主设备不接子设备,2、本机为单个子设备
typedef struct {//网关与主设备固定帧
@@ -173,7 +173,7 @@ typedef enum {
RS485 = 0x02, //0x02 RS485通讯
RS232 = 0x03, //0x03 RS232通讯
CAN = 0x04, //0x04 CAN通讯
_4G = 0x05, //0x05 _4G通讯
CATONE = 0x05, //0x05 _4G通讯
BLE = 0x06, //0x06 BLE通讯
WIFI = 0x07, //0x07 WIFI通讯
UART = 0x08, //0x08 UART通讯
+2 -15
View File
@@ -3,7 +3,6 @@
#include <stdint.h>
#include "bsp.h"
#include "UartDebug.h"
#define APP_START_FLAG 0x55AA5A5A
#define APP_UPDATE_FLAG 0xA5A5AA55
@@ -23,17 +22,6 @@
#define BOOT_PARA_ADDRESS (0x0001FC00)//(FLASH_BASE + BOOT_SIZE)
#define BOOT_PARA_SIZE (FLASH_SECTOR_SIZE)
typedef struct {
uint32_t AppFlag;
uint32_t UpdateFlag;
uint32_t PackageCnt;
uint32_t AppSize;
uint32_t Crc32Check;
uint32_t FirstRunFlag;//第一次运行
uint8_t DevMac[6];//设备MAC
uint32_t LoraFreq;//Lora频率
}BootPara_t, *BootPara;
//主机下发升级请求载荷结构体
typedef struct {
@@ -55,11 +43,10 @@ typedef struct {
#define U_DBG_LOG(...) DBG_LOG(__VA_ARGS__)
#define U_DELAY_MS(x) delay_ms(x)
#define U_SYSTEM_TESET() SystemReset()
#define SAVE_BOOT_PARA(addr) FlashWrite(BOOT_PARA_ADDRESS, addr, sizeof(BLPara) / 4)
#define READ_BOOT_PARA(addr) FlashRead(BOOT_PARA_ADDRESS, addr, sizeof(BLPara) / 4)
#define SAVE_BOOT_PARA(addr) SAVE_APP_PARA(addr)
#define READ_BOOT_PARA(addr) READ_APP_PARA(addr)
//输出接口
void Update(uint8_t *PayLoad);
void UpdateInit(void);
extern BootPara_t BLPara;
#endif
+44 -10
View File
@@ -6,6 +6,7 @@
#include <time.h>
#include "gpio.h"
#include "spi.h"
#include "Update.h"
/*模块启用与关闭*/
#define USE_DEBUG 1 //调试串口选择,0、关闭,1、启用
@@ -23,8 +24,7 @@
#define USE_SPI0 1 //SPI1开关,0、关闭,1、启用
#define USE_SPI1 0 //SPI1开关,0、关闭,1、启用
#define USE_BOOTLOADER 1 //BOOTLOADER开关,0、关闭,1、启用
#define USE_LORA_CH 0 //0为测试通道
//#define USE_BOOTLOADER 1 //BOOTLOADER开关,0、关闭,1、启用
//<<---------------------------- MCU -------------------------------->>
//< UART0
@@ -209,12 +209,22 @@
extern float VBAT_8V4;
extern uint8_t VBAT_Percentage;
typedef struct {
uint32_t AppFlag;
uint32_t UpdateFlag;
uint32_t PackageCnt;
uint32_t AppSize;
uint32_t Crc32Check;
uint32_t FirstRunFlag;//第一次运行
uint8_t DevMac[6];//设备MAC
uint32_t LoraFreq;//Lora频率
}BootPara_t, *BootPara;
typedef struct {
uint16_t CollectTime; //数据采集时间间隔,设置范围30*N秒,1<=N<=240(默认5分钟,N=10)
uint16_t ReportInterval; //上报时间间隔,设置范围,30*N秒,10<=N<=1440(默认20分钟,N=40
uint8_t ERInterval; //紧急上报时间间隔,设置范围,30*N秒,2<=N<=10(默认2分钟,N=4
uint8_t ERTime; //紧急上报时长,设置范围,30*N秒,20<=N<=240(默认20分钟,N=40
uint16_t CollectTime; //数据采集时间间隔,设置范围30*N秒,1<=N<=240(默认300秒,N=10)
uint16_t ReportInterval; //上报时间间隔,设置范围,30*N秒,10<=N<=1440(默认1200秒,N=40
uint8_t ERInterval; //紧急上报时间间隔,设置范围,30*N秒,2<=N<=10(默认120秒,N=4
uint8_t ERTime; //紧急上报时长,设置范围,30*N秒,20<=N<=240(默认1200秒,N=40
uint32_t TimeStamp; //网关返回RTC时间戳
}__attribute__((packed))LayoutPara_t,*LayoutPara;//上位机下发的配置参数
@@ -225,16 +235,39 @@ typedef struct {
}__attribute__ ((packed))CalibratePara_t, *CalibratePara;
typedef struct {
bool OnOff;
uint8_t ucChannel;
int8_t ucPower;
uint8_t SignalBw;
uint8_t SpreadFactor;
uint8_t ErrorCoding;
uint8_t RegPreamble;
uint32_t FreqCent;
}__attribute__ ((packed))LoraPara_t, *pLoraPara;
typedef struct {
bool Enable; //串口使能
bool UpgradeEnable;//升级功能使能
uint32_t Addr; //本机485地址
uint32_t BaudRate;
}__attribute__((packed))RS485Para_t, *RS485Para;
typedef struct {
BootPara_t BLPara;
LayoutPara_t Layout;
CalibratePara_t CaliPara;
uint32_t RS485Addr; //本机485地址
RS485Para_t Rs485Ch1;
RS485Para_t Rs485Ch2;
uint32_t FactoryFlag;//出厂标志位
LoraPara_t Lora;
}AppPara_T, *pAppPara;
#define APP_PARA_ADDRESS (0x0001FE00)
#define SAVE_APP_PARA(addr) FlashWrite(APP_PARA_ADDRESS, addr, sizeof(App.Para) / 4)
#define READ_APP_PARA(addr) FlashRead(APP_PARA_ADDRESS, addr, sizeof(App.Para) / 4)
//#define APP_PARA_ADDRESS (0x0001FC00)
#define SAVE_APP_PARA(addr) FlashWrite(BOOT_PARA_ADDRESS, addr, sizeof(App.Para) / 4)
#define READ_APP_PARA(addr) FlashRead(BOOT_PARA_ADDRESS, addr, sizeof(App.Para) / 4)
void BspInit(void);
void LpUart0Init(uint32_t Baud);
void Uart0Init(uint32_t Baud);
void EnterDeepSleep(void);
void DBGUartSendByte(uint8_t sData);
void DBGUartSend(uint8_t *sData, int sLen);
@@ -269,3 +302,4 @@ void LORAIntDisable(void);
void ACCandMMCIntEnable(void);
void ACCandMMCIntDisable(void);
#endif
+13 -3
View File
@@ -2,8 +2,16 @@
#define __MAIN_H
#include "bsp.h"
#include "UartDebug.h"
#include "Update.h"
#include "Imu.h"
#define SOFTWARE_VERSION 12 //软件版本
#define HARDWARE_VERSION 11 //硬件版本
#define MAIN_DBG_LOG(...) { if(MainDispEn) DBG_LOG(__VA_ARGS__);}
#define DATA_DBG_LOG(...) { if(DataDispEn) DBG_LOG(__VA_ARGS__);}
#define X 0
#define Y 1
#define Z 2
@@ -94,14 +102,16 @@ typedef struct {
int16_t Nonce; //随机数
uint32_t TestTimeCnt;
uint8_t Tcnt;
bool LaserFlag;
}AppDetect_t;
extern AppDetect_t App;
void MainDBGOnOff(bool OnOff);
void DataDBGOnOff(bool OnOff);
#endif