Merge pull request #32 from armfly/origin/armfly

脱机烧录增加雅特力AT32; 增加串口监视器功能
This commit is contained in:
armfly 2020-09-24 17:20:13 +08:00 committed by GitHub
commit 29305734cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
45 changed files with 3077 additions and 4403 deletions

View File

@ -1,3 +1,51 @@
----------------------------------------------------------------------------
2020-09-24 V1.32
1. 增加串口监视功能
- 联机模式界面长按S进入进入扩展功能界面选择数据监视器
- 支持2路串口数据显示,第1路: 232RX,485,TTTLRX 第2路:D1 URX
- 支持HEX,ASCII格式选择字体12点阵和16点阵
- 支持加时间戳功能精确显示到us 双路时误差30us)
2. 优化emmc驱动
- 由1线模式修改为了8线
- MSC_MEDIA_PACKET 由512改为16*1024
- 4线的读速度10.5MB/s, 8线的读速度15.2MB/s
- 8线模式写速度 6-9MB/s
3. 脱机烧录器 需要配套PC软件升级V0.9
- 新增支持雅特力AT32。
AT32F403的FLM文件中page size字段不正确超过了OB Size导致写OB失败。
程序进行自动修正page size 必须小于等于device size.
- 重新加入复位模式选择参数。上个版本做的自动模式在无RST条件下成功率不高。PC软件上选择复位模式
-- 自动模式临时按软件模式操作0自动模式 1软件模式 2硬件模式
- 烧录完毕后,在硬件复位期间同时发送软件复位指令. static int h7_reset(lua_State* L)
- PC软件显示的烧录算法列表可以通过lua文件设置
4. 显示驱动修正 void ST7789_DrawScreen(void) 等待DMA传输完毕的语句放到DMA传输之后死等。
之前的固件是先等待在DMA传输容易导致视觉闪裂现象
5. 串口驱动优化
- UART_IRQ(). 增加奇偶校验判断,但是没起作用,无论是无校验、奇校验、偶校验都可以接收数据
if ((isrflags & USART_ISR_RXNE_RXFNE) != 0 && (isrflags & USART_ISR_PE) == 0U)
- 串口中断添加 IdleLine回调函数字符间超时中断。 用于串口监视功能
6. bsp_timer.c 增加精确到us的运行时间函数uint64_t类型。用于串口监视器功能
- uint64_t bsp_GetRunTimeUs() 获得CPU运行时间uint64_t
- uint64_t bsp_CheckRunTimeUs(x) 当前时间和之前的时间差值
7. LCD_DrawMemo(), 文本框显示函数修改为FiFo机制. 文本框缓冲调大到4KB.
8. 新增c文件:modify_param.c, 专门用于设置应用程序参数.
BUG修复:
1.完善示波器普通触发功能,修正触发死机问题(不过很小几率还是会挂,并未完全解决)
2. lua_udp_SendBuf() 中 bsp_StartHardTimer(3, 5, udp_print_send), 单位是us原计划是5ms的
此处未改改了PC界面居然打印显示不全
3. 电压表功能,修改自动量程的判断条件
static void AutoVoltRange(void) 中最后一档100mV量程判据由0.1V改为0.095V.
----------------------------------------------------------------------------
2020-09-20 V1.31
1. 适配RT1052, 支持Hyper Flash 和 QSPI Flash.

View File

@ -6,4 +6,7 @@
#define TICK_INT_PRIORITY 0 // ((uint32_t)0x0F) /*!< tick interrupt priority */
4. bsp_CheckRunTime, bsp_GetRunTime 函数内部去掉关闭中断的操作影响QSPI写操作。
2020-09-16 V1.31固件
普通触发模式还有遗留问题拖动触发位置滚动条时超出波形范围后H7-TOOL程序假死频繁进入看门狗中断暂未解决。H7-TOOL界面翻到电压档界面可恢复。

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<component_viewer schemaVersion="0.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="Component_Viewer.xsd">
<component name="EventRecorderStub" version="1.0.0"/> <!--name and version of the component-->
<events>
</events>
</component_viewer>

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -478,6 +478,21 @@
<FileType>1</FileType>
<FilePath>..\..\User\app\src\status_mini_dso.c</FilePath>
</File>
<File>
<FileName>modify_param.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\User\app\src\modify_param.c</FilePath>
</File>
<File>
<FileName>status_can_monitor.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\User\app\src\status_can_monitor.c</FilePath>
</File>
<File>
<FileName>status_uart_monitor.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\User\app\src\status_uart_monitor.c</FilePath>
</File>
</Files>
</Group>
<Group>
@ -493,11 +508,6 @@
<FileType>1</FileType>
<FilePath>..\..\User\bsp\bsp.c</FilePath>
</File>
<File>
<FileName>bsp_user_lib.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\User\bsp\src\bsp_user_lib.c</FilePath>
</File>
<File>
<FileName>bsp_timer.c</FileName>
<FileType>1</FileType>
@ -554,6 +564,11 @@
</FileArmAds>
</FileOption>
</File>
<File>
<FileName>bsp_user_lib.c</FileName>
<FileType>1</FileType>
<FilePath>..\..\User\bsp\src\bsp_user_lib.c</FilePath>
</File>
<File>
<FileName>bsp_led.c</FileName>
<FileType>1</FileType>

View File

@ -68,7 +68,7 @@ __Vectors DCD __initial_sp ; Top of Stack
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0x00000131 ; Reserved H7-TOOL APP 固件版本
DCD 0x00000132 ; Reserved H7-TOOL APP 固件版本
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved

Binary file not shown.

Binary file not shown.

View File

@ -54,6 +54,8 @@ typedef struct
uint8_t RollBackEn; /* 回滚使能 */
uint8_t GBK; /* 文字编码 0=UTF8, 1=GBK */
uint8_t ActiveBackColor; /* 选中行背景色,0表示黄色 1表示参数修改状态 */
} MENU_T;
/* 菜单显示类 */

View File

@ -46,6 +46,11 @@ enum
MS_LUA_SELECT_FILE, /* 浏览lua文件 */
MS_LUA_EXEC_FILE, /* 执行lua文件 */
MS_MONITOR_UART, /* 串口监视器 */
MS_MONITOR_CAN, /* CAN监视器 */
MS_MONITOR_GPIO, /* IO监视器 */
MS_MONITOR_ANALOG, /* 模拟量监视器 */
};
void DispHeader(char *_str);

View File

@ -0,0 +1,33 @@
/*
*********************************************************************************************************
*
* :
* : modify_param.h
* : V1.0
* :
*
* Copyright (C), 2020-2030, www.armfly.com
*
*********************************************************************************************************
*/
#ifndef _MODIFY_PARAM_H
#define _MODIFY_PARAM_H
/* 参数列表结构 */
typedef struct
{
uint8_t DataType; /* 参数类型 0 = uint16_t */
const char *ParamName; /* 参数名 */
const char **ParamItems; /* 可选的参数项 */
int32_t MinValue; /* 最小值 */
int32_t MaxValue; /* 最大值 */
int32_t DefaultValue; /* 缺省值 */
}PARAM_LIST_T;
void ModifyParam(uint16_t _MainStatus);
void UartMonCheckParam(void);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -17,7 +17,7 @@
#define PARAM_ADDR 0 /* 基本参数区地址 */
#define PARAM_SIZE 256 /* 最大空间,用于编译查错 */
#define PARAM_CALIB_ADDR 1024 /* 基本参数区地址 */
#define PARAM_CALIB_ADDR 1024 /* 校准参数区地址 */
#define PARAM_CALIB_SIZE 512 /* 最大空间,用于编译查错 */
#define PARAM_VER 0x00000101 /* 基本参数版本 100 */
@ -108,6 +108,16 @@ typedef struct
uint16_t ToolSn; /* 烧录器编号 */
uint8_t StartRun; /* 开机启动0表示缺省1表示单机烧录 2表示多路烧录 */
/* V1.32 */
uint8_t UartMonBaud; /* 串口监视,波特率 */
uint8_t UartMonParit; /* 串口监视,奇偶校验 */
uint8_t UartMonWordWrap; /* 串口监视,自动换行 */
uint8_t UartMonFont; /* 串口监视,字体 */
uint8_t UartMonHex; /* 串口监视按HEX显示 */
uint8_t UartMonTimeStamp; /* 串口监视,加上时间戳 */
uint8_t UartMonProxy; /* 串口监视,协议 */
} PARAM_T;
/* 模拟量校准参数 */

View File

@ -0,0 +1,17 @@
/*
*********************************************************************************************************
*
* : CAN数据监视器功能模块
* : status_can_monitor.h
*
*********************************************************************************************************
*/
#ifndef _STATUS_CAN_MONITOR_H_
#define _STATUS_CAN_MONITOR_H_
void status_MonitorCan(void);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -0,0 +1,17 @@
/*
*********************************************************************************************************
*
* : UART数据监视器功能模块
* : status_uart_monitor.h
*
*********************************************************************************************************
*/
#ifndef _STATUS_UART_MONITOR_H_
#define _STATUS_UART_MONITOR_H_
void status_MonitorUart(void);
#endif
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -63,9 +63,11 @@
#define CL_MENU_TEXT1 RGB(189, 189, 189) /* 菜单文字颜色 */
//#define CL_MENU_BACK1 RGB(5, 54, 131) /* 菜单文字背景颜色 */
#define CL_MENU_BACK1 CL_WHITE /* 菜单文字背景颜色 */
#define CL_MENU_TEXT2 RGB(189, 189, 189) /* 光标选中文字颜色 */
#define CL_MENU_BACK2 CL_YELLOW /* 光标选中文字背景颜色 */
#define CL_MENU_ACTIVE_BODER MEAS_BODER_COLOR /* 光标选中文字背景颜色 */
#define CL_MENU_TEXT2 RGB(160, 160, 160) /* 光标选中文字颜色 */
#define CL_MENU_BACK2 CL_YELLOW /* 光标选中文字背景颜色 */
#define CL_MENU_ACTIVE_BODER MEAS_BODER_COLOR /* 光标选中文字背景颜色 */
#define CL_MENU_BACK3 RGB(255, 236, 222) /* 光标选中文字背景颜色 - 用于修改参数 */
#define CL_MENU_TEXT3 RGB(50, 50, 50) /* 光标选中文字颜色 */
#define LIST_COLOR1 RGB(255, 255, 255)
#define LIST_COLOR2 RGB(240, 240, 240)

View File

@ -1244,7 +1244,7 @@ uint8_t SelectFile(char *_InitPath, uint16_t _MainStatus, uint16_t _RetStatus, c
g_tMenuLua.Font.Space = 0;
g_tMenuLua.RollBackEn = 1;
g_tMenuLua.GBK = 1;
g_tMenuLua.ActiveBackColor = 0; /* 选中行背景色ID */
for (i = 0; i < g_tFileList.Count; i++)
{
g_MenuLua_Text[i] = (uint8_t *)g_tFileList.Name[i];

View File

@ -92,14 +92,23 @@ void LCD_DispMenu(MENU_T *_pMenu)
if (i + _pMenu->Offset == _pMenu->Cursor) /* 选钟行 */
{
/* 设置为反白 */
_pMenu->Font.FrontColor = CL_MENU_TEXT1;
_pMenu->Font.BackColor = CL_MASK;
y = _pMenu->Top + i * (FontHeight + _pMenu->LineCap);
/* 清全行背景 */
LCD_Fill_Rect(_pMenu->Left, y, _pMenu->LineCap + FontHeight, _pMenu->Width, CL_MENU_BACK2);
if (_pMenu->ActiveBackColor == 0)
{
_pMenu->Font.FrontColor = CL_MENU_TEXT2;
LCD_Fill_Rect(_pMenu->Left, y, _pMenu->LineCap + FontHeight, _pMenu->Width, CL_MENU_BACK2);
}
else
{
_pMenu->Font.FrontColor = CL_MENU_TEXT3;
LCD_Fill_Rect(_pMenu->Left, y, _pMenu->LineCap + FontHeight, _pMenu->Width, CL_MENU_BACK3);
}
/* 刷新文本 */
if (_pMenu->GBK == 1)
{

View File

@ -31,7 +31,8 @@
#include "status_extend_menu.h"
#include "status_mini_dso.h"
#include "status_lua.h"
#include "status_can_monitor.h"
#include "status_uart_monitor.h"
#include "wifi_if.h"
#include "ff.h"
#include "ff_gen_drv.h"
@ -256,6 +257,22 @@ int main(void)
status_LuaRun();
break;
case MS_MONITOR_UART: /* 串口监视 */
status_MonitorUart();
break;
case MS_MONITOR_CAN: /* CAN监视 */
status_MonitorCan();
break;
case MS_MONITOR_GPIO: /* IO监视器 */
status_MonitorUart();
break;
case MS_MONITOR_ANALOG: /* 模拟量监视器 */
status_MonitorUart();
break;
default:
g_MainStatus = MS_LINK_MODE;
break;

358
User/app/src/modify_param.c Normal file
View File

@ -0,0 +1,358 @@
/*
*********************************************************************************************************
*
* :
* : modify_param.c
* : V1.0
* :
* :
*
* v1.0 2020-09-20 armfly
*
* Copyright (C), 2020-2030, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "fonts.h"
#include "ui_def.h"
#include "main.h"
#include "lcd_menu.h"
#include "modify_param.h"
/* 多行文本框 */
#define MEMO_X 5
#define MEMO_Y 5
#define MEMO_H (240 - MEMO_Y - 0)
#define MEMO_W (240 - 2 * MEMO_X)
/* 菜单 */
#define MENU_ITEM_COUNT_MAX 20 /* 菜单项最大数量 */
char g_MenuBuf[20][32];
char *g_MenuParam_Text[MENU_ITEM_COUNT_MAX + 1];
MENU_T g_tMenuParam;
static void UartMonDispParam(void);
static void UartMonAdjustParam(uint8_t _index, int16_t _adj);
/*
*********************************************************************************************************
* : ModifyParam
* : .
* :
* :
*********************************************************************************************************
*/
void ModifyParam(uint16_t _MainStatus)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t fRefresh;
static uint8_t s_enter_sub_menu = 0;
uint8_t fQuit = 0;
uint8_t ucModifyStatus = 0;
DispHeader2(90, "设置参数");
/* 动态菜单项初始化指针 */
{
uint8_t i;
for (i = 0; i < MENU_ITEM_COUNT_MAX; i++)
{
g_MenuParam_Text[i] = g_MenuBuf[i];
}
}
if (_MainStatus == MS_MONITOR_UART)
{
UartMonDispParam();
}
if (s_enter_sub_menu == 0)
{
g_tMenuParam.Left = MENU_LEFT;
g_tMenuParam.Top = MENU_TOP;
g_tMenuParam.Height = MENU_HEIGHT;
g_tMenuParam.Width = MENU_WIDTH;
g_tMenuParam.LineCap = MENU_CAP;
g_tMenuParam.ViewLine = 8;
g_tMenuParam.Font.FontCode = FC_ST_24;
// g_tMenuParam.Font.FrontColor = CL_BLACK; /* 字体颜色 */
// g_tMenuParam.Font.BackColor = FORM_BACK_COLOR; /* 文字背景颜色 */
g_tMenuParam.Font.Space = 0;
g_tMenuParam.RollBackEn = 1; /* 允许回滚 */
g_tMenuParam.GBK = 0;
g_tMenuParam.ActiveBackColor = 0; /* 选中行背景色ID */
LCD_InitMenu(&g_tMenuParam, (char **)g_MenuParam_Text); /* 初始化菜单结构 */
}
fRefresh = 1;
while (fQuit == 0)
{
if (fRefresh) /* 刷新整个界面 */
{
fRefresh = 0;
if (_MainStatus == MS_MONITOR_UART)
{
UartMonDispParam();
LCD_DispMenu(&g_tMenuParam);
}
}
bsp_Idle();
if (ucModifyStatus == 0)
{
ucKeyCode = bsp_GetKey(); /* 读取键值, 无键按下时返回 KEY_NONE = 0 */
if (ucKeyCode != KEY_NONE)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_UP_S: /* S键 上 */
LCD_MoveUpMenu(&g_tMenuParam);
break;
case KEY_LONG_DOWN_S: /* S键 上 */
PlayKeyTone();
ucModifyStatus = 1;
g_tMenuParam.ActiveBackColor = 1; /* 选中行背景色ID */
fRefresh = 1;
break;
case KEY_LONG_UP_S: /* 长按弹起 */
break;
case KEY_UP_C: /* C键 下 */
LCD_MoveDownMenu(&g_tMenuParam);
break;
case KEY_LONG_DOWN_C: /* C键长按 */
PlayKeyTone();
s_enter_sub_menu = 0;
fQuit = 1;
break;
default:
break;
}
}
}
else /* 修改状态 */
{
ucKeyCode = bsp_GetKey(); /* 读取键值, 无键按下时返回 KEY_NONE = 0 */
if (ucKeyCode != KEY_NONE)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_UP_S: /* S键 上 */
UartMonAdjustParam(g_tMenuParam.Cursor, -1);
fRefresh = 1;
break;
case KEY_LONG_DOWN_S: /* S键 上 */
break;
case KEY_LONG_UP_S: /* 长按弹起 */
break;
case KEY_UP_C: /* C键 下 */
UartMonAdjustParam(g_tMenuParam.Cursor, 1);
fRefresh = 1;
break;
case KEY_LONG_DOWN_C: /* C键长按 */
SaveParam();
g_tMenuParam.ActiveBackColor = 0; /* 选中行背景色ID */
ucModifyStatus = 0;
fRefresh = 1;
break;
default:
break;
}
}
}
}
}
#define UART_MON_PARAM_COUTN 7
const char *UartMonParam0[] = {"1200", "2400", "4700", "9600", "19200", "38400", "57600", "115200"};
const char *UartMonParam1[] = {"无校验", "奇校验", "偶校验"};
const char *UartMonParam2[] = {"关闭", "启用"};
const char *UartMonParam3[] = {"12点阵", "16点阵"};
const char *UartMonParam4[] = {"关闭", "启用"};
const char *UartMonParam5[] = {"关闭", "启用"};
const char *UartMonParam6[] = {"无协议", "Modbus RTU"};
const PARAM_LIST_T UartMonParamList[UART_MON_PARAM_COUTN] =
{
/* 数据类型, 名称 可选列表, 最小值, 最大值, 缺省值 */
{ 0, "波特率:", UartMonParam0, 0, 7, 7},
{ 0, "奇偶校验:", UartMonParam1, 0, 2, 0},
{ 0, "自动换行:", UartMonParam2, 0, 1, 1},
{ 0, "字体:", UartMonParam3, 0, 1, 1},
{ 0, "HEX显示:", UartMonParam4, 0, 1, 0},
{ 0, "时间戳:", UartMonParam5, 0, 1, 0},
{ 0, "协议:", UartMonParam6, 0, 1, 0},
};
/*
*********************************************************************************************************
* : MonDispReadParam
* :
* : _index :
* :
*********************************************************************************************************
*/
static int32_t MonDispReadParam(uint8_t _index)
{
int32_t value = 0;
if (_index == 0) value = g_tParam.UartMonBaud;
if (_index == 1) value = g_tParam.UartMonParit;
if (_index == 2) value = g_tParam.UartMonWordWrap;
if (_index == 3) value = g_tParam.UartMonFont;
if (_index == 4) value = g_tParam.UartMonHex;
if (_index == 5) value = g_tParam.UartMonTimeStamp;
if (_index == 6) value = g_tParam.UartMonProxy;
return value;
}
/*
*********************************************************************************************************
* : MonDispWriteParam
* :
* : _index :
* _value :
* :
*********************************************************************************************************
*/
static void MonDispWriteParam(uint8_t _index, int32_t _value)
{
if (_index == 0) g_tParam.UartMonBaud = _value;
else if (_index == 1) g_tParam.UartMonParit = _value;
else if (_index == 2) g_tParam.UartMonWordWrap = _value;
else if (_index == 3) g_tParam.UartMonFont = _value;
else if (_index == 4) g_tParam.UartMonHex = _value;
else if (_index == 5) g_tParam.UartMonTimeStamp = _value;
else if (_index == 6) g_tParam.UartMonProxy = _value;
}
/*
*********************************************************************************************************
* : UartMonDispParam
* :
* :
* :
*********************************************************************************************************
*/
static void UartMonDispParam(void)
{
uint8_t i;
int32_t min, max, def;
int32_t now;
for (i = 0; i < UART_MON_PARAM_COUTN; i++)
{
min = UartMonParamList[i].MinValue;
max = UartMonParamList[i].MaxValue;
def = UartMonParamList[i].DefaultValue;
now = MonDispReadParam(i);
if (now < min || now > max)
{
now = def;
}
sprintf(g_MenuBuf[i], "%s%s", UartMonParamList[i].ParamName, UartMonParamList[i].ParamItems[now]);
}
sprintf(g_MenuBuf[i], "&"); /* 结束符 */
}
/*
*********************************************************************************************************
* : UartMonAdjustParam
* :
* : _index :
* _adj :
* :
*********************************************************************************************************
*/
static void UartMonAdjustParam(uint8_t _index, int16_t _adj)
{
int32_t min, max, def;
int32_t OldValue, NewValue;
if (_index >= UART_MON_PARAM_COUTN)
{
return;
}
min = UartMonParamList[_index].MinValue;
max = UartMonParamList[_index].MaxValue;
def = UartMonParamList[_index].DefaultValue;
OldValue = MonDispReadParam(_index);
if (OldValue < min || OldValue > max)
{
NewValue = def;
}
else
{
NewValue = OldValue + _adj;
if (NewValue > max)
{
NewValue = min;
}
if (NewValue < min)
{
NewValue = max;
}
}
MonDispWriteParam(_index, NewValue);
}
/*
*********************************************************************************************************
* : UartMonCheckParam
* :
* :
* :
*********************************************************************************************************
*/
void UartMonCheckParam(void)
{
uint8_t i;
int32_t min, max, def;
int32_t now;
for (i = 0; i < UART_MON_PARAM_COUTN; i++)
{
min = UartMonParamList[i].MinValue;
max = UartMonParamList[i].MaxValue;
def = UartMonParamList[i].DefaultValue;
now = MonDispReadParam(i);
if (now < min || now > max)
{
now = def;
}
MonDispWriteParam(i, now);
}
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -34,7 +34,6 @@ void LoadCalibParam(void);
*/
void LoadParam(void)
{
/* 读取EEPROM中的参数 */
ee_ReadBytes((uint8_t *)&g_tParam, PARAM_ADDR, sizeof(PARAM_T));

View File

@ -0,0 +1,269 @@
/*
*********************************************************************************************************
*
* : CAN数据监视器
* : status_can_monitor.c
* : V1.0
* :
* :
*
* V1.0 2020-09-16 armfly
*
* Copyright (C), 2018-2030, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "lcd_menu.h"
#include "file_lib.h"
#include "lua_if.h"
#include "prog_if.h"
#include "modify_param.h"
/* 多行文本框 */
#define MEMO_X 0
#define MEMO_Y 20
#define MEMO_H (240 - MEMO_Y - 0)
#define MEMO_W (240 - 2 * MEMO_X)
extern char g_OutText[4 * 1024];
extern MEMO_T g_RecMemo;
static uint8_t s_FrameHead1 = 1;
static uint64_t s_FrameHeadTime1;
static uint64_t s_BeginTime;
static uint32_t s_RxCount1;
static void DispRxCounter(uint32_t _count1, uint32_t _count2);
/*
*********************************************************************************************************
* : CanReciveNew
* : CAN接收到新的字节的回调函数
* :
* :
*********************************************************************************************************
*/
void CanReciveNew(uint8_t _byte)
{
char buf[32];
if (s_FrameHead1 == 1)
{
s_FrameHead1 = 2;
/* 记录下准确的首字符时刻 us */
s_FrameHeadTime1 = bsp_GetRunTimeUs() - s_BeginTime;
{
if (g_tParam.UartMonTimeStamp == 1) /* 加上时间戳 */
{
if (g_tParam.UartMonHex == 0) /* ASCII格式显示 */
{
uint8_t LastChar;
if (g_RecMemo.Len > 0)
{
LastChar = g_RecMemo.Text[g_RecMemo.Len - 1];
if (LastChar == 0x0D || LastChar == 0x0A)
{
sprintf(buf, "[%d.%03d] ", (int32_t)s_FrameHeadTime1 / 1000, (int32_t)s_FrameHeadTime1 % 1000);
}
else
{
sprintf(buf, "\r\n[%d.%03d] ", (int32_t)s_FrameHeadTime1 / 1000, (int32_t)s_FrameHeadTime1 % 1000);
}
}
else
{
sprintf(buf, "\r\n[%d.%03d] ", (int32_t)s_FrameHeadTime1 / 1000, (int32_t)s_FrameHeadTime1 % 1000);
}
LCD_MemoAddStr(&g_RecMemo, buf);
}
else /* HEX */
{
sprintf(buf, "\r\n[%d.%03d] ", (int32_t)s_FrameHeadTime1 / 1000, (int32_t)s_FrameHeadTime1 % 1000);
LCD_MemoAddStr(&g_RecMemo, buf);
}
}
}
}
if (g_tParam.UartMonHex == 0) /* ASCII格式显示 */
{
LCD_MemoAddChar(&g_RecMemo, _byte);
}
else /* HEX格式显示 */
{
sprintf(buf, "%02X ", _byte);
LCD_MemoAddStr(&g_RecMemo, buf);
}
s_RxCount1++;
}
/*
*********************************************************************************************************
* : status_MonitorCan
* :
* :
* :
*********************************************************************************************************
*/
void status_MonitorCan(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t fRefresh;
uint8_t fInit;
FONT_T tFontMemo;
{
tFontMemo.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFontMemo.FrontColor = CL_WHITE; /* 字体颜色 */
tFontMemo.BackColor = CL_MASK; /* 文字背景颜色 */
tFontMemo.Space = 0; /* 文字间距,单位 = 像素 */
}
{
g_RecMemo.Left = MEMO_X;
g_RecMemo.Top = MEMO_Y;
g_RecMemo.Height = MEMO_H;
g_RecMemo.Width = MEMO_W;
g_RecMemo.Font = &tFontMemo;
//g_LuaMemo.Color = CL_WHITE;
g_RecMemo.Text = g_OutText;
g_RecMemo.MaxLen = sizeof(g_OutText);
g_RecMemo.LineCount = 0;
g_RecMemo.WordWrap = 1;
g_RecMemo.LineOffset = 0;
LCD_InitMemo(&g_RecMemo);
LCD_DrawMemo(&g_RecMemo);
}
LCD_SetEncode(ENCODE_GBK);
UartMonCheckParam(); /* 检查参数 */
fInit = 1;
fRefresh = 1;
while (g_MainStatus == MS_MONITOR_CAN)
{
bsp_Idle();
if (fInit == 1)
{
fInit = 0;
/* 字体 */
if (g_tParam.UartMonFont == 0)
{
tFontMemo.FontCode = FC_ST_12;
}
else if (g_tParam.UartMonFont == 1)
{
tFontMemo.FontCode = FC_ST_16;
}
else if (g_tParam.UartMonFont == 2)
{
tFontMemo.FontCode = FC_ST_24;
}
else
{
tFontMemo.FontCode = FC_ST_16;
}
s_BeginTime = bsp_GetRunTimeUs();
LCD_MemoAddStr(&g_RecMemo, "CAN 功能预留");
s_RxCount1 = 0;
}
if (fRefresh) /* 刷新整个界面 */
{
fRefresh = 0;
DispRxCounter(s_RxCount1, 0);
LCD_DrawMemo(&g_RecMemo);
}
ucKeyCode = bsp_GetKey(); /* 读取键值, 无键按下时返回 KEY_NONE = 0 */
if (ucKeyCode != KEY_NONE)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_UP_S: /* S键 上 */
LCD_MemoPageUp(&g_RecMemo, 1);
fRefresh = 1;
break;
case KEY_LONG_DOWN_S: /* S键 长按 */
LCD_SetEncode(ENCODE_UTF8);
ModifyParam(MS_MONITOR_UART); /* 参数修改界面,阻塞 */
LCD_SetEncode(ENCODE_GBK);
fRefresh = 1;
fInit = 1;
break;
case KEY_UP_C: /* C键 下 */
LCD_MemoPageDown(&g_RecMemo, 1);
fRefresh = 1;
break;
case KEY_LONG_DOWN_C: /* C键长按 */
g_MainStatus = MS_EXTEND_MENU_REC;
break;
default:
break;
}
}
}
LCD_SetEncode(ENCODE_UTF8);
}
/*
*********************************************************************************************************
* : DispRxCounter
* :
* :
* :
*********************************************************************************************************
*/
static void DispRxCounter(uint32_t _count1, uint32_t _count2)
{
FONT_T tFont;
uint16_t x;
uint16_t y;
char buf[128];
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = INFO_NAME_COLOR; /* 字体颜色 */
tFont.BackColor = INFO_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
x = 2;
y = 2;
sprintf(buf, "%8d %8d", _count1, _count2);
LCD_DispStr(x, y, buf, &tFont);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -23,8 +23,8 @@ const uint8_t *g_Menu1_Text[] =
" 1 脱机烧录器(单路)",
" 2 脱机烧录器(多路)",
" 3 LUA小程序",
" 4 数据记录仪",
" 6 系统设置",
" 4 数据监视器",
" 5 系统设置",
/* 结束符号, 用于菜单函数自动识别菜单项个数 */
"&"
@ -34,10 +34,8 @@ MENU_T g_tMenu1;
const uint8_t *g_MenuRec_Text[] =
{
// " 1 串口记录仪",
// " 2 CAN记录仪",
// " 3 IO记录仪",
// " 4 模拟量记录仪",
"1 串口(TTL 485 232)",
"2 CAN总线(预留)",
/* 结束符号, 用于菜单函数自动识别菜单项个数 */
"&"
@ -78,6 +76,7 @@ void status_ExtendMenu1(void)
g_tMenu1.Font.Space = 0;
g_tMenu1.RollBackEn = 1; /* 允许回滚 */
g_tMenu1.GBK = 0;
g_tMenu1.ActiveBackColor = 0; /* 选中行背景色ID */
LCD_InitMenu(&g_tMenu1, (char **)g_Menu1_Text); /* 初始化菜单结构 */
}
LCD_DispMenu(&g_tMenu1);
@ -103,13 +102,11 @@ void status_ExtendMenu1(void)
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_UP_S: /* S键 上 */
case KEY_UP_S: /* S键 上 */
LCD_MoveUpMenu(&g_tMenu1);
break;
case KEY_LONG_DOWN_S: /* S键 上 */
PlayKeyTone();
case KEY_LONG_DOWN_S: /* S键 上 */
if (g_tMenu1.Cursor == 0)
{
g_gMulSwd.MultiMode = 0;
@ -134,11 +131,11 @@ void status_ExtendMenu1(void)
}
break;
case KEY_UP_C: /* C键 下 */
case KEY_UP_C: /* C键 下 */
LCD_MoveDownMenu(&g_tMenu1);
break;
case KEY_LONG_DOWN_C: /* C键长按 */
case KEY_LONG_DOWN_C: /* C键长按 */
PlayKeyTone();
g_MainStatus = MS_LINK_MODE;
break;
@ -177,7 +174,8 @@ void status_ExtendMenuRec(void)
g_tMenuRec.Font.FontCode = FC_ST_24;
g_tMenuRec.Font.Space = 0;
g_tMenuRec.RollBackEn = 1; /* 允许回滚 */
g_tMenuRec.GBK = 0;
g_tMenuRec.GBK = 0;
g_tMenuRec.ActiveBackColor = 0; /* 选中行背景色ID */
LCD_InitMenu(&g_tMenuRec, (char **)g_MenuRec_Text); /* 初始化菜单结构 */
}
LCD_DispMenu(&g_tMenuRec);
@ -209,36 +207,38 @@ void status_ExtendMenuRec(void)
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_UP_S: /* S键 上 */
case KEY_UP_S: /* S键 上 */
PlayKeyTone();
LCD_MoveUpMenu(&g_tMenuRec);
break;
case KEY_LONG_DOWN_S: /* S键 上 */
case KEY_LONG_DOWN_S: /* S键 上 */
PlayKeyTone();
// if (g_tMenuRec.Cursor == 0)
// {
// g_MainStatus = MS_PROG_WORK;
// }
// else if (g_tMenuRec.Cursor == 1)
// {
// g_MainStatus = MS_MODIFY_PARAM;
// }
// else if (g_tMenuRec.Cursor == 2)
// {
// g_MainStatus = MS_ESP32_TEST;
// }
// else if (g_tMenuRec.Cursor == 3)
// {
// g_MainStatus = MS_USB_EMMC;
// }
if (g_tMenuRec.Cursor == 0)
{
g_MainStatus = MS_MONITOR_UART;
}
else if (g_tMenuRec.Cursor == 1)
{
g_MainStatus = MS_MONITOR_CAN;
}
else if (g_tMenuRec.Cursor == 2)
{
g_MainStatus = MS_MONITOR_GPIO;
}
else if (g_tMenuRec.Cursor == 3)
{
g_MainStatus = MS_MONITOR_ANALOG;
}
break;
case KEY_UP_C: /* C键 下 */
case KEY_UP_C: /* C键 下 */
PlayKeyTone();
LCD_MoveDownMenu(&g_tMenuRec);
break;
case KEY_LONG_DOWN_C: /* C键长按 */
case KEY_LONG_DOWN_C: /* C键长按 */
PlayKeyTone();
g_MainStatus = MS_EXTEND_MENU1;
break;

View File

@ -93,6 +93,9 @@ typedef struct
CMD_LIST_T tBtnList[16];
char g_OutText[4 * 1024] = {0}; /* 最多支持4K字节文本缓存 */
MEMO_T g_LuaMemo = {0};
/*
char s_lua_prog_buf[LUA_PROG_LEN_MAX + 1];
uint32_t s_lua_prog_len;
@ -154,8 +157,6 @@ void FindBtnNoteCmd(void)
}
}
char g_OutText[2 * 1024] = {0}; /* 最多支持2K字节文本缓存 */
MEMO_T g_LuaMemo = {0};
void status_LuaRun(void)
{
uint8_t ucKeyCode; /* 按键代码 */
@ -175,7 +176,9 @@ void status_LuaRun(void)
//g_LuaMemo.Color = CL_WHITE;
g_LuaMemo.Text = g_OutText;
g_LuaMemo.MaxLen = sizeof(g_OutText);
g_LuaMemo.LineCount = 0;
g_LuaMemo.LineCount = 0;
g_LuaMemo.WordWrap = 0;
g_LuaMemo.LineOffset = 0;
LCD_InitMemo(&g_LuaMemo);
LCD_DrawMemo(&g_LuaMemo);

View File

@ -893,6 +893,7 @@ void status_ProgSetting(void)
g_tMenuProg1.Font.Space = 0;
g_tMenuProg1.RollBackEn = 1; /* 允许回滚 */
g_tMenuProg1.GBK = 0;
g_tMenuProg1.ActiveBackColor = 0; /* 选中行背景色ID */
LCD_InitMenu(&g_tMenuProg1, (char **)g_MenuProg1_Text); /* 初始化菜单结构 */
}
LCD_DispMenu(&g_tMenuProg1);

View File

@ -29,6 +29,7 @@ const uint8_t *g_MenuSys_Text[] =
" 3 ESP32固件升级",
" 4 USB eMMC磁盘",
" 5 数据维护",
" 6 重启",
/* 结束符号, 用于菜单函数自动识别菜单项个数 */
"&"
};
@ -56,6 +57,7 @@ void status_SystemSetMain(void)
uint8_t ucKeyCode; /* 按键代码 */
uint8_t fRefresh;
static uint8_t s_enter_sub_menu = 0;
uint8_t ResetReq = 0;
DispHeader2(90, "系统设置");
@ -73,6 +75,7 @@ void status_SystemSetMain(void)
g_tMenuSys.Font.Space = 0;
g_tMenuSys.RollBackEn = 1; /* 允许回滚 */
g_tMenuSys.GBK = 0;
g_tMenuSys.ActiveBackColor = 0; /* 选中行背景色ID */
LCD_InitMenu(&g_tMenuSys, (char **)g_MenuSys_Text); /* 初始化菜单结构 */
}
LCD_DispMenu(&g_tMenuSys);
@ -98,7 +101,7 @@ void status_SystemSetMain(void)
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_UP_S: /* S键 上 */
case KEY_UP_S: /* S键 上 */
LCD_MoveUpMenu(&g_tMenuSys);
break;
@ -125,9 +128,22 @@ void status_SystemSetMain(void)
else if (g_tMenuSys.Cursor == 4)
{
g_MainStatus = MS_FILE_MANAGE;
}
}
else if (g_tMenuSys.Cursor == 5) /* 重启 */
{
ResetReq = 1;
}
break;
case KEY_LONG_UP_S: /* 长按弹起 */
if (ResetReq == 1)
{
/* 复位进入APP */
*(uint32_t *)0x20000000 = 0;
NVIC_SystemReset(); /* 复位CPU */
}
break;
case KEY_UP_C: /* C键 下 */
LCD_MoveDownMenu(&g_tMenuSys);
break;

View File

@ -0,0 +1,547 @@
/*
*********************************************************************************************************
*
* :
* : status_DataMonitor.c
* : V1.0
* :
* :
*
* V1.0 2020-09-16 armfly
*
* Copyright (C), 2018-2030, www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "main.h"
#include "lcd_menu.h"
#include "file_lib.h"
#include "lua_if.h"
#include "prog_if.h"
#include "modify_param.h"
/* 多行文本框 */
#define TITLE_X 0
#define TITLE_Y 0
#define TITLE_H 20
#define TITLE_W (240 - 2 * TITLE_X)
/* 多行文本框 */
#define MEMO_X 0
#define MEMO_Y 20
#define MEMO_H (240 - MEMO_Y - 0)
#define MEMO_W (240 - 2 * MEMO_X)
extern char g_OutText[4 * 1024];
MEMO_T g_RecMemo = {0};
static uint8_t s_FrameHead1 = 1;
static uint8_t s_FrameHead2 = 1;
static uint8_t s_FrameTimeout1 = 1;
static uint8_t s_FrameTimeout2 = 1;
static uint64_t s_FrameHeadTime1;
static uint64_t s_FrameHeadTime2;
static uint64_t s_BeginTime;
static uint32_t s_RxCount1, s_RxCount2;
static uint8_t s_Pause = 0;
static void DispRxCounter(uint32_t _count1, uint32_t _count2);
static void UartSettingMenu(void);
static void DispClearTitle(void);
MENU_T g_tMenuUart;
/*
*********************************************************************************************************
* : Uart1ReciveNew
* : RS485串口接收到新的字节的回调函数
* :
* :
*********************************************************************************************************
*/
void UartReciveNew1(uint8_t _byte)
{
char buf[32];
static uint8_t LastChar = 0;
if (s_Pause == 1) /* 暂停 */
{
return;
}
if (s_FrameHead1 == 1)
{
s_FrameHead1 = 0;
/* 记录下准确的首字符时刻 us */
s_FrameHeadTime1 = bsp_GetRunTimeUs() - s_BeginTime;
{
if (g_tParam.UartMonTimeStamp == 1) /* 加上时间戳 */
{
if (g_tParam.UartMonHex == 0) /* ASCII格式显示 */
{
if (LastChar == 0x0D || LastChar == 0x0A)
{
sprintf(buf, "[%llu.%03llu] ", s_FrameHeadTime1 / 1000, s_FrameHeadTime1 % 1000);
}
else
{
sprintf(buf, "\r\n[%llu.%03llu] ", s_FrameHeadTime1 / 1000, s_FrameHeadTime1 % 1000);
}
LCD_MemoAddStr(&g_RecMemo, buf);
}
else /* HEX */
{
sprintf(buf, "\r\n[%llu.%03llu] ", s_FrameHeadTime1 / 1000, s_FrameHeadTime1 % 1000);
LCD_MemoAddStr(&g_RecMemo, buf);
}
}
else
{
/* 无时间戳HEX格式自动换行使能时自动增加回车换行 */
if (g_tParam.UartMonHex == 1 && g_tParam.UartMonWordWrap == 1)
{
sprintf(buf, "\r\n");
LCD_MemoAddStr(&g_RecMemo, buf);
}
}
}
}
if (g_tParam.UartMonHex == 0) /* ASCII格式显示 */
{
LCD_MemoAddChar(&g_RecMemo, _byte);
}
else /* HEX格式显示 */
{
sprintf(buf, "%02X ", _byte);
LCD_MemoAddStr(&g_RecMemo, buf);
}
LastChar = _byte;
s_RxCount1++;
}
void UartReciveNew2(uint8_t _byte)
{
char buf[32];
static uint8_t LastChar = 0;
if (s_Pause == 1) /* 暂停 */
{
return;
}
if (s_FrameHead2 == 1)
{
s_FrameHead2 = 0;
/* 记录下准确的首字符时刻 us */
s_FrameHeadTime2 = bsp_GetRunTimeUs() - s_BeginTime;
{
if (g_tParam.UartMonTimeStamp == 1) /* 加上时间戳 */
{
if (g_tParam.UartMonHex == 0) /* ASCII格式显示 */
{
if (LastChar == 0x0D || LastChar == 0x0A)
{
sprintf(buf, "<%llu.%03llu> ", s_FrameHeadTime2 / 1000, s_FrameHeadTime2 % 1000);
}
else
{
sprintf(buf, "\r\n<%llu.%03llu> ", s_FrameHeadTime2 / 1000, s_FrameHeadTime2 % 1000);
}
LCD_MemoAddStr(&g_RecMemo, buf);
}
else /* HEX */
{
sprintf(buf, "\r\n<%llu.%03llu> ", s_FrameHeadTime2 / 1000, s_FrameHeadTime2 % 1000);
LCD_MemoAddStr(&g_RecMemo, buf);
}
}
else
{
/* 无时间戳HEX格式自动换行使能时自动增加回车换行 */
if (g_tParam.UartMonHex == 1 && g_tParam.UartMonWordWrap == 1)
{
sprintf(buf, "\r\n");
LCD_MemoAddStr(&g_RecMemo, buf);
}
}
}
}
if (g_tParam.UartMonHex == 0) /* ASCII格式显示 */
{
LCD_MemoAddChar(&g_RecMemo, _byte);
}
else /* HEX格式显示 */
{
sprintf(buf, "%02X ", _byte);
LCD_MemoAddStr(&g_RecMemo, buf);
}
LastChar = _byte;
s_RxCount2++;
}
/*
*********************************************************************************************************
* : UartIdleLine1
* : RS485串口线路空闲中断回调函数
* :
* :
*********************************************************************************************************
*/
void UartIdleLine1(void)
{
s_FrameHead1 = 1;
s_FrameTimeout1 = 1;
}
void UartIdleLine2(void)
{
s_FrameHead2 = 1;
s_FrameTimeout2 = 1;
}
/*
*********************************************************************************************************
* : status_MonitorUart
* :
* :
* :
*********************************************************************************************************
*/
extern const char *UartMonParam1[];
extern const char *UartMonParam6[];
void status_MonitorUart(void)
{
uint8_t ucKeyCode; /* 按键代码 */
uint8_t fRefresh;
uint8_t fInit;
FONT_T tFontMemo;
char buf[128];
{
tFontMemo.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFontMemo.FrontColor = CL_WHITE; /* 字体颜色 */
tFontMemo.BackColor = CL_MASK; /* 文字背景颜色 */
tFontMemo.Space = 0; /* 文字间距,单位 = 像素 */
}
DispClearTitle();
{
g_RecMemo.Left = MEMO_X;
g_RecMemo.Top = MEMO_Y;
g_RecMemo.Height = MEMO_H;
g_RecMemo.Width = MEMO_W;
g_RecMemo.Font = &tFontMemo;
//g_LuaMemo.Color = CL_WHITE;
g_RecMemo.Text = g_OutText;
g_RecMemo.MaxLen = sizeof(g_OutText);
g_RecMemo.LineCount = 0;
g_RecMemo.WordWrap = 1;
g_RecMemo.LineOffset = 0;
LCD_InitMemo(&g_RecMemo);
LCD_DrawMemo(&g_RecMemo);
}
LCD_SetEncode(ENCODE_GBK);
UartMonCheckParam(); /* 检查参数 */
s_Pause = 0;
fInit = 1;
fRefresh = 1;
s_FrameHead1 = 1;
s_FrameHead2 = 1;
while (g_MainStatus == MS_MONITOR_UART)
{
bsp_Idle();
if (fInit == 1)
{
uint32_t BaudTab[] = {1200, 2400, 4700, 9600, 19200, 38400, 57600, 115200};
uint32_t parity[] = {UART_PARITY_NONE, UART_PARITY_ODD, UART_PARITY_EVEN};
char *ParTable[] = {"None", "Odd", "Even"};
fInit = 0;
/* 字体 */
if (g_tParam.UartMonFont == 0)
{
tFontMemo.FontCode = FC_ST_12;
}
else if (g_tParam.UartMonFont == 1)
{
tFontMemo.FontCode = FC_ST_16;
}
else if (g_tParam.UartMonFont == 2)
{
tFontMemo.FontCode = FC_ST_24;
}
else
{
tFontMemo.FontCode = FC_ST_16;
}
s_BeginTime = bsp_GetRunTimeUs();
/* 设置第1个串口 9600 无校验 */
bsp_SetUartParam(COM_RS485, BaudTab[g_tParam.UartMonBaud],
parity[g_tParam.UartMonParit], UART_WORDLENGTH_8B, UART_STOPBITS_1);
/* 配置第1个串口中断回调函数 */
comSetCallBackReciveNew(COM_RS485, UartReciveNew1);
comSetCallBackIdleLine(COM_RS485, UartIdleLine1);
comSetReciverTimeout(COM_RS485, 20); /* 接收器超时时间 */
/* 设置第2个串口 9600 无校验 */
EIO_ConfigPort(EIO_D1, ES_GPIO_UART); /* UART7_RX */
bsp_SetUartParam(COM_UART7, BaudTab[g_tParam.UartMonBaud],
parity[g_tParam.UartMonParit], UART_WORDLENGTH_8B, UART_STOPBITS_1);
/* 配置第2个串口中断回调函数 */
comSetCallBackReciveNew(COM_UART7, UartReciveNew2);
comSetCallBackIdleLine(COM_UART7, UartIdleLine2);
comSetReciverTimeout(COM_UART7, 20); /* 接收器超时时间 */
sprintf(buf, "Uart : %d, %s", BaudTab[g_tParam.UartMonBaud], ParTable[g_tParam.UartMonParit]);
if (g_tParam.UartMonHex == 0) strcat(buf, ", ASCII\r\n"); else strcat(buf, ", HEX\r\n");
LCD_MemoAddStr(&g_RecMemo, buf);
s_RxCount1 = 0;
s_RxCount2 = 0;
}
if (fRefresh) /* 刷新整个界面 */
{
fRefresh = 0;
DispRxCounter(s_RxCount1, s_RxCount2);
LCD_DrawMemo(&g_RecMemo);
}
if (s_FrameTimeout1 == 1)
{
s_FrameTimeout1 = 0;
fRefresh = 1;
}
if (s_FrameTimeout2 == 1)
{
s_FrameTimeout2 = 0;
fRefresh = 1;
}
ucKeyCode = bsp_GetKey(); /* 读取键值, 无键按下时返回 KEY_NONE = 0 */
if (ucKeyCode != KEY_NONE)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_UP_S: /* S键 上 */
LCD_MemoPageUp(&g_RecMemo, 5);
fRefresh = 1;
break;
case KEY_LONG_DOWN_S: /* S键 长按 */
UartSettingMenu(); /* 参数设置,阻塞 */
if (g_tMenuUart.Cursor == 0) /* 返回 */
{
;
}
else if (g_tMenuUart.Cursor == 1) /* 暂停/恢复 */
{
if (s_Pause == 0)
{
s_Pause = 1;
LCD_MemoAddStr(&g_RecMemo, "\r\npause\r\n");
}
else
{
s_Pause = 0;
LCD_MemoAddStr(&g_RecMemo, "\r\nresume\r\n");
}
}
else if (g_tMenuUart.Cursor == 2) /* 清屏 */
{
LCD_MemoClear(&g_RecMemo);
s_RxCount1 = 0;
s_RxCount2 = 0;
}
else if (g_tMenuUart.Cursor == 3) /* 设置串口参数 */
{
LCD_SetEncode(ENCODE_UTF8);
ModifyParam(MS_MONITOR_UART); /* 参数修改界面,阻塞 */
LCD_SetEncode(ENCODE_GBK);
fInit = 1;
}
DispClearTitle();
fRefresh = 1;
break;
case KEY_UP_C: /* C键 下 */
LCD_MemoPageDown(&g_RecMemo, 5);
fRefresh = 1;
break;
case KEY_LONG_DOWN_C: /* C键长按 */
g_MainStatus = MS_EXTEND_MENU_REC;
break;
default:
break;
}
}
}
LCD_SetEncode(ENCODE_UTF8);
/* 取消所有的回调函数 */
comSetCallBackReciveNew(COM_RS485, 0);
comSetCallBackIdleLine(COM_RS485, 0);
comSetCallBackReciveNew(COM_UART7, 0);
comSetCallBackIdleLine(COM_UART7, 0);
EIO_ConfigPort(EIO_D1, ES_GPIO_IN); /* UART7_RX */
}
/*
*********************************************************************************************************
* : DispClearTitle
* :
* :
* :
*********************************************************************************************************
*/
static void DispClearTitle(void)
{
LCD_Fill_Rect(TITLE_X, TITLE_Y, TITLE_H, TITLE_W, CL_WHITE);
}
static void DispRxCounter(uint32_t _count1, uint32_t _count2)
{
FONT_T tFont;
uint16_t x;
uint16_t y;
char buf[128];
/* 设置字体参数 */
{
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
tFont.FrontColor = INFO_NAME_COLOR; /* 字体颜色 */
tFont.BackColor = INFO_BACK_COLOR; /* 文字背景颜色 */
tFont.Space = 0; /* 文字间距,单位 = 像素 */
}
x = 2;
y = 2;
sprintf(buf, "[RX1:%8d] <RX2:%8d>", _count1, _count2);
LCD_DispStr(x, y, buf, &tFont);
}
const uint8_t *g_MenuUart_Text[] =
{
"0 返回",
"1 暂停/恢复",
"2 清屏",
"3 设置串口参数",
/* 结束符号, 用于菜单函数自动识别菜单项个数 */
"&"
};
/*
*********************************************************************************************************
* : UartMenuPro
* :
* :
* :
*********************************************************************************************************
*/
static void UartSettingMenu(void)
{
uint8_t ucKeyCode; /* 按键代码 */
static uint8_t s_MenuInit = 0;
uint8_t fQuit = 0;
if (s_MenuInit == 0)
{
s_MenuInit = 1;
g_tMenuUart.Left = MENU_LEFT;
g_tMenuUart.Top = MENU_TOP;
g_tMenuUart.Height = MENU_HEIGHT;
g_tMenuUart.Width = MENU_WIDTH;
g_tMenuUart.LineCap = MENU_CAP;
g_tMenuUart.ViewLine = 8;
g_tMenuUart.Font.FontCode = FC_ST_24;
g_tMenuUart.Font.Space = 0;
g_tMenuUart.RollBackEn = 1; /* 允许回滚 */
g_tMenuUart.GBK = 0;
g_tMenuUart.ActiveBackColor = 0; /* 选中行背景色ID */
LCD_InitMenu(&g_tMenuUart, (char **)g_MenuUart_Text); /* 初始化菜单结构 */
}
LCD_DispMenu(&g_tMenuUart);
DispHeader("请选择");
LCD_DispMenu(&g_tMenuUart);
while (fQuit == 0)
{
bsp_Idle();
ucKeyCode = bsp_GetKey(); /* 读取键值, 无键按下时返回 KEY_NONE = 0 */
if (ucKeyCode != KEY_NONE)
{
/* 有键按下 */
switch (ucKeyCode)
{
case KEY_UP_S: /* S键 上 */
LCD_MoveUpMenu(&g_tMenuUart);
break;
case KEY_LONG_DOWN_S: /* S键长按 */
fQuit = 1;
break;
case KEY_UP_C: /* C键 下 */
LCD_MoveDownMenu(&g_tMenuUart);
break;
case KEY_LONG_DOWN_C: /* C键长按 */
fQuit = 1;
break;
default:
break;
}
}
}
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -100,7 +100,7 @@ void status_VoltageMeter(void)
*/
static void AutoVoltRange(void)
{
float range[] = {13.8, 6.4, 3.2, 1.6, 0.8, 0.4, 0.2, 0.1};
float range[] = {13.8, 6.4, 3.2, 1.6, 0.8, 0.4, 0.2, 0.095};
uint8_t i;
for (i = 0; i < 8; i++)

View File

@ -342,12 +342,17 @@ typedef struct
uint16_t Arc; /* 圆角弧半径 */
uint16_t Color; /* 填充颜色 */
char *Text; /* 执行文本区 */
uint32_t MaxLen; /* 文本最大长度 */
uint16_t LineCount; /* 行数 */
uint32_t Len; /* 字符串长度 */
uint32_t FifoRead; /* FIFO读位置 */
uint32_t FifoWrite; /* FIFO写位置 */
FONT_T *Font; /* 字体 */
uint16_t Cursor; /* 行光标, 保留未用 */
uint8_t Refresh; /* 1表示内容变化需要显示刷新 */
uint8_t WordWrap; /* 1表示自动换行 */
int32_t LineOffset; /* 查询时向前翻行的行数 */
}MEMO_T;
/* 背景光控制 */
@ -412,7 +417,9 @@ void LCD_DrawMemo(MEMO_T *_pMemo);
void LCD_MemoAddStr(MEMO_T *_pMemo, char *_str);
void LCD_MemoAddChar(MEMO_T *_pMemo, char _ch);
void LCD_MemoClear(MEMO_T *_pMemo);
void LCD_MemoPageDown(MEMO_T *_pMemo, uint16_t _LineNum);
void LCD_MemoPageUp(MEMO_T *_pMemo, uint16_t _LineNum);
void LCD_SetEncode(uint8_t _code);
uint8_t LCD_GetEncode(void);

View File

@ -47,6 +47,9 @@ uint8_t bsp_CheckTimer(uint8_t _id);
int32_t bsp_GetRunTime(void);
int32_t bsp_CheckRunTime(int32_t _LastTime);
uint64_t bsp_GetRunTimeUs(void);
int64_t bsp_CheckRunTimeUs(int64_t _LastTime);
void bsp_InitHardTimer(void);
void bsp_StartHardTimer(uint8_t _CC, uint32_t _uiTimeOut, void *_pCallBack);
void bsp_DelayNS(uint32_t n);

View File

@ -181,6 +181,8 @@ typedef struct
void (*SendBefor)(void); /* 开始发送之前的回调函数指针主要用于RS485切换到发送模式 */
void (*SendOver)(void); /* 发送完毕的回调函数指针主要用于RS485将发送模式切换为接收模式 */
void (*ReciveNew)(uint8_t _byte); /* 串口收到数据的回调函数指针 */
void (*IdleLine)(void); /* 字符间超时(线路空闲)中断 */
uint8_t Sending; /* 正在发送中 */
}UART_T;
@ -210,6 +212,9 @@ void bsp_SetUartParam(COM_PORT_E _ucPort, uint32_t BaudRate, uint32_t Parity, ui
uint32_t comGetBaud(COM_PORT_E _ucPort);
void comSetBaud(COM_PORT_E _ucPort, uint32_t _BaudRate);
void comSetCallBackReciveNew(COM_PORT_E _ucPort, void (*_ReciveNew)(uint8_t _byte));
void comSetCallBackIdleLine(COM_PORT_E _ucPort, void (*_IdleLine)(void));
void comSetReciverTimeout(COM_PORT_E _ucPort, uint32_t _Timeout);
#endif

View File

@ -349,14 +349,6 @@ void IRQ_WatchDog(void)
uint8_t triged = 0;
uint16_t *pAdcBuf;
ADC_HandleTypeDef *hadc;
static uint8_t s_TrigToggle = 0;
// HAL_ADC_IRQHandler(&AdcHandle1);
// HAL_ADC_IRQHandler(&AdcHandle2);
// __DSO_DisableDog();
/* CH1 触发 */
tmp_isr = AdcHandle1.Instance->ISR;
@ -371,20 +363,6 @@ void IRQ_WatchDog(void)
DmaPos = ADC_BUFFER_SIZE - CT_CH1_DMA_Stream->NDTR; /* DMA传输位置 */
triged = 1;
}
// if (s_TrigToggle == 1)
// {
// if (g_tDSO.TrigEdge == TRIG_EDGE_FALLING)
// {
// DSO_SetTrigerToggle(TRIG_EDGE_FALLING); /* 切换触发方向 */
// }
// else
// {
// DSO_SetTrigerToggle(TRIG_EDGE_RISING); /* 切换触发方向 */
// }
// s_TrigToggle = 0;
// return;
// }
/* CH2 触发*/
tmp_isr = AdcHandle2.Instance->ISR;
@ -482,27 +460,42 @@ void IRQ_WatchDog(void)
BeginPos = ADC_BUFFER_SIZE + BeginPos;
}
g_tDSO.DmaPos = BeginPos; /* 保存触发前的位置 */
s_TrigToggle = 0;
g_tDSO.DmaPos = BeginPos; /* 保存触发前的位置 */
}
else
{
{
if (g_tDSO.TrigEdge == TRIG_EDGE_FALLING)
{
DSO_SetTrigerToggle(TRIG_EDGE_RISING); /* 切换触发方向 */
if (avg_last < g_tDSO.TrigLevel)
{
DSO_SetTrigerToggle(TRIG_EDGE_RISING);
}
else
{
DSO_SetTrigerToggle(TRIG_EDGE_FALLING);
}
}
else
else /* TRIG_EDGE_RISING */
{
DSO_SetTrigerToggle(TRIG_EDGE_FALLING); /* 切换触发方向 */
if (avg_last < g_tDSO.TrigLevel)
{
DSO_SetTrigerToggle(TRIG_EDGE_RISING);
}
else
{
DSO_SetTrigerToggle(TRIG_EDGE_FALLING);
}
}
s_TrigToggle = 1;
/* Clear ADC Analog watchdog flag */
AdcHandle1.Instance->ISR = ADC_FLAG_AWD1;
AdcHandle2.Instance->ISR = ADC_FLAG_AWD1;
}
}
}
}
void ADC_IRQHandler(void)
{
IRQ_WatchDog();

View File

@ -3,12 +3,13 @@
*
* : emmc驱动模块
* : bsp_emmc.c
* : V1.0
* : V1.1
* : emmc存储器底层驱动 stm32h750b_discovery_mmc.c文件修改
*
* :
*
* V1.0 2019-08-13 armfly
*
* V1.0 2019-08-13 armfly
* V1.1 2020-09-17 baiyongbin emmc驱动4线
*
* Copyright (C), 2018-2030, www.armfly.com
*
@ -110,17 +111,21 @@ uint8_t BSP_MMC_Init(void)
{
uint8_t mmc_state = MMC_OK;
BSP_MMC_DeInit();
/* uMMC device interface configuration */
uSdHandle.Instance = SDMMC1;
/* if CLKDIV = 0 then SDMMC Clock frequency = SDMMC Kernel Clock
else SDMMC Clock frequency = SDMMC Kernel Clock / [2 * CLKDIV].
200MHz / (2*2) = 50MHz
200MHz / (2*3) = 33MHz
*/
uSdHandle.Init.ClockDiv = 3; /* 2019-12-13 2 -> 3 */
uSdHandle.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE;
uSdHandle.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING;
uSdHandle.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE;
uSdHandle.Init.BusWide = SDMMC_BUS_WIDE_8B;
uSdHandle.Init.BusWide = SDMMC_BUS_WIDE_4B;
/* Msp MMC initialization */
BSP_MMC_MspInit(&uSdHandle, NULL);
@ -130,6 +135,9 @@ uint8_t BSP_MMC_Init(void)
{
mmc_state = MMC_ERROR;
}
/* SDIO的四线方式或8线方式 */
HAL_MMC_ConfigWideBusOperation(&uSdHandle, SDMMC_BUS_WIDE_8B);
return mmc_state;
}
@ -294,7 +302,7 @@ __weak void BSP_MMC_MspInit(MMC_HandleTypeDef *hmmc, void *Params)
/* Common GPIO configuration */
gpio_init_structure.Mode = GPIO_MODE_AF_PP;
gpio_init_structure.Pull = GPIO_PULLUP;
gpio_init_structure.Speed = GPIO_SPEED_FREQ_HIGH; /* 改为GPIO_SPEED_FREQ_HIGH 以前GPIO_SPEED_FREQ_VERY_HIGH*/
gpio_init_structure.Speed = GPIO_SPEED_FREQ_MEDIUM; /* 改为GPIO_SPEED_FREQ_HIGH 以前GPIO_SPEED_FREQ_VERY_HIGH*/
gpio_init_structure.Alternate = GPIO_AF12_SDIO1;
/* SDMMC GPIO CLKIN PB8, D0 PC8, D1 PC9, D2 PC10, D3 PC11, CK PC12, CMD PD2 */

View File

@ -3169,44 +3169,39 @@ void LCD_MemoAddStr(MEMO_T *_pMemo, char *_str)
{
uint32_t i = 0;
uint32_t InputLen;
uint32_t len;
uint32_t fond = 0;
InputLen = strlen(_str);
/* 如果超过容器长度, 则清除以前的数据清除前面的30% */
len = 0;
if (_pMemo->Len + len >= _pMemo->MaxLen)
{
for (i = _pMemo->MaxLen / 3; i < _pMemo->MaxLen; i++)
{
if (fond == 0)
{
if (_pMemo->Text[i] == 0x0A)
{
fond = 1;
}
}
else
{
_pMemo->Text[len++] = _pMemo->Text[i];
if (_pMemo->Text[i] == 0)
{
break;
}
}
}
_pMemo->Len = len;
}
/* 追加新字符串填入 */
for (i = 0; i < InputLen; i++)
{
_pMemo->Text[_pMemo->Len++] = _str[i];
_pMemo->Text[_pMemo->FifoWrite] = _str[i];
if (++_pMemo->FifoWrite >= _pMemo->MaxLen)
{
_pMemo->FifoWrite = 0;
}
if (_pMemo->Len < _pMemo->MaxLen)
{
_pMemo->Len++;
}
}
if (_pMemo->Len < _pMemo->MaxLen)
{
_pMemo->FifoRead = 0;
}
_pMemo->Text[_pMemo->Len] = 0;
_pMemo->Refresh = 1; /* 内容变化,需要刷新显示 */
else
{
_pMemo->FifoRead = _pMemo->FifoWrite + 1024; /* 预留1K缓冲带 */
if (_pMemo->FifoRead >= _pMemo->MaxLen)
{
_pMemo->FifoRead = 0;
}
}
_pMemo->Refresh = 1; /* 内容变化,需要刷新显示 */
}
/*
@ -3220,11 +3215,66 @@ void LCD_MemoAddStr(MEMO_T *_pMemo, char *_str)
*/
void LCD_MemoAddChar(MEMO_T *_pMemo, char _ch)
{
char buf[2];
_pMemo->Text[_pMemo->FifoWrite] = _ch;
if (++_pMemo->FifoWrite >= _pMemo->MaxLen)
{
_pMemo->FifoWrite = 0;
_pMemo->FifoRead = 1;
}
buf[0] = _ch;
buf[1] = 0;
LCD_MemoAddStr(_pMemo, buf);
_pMemo->Text[_pMemo->FifoWrite] = 0;
if (_pMemo->Len < _pMemo->MaxLen)
{
_pMemo->FifoRead = 0;
_pMemo->Len++;
}
else
{
_pMemo->FifoRead = _pMemo->FifoWrite + 1024; /* 预留1K缓冲带 */
if (_pMemo->FifoRead >= _pMemo->MaxLen)
{
_pMemo->FifoRead = 0;
}
}
_pMemo->Refresh = 1; /* 内容变化,需要刷新显示 */
}
/*
*********************************************************************************************************
* : LCD_MemoPageDown
* :
* : _pMemo :
* _LineNum :
* :
*********************************************************************************************************
*/
void LCD_MemoPageDown(MEMO_T *_pMemo, uint16_t _LineNum)
{
if (_pMemo->LineOffset < _pMemo->LineCount)
{
_pMemo->LineOffset += _LineNum;
}
}
/*
*********************************************************************************************************
* : LCD_MemoPageUp
* :
* : _pMemo :
* _LineNum :
* :
*********************************************************************************************************
*/
void LCD_MemoPageUp(MEMO_T *_pMemo, uint16_t _LineNum)
{
if (_pMemo->LineOffset > -_pMemo->LineCount)
{
_pMemo->LineOffset -= _LineNum;
}
}
/*
@ -3239,6 +3289,9 @@ void LCD_MemoClear(MEMO_T *_pMemo)
{
_pMemo->Len = 0;
_pMemo->Text[0] = 0;
_pMemo->FifoWrite = 0;
_pMemo->FifoRead = 0;
LCD_Fill_Rect(_pMemo->Left + 1, _pMemo->Top + 1, _pMemo->Height - 2, _pMemo->Width - 2, EDIT_BACK_COLOR);
}
@ -3255,6 +3308,8 @@ void LCD_InitMemo(MEMO_T *_pMemo)
_pMemo->id = 0;
_pMemo->Len = 0;
_pMemo->Text[0] = 0;
_pMemo->FifoWrite = 0;
_pMemo->FifoRead = 0;
_pMemo->Refresh = 0;
}
@ -3277,12 +3332,15 @@ void LCD_DrawMemo(MEMO_T *_pMemo)
uint16_t TextLineNum;
uint16_t line;
uint16_t CanDispLineNum; /* 可以显示的行数 */
uint16_t BeginLine;
uint32_t i,k;
int16_t BeginLine;
uint32_t i;
uint8_t FontHeight;
char *pSave;
char *p;
char buf[128]; /* 每行最大128字符 */
char buf[128]; /* 每行最大128字符 */
uint16_t CharNum; /* 自动换行时,每行字符个数 */
uint16_t LenPerLine; /* 每行最大字符数 */
uint16_t FifoRead;
uint16_t FifoWrite;
uint16_t FifoLen;
_pMemo->Refresh = 0;
@ -3291,84 +3349,351 @@ void LCD_DrawMemo(MEMO_T *_pMemo)
return;
}
DISABLE_INT();
FifoRead = _pMemo->FifoRead; /* 确定首字符位置 */
FifoWrite = _pMemo->FifoWrite;
ENABLE_INT();
if (FifoRead == FifoWrite)
{
return;
}
else if (FifoWrite > FifoRead)
{
FifoLen = FifoWrite - FifoRead;
}
else
{
FifoLen = _pMemo->MaxLen - FifoRead + FifoWrite;
}
/* 绘制边框,填充窗口 */
LCD_DrawRect(_pMemo->Left, _pMemo->Top, _pMemo->Height, _pMemo->Width, EDIT_BORDER_COLOR);
LCD_Fill_Rect(_pMemo->Left + 1, _pMemo->Top + 1, _pMemo->Height - 2, _pMemo->Width - 2, EDIT_BACK_COLOR);
/* 解析文本,计算行数 */
p = _pMemo->Text;
TextLineNum = 0;
for (i = 0; i < _pMemo->MaxLen; i++)
if (_pMemo->WordWrap == 0) /* 不自动换行 */
{
if (p[i] == 0)
{
break;
}
if (p[i] == 0x0D || p[i] == 0x0A)
{
TextLineNum++;
if (p[i + 1] == 0x0A)
{
i++;
}
}
}
_pMemo->LineCount = TextLineNum;
/* 计算可以显示的行数 */
FontHeight = LCD_GetFontHeight(_pMemo->Font);
CanDispLineNum = (_pMemo->Height - 2) / (FontHeight + LINE_CAP);
/* 计算第1行位置 */
if (TextLineNum <= CanDispLineNum)
{
BeginLine = 0;
}
else
{
BeginLine = TextLineNum - CanDispLineNum;
}
x = _pMemo->Left + 2;
y = _pMemo->Top + 2;
line = 0;
p = _pMemo->Text;
pSave = p;
for (i = 0; i < _pMemo->MaxLen; i++)
{
if (p[i] == 0)
{
break;
}
if (p[i] == 0x0D || p[i] == 0x0A)
{
if (line++ >= BeginLine)
{
for (k = 0; k < sizeof(buf); k++)
{
if (pSave[k] == 0x0D || pSave[k] == 0x0A)
{
buf[k] = 0;
break;
}
else
{
buf[k] = pSave[k];
}
}
LCD_DispStrEx(x, y, buf, _pMemo->Font, _pMemo->Width - 4, ALIGN_LEFT);
y += FontHeight + LINE_CAP;
}
if (p[i + 1] == 0x0A)
/* 解析文本,计算行数 */
TextLineNum = 0;
for (i = 0; i < FifoLen; i++)
{
uint8_t ch;
uint16_t idx;
idx = FifoRead + i;
if (idx >= _pMemo->MaxLen)
{
i++;
idx = idx - _pMemo->MaxLen;
}
ch = _pMemo->Text[idx];
if (ch == 0)
{
break;
}
if (ch == 0x0D || ch == 0x0A)
{
TextLineNum++;
idx++;
if (idx >= _pMemo->MaxLen)
{
idx = idx - _pMemo->MaxLen;
}
ch = _pMemo->Text[idx];
if (ch == 0x0A)
{
i++;
}
}
}
_pMemo->LineCount = TextLineNum;
/* 计算可以显示的行数 */
FontHeight = LCD_GetFontHeight(_pMemo->Font);
CanDispLineNum = (_pMemo->Height - 2) / (FontHeight + LINE_CAP) - 1;
/* 计算第1行位置 */
if (TextLineNum <= CanDispLineNum)
{
BeginLine = 0;
}
else
{
BeginLine = TextLineNum - CanDispLineNum;
}
/* 翻页功能 */
BeginLine += _pMemo->LineOffset;
if (BeginLine >= TextLineNum)
{
BeginLine = TextLineNum - 1;
//_pMemo->LineOffset = 0;
}
if (BeginLine < 0)
{
BeginLine = 0;
//_pMemo->LineOffset = 0;
}
x = _pMemo->Left + 2;
y = _pMemo->Top + 2;
line = 0;
CharNum = 0;
for (i = 0; i < FifoLen; i++)
{
uint8_t ch;
uint16_t idx;
idx = FifoRead + i;
if (idx >= _pMemo->MaxLen)
{
idx = idx - _pMemo->MaxLen;
}
ch = _pMemo->Text[idx];
if (ch == 0)
{
if (CharNum > 0)
{
buf[CharNum] = 0;
LCD_DispStrEx(x, y, buf, _pMemo->Font, _pMemo->Width - 4, ALIGN_LEFT);
}
break;
}
if (CharNum < sizeof(buf))
{
buf[CharNum++] = ch;
}
if (ch == 0x0D || ch == 0x0A)
{
if (line++ >= BeginLine)
{
buf[CharNum] = 0;
LCD_DispStrEx(x, y, buf, _pMemo->Font, _pMemo->Width - 4, ALIGN_LEFT);
y += FontHeight + LINE_CAP;
}
CharNum = 0;
pSave = &p[i + 1]; /* 下一行起始位置 */
}
}
if (++idx >= _pMemo->MaxLen)
{
idx = idx - _pMemo->MaxLen;
}
ch = _pMemo->Text[idx];
if (ch == 0x0A)
{
i++;
}
}
}
}
else /* 自动换行 */
{
if (_pMemo->Font->FontCode == FC_ST_12)
{
LenPerLine = (_pMemo->Width - 4) / 6;
}
else if (_pMemo->Font->FontCode == FC_ST_16)
{
LenPerLine = (_pMemo->Width - 4) / 8;
}
else if (_pMemo->Font->FontCode == FC_ST_24)
{
LenPerLine = (_pMemo->Width - 4) / 12;
}
else
{
LenPerLine = (_pMemo->Width - 4) / 8;
}
/* 解析文本,计算行数 */
TextLineNum = 0;
CharNum = 0;
for (i = 0; i < FifoLen; i++)
{
uint8_t ch;
uint16_t idx;
idx = FifoRead + i;
if (idx >= _pMemo->MaxLen)
{
idx = idx - _pMemo->MaxLen;
}
ch = _pMemo->Text[idx];
if (ch == 0x0D || ch == 0x0A)
{
TextLineNum++;
CharNum = 0;
if (++idx >= _pMemo->MaxLen)
{
idx = idx - _pMemo->MaxLen;
}
ch = _pMemo->Text[idx];
if (ch == 0x0A)
{
i++;
}
}
else
{
if (ch == 0)
{
if (CharNum > 0)
{
TextLineNum++;
}
break;
}
CharNum++;
if (ch > 0x80) /* 简单处理半个汉字问题 */
{
CharNum++;
i++;
}
if (CharNum > LenPerLine - 1)
{
TextLineNum++;
CharNum = 0;
}
}
}
_pMemo->LineCount = TextLineNum;
/* 计算可以显示的行数 */
FontHeight = LCD_GetFontHeight(_pMemo->Font);
CanDispLineNum = (_pMemo->Height - 2) / (FontHeight + LINE_CAP) - 1;
/* 计算第1行位置 */
if (TextLineNum <= CanDispLineNum)
{
BeginLine = 0;
}
else
{
BeginLine = TextLineNum - CanDispLineNum;
}
/* 翻页功能 */
BeginLine += _pMemo->LineOffset;
if (BeginLine >= TextLineNum)
{
BeginLine = TextLineNum - 1;
_pMemo->LineOffset--;
}
if (BeginLine < 0)
{
BeginLine = 0;
_pMemo->LineOffset++;
}
/* 开始显示 */
x = _pMemo->Left + 2;
y = _pMemo->Top + 2;
line = 0;
CharNum = 0;
for (i = 0; i < FifoLen; i++)
{
uint8_t ch;
uint16_t idx;
idx = FifoRead + i;
if (idx >= _pMemo->MaxLen)
{
idx = idx - _pMemo->MaxLen;
}
ch = _pMemo->Text[idx];
if (ch == 0x0D || ch == 0x0A)
{
buf[CharNum] = 0;
CharNum = 0;
if (line >= BeginLine && line < BeginLine + CanDispLineNum)
{
LCD_DispStrEx(x, y, buf, _pMemo->Font, _pMemo->Width - 4, ALIGN_LEFT);
y += FontHeight + LINE_CAP;
}
line++;
if (++idx >= _pMemo->MaxLen)
{
idx = idx - _pMemo->MaxLen;
}
ch = _pMemo->Text[idx];
if (ch == 0x0A)
{
i++;
}
}
else
{
if (ch == 0)
{
if (CharNum > 0)
{
buf[CharNum] = 0;
CharNum = 0;
if (line >= BeginLine && line < BeginLine + CanDispLineNum)
{
LCD_DispStrEx(x, y, buf, _pMemo->Font, _pMemo->Width - 4, ALIGN_LEFT);
y += FontHeight + LINE_CAP;
}
line++;
}
break;
}
buf[CharNum] = ch;
CharNum++;
if (ch > 0x80) /* 简单处理半个汉字问题 */
{
if (++idx >= _pMemo->MaxLen)
{
idx = idx - _pMemo->MaxLen;
}
ch = _pMemo->Text[idx];
buf[CharNum] = ch;
CharNum++;
i++;
}
if (CharNum > LenPerLine - 1)
{
if (line >= BeginLine && line < BeginLine + CanDispLineNum)
{
buf[CharNum] = 0;
LCD_DispStrEx(x, y, buf, _pMemo->Font, _pMemo->Width - 4, ALIGN_LEFT);
y += FontHeight + LINE_CAP;
}
line++;
CharNum = 0;
}
}
}
}
if (CharNum > 0)
{
buf[CharNum] = 0;
LCD_DispStrEx(x, y, buf, _pMemo->Font, _pMemo->Width - 4, ALIGN_LEFT);
y += FontHeight + LINE_CAP;
CharNum = 0;
}
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/

View File

@ -344,9 +344,6 @@ void ST7789_DrawScreen(void)
{
return;
}
/* 放到前面判断 */
while (wTransferState == 0){}
s_DispRefresh = 0;
@ -359,6 +356,8 @@ void ST7789_DrawScreen(void)
wTransferState = 0;
HAL_SPI_Transmit_DMA(&hspi5, (uint8_t *)(0x30000000), 240 * 240);
while (wTransferState == 0){}
s_time1 = bsp_GetRunTime();
#endif

View File

@ -62,7 +62,7 @@
#define TIM_HARD_IRQHandler TIM5_IRQHandler
#endif
__IO uint32_t g_uiTimeHighWord = 0;
/* 保存 TIM定时中断到后执行的回调函数指针 */
static void (*s_TIM_CallBack1)(void);
@ -77,11 +77,13 @@ static volatile uint8_t s_ucTimeOutFlag = 0;
/* 定于软件定时器结构体变量 */
static SOFT_TMR s_tTmr[TMR_COUNT] = {0};
/*
1ms
24.85
*/
__IO int32_t g_iRunTime = 0;
__IO uint64_t g_uiTimeHighWord = 0;
static __IO uint8_t g_ucEnableSystickISR = 0; /* 等待变量初始化 */
@ -408,7 +410,8 @@ uint8_t bsp_CheckTimer(uint8_t _id)
/*
*********************************************************************************************************
* : bsp_GetRunTime
* : CPU运行时间1ms 24.85
* : CPU运行时间1ms 24.85
*
* :
* : CPU运行时间1ms
*********************************************************************************************************
@ -425,7 +428,8 @@ int32_t bsp_GetRunTime(void)
// return runtime;
g_iRunTime = TIM_HARD->CNT / 1000;
/* 用硬件定时器计时后4294秒约 1.19小时 */
g_iRunTime = (TIM_HARD->CNT / 1000);
return g_iRunTime;
}
@ -459,6 +463,48 @@ int32_t bsp_CheckRunTime(int32_t _LastTime)
return time_diff;
}
/*
*********************************************************************************************************
* : bsp_GetRunTimeUs
* : CPU运行时间1ms 24.85
*
* :
* : CPU运行时间1us.
*********************************************************************************************************
*/
uint64_t bsp_GetRunTimeUs(void)
{
return TIM_HARD->CNT + g_uiTimeHighWord;;
}
/*
*********************************************************************************************************
* : bsp_CheckRunTimeUs
* :
* : _LastTime
* : 1us
*********************************************************************************************************
*/
int64_t bsp_CheckRunTimeUs(int64_t _LastTime)
{
int64_t now_time;
int64_t time_diff;
now_time = TIM_HARD->CNT + g_uiTimeHighWord;
if (now_time >= _LastTime)
{
time_diff = now_time - _LastTime;
}
else
{
/* Windwos计算机将 0xFFFFFFFFFFFFFFFF 做 -1处理 */
time_diff = 0xFFFFFFFFFFFFFFFE - _LastTime + now_time;
}
return time_diff;
}
/*
*********************************************************************************************************
* : bsp_DelayNS
@ -714,7 +760,7 @@ void TIM_HARD_IRQHandler(void)
{
TIMx->SR = (uint16_t)~TIM_IT_UPDATE;
g_uiTimeHighWord++;
g_uiTimeHighWord += 0x100000000;
}
itstatus = timesr & TIM_IT_CC1;

View File

@ -1129,8 +1129,8 @@ static void InitHardUart(void)
/* 配置波特率、奇偶校验 */
bsp_InitUartParam(COM1, UART1_BAUD, UART_PARITY_NONE, UART_MODE_TX_RX);
// USART_CR1_PEIE | USART_CR1_RXNEIE
SET_BIT(USART1->CR1, USART_CR1_RXNEIE); /* 使能PE. RX接受中断 */
/* 使能RX接受中断接收超时中断 */
SET_BIT(USART1->CR1, USART_CR1_RXNEIE | USART_CR1_RTOIE);
#endif
#if UART2_FIFO_EN == 1 /* 串口2 */
@ -1316,7 +1316,8 @@ static void InitHardUart(void)
/* 配置波特率、奇偶校验 */
bsp_InitUartParam(COM7, UART7_BAUD, UART_PARITY_NONE, UART_MODE_TX_RX);
SET_BIT(UART7->CR1, USART_CR1_RXNEIE); /* 使能PE. RX接受中断 */
/* 使能RX接受中断接收超时中断 */
SET_BIT(UART7->CR1, USART_CR1_RXNEIE | USART_CR1_RTOIE);
#endif
#if UART8_FIFO_EN == 1 /* UART8 */
@ -1503,6 +1504,70 @@ void comPutRxFifo(COM_PORT_E _ucPort, uint8_t *_buf, uint16_t _len)
}
}
/*
*********************************************************************************************************
* : comSetCallBackReciveNew
* :
* : _pUart :
* _ReciveNew : 0
* :
*********************************************************************************************************
*/
void comSetCallBackReciveNew(COM_PORT_E _ucPort, void (*_ReciveNew)(uint8_t _byte))
{
UART_T *pUart;
pUart = ComToUart(_ucPort);
if (pUart == 0)
{
return;
}
pUart->ReciveNew = _ReciveNew;
}
/*
*********************************************************************************************************
* : comSetCallBackIdleLine
* : 线
* : _pUart :
* _IdleLine : 0
* :
*********************************************************************************************************
*/
void comSetCallBackIdleLine(COM_PORT_E _ucPort, void (*_IdleLine)(void))
{
UART_T *pUart;
pUart = ComToUart(_ucPort);
if (pUart == 0)
{
return;
}
pUart->IdleLine = _IdleLine;
}
/*
*********************************************************************************************************
* : comSetReciverTimeout
* :
* : _pUart :
* _Timeout : , bit单位
* :
*********************************************************************************************************
*/
void comSetReciverTimeout(COM_PORT_E _ucPort, uint32_t _Timeout)
{
UART_T *pUart;
pUart = ComToUart(_ucPort);
if (pUart == 0)
{
return;
}
pUart->huart.Instance->RTOR = _Timeout;
pUart->huart.Instance->CR2 |= USART_CR2_RTOEN;
}
/*
*********************************************************************************************************
* : UartIRQ
@ -1518,7 +1583,7 @@ void UartIRQ(UART_T *_pUart)
uint32_t cr3its = READ_REG(_pUart->huart.Instance->CR3);
/* 处理接收中断 */
if ((isrflags & USART_ISR_RXNE_RXFNE) != RESET)
if ((isrflags & USART_ISR_RXNE_RXFNE) != 0 && (isrflags & USART_ISR_PE) == 0U)
{
/* 从串口接收数据寄存器读取数据存放到接收FIFO */
uint8_t ch;
@ -1544,6 +1609,16 @@ void UartIRQ(UART_T *_pUart)
}
}
}
/* 字节间超时中断 (MODBUS RTU 3.5字符超时) */
if (isrflags & USART_ISR_RTOF)
{
SET_BIT(_pUart->huart.Instance->ICR, UART_CLEAR_RTOF);
if (_pUart->IdleLine)
{
_pUart->IdleLine();
}
}
/* 处理发送缓冲区空中断 */
if (((isrflags & USART_ISR_TXE_TXFNF) != RESET) && (cr1its & USART_CR1_TXEIE) != RESET)

View File

@ -1661,48 +1661,40 @@ uint8_t swd_set_target_state_sw(TARGET_RESET_STATE state)
uint8_t swd_enter_debug_program(void)
{
uint32_t val;
uint8_t ResetMode;
/* 进入编程状态,先复位一次,应对已看门狗低功耗程序的片子 */
swd_set_target_reset(1);
osDelay(10);
swd_set_target_reset(0);
/* --0:自动模式, 1:软件模式 2:硬件UnderReset */
ResetMode = g_tProg.ResetMode;
if (swd_init_debug() == 0)
/* 自动模式暂未实现 */
if (ResetMode == 0)
{
printf("error 1: swd_init_debug()\r\n");
return 0;
ResetMode = 1;
}
if (swd_freeze_dog() == 0) /* 如果冻结看门狗时钟失败STM32H7*/
/* 软件复位 */
if (ResetMode == 1)
{
if (swd_get_target_reset() == 0)
{
swd_set_target_reset(1); /* 硬件复位 */
osDelay(g_tProg.SwdResetDelay);
}
if (swd_init_debug() == 0)
{
printf("error 2: swd_init_debug()\r\n");
uint32_t i;
if (!swd_init_debug()) {
return 0;
}
if (swd_freeze_dog() == 0)
{
;
}
}
/*
DBG_HCSR : .
*/
// Enable debug and halt the core (DHCSR <- 0xA05F0003)
{
uint8_t i;
if (swd_freeze_dog() == 0) /* 如果冻结看门狗时钟失败STM32H7*/
{
if (swd_freeze_dog() == 0)
{
;
}
}
for (i = 0; i < 10; i++)
/*
DBG_HCSR : .
*/
// Enable debug and halt the core (DHCSR <- 0xA05F0003)
for (i = 0; i < 5; i++)
{
if (swd_write_word(DBG_HCSR, DBGKEY | C_DEBUGEN | C_HALT) != 0)
{
@ -1711,85 +1703,223 @@ uint8_t swd_enter_debug_program(void)
swd_set_target_reset(1);
osDelay(20);
swd_set_target_reset(0);
osDelay(i * 5); /* 硬件复位退出后 立即写指令 */
}
}
// Enable halt on reset
if (!swd_write_word(DBG_EMCR, VC_CORERESET)) {
printf("error 3: swd_write_word(DBG_EMCR, VC_CORERESET)\r\n");
return 0; /* 超时 */
}
swd_read_word(DBG_HCSR, &val);
if ((val & S_HALT) == 0)
{
if (swd_get_target_reset() == 0)
osDelay(i * 5);
}
if (i >= 5)
{
printf("error : swd_write_word(DBG_HCSR, DBGKEY | C_DEBUGEN | C_HALT)\r\n");
return 0;
}
/* 2020-01-18 armfly 增加退出机制 */
// Wait until core is halted
{
swd_set_target_reset(1);
osDelay(20);
uint32_t i;
for (i = 0; i < 100000; i++)
{
if (!swd_read_word(DBG_HCSR, &val)) {
printf("error: swd_read_word(DBG_HCSR, &val) --1 i = %d\r\n", i);
return 0;
}
if ((val & S_HALT) != 0)
{
break;
}
}
if (i == 100000)
{
printf("error: swd_read_word(DBG_HCSR, &val) --1\r\n");
return 0; /* 超时 */
}
}
if (swd_get_target_reset() == 1)
{
swd_set_target_reset(0); /* 退出硬件复位 */
osDelay(g_tProg.SwdResetDelay);
}
}
// // Perform a soft reset
// if (!swd_read_word(NVIC_AIRCR, &val)) {
// printf("error 2: swd_read_word(NVIC_AIRCR, &val)\r\n");
// return 0;
// }
// Enable halt on reset
if (!swd_write_word(DBG_EMCR, VC_CORERESET)) {
printf("error: swd_write_word(DBG_EMCR, VC_CORERESET)\r\n");
return 0;
}
// if (!swd_write_word(NVIC_AIRCR, VECTKEY | (val & SCB_AIRCR_PRIGROUP_Msk) | soft_reset)) {
// printf("error 3: swd_write_word(NVIC_AIRCR, VECTKEY | (val & SCB_AIRCR_PRIGROUP_Msk) | soft_reset)\r\n");
// return 0;
// }
/* 2020-01-18 armfly 增加退出机制 */
{
uint32_t i;
for (i = 0; i < 100000; i++)
// Perform a soft reset
if (!swd_read_word(NVIC_AIRCR, &val)) {
printf("error: swd_read_word(NVIC_AIRCR, &val)\r\n");
return 0;
}
if (!swd_write_word(NVIC_AIRCR, VECTKEY | (val & SCB_AIRCR_PRIGROUP_Msk) | soft_reset)) {
printf("error: swd_write_word(NVIC_AIRCR, VECTKEY | (val & SCB_AIRCR_PRIGROUP_Msk) | soft_reset)\r\n");
return 0;
}
osDelay(2);
/* 增加超时退出机制 */
{
if (!swd_read_word(DBG_HCSR, &val)) {
printf("error 4: swd_read_word(DBG_HCSR, &val) i = %d\r\n", i);
uint32_t i;
for (i = 0; i < 100000; i++)
{
if (!swd_read_word(DBG_HCSR, &val)) {
printf("error: swd_read_word(DBG_HCSR, &val) --2 i = %d\r\n", i);
return 0;
}
if ((val & S_HALT) != 0)
{
break;
}
}
if (i == 100000)
{
printf("error: swd_read_word(DBG_HCSR, &val) --2\r\n");
return 0; /* 超时 */
}
}
// Disable halt on reset
if (!swd_write_word(DBG_EMCR, 0)) {
return 0;
}
{
uint32_t cpuid;
/* NVIC_CPUID = 0xE000ED00 */
if (!swd_read_memory(NVIC_CPUID, (uint8_t *)&cpuid, 4))
{
return 0;
}
printf(".NVIC_CPUID = %08X, %s\r\n", cpuid, swd_arm_core_info(cpuid));
}
return 1;
}
/* 硬件复位 */
if (ResetMode == 2)
{
/* 进入编程状态,先复位一次,应对已看门狗低功耗程序的片子 */
swd_set_target_reset(1);
osDelay(10);
swd_set_target_reset(0);
if (swd_init_debug() == 0)
{
printf("error 1: swd_init_debug()\r\n");
return 0;
}
if (swd_freeze_dog() == 0) /* 如果冻结看门狗时钟失败STM32H7*/
{
if (swd_get_target_reset() == 0)
{
swd_set_target_reset(1); /* 硬件复位 */
osDelay(g_tProg.SwdResetDelay);
}
if (swd_init_debug() == 0)
{
printf("error 2: swd_init_debug()\r\n");
return 0;
}
if ((val & S_HALT) != 0)
if (swd_freeze_dog() == 0)
{
break;
;
}
}
/*
DBG_HCSR : .
*/
// Enable debug and halt the core (DHCSR <- 0xA05F0003)
{
uint8_t i;
for (i = 0; i < 10; i++)
{
if (swd_write_word(DBG_HCSR, DBGKEY | C_DEBUGEN | C_HALT) != 0)
{
break;
}
swd_set_target_reset(1);
osDelay(20);
swd_set_target_reset(0);
osDelay(i * 5); /* 硬件复位退出后 立即写指令 */
}
}
// Enable halt on reset
if (!swd_write_word(DBG_EMCR, VC_CORERESET)) {
printf("error 3: swd_write_word(DBG_EMCR, VC_CORERESET)\r\n");
return 0; /* 超时 */
}
swd_read_word(DBG_HCSR, &val);
if ((val & S_HALT) == 0)
{
if (swd_get_target_reset() == 0)
{
swd_set_target_reset(1);
osDelay(20);
}
if (swd_get_target_reset() == 1)
{
swd_set_target_reset(0); /* 退出硬件复位 */
osDelay(g_tProg.SwdResetDelay);
}
}
/* 2020-01-18 armfly 增加退出机制 */
{
uint32_t i;
for (i = 0; i < 100000; i++)
{
if (!swd_read_word(DBG_HCSR, &val)) {
printf("error 4: swd_read_word(DBG_HCSR, &val) i = %d\r\n", i);
return 0;
}
if ((val & S_HALT) != 0)
{
break;
}
}
if (i == 100000)
{
printf("error 5: swd_read_word(DBG_HCSR, &val)\r\n");
return 0; /* 超时 */
}
}
if (i == 100000)
{
printf("error 5: swd_read_word(DBG_HCSR, &val)\r\n");
return 0; /* 超时 */
// Disable halt on reset
if (!swd_write_word(DBG_EMCR, 0)) {
printf("error 6: swd_write_word(DBG_EMCR, 0)\r\n");
return 0;
}
{
uint32_t cpuid;
/* NVIC_CPUID = 0xE000ED00 */
if (!swd_read_memory(NVIC_CPUID, (uint8_t *)&cpuid, 4))
{
return 0;
}
printf(".NVIC_CPUID = %08X, %s\r\n", cpuid, swd_arm_core_info(cpuid));
}
return 1;
}
// Disable halt on reset
if (!swd_write_word(DBG_EMCR, 0)) {
printf("error 6: swd_write_word(DBG_EMCR, 0)\r\n");
return 0;
}
{
uint32_t cpuid;
/* NVIC_CPUID = 0xE000ED00 */
if (!swd_read_memory(NVIC_CPUID, (uint8_t *)&cpuid, 4))
{
return 0;
}
printf(".NVIC_CPUID = %08X, %s\r\n", cpuid, swd_arm_core_info(cpuid));
}
return 1;
return 0;
}
#endif

View File

@ -2080,188 +2080,363 @@ uint8_t MUL_swd_enter_debug_program(void)
{
uint32_t val[4];
uint32_t i;
uint8_t ResetMode;
/* 进入编程状态,先复位一次,应对已看门狗低功耗程序的片子 */
MUL_swd_set_target_reset(1);
osDelay(10);
MUL_swd_set_target_reset(0);
/* --0:自动模式, 1:软件模式 2:硬件UnderReset */
ResetMode = g_tProg.ResetMode;
if (MUL_swd_init_debug() == 0)
/* 自动模式暂未实现 */
if (ResetMode == 0)
{
printf("error 1: MUL_swd_init_debug()\r\n");
return 0;
}
osDelay(5);
ResetMode = 1;
}
if (swd_freeze_dog() == 0) /* 如果冻结看门狗时钟失败STM32H7*/
/* 软件复位 */
if (ResetMode == 1)
{
if (MUL_swd_get_target_reset() == 0)
{
MUL_swd_set_target_reset(1); /* 硬件复位 */
osDelay(g_tProg.SwdResetDelay);
if (!MUL_swd_init_debug()) {
return 0;
}
if (swd_freeze_dog() == 0) /* 如果冻结看门狗时钟失败STM32H7*/
{
if (swd_freeze_dog() == 0)
{
/* 失败 */;
}
}
// Enable debug and halt the core (DHCSR <- 0xA05F0003)
for (i = 0; i < 5; i++)
{
if (MUL_swd_write_word(DBG_HCSR, DBGKEY | C_DEBUGEN | C_HALT) != 0)
{
break;
}
// Target is in invalid state?
MUL_swd_set_target_reset(1);
osDelay(20);
MUL_swd_set_target_reset(0);
osDelay(i * 5);
}
// Wait until core is halted
for (i = 0; i < 500; i++)
{
uint8_t err;
if (!MUL_swd_read_word(DBG_HCSR, val))
{
return 0;
}
err = 0;
if (g_gMulSwd.Active[0] == 1 && ((val[0] & S_HALT) == 0))
{
err = 1;
}
if (g_gMulSwd.Active[1] == 1 && ((val[1] & S_HALT) == 0))
{
err = 1;
}
if (g_gMulSwd.Active[2] == 1 && ((val[2] & S_HALT) == 0))
{
err = 1;
}
if (g_gMulSwd.Active[3] == 1 && ((val[3] & S_HALT) == 0))
{
err = 1;
}
if (err == 0)
{
break;
}
bsp_DelayUS(100);
}
// Enable halt on reset
if (!MUL_swd_write_word(DBG_EMCR, VC_CORERESET)) {
return 0;
}
// Perform a soft reset
if (!MUL_swd_read_word(NVIC_AIRCR, val)) {
return 0;
}
if (!MUL_swd_write_word(NVIC_AIRCR, VECTKEY | (val[0] & SCB_AIRCR_PRIGROUP_Msk) | soft_reset)) {
return 0;
}
osDelay(2);
for (i = 0; i < 500; i++)
{
uint8_t err;
if (!MUL_swd_read_word(DBG_HCSR, val))
{
return 0;
}
err = 0;
if (g_gMulSwd.Active[0] == 1 && ((val[0] & S_HALT) == 0))
{
err = 1;
}
if (g_gMulSwd.Active[1] == 1 && ((val[1] & S_HALT) == 0))
{
err = 1;
}
if (g_gMulSwd.Active[2] == 1 && ((val[2] & S_HALT) == 0))
{
err = 1;
}
if (g_gMulSwd.Active[3] == 1 && ((val[3] & S_HALT) == 0))
{
err = 1;
}
if (err == 0)
{
break;
}
bsp_DelayUS(100);
}
// Disable halt on reset
if (!MUL_swd_write_word(DBG_EMCR, 0)) {
return 0;
}
/* 解锁后重读 NVIC_CPUID */
{
uint32_t cpuid[4];
/* NVIC_CPUID = 0xE000ED00 */
if (!MUL_swd_read_word(NVIC_CPUID, cpuid))
{
printf(".MUL_swd_read_word(NVIC_CPUID, cpuid) error\r\n");
return 0;
}
if (g_gMulSwd.MultiMode >= 1)
{
printf(".NVIC_CPUID1 = %08X, %s\r\n", cpuid[0], swd_arm_core_info(cpuid[0]));
}
if (g_gMulSwd.MultiMode >= 2)
{
printf(".NVIC_CPUID2 = %08X, %s\r\n", cpuid[1], swd_arm_core_info(cpuid[1]));
}
if (g_gMulSwd.MultiMode >= 3)
{
printf(".NVIC_CPUID3 = %08X, %s\r\n", cpuid[2], swd_arm_core_info(cpuid[2]));
}
if (g_gMulSwd.MultiMode >= 4)
{
printf(".NVIC_CPUID4 = %08X, %s\r\n", cpuid[3], swd_arm_core_info(cpuid[3]));
}
{
uint8_t err = 0;
for (i = 0; i < 4; i++)
{
if (g_gMulSwd.Active[i] == 1)
{
if ((cpuid[i] & 0xFF000000) != 0x41000000)
{
err = 1;
}
}
}
if (err == 1)
{
;
}
}
}
return 1;
}
/* 硬件复位 */
if (ResetMode == 2)
{
/* 进入编程状态,先复位一次,应对已看门狗低功耗程序的片子 */
MUL_swd_set_target_reset(1);
osDelay(10);
MUL_swd_set_target_reset(0);
if (MUL_swd_init_debug() == 0)
{
printf("error 2: MUL_swd_init_debug()\r\n");
printf("error 1: MUL_swd_init_debug()\r\n");
return 0;
}
if (swd_freeze_dog() == 0)
{
/* 失败 */;
}
}
// Enable debug and halt the core (DHCSR <- 0xA05F0003)
for (i = 0; i < 10; i++)
{
if (MUL_swd_write_word(DBG_HCSR, DBGKEY | C_DEBUGEN | C_HALT) != 0)
{
break;
}
// Target is in invalid state?
MUL_swd_set_target_reset(1);
osDelay(20);
MUL_swd_set_target_reset(0);
osDelay(i * 5);
}
if (i == 10)
{
printf("error 3: MUL_swd_write_word(DBG_HCSR, DBGKEY | C_DEBUGEN | C_HALT)\r\n");
return 0;
}
// Enable halt on reset
if (!MUL_swd_write_word(DBG_EMCR, VC_CORERESET)) {
printf("error 4: MUL_swd_write_word(DBG_EMCR, VC_CORERESET)\r\n");
return 0; /* 超时 */
}
MUL_swd_read_word(DBG_HCSR, val);
if ((val[0] & S_HALT) == 0)
{
if (MUL_swd_get_target_reset() == 0)
{
MUL_swd_set_target_reset(1); /* 硬件复位 */
osDelay(20);
}
osDelay(5);
if (MUL_swd_get_target_reset() == 1)
if (swd_freeze_dog() == 0) /* 如果冻结看门狗时钟失败STM32H7*/
{
MUL_swd_set_target_reset(0); /* 退出硬件复位 */
osDelay(g_tProg.SwdResetDelay);
}
}
// Wait until core is halted
for (i = 0; i < 1000; i++)
{
uint8_t err;
if (!MUL_swd_read_word(DBG_HCSR, val))
{
printf("error 5: MUL_swd_read_word(DBG_HCSR, val)\r\n");
return 0;
}
err = 0;
if (g_gMulSwd.Active[0] == 1 && ((val[0] & S_HALT) == 0))
{
err = 1;
}
if (g_gMulSwd.Active[1] == 1 && ((val[1] & S_HALT) == 0))
{
err = 1;
}
if (g_gMulSwd.Active[2] == 1 && ((val[2] & S_HALT) == 0))
{
err = 1;
}
if (g_gMulSwd.Active[3] == 1 && ((val[3] & S_HALT) == 0))
{
err = 1;
}
if (err == 0)
{
break;
}
bsp_DelayUS(1000);
}
if (i == 1000)
{
printf("error 6: MUL_swd_read_word(DBG_HCSR, val)\r\n");
return 0;
}
// Perform a soft reset
// if (!swd_read_word(NVIC_AIRCR, &val)) {
// printf("error 2: swd_read_word(NVIC_AIRCR, &val)\r\n");
// return 0;
// }
// if (!swd_write_word(NVIC_AIRCR, VECTKEY | (val & SCB_AIRCR_PRIGROUP_Msk) | soft_reset)) {
// printf("error 3: swd_write_word(NVIC_AIRCR, VECTKEY | (val & SCB_AIRCR_PRIGROUP_Msk) | soft_reset)\r\n");
// return 0;
// }
// Disable halt on reset
if (!MUL_swd_write_word(DBG_EMCR, 0))
{
printf("error 7: MUL_swd_write_word(DBG_EMCR, 0)\r\n");
return 0;
}
/* 解锁后重读 NVIC_CPUID */
{
uint32_t cpuid[4];
/* NVIC_CPUID = 0xE000ED00 */
if (!MUL_swd_read_word(NVIC_CPUID, cpuid))
{
printf(".MUL_swd_read_word(NVIC_CPUID, cpuid) error\r\n");
return 0;
}
if (g_gMulSwd.MultiMode >= 1)
{
printf(".NVIC_CPUID1 = %08X, %s\r\n", cpuid[0], swd_arm_core_info(cpuid[0]));
}
if (g_gMulSwd.MultiMode >= 2)
{
printf(".NVIC_CPUID2 = %08X, %s\r\n", cpuid[1], swd_arm_core_info(cpuid[1]));
}
if (g_gMulSwd.MultiMode >= 3)
{
printf(".NVIC_CPUID3 = %08X, %s\r\n", cpuid[2], swd_arm_core_info(cpuid[2]));
}
if (g_gMulSwd.MultiMode >= 4)
{
printf(".NVIC_CPUID4 = %08X, %s\r\n", cpuid[3], swd_arm_core_info(cpuid[3]));
}
{
uint8_t err = 0;
for (i = 0; i < 4; i++)
if (MUL_swd_get_target_reset() == 0)
{
if (g_gMulSwd.Active[i] == 1)
MUL_swd_set_target_reset(1); /* 硬件复位 */
osDelay(g_tProg.SwdResetDelay);
}
if (MUL_swd_init_debug() == 0)
{
printf("error 2: MUL_swd_init_debug()\r\n");
return 0;
}
if (swd_freeze_dog() == 0)
{
/* 失败 */;
}
}
// Enable debug and halt the core (DHCSR <- 0xA05F0003)
for (i = 0; i < 10; i++)
{
if (MUL_swd_write_word(DBG_HCSR, DBGKEY | C_DEBUGEN | C_HALT) != 0)
{
break;
}
// Target is in invalid state?
MUL_swd_set_target_reset(1);
osDelay(20);
MUL_swd_set_target_reset(0);
osDelay(i * 5);
}
if (i == 10)
{
printf("error 3: MUL_swd_write_word(DBG_HCSR, DBGKEY | C_DEBUGEN | C_HALT)\r\n");
return 0;
}
// Enable halt on reset
if (!MUL_swd_write_word(DBG_EMCR, VC_CORERESET)) {
printf("error 4: MUL_swd_write_word(DBG_EMCR, VC_CORERESET)\r\n");
return 0; /* 超时 */
}
MUL_swd_read_word(DBG_HCSR, val);
if ((val[0] & S_HALT) == 0)
{
if (MUL_swd_get_target_reset() == 0)
{
MUL_swd_set_target_reset(1); /* 硬件复位 */
osDelay(20);
}
if (MUL_swd_get_target_reset() == 1)
{
MUL_swd_set_target_reset(0); /* 退出硬件复位 */
osDelay(g_tProg.SwdResetDelay);
}
}
// Wait until core is halted
for (i = 0; i < 1000; i++)
{
uint8_t err;
if (!MUL_swd_read_word(DBG_HCSR, val))
{
printf("error 5: MUL_swd_read_word(DBG_HCSR, val)\r\n");
return 0;
}
err = 0;
if (g_gMulSwd.Active[0] == 1 && ((val[0] & S_HALT) == 0))
{
err = 1;
}
if (g_gMulSwd.Active[1] == 1 && ((val[1] & S_HALT) == 0))
{
err = 1;
}
if (g_gMulSwd.Active[2] == 1 && ((val[2] & S_HALT) == 0))
{
err = 1;
}
if (g_gMulSwd.Active[3] == 1 && ((val[3] & S_HALT) == 0))
{
err = 1;
}
if (err == 0)
{
break;
}
bsp_DelayUS(1000);
}
if (i == 1000)
{
printf("error 6: MUL_swd_read_word(DBG_HCSR, val)\r\n");
return 0;
}
// Disable halt on reset
if (!MUL_swd_write_word(DBG_EMCR, 0))
{
printf("error 7: MUL_swd_write_word(DBG_EMCR, 0)\r\n");
return 0;
}
/* 解锁后重读 NVIC_CPUID */
{
uint32_t cpuid[4];
/* NVIC_CPUID = 0xE000ED00 */
if (!MUL_swd_read_word(NVIC_CPUID, cpuid))
{
printf(".MUL_swd_read_word(NVIC_CPUID, cpuid) error\r\n");
return 0;
}
if (g_gMulSwd.MultiMode >= 1)
{
printf(".NVIC_CPUID1 = %08X, %s\r\n", cpuid[0], swd_arm_core_info(cpuid[0]));
}
if (g_gMulSwd.MultiMode >= 2)
{
printf(".NVIC_CPUID2 = %08X, %s\r\n", cpuid[1], swd_arm_core_info(cpuid[1]));
}
if (g_gMulSwd.MultiMode >= 3)
{
printf(".NVIC_CPUID3 = %08X, %s\r\n", cpuid[2], swd_arm_core_info(cpuid[2]));
}
if (g_gMulSwd.MultiMode >= 4)
{
printf(".NVIC_CPUID4 = %08X, %s\r\n", cpuid[3], swd_arm_core_info(cpuid[3]));
}
{
uint8_t err = 0;
for (i = 0; i < 4; i++)
{
if ((cpuid[i] & 0xFF000000) != 0x41000000)
if (g_gMulSwd.Active[i] == 1)
{
err = 1;
if ((cpuid[i] & 0xFF000000) != 0x41000000)
{
err = 1;
}
}
}
if (err == 1)
{
;
}
}
if (err == 1)
{
;
}
}
}
return 1;
}
return 1;
}
return 0;
}
#endif

View File

@ -17,6 +17,7 @@
#include "stm8_swim.h"
#include "swd_flash.h"
#include "SW_DP_Multi.h"
#include "debug_cm.h"
/* 为了避免和DAP驱动中的函数混淆本模块函数名前缀用 h7swd */
@ -1179,6 +1180,7 @@ static int h7_ProgFile(lua_State* L)
*********************************************************************************************************
*/
extern void MUL_swd_set_target_reset(uint8_t asserted);
#define NVIC_Addr (0xe000e000)
static int h7_reset(lua_State* L)
{
uint32_t delay;
@ -1200,13 +1202,33 @@ static int h7_reset(lua_State* L)
{
MUL_swd_set_target_reset(1);
osDelay(delay);
// Perform a soft reset
{
uint32_t val[4];
MUL_swd_read_word(NVIC_AIRCR, val);
swd_write_word(NVIC_AIRCR, VECTKEY | (val[0] & SCB_AIRCR_PRIGROUP_Msk) | SYSRESETREQ);
}
osDelay(delay);
MUL_swd_set_target_reset(0);
osDelay(delay);
}
else
{
swd_set_target_reset(1);
// Perform a soft reset
{
uint32_t val;
swd_read_word(NVIC_AIRCR, &val);
swd_write_word(NVIC_AIRCR, VECTKEY | (val & SCB_AIRCR_PRIGROUP_Msk) | SYSRESETREQ);
}
osDelay(delay);
swd_set_target_reset(0);
osDelay(delay);

View File

@ -117,7 +117,7 @@ void udp_print_send(void)
/*
*********************************************************************************************************
* : udp_SendBuf
* : UDP数据包lua. . 5ms超时汇总后集中发
* : UDP数据包lua. .
* :
* :
*********************************************************************************************************

View File

@ -461,13 +461,31 @@ error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t si
STM32F429BI 16 2MB
*/
g_tProg.FLMFuncTimeout = g_tProg.EraseChipTime;
if (g_tFLM.Device.toProg > g_tProg.FLMFuncTimeout)
{
g_tProg.FLMFuncTimeout = g_tFLM.Device.toProg;
}
}
else
{
g_tProg.FLMFuncTimeout = g_tFLM.Device.toProg;
}
/* AT32F403的FLMUOB page size = 1K, 应该等于OB的size */
if (size > g_tFLM.Device.szDev)
{
size = g_tFLM.Device.szDev;
}
while (size > 0) {
uint32_t write_size = size > flash_algo.program_buffer_size ? flash_algo.program_buffer_size : size;
uint32_t write_size;
write_size = flash_algo.program_buffer_size;
if (write_size > g_tFLM.Device.szDev)
{
write_size = g_tFLM.Device.szDev;
}
if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
{
@ -480,7 +498,7 @@ error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t si
if (!MUL_swd_flash_syscall_exec(&flash_algo.sys_call_s,
flash_algo.program_page,
addr,
flash_algo.program_buffer_size,
write_size,
flash_algo.program_buffer,
0)) {
return ERROR_WRITE;
@ -498,7 +516,7 @@ error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t si
if (!swd_flash_syscall_exec(&flash_algo.sys_call_s,
flash_algo.program_page,
addr,
flash_algo.program_buffer_size,
write_size,
flash_algo.program_buffer,
0)) {
return ERROR_WRITE;
@ -519,11 +537,23 @@ error_t target_flash_verify_page(uint32_t addr, const uint8_t *buf, uint32_t siz
{
return ERROR_SUCCESS;
}
/* AT32F403的FLMUOB page size = 1K, 应该等于OB的size */
if (size > g_tFLM.Device.szDev)
{
size = g_tFLM.Device.szDev;
}
g_tProg.FLMFuncTimeout = 3000;
while (size > 0)
{
uint32_t write_size = size > flash_algo.program_buffer_size ? flash_algo.program_buffer_size : size;
uint32_t write_size;
write_size = flash_algo.program_buffer_size;
if (write_size > g_tFLM.Device.szDev)
{
write_size = g_tFLM.Device.szDev;
}
if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
{
@ -540,7 +570,7 @@ error_t target_flash_verify_page(uint32_t addr, const uint8_t *buf, uint32_t siz
ret_val = (uint32_t *)MUL_swd_flash_syscall_exec_ex(&flash_algo.sys_call_s,
flash_algo.verify,
addr,
flash_algo.program_buffer_size,
write_size,
flash_algo.program_buffer,
0);
@ -577,7 +607,7 @@ error_t target_flash_verify_page(uint32_t addr, const uint8_t *buf, uint32_t siz
ret_val = (uint32_t *)swd_flash_syscall_exec_ex(&flash_algo.sys_call_s,
flash_algo.verify,
addr,
flash_algo.program_buffer_size,
write_size,
flash_algo.program_buffer,
0);
if (ret_val == 0) /* 通信错误 */

View File

@ -1270,7 +1270,7 @@ uint16_t PG_SWD_ProgBuf(uint32_t _FlashAddr, uint8_t *_DataBuf, uint32_t _BufLen
if (_Mode == 2) /* 擦除所在扇区后,写入,其他数据会清空. 用于Options bytes编程 */
{
uint32_t write_size;
/* 开始擦除 - STM32F429 包含解除读保护 */
//printf("\r\nOption Bytes: erase_chip()\r\n");
@ -1296,8 +1296,15 @@ uint16_t PG_SWD_ProgBuf(uint32_t _FlashAddr, uint8_t *_DataBuf, uint32_t _BufLen
//PG_PrintText("正在编程...");
g_tProg.FLMFuncDispProgress = 1;
g_tProg.FLMFuncDispAddr = g_tFLM.Device.DevAdr + PageStartAddr;
write_size = PageSize;
if (write_size > g_tFLM.Device.szDev)
{
write_size = g_tFLM.Device.szDev;
}
//printf("Option Bytes: program_page()\r\n");
if (target_flash_program_page(g_tFLM.Device.DevAdr + PageStartAddr, _DataBuf, PageSize) != 0)
if (target_flash_program_page(g_tFLM.Device.DevAdr + PageStartAddr, _DataBuf, write_size) != 0)
{
PG_PrintText("program_page failed");
err = 1;

View File

@ -63,6 +63,8 @@
#define USBD_SELF_POWERED 1
#define USBD_DEBUG_LEVEL 0
#define MSC_MEDIA_PACKET 1024*16 //512
/* Exported macro ------------------------------------------------------------*/
/* Memory management macros */
#define USBD_malloc malloc