mirror of
https://github.com/armfly/H7-TOOL_STM32H7_App.git
synced 2024-08-09 10:05:34 +08:00
Merge pull request #42 from armfly/origin/armfly
解决脱机烧录的几个BUG,增加大容量SPI Flash支持
This commit is contained in:
commit
76b03e0b85
22
CHANGELOG
22
CHANGELOG
@ -1,3 +1,25 @@
|
||||
----------------------------------------------------------------------------
|
||||
2020-12-17 V1.43 对应PC软件版本 V1.4.0
|
||||
1.脱机烧录增加苏州国芯的2个M4芯片.
|
||||
2.脱机烧录增加SPI Flash型号:MXIC的MX25L256, MX25L512和镁光25QL128、25QL256、25QL512等几个大容量芯片
|
||||
3.解决脱机烧录中的几个BUG
|
||||
- 解决SST25VFXXX系列串行FLASH不能正确识别的问题。这个片子读ID和编程的方法与其他厂家差别较大
|
||||
- 解决大容量芯片(大于16MB)烧录异常的问题(需要4字节地址访问)
|
||||
- ARM芯片烧录,编程完毕后执行FLM中的uninit()、target_flash_init(_FlashAddr, 0, FLM_INIT_VERIFY) 后再执行读回校验
|
||||
- 解决FLM文件不规范导致的器件信号区信号解码错误(目前为止,只遇到过一个这样的FLM)
|
||||
- FLM有verify校验函数的, page_size按照FLM中来
|
||||
- 查空前, 先执行FLM中的init(verify), 再装载和执行check_blank函数。实测有些FLM文件不行,放弃改动.
|
||||
- 单路模式机台信号,D7无法触发烧录,原因:
|
||||
(1)void status_ProgWork(void) 单路和多路SWD GPIO初始代码反了,导致D7配置为输出
|
||||
(2)从00界面进入脱机界面,未启动ADC多通道扫描,导致lua脚本判断TVCC过低,不执行触发信号检测
|
||||
|
||||
4. PC机传送文件到H7-TOOL,解决小文件(比如ini文件)不会写入的bug
|
||||
5. PC机传送文件,增加USB接口支持.
|
||||
6. 调整USB中断和EMMC中断优先级,避免死机问题
|
||||
7. USB串口中断中处理modbus指令,遇到写SD卡操作,会阻塞死机,已解决
|
||||
8. 通信协议中新增加一个指令,PC可以控制H7-TOOL进入U盘模式、DAP模式
|
||||
9. lua_DrawLine(), 解决颜色形参取值bug
|
||||
|
||||
----------------------------------------------------------------------------
|
||||
2020-12-09 V1.42
|
||||
1.DAP固件升级到V1.04版本
|
||||
|
@ -6,6 +6,14 @@
|
||||
#define TICK_INT_PRIORITY 0 // ((uint32_t)0x0F) /*!< tick interrupt priority */
|
||||
4. bsp_CheckRunTime, bsp_GetRunTime 函数内部去掉关闭中断的操作,影响QSPI写操作。
|
||||
|
||||
|
||||
2020-12-13 V1.42 swd_prog_file.c
|
||||
1. SWD烧录,编程完毕后执行FLM中的uninit()、target_flash_init(_FlashAddr, 0, FLM_INIT_VERIFY) 后再执行校验。
|
||||
- 烧录STM32F407,会出现init失败。还是还原,取消掉。
|
||||
- 代码可能存在其他问题
|
||||
2. FLM文件的校验问题,苏州国芯的QSP FLM,使用FLM_Verify校验失败,使用读回校验正常。
|
||||
|
||||
|
||||
2020-09-16 V1.31固件
|
||||
普通触发模式还有遗留问题:拖动触发位置滚动条时,超出波形范围后H7-TOOL程序假死(频繁进入看门狗中断),暂未解决。H7-TOOL界面翻到电压档界面可恢复。
|
||||
|
||||
@ -28,5 +36,33 @@
|
||||
RS232_TX - RS232串口机台信号扩展 START BUSY OK NG
|
||||
RS232_RX - RS232串口机台信号扩展
|
||||
|
||||
---中断优先级---
|
||||
|
||||
HAL_NVIC_SetPriority(USART1_IRQn, 0, 1);
|
||||
HAL_NVIC_SetPriority(UART4_IRQn, 0, 4);
|
||||
HAL_NVIC_SetPriority(UART8_IRQn, 0, 6);
|
||||
HAL_NVIC_SetPriority(TIM_HARD_IRQn, 0, 2);
|
||||
|
||||
tft HAL_NVIC_SetPriority(DMA2_Stream3_IRQn, 1, 1);
|
||||
tft HAL_NVIC_SetPriority(SPI5_IRQn, 1, 0);
|
||||
|
||||
/* 使能QSPI中断 */
|
||||
HAL_NVIC_SetPriority(QUADSPI_IRQn, 0x0F, 0); /* 0x0F --> 0x04, 要高于USB中断 */
|
||||
|
||||
/* 使能MDMA中断,并配置优先级 */
|
||||
QSPI HAL_NVIC_SetPriority(MDMA_IRQn, 0x02, 0);
|
||||
|
||||
HAL_NVIC_SetPriority(OTG_HS_IRQn, 0, 0);
|
||||
HAL_NVIC_SetPriority(SDMMC1_IRQn, 0, 0);
|
||||
|
||||
HAL_NVIC_SetPriority(ADC_IRQn, 0, 0);
|
||||
HAL_NVIC_SetPriority(ADC3_IRQn, 0, 0);
|
||||
HAL_NVIC_SetPriority(CH1_DMA_Stream_IRQn, 1, 0);
|
||||
HAL_NVIC_SetPriority(CH2_DMA_Stream_IRQn, 1, 0);
|
||||
|
||||
|
||||
【通信协议】
|
||||
功能码
|
||||
0x61 : H7-TOOL主动发送,比如print信息. 不要求主机应答
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -468,6 +468,11 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\User\app\src\status_lua.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>status_usb_uart.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\User\app\src\status_usb_uart.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>file_lib.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
@ -1524,6 +1529,16 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\User\modbus\modbus_swd.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>modbus_print.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\User\modbus\modbus_print.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>modbus_host.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\User\modbus\modbus_host.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
@ -2067,6 +2082,16 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\User\daplink\source\daplink\cmsis-dap\SW_DP_Multi.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>DAP.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\User\daplink\source\daplink\cmsis-dap\DAP.h</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>DAP_config.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>..\..\User\daplink\source\hic_hal\stm32\stm32h750\DAP_config.h</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
|
@ -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 0x00000142 ; Reserved H7-TOOL APP 固件版本
|
||||
DCD 0x00000143 ; Reserved H7-TOOL APP 固件版本
|
||||
DCD 0 ; Reserved 固件小版本
|
||||
DCD 0 ; Reserved
|
||||
DCD 0 ; Reserved
|
||||
|
Binary file not shown.
@ -33,6 +33,7 @@
|
||||
#include "ui_def.h"
|
||||
#include "param.h"
|
||||
#include "modbus_register.h"
|
||||
#include "modbus_reg_addr.h"
|
||||
#include "disp_lib.h"
|
||||
#include "lcd_menu.h"
|
||||
#include "file_lib.h"
|
||||
@ -84,6 +85,7 @@ enum
|
||||
MS_JUMP_APP, /* 跳到APP状态 */
|
||||
|
||||
MS_DS18B20_METER, /* DS18B20温度表 */
|
||||
MS_USB_UART, /* USB虚拟串口 */
|
||||
};
|
||||
|
||||
uint16_t NextStatus(uint16_t _NowStatus);
|
||||
|
32
User/app/inc/status_usb_uart.h
Normal file
32
User/app/inc/status_usb_uart.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* 模块名称 : USB虚拟串口功能模块
|
||||
* 文件名称 : status_usb_uart.h
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _STATUS_USB_UART_H_
|
||||
#define _STATUS_USB_UART_H_
|
||||
|
||||
/* 这个结构在 usbd_cdc_interface.c中被引用 */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t Baud;
|
||||
uint8_t DataBit;
|
||||
uint8_t StopBit;
|
||||
uint8_t Parity;
|
||||
uint8_t Connected;
|
||||
uint32_t PcTxCount;
|
||||
uint32_t DevTxCount;
|
||||
uint8_t Changed;
|
||||
}USB_UART_T;
|
||||
|
||||
extern USB_UART_T g_tUasUart;
|
||||
|
||||
void status_UsbUart(void);
|
||||
|
||||
#endif
|
||||
|
||||
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/
|
@ -132,7 +132,7 @@ void DispBox(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: DispLabel
|
||||
* 功能说明: 显示一个文本标签框
|
||||
* 功能说明: 显示一个文本标签框, 矩形边角
|
||||
* 形 参: _usX : 坐标X
|
||||
* _usY : 坐标Y
|
||||
* _usHeight : 高度
|
||||
@ -146,9 +146,22 @@ void DispBox(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth
|
||||
void DispLabel(uint16_t _usX, uint16_t _usY, uint16_t _usHeight, uint16_t _usWidth,
|
||||
uint16_t _usColor, char *_pStr, FONT_T *_tFont)
|
||||
{
|
||||
uint16_t fh;
|
||||
uint16_t offset;
|
||||
|
||||
fh = LCD_GetFontHeight(_tFont);
|
||||
if (_usHeight > fh)
|
||||
{
|
||||
offset = (_usHeight - fh) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
/* 填充矩形 */
|
||||
LCD_Fill_Rect(_usX, _usY, _usHeight, _usWidth, _usColor);
|
||||
LCD_DispStr(_usX, _usY, _pStr, _tFont);
|
||||
LCD_DispStr(_usX + 2, _usY + offset, _pStr, _tFont);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1761,30 +1761,19 @@ int fgetc(FILE *f)
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
extern uint8_t USBCom_SendBuf(int _Port, uint8_t *_Buf, uint16_t _Len);
|
||||
extern void lua_udp_SendBuf(uint8_t *_buf, uint16_t _len, uint16_t _port);
|
||||
extern MEMO_T g_LuaMemo;
|
||||
extern uint16_t g_MainStatus;
|
||||
extern void MODH_PrintByte(char _ch);
|
||||
int fputc(int ch, FILE *f)
|
||||
{
|
||||
if (f == &__stdout)
|
||||
{
|
||||
uint8_t buf[1];
|
||||
|
||||
buf[0] = ch;
|
||||
|
||||
#if PRINT_TO_UDP == 1
|
||||
lua_udp_SendBuf(buf, 1, LUA_UDP_PORT);
|
||||
|
||||
if (g_MainStatus == MS_LUA_EXEC_FILE)
|
||||
{
|
||||
LCD_MemoAddChar(&g_LuaMemo, ch);
|
||||
}
|
||||
#else
|
||||
USBCom_SendBuf(1, buf, 1);
|
||||
#endif
|
||||
|
||||
//comSendChar(COM1, ch);
|
||||
MODH_PrintByte(ch);
|
||||
return ch;
|
||||
}
|
||||
else
|
||||
|
@ -82,6 +82,7 @@ static const uint16_t StatusOrder[] =
|
||||
*/
|
||||
void JumpToDAPLink(void);
|
||||
extern MENU_T g_tMenu1;
|
||||
extern void status_UsbUart(void);
|
||||
int main(void)
|
||||
{
|
||||
bsp_Init();
|
||||
@ -175,9 +176,12 @@ int main(void)
|
||||
|
||||
FileSystemLoad(); /* 挂载文件系统 */
|
||||
|
||||
lua_Init(); /* 启动lua */
|
||||
lua_PowerOnLua(); /* 启动lua */
|
||||
}
|
||||
|
||||
usbd_CloseCDC();
|
||||
usbd_OpenCDC(COM_USB1); /* 启用USB虚拟串口8, 用于和PC软件USB通信 */
|
||||
|
||||
//wifi_state = WIFI_INIT;
|
||||
|
||||
while (1)
|
||||
@ -288,6 +292,10 @@ int main(void)
|
||||
status_DS18B20Meter();
|
||||
break;
|
||||
|
||||
case MS_USB_UART: /* USB虚拟串口 */
|
||||
status_UsbUart();
|
||||
break;
|
||||
|
||||
default:
|
||||
g_MainStatus = MS_LINK_MODE;
|
||||
break;
|
||||
|
@ -26,8 +26,9 @@ const uint8_t *g_Menu1_Text[] =
|
||||
" 3 脱机烧录器(多路)",
|
||||
" 4 LUA小程序",
|
||||
" 5 数据监视器",
|
||||
" 6 系统设置",
|
||||
|
||||
" 6 USB虚拟串口",
|
||||
" 7 系统设置",
|
||||
|
||||
/* 结束符号, 用于菜单函数自动识别菜单项个数 */
|
||||
"&"
|
||||
};
|
||||
@ -135,9 +136,13 @@ void status_ExtendMenu1(void)
|
||||
g_MainStatus = MS_EXTEND_MENU_REC;
|
||||
}
|
||||
else if (g_tMenu1.Cursor == 5)
|
||||
{
|
||||
g_MainStatus = MS_USB_UART;
|
||||
}
|
||||
else if (g_tMenu1.Cursor == 6)
|
||||
{
|
||||
g_MainStatus = MS_SYSTEM_SET;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY_UP_C: /* C键 下 */
|
||||
|
@ -58,8 +58,8 @@ void status_LinkMode(void)
|
||||
DispHelpBar("长按S进入扩展功能",
|
||||
"长按C切换方向");
|
||||
|
||||
usbd_CloseCDC();
|
||||
usbd_OpenCDC(COM_USB1); /* 启用USB虚拟串口8, 用于和PC软件USB通信 */
|
||||
// usbd_CloseCDC();
|
||||
// usbd_OpenCDC(COM_USB1); /* 启用USB虚拟串口8, 用于和PC软件USB通信 */
|
||||
|
||||
fRefresh = 1;
|
||||
|
||||
@ -136,13 +136,16 @@ void status_LinkMode(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (g_MainStatus != MS_SYSTEM_SET)
|
||||
{
|
||||
usbd_CloseCDC();
|
||||
usbd_OpenCDC(COM1); /* 启用USB虚拟串口1, 用于虚拟串口,RS232 RS485 TTL-UART */
|
||||
}
|
||||
// if (g_MainStatus != MS_SYSTEM_SET)
|
||||
// {
|
||||
// usbd_CloseCDC();
|
||||
// usbd_OpenCDC(COM1); /* 启用USB虚拟串口1, 用于虚拟串口,RS232 RS485 TTL-UART */
|
||||
// }
|
||||
|
||||
DSO_StartMode2(); /* 示波器启动模式2-低速多通道扫描 */
|
||||
if (g_MainStatus != MS_EXTEND_MENU1)
|
||||
{
|
||||
DSO_StartMode2(); /* 示波器启动模式2-低速多通道扫描 */
|
||||
}
|
||||
|
||||
bsp_StopTimer(0);
|
||||
}
|
||||
|
@ -138,6 +138,8 @@ void status_ProgWork(void)
|
||||
uint8_t ucAutoState = 0;
|
||||
uint8_t ucDetectCount = 0; /* 连续多少次没有检测到芯片则认为目标板已拔出 */
|
||||
int32_t iDetectTime;
|
||||
|
||||
DSO_StartMode2(); /* 示波器启动模式2-低速多通道扫描 */
|
||||
|
||||
/* 读autorun.ini文件,获得缺省lua文件路径 */
|
||||
LoadProgAutorunFile(g_tProg.FilePath, sizeof(g_tProg.FilePath));
|
||||
@ -282,12 +284,12 @@ void status_ProgWork(void)
|
||||
/* V1.36 解决第一次上电第1次烧录失败问题 */
|
||||
{
|
||||
if (g_gMulSwd.MultiMode == 0)
|
||||
{
|
||||
MUL_PORT_SWD_SETUP();
|
||||
{
|
||||
swd_init();
|
||||
}
|
||||
else
|
||||
{
|
||||
swd_init();
|
||||
MUL_PORT_SWD_SETUP();
|
||||
}
|
||||
}
|
||||
|
||||
|
143
User/app/src/status_usb_uart.c
Normal file
143
User/app/src/status_usb_uart.c
Normal file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* 模块名称 : 联机界面
|
||||
* 文件名称 : status_link_mode.c
|
||||
* 版 本 : V1.0
|
||||
* 说 明 :
|
||||
* 修改记录 :
|
||||
* 版本号 日期 作者 说明
|
||||
* V1.0 2019-10-06 armfly 正式发布
|
||||
*
|
||||
* Copyright (C), 2019-2030, 安富莱电子 www.armfly.com
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
#include "includes.h"
|
||||
#include "status_usb_uart.h"
|
||||
|
||||
USB_UART_T g_tUasUart;
|
||||
|
||||
static void DispUsbUartStatus(void);
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: status_UsbUart
|
||||
* 功能说明: USB虚拟串口.
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void status_UsbUart(void)
|
||||
{
|
||||
uint8_t ucKeyCode; /* 按键代码 */
|
||||
uint8_t fRefresh;
|
||||
|
||||
DispHeader2(93, "USB 虚拟串口");
|
||||
|
||||
usbd_CloseCDC();
|
||||
usbd_OpenCDC(COM1); /* 启用USB虚拟串口1, 用于虚拟串口,RS232 RS485 TTL-UART */
|
||||
|
||||
g_tUasUart.Baud = 0;
|
||||
g_tUasUart.DataBit = 8;
|
||||
g_tUasUart.Parity = 0;
|
||||
g_tUasUart.Connected = 0;
|
||||
g_tUasUart.PcTxCount = 0;
|
||||
g_tUasUart.DevTxCount = 0;
|
||||
g_tUasUart.Changed = 0;
|
||||
|
||||
fRefresh = 1;
|
||||
while (g_MainStatus == MS_USB_UART)
|
||||
{
|
||||
bsp_Idle();
|
||||
|
||||
if (fRefresh == 1)
|
||||
{
|
||||
fRefresh = 0;
|
||||
|
||||
DispUsbUartStatus();
|
||||
}
|
||||
|
||||
if (g_tUasUart.Changed == 1)
|
||||
{
|
||||
g_tUasUart.Changed = 0;
|
||||
fRefresh = 1;
|
||||
}
|
||||
|
||||
ucKeyCode = bsp_GetKey(); /* 读取键值, 无键按下时返回 KEY_NONE = 0 */
|
||||
if (ucKeyCode != KEY_NONE)
|
||||
{
|
||||
/* 有键按下 */
|
||||
switch (ucKeyCode)
|
||||
{
|
||||
case KEY_UP_S: /* S键 弹起 */
|
||||
break;
|
||||
|
||||
case KEY_UP_C: /* C键 下 */
|
||||
break;
|
||||
|
||||
case KEY_LONG_DOWN_S: /* S键 上 */
|
||||
break;
|
||||
|
||||
case KEY_LONG_DOWN_C: /* C键长按 */
|
||||
g_MainStatus = MS_SYSTEM_SET;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
usbd_CloseCDC();
|
||||
usbd_OpenCDC(COM_USB1); /* 启用USB虚拟串口8, 用于和PC软件USB通信 */
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: DispUsbUartStatus
|
||||
* 功能说明: 显示USB虚拟串口连接状态
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
static void DispUsbUartStatus(void)
|
||||
{
|
||||
FONT_T tFont;
|
||||
char buf[48];
|
||||
uint16_t x,y,h,w;
|
||||
const char *ParityName[3] = {"无校验", "奇校验", "偶校验"};
|
||||
|
||||
/* 设置字体参数 */
|
||||
{
|
||||
tFont.FontCode = FC_ST_16; /* 字体代码 16点阵 */
|
||||
tFont.FrontColor = RGB(100,100,100); /* 字体颜色 */
|
||||
tFont.BackColor = CL_MASK; /* 文字背景颜色 */
|
||||
tFont.Space = 0; /* 文字间距,单位 = 像素 */
|
||||
}
|
||||
|
||||
x = 5;
|
||||
y = 35;
|
||||
h = 20;
|
||||
w = 230;
|
||||
if (g_tUasUart.Connected == 0)
|
||||
{
|
||||
// 波特率 115200,无校验
|
||||
sprintf(buf, "------未连接------");
|
||||
DispLabel(x, y, h, w, RGB(168,255,168), buf, &tFont);
|
||||
y += 20;
|
||||
sprintf(buf, "------------------");
|
||||
DispLabel(x, y, h, w, RGB(168,255,168), buf, &tFont);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 波特率 115200,无校验
|
||||
sprintf(buf, "已连接 波特率:%d %s", g_tUasUart.Baud, ParityName[g_tUasUart.Parity]);
|
||||
DispLabel(x, y, h, w, RGB(168,255,168), buf, &tFont);
|
||||
y += 25;
|
||||
sprintf(buf, "PC:%10u DEV:%10u", g_tUasUart.PcTxCount, g_tUasUart.DevTxCount);
|
||||
DispLabel(x, y, h, w, RGB(168,255,168), buf, &tFont);
|
||||
}
|
||||
}
|
||||
|
||||
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/
|
@ -128,7 +128,7 @@ enum
|
||||
|
||||
/* 4-byte Address Mode Operations */
|
||||
#define ENTER_4_BYTE_ADDR_MODE_CMD 0xB7
|
||||
#define EXIT_4_BYTE_ADDR_MODE_CMD 0xE9
|
||||
#define EXIT_4_BYTE_ADDR_MODE_CMD 0xE9
|
||||
|
||||
/* Quad Operations */
|
||||
#define ENTER_QUAD_CMD 0x35
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "main.h"
|
||||
#include "prog_if.h"
|
||||
#include "crc32_stm32.h"
|
||||
#include "modbus_print.h"
|
||||
|
||||
/*
|
||||
|
||||
@ -253,6 +254,16 @@ int lua_CheckGlobal(const char *name)
|
||||
|
||||
return re;
|
||||
}
|
||||
|
||||
// H7-TOOL上电时,启动lua
|
||||
void lua_PowerOnLua(void)
|
||||
{
|
||||
lua_DeInit(); // 先释放
|
||||
|
||||
lua_Init(); // 重新分配内存
|
||||
|
||||
lua_do("beep()");
|
||||
}
|
||||
|
||||
// 装载文件并初始化lua全局对象
|
||||
void lua_DownLoadFile(char *_path)
|
||||
@ -587,8 +598,7 @@ static int HexToBinString(lua_State* L)
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
extern uint8_t USBCom_SendBuf(int _Port, uint8_t *_Buf, uint16_t _Len);
|
||||
extern void lua_udp_SendBuf(uint8_t *_buf, uint16_t _len, uint16_t _port);
|
||||
extern void MODH_PrintByte(char _ch);
|
||||
static int print_hex(lua_State* L)
|
||||
{
|
||||
const char *data;
|
||||
@ -627,11 +637,8 @@ static int print_hex(lua_State* L)
|
||||
if (i > 1)
|
||||
{
|
||||
strcpy(&buf[strlen(buf)], "\r\n");
|
||||
#if PRINT_TO_UDP == 1
|
||||
lua_udp_SendBuf((uint8_t *)buf, strlen(buf), LUA_UDP_PORT);
|
||||
#else
|
||||
USBCom_SendBuf(1, (uint8_t *)buf, strlen(buf));
|
||||
#endif
|
||||
|
||||
MODH_PrintBuf((uint8_t *)buf, strlen(buf));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -684,11 +691,7 @@ static int print_hex(lua_State* L)
|
||||
}
|
||||
buf[pos++] = '\r';
|
||||
buf[pos++] = '\n';
|
||||
#if PRINT_TO_UDP == 1
|
||||
lua_udp_SendBuf((uint8_t *)buf, pos, LUA_UDP_PORT);
|
||||
#else
|
||||
USBCom_SendBuf(1, (uint8_t *)buf, pos);
|
||||
#endif
|
||||
MODH_PrintBuf((uint8_t *)buf, pos);
|
||||
bsp_Idle();
|
||||
}
|
||||
|
||||
@ -704,12 +707,8 @@ static int print_hex(lua_State* L)
|
||||
buf[pos++] = ' ';
|
||||
}
|
||||
buf[pos++] = '\r';
|
||||
buf[pos++] = '\n';
|
||||
#if PRINT_TO_UDP == 1
|
||||
lua_udp_SendBuf((uint8_t *)buf, pos, LUA_UDP_PORT);
|
||||
#else
|
||||
USBCom_SendBuf(1, (uint8_t *)buf, pos);
|
||||
#endif
|
||||
buf[pos++] = '\n';
|
||||
MODH_PrintBuf((uint8_t *)buf, pos);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -43,6 +43,7 @@
|
||||
|
||||
void lua_Test(void);
|
||||
void lua_Init(void);
|
||||
void lua_PowerOnLua(void);
|
||||
void lua_DeInit(void);
|
||||
void lua_StackDump(lua_State *L);
|
||||
void lua_DownLoad(uint32_t _addr, uint8_t *_buf, uint32_t _len, uint32_t _total_len);
|
||||
|
@ -528,7 +528,7 @@ static int lua_DrawLine(lua_State* L)
|
||||
/* 第5个参数 */
|
||||
if (lua_type(L, 5) == LUA_TNUMBER)
|
||||
{
|
||||
color = luaL_checknumber(L, 4);
|
||||
color = luaL_checknumber(L, 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -21,129 +21,26 @@
|
||||
#include "param.h"
|
||||
#include "modbus_slave.h"
|
||||
|
||||
#define MODS_ADDR 0x01 /* MODBSU 从站地址 */
|
||||
|
||||
#define UDP_TX_SIZE (1500 + 8)
|
||||
#define MODS_ADDR 0x01 /* MODBSU 从站地址 */
|
||||
|
||||
struct udp_pcb *g_udp_pcb;
|
||||
struct pbuf *p_udp_tx;
|
||||
|
||||
static uint8_t udp_tx_buf[UDP_TX_SIZE];
|
||||
//static uint16_t udp_tx_len;
|
||||
|
||||
//typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
|
||||
// const ip_addr_t *addr, u16_t port);
|
||||
uint8_t udp_tx_buf[UDP_TX_SIZE];
|
||||
uint16_t udp_tx_len;
|
||||
|
||||
static void udp_server_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p_rx, const ip_addr_t *addr, u16_t port);
|
||||
|
||||
ip_addr_t destAddr;
|
||||
|
||||
#define PRINT_FIFO_SIZE 1024
|
||||
static uint8_t udp_print_buf[PRINT_FIFO_SIZE];
|
||||
static uint16_t udp_print_putp = 0;
|
||||
static uint16_t udp_print_getp = 0;
|
||||
static uint16_t udp_print_count = 0;
|
||||
|
||||
void udp_print_put(uint8_t ch)
|
||||
{
|
||||
// while (udp_print_count == PRINT_FIFO_SIZE - 1)
|
||||
// {
|
||||
// bsp_Idle();
|
||||
// }
|
||||
|
||||
udp_print_buf[udp_print_putp] = ch;
|
||||
if (++udp_print_putp >= PRINT_FIFO_SIZE)
|
||||
{
|
||||
udp_print_putp = 0;
|
||||
}
|
||||
udp_print_count++;
|
||||
}
|
||||
|
||||
uint8_t udp_print_get(uint8_t *ch)
|
||||
void udp_print_send(uint8_t *_buf, uint16_t _len)
|
||||
{
|
||||
uint8_t data;
|
||||
|
||||
if (udp_print_putp != udp_print_getp)
|
||||
{
|
||||
data = udp_print_buf[udp_print_getp];
|
||||
if (++udp_print_getp >= PRINT_FIFO_SIZE)
|
||||
{
|
||||
udp_print_getp = 0;
|
||||
}
|
||||
*ch = data;
|
||||
|
||||
if (udp_print_count > 0)
|
||||
{
|
||||
udp_print_count--;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void udp_print_send(void)
|
||||
{
|
||||
uint16_t len;
|
||||
uint8_t data;
|
||||
|
||||
len = 0;
|
||||
while (1)
|
||||
{
|
||||
if (udp_print_get(&data))
|
||||
{
|
||||
udp_tx_buf[len] = data;
|
||||
|
||||
if (++len >= UDP_TX_SIZE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* 准备应答数据 */
|
||||
p_udp_tx->payload = udp_tx_buf;
|
||||
p_udp_tx->len = len;
|
||||
p_udp_tx->tot_len = len;
|
||||
p_udp_tx->payload = _buf;
|
||||
p_udp_tx->len = _len;
|
||||
p_udp_tx->tot_len = _len;
|
||||
|
||||
udp_sendto(g_udp_pcb, p_udp_tx, &destAddr, LUA_UDP_PORT); /* 数据发送出去 */
|
||||
|
||||
//ERR_OK
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: udp_SendBuf
|
||||
* 功能说明: 发送UDP数据包,用于lua. 先缓存再发送.超时汇总后集中发送
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void lua_udp_SendBuf(uint8_t *_buf, uint16_t _len, uint16_t _port)
|
||||
{
|
||||
uint16_t i;
|
||||
uint8_t nowsend = 0;
|
||||
|
||||
for (i = 0; i < _len; i++)
|
||||
{
|
||||
udp_print_put(_buf[i]);
|
||||
if (_buf[i] == 0x0A)
|
||||
{
|
||||
nowsend = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (nowsend == 1)
|
||||
{
|
||||
udp_print_send();
|
||||
}
|
||||
else
|
||||
{
|
||||
bsp_StartHardTimer(3, 5000, udp_print_send);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -11,6 +11,11 @@
|
||||
#ifndef _NET_UDP_H
|
||||
#define _NET_UDP_H
|
||||
|
||||
#define UDP_TX_SIZE (1500 + 8)
|
||||
|
||||
extern uint8_t udp_tx_buf[];
|
||||
extern uint16_t udp_tx_len;
|
||||
|
||||
void udp_server_init(void);
|
||||
|
||||
void lua_udp_SendBuf(uint8_t *_buf, uint16_t _len, uint16_t _port);
|
||||
|
@ -513,8 +513,9 @@ static void MODS64_WriteFile(void)
|
||||
}
|
||||
|
||||
/* 第1包就文件结束 */
|
||||
if (s_FileOffset + s_FileRxLen >= total_len)
|
||||
{
|
||||
//if (s_FileOffset + s_FileRxLen >= total_len) ---BUG : 小文件不写入
|
||||
if (s_FileRxLen >= total_len - s_HeaderLen)
|
||||
{
|
||||
if (WriteFile(s_FileName, s_FileOffset, (char *)FsReadBuf, s_FileRxLen) == 0)
|
||||
{
|
||||
s_FileOffset = s_FileRxLen;
|
||||
@ -536,10 +537,10 @@ static void MODS64_WriteFile(void)
|
||||
|
||||
if (s_LastPackaOffsetAddr != offset_addr) /* 不是重复帧 */
|
||||
{
|
||||
s_LastPackaOffsetAddr = offset_addr;
|
||||
s_LastPackaOffsetAddr = offset_addr;
|
||||
|
||||
if (s_FileRxLen + DataLen < sizeof(FsReadBuf))
|
||||
{
|
||||
{
|
||||
memcpy(&FsReadBuf[s_FileRxLen], (char *)pData, DataLen);
|
||||
s_FileRxLen += DataLen;
|
||||
err = 0; /* 文件写入OK */
|
||||
@ -570,7 +571,8 @@ static void MODS64_WriteFile(void)
|
||||
}
|
||||
|
||||
/* 文件数据传输完毕 */
|
||||
if (s_FileOffset + s_FileRxLen >= total_len - s_HeaderLen)
|
||||
//if (s_FileOffset + s_FileRxLen >= total_len - s_HeaderLen)
|
||||
if (s_FileRxLen >= total_len - s_HeaderLen)
|
||||
{
|
||||
if (WriteFile(s_FileName, s_FileOffset, (char *)FsReadBuf, s_FileRxLen) == 0)
|
||||
{
|
||||
|
File diff suppressed because it is too large
Load Diff
73
User/modbus/modbus_host.h
Normal file
73
User/modbus/modbus_host.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* 模块名称 : MODEBUS 通信模块 (主机程序)
|
||||
* 文件名称 : modbus_host.h
|
||||
* 版 本 : V1.0
|
||||
* 说 明 : 头文件
|
||||
*
|
||||
* Copyright (C), 2015-2016, 安富莱电子 www.armfly.com
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __MOSBUS_HOST_H
|
||||
#define __MOSBUS_HOST_H
|
||||
|
||||
#define SlaveAddr 0x55 /* 面板作为时,主板作从机 */
|
||||
|
||||
#define REG_P16 0x000F
|
||||
#define REG_P18 0x0011
|
||||
|
||||
#define REG_P63 0x003E /* 主板软件版本号 */
|
||||
|
||||
|
||||
/* RTU 应答代码 */
|
||||
#define RSP_OK 0 /* 成功 */
|
||||
#define RSP_ERR_CMD 0x01 /* 不支持的功能码 */
|
||||
#define RSP_ERR_REG_ADDR 0x02 /* 寄存器地址错误 */
|
||||
#define RSP_ERR_VALUE 0x03 /* 数据值域错误 */
|
||||
#define RSP_ERR_WRITE 0x04 /* 写入失败 */
|
||||
|
||||
#define H_RX_BUF_SIZE (2 * 1024)
|
||||
#define H_TX_BUF_SIZE (2 * 1024)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t *RxBuf; /* 注意是指针,没有分配内存 */
|
||||
uint8_t RxCount;
|
||||
uint8_t RxStatus;
|
||||
uint8_t RxNewFlag;
|
||||
|
||||
uint8_t RspCode;
|
||||
|
||||
uint8_t TxBuf[H_TX_BUF_SIZE];
|
||||
uint8_t TxCount;
|
||||
|
||||
uint16_t Reg03H; /* 保存主机发送的03H指令的寄存器首地址 */
|
||||
uint16_t Reg30H; /* 保存主机发送的30H指令的寄存器首地址 */
|
||||
uint8_t RegNum; /* 寄存器个数 */
|
||||
|
||||
uint8_t fAck05H; /* 05H指令的应答 */
|
||||
uint8_t fAck06H; /* 06H指令的应答。0 表示执行失败 1表示执行成功 */
|
||||
uint8_t fAck03H;
|
||||
}MODH_T;
|
||||
|
||||
extern MODH_T g_tModH;
|
||||
|
||||
void MODH_SendWithCRC(void);
|
||||
|
||||
void MODH_Send03H(uint8_t _addr, uint16_t _reg, uint16_t _num);
|
||||
void MODH_Send05H(uint8_t _addr, uint16_t _reg, uint16_t _value);
|
||||
void MODH_Send06H(uint8_t _addr, uint16_t _reg, uint16_t _value);
|
||||
void MODH_Send10H(uint8_t _addr, uint16_t _reg, uint8_t _num, uint8_t *_buf);
|
||||
|
||||
uint8_t MODH_WriteParam_06H(uint16_t _reg, uint16_t _value);
|
||||
uint8_t MODH_WriteParam_05H(uint16_t _reg, uint16_t _value);
|
||||
uint8_t MODH_ReadParam_03H(uint16_t _reg, uint16_t _num);
|
||||
|
||||
uint8_t MODH_Poll(uint8_t *_buf, uint16_t _len);
|
||||
|
||||
#endif
|
||||
|
||||
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/
|
197
User/modbus/modbus_print.c
Normal file
197
User/modbus/modbus_print.c
Normal file
@ -0,0 +1,197 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* 模块名称 : MODBUS发送print数据
|
||||
* 文件名称 : modbus_print.c
|
||||
* 版 本 : V1.0
|
||||
* 说 明 : 将print内容包装为modbus标准帧,由H7-TOOL主动发送给PC机,支持USB链路或者UDP链路
|
||||
*
|
||||
* Copyright (C), 2020, 安富莱电子 www.armfly.com
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#include "Includes.h"
|
||||
#include "modbus_host.h"
|
||||
#include "modbus_print.h"
|
||||
#include "net_udp.h"
|
||||
|
||||
#define PRINT_FIFO_SIZE 1024
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t TxBuf[PRINT_FIFO_SIZE];
|
||||
uint32_t Write;
|
||||
uint32_t Read;
|
||||
int32_t Count;
|
||||
}PRINT_FIFO_T;
|
||||
|
||||
static PRINT_FIFO_T s_tPrintFiFo;
|
||||
|
||||
static void print_send(void);
|
||||
|
||||
extern void udp_print_send(uint8_t *_buf, uint16_t _len);
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: MODH_Send61H
|
||||
* 功能说明: 发送61H数据包, 主要用以将print信息传送到上位机。不要求应答
|
||||
* 形 参: _Ch : 通道号, 0表示print, 其他值功能保留
|
||||
* _TxBuf : 数据缓冲区
|
||||
* _TxLen : 长度, 0-1024
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void MODH_Send61H(uint8_t _Ch, uint8_t *_TxBuf, uint16_t _TxLen)
|
||||
{
|
||||
/*
|
||||
H7-TOOL主动发送:
|
||||
01 ; 从机地址 ,为1
|
||||
61 ; 功能码
|
||||
00 ; 通道号,00表示print
|
||||
01 : 长度高字节
|
||||
08 : 长度低字节
|
||||
xx xx xx xx ... : 数据体
|
||||
CC CC : CRC16
|
||||
*/
|
||||
uint16_t i;
|
||||
|
||||
g_tModH.TxCount = 0;
|
||||
g_tModH.TxBuf[g_tModH.TxCount++] = g_tParam.Addr485; /* 本机地址 */
|
||||
g_tModH.TxBuf[g_tModH.TxCount++] = 0x61; /* 功能码 */
|
||||
g_tModH.TxBuf[g_tModH.TxCount++] = _Ch;
|
||||
|
||||
for (i = 0; i < _TxLen; i++)
|
||||
{
|
||||
g_tModH.TxBuf[g_tModH.TxCount++] = _TxBuf[i];
|
||||
}
|
||||
|
||||
MODH_SendWithCRC();
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: MODH_PrintByte
|
||||
* 功能说明: 打印的字符填入FIFO
|
||||
* 形 参: _ch : 输入字符
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void MODH_PrintByte(char _ch)
|
||||
{
|
||||
uint16_t stime;
|
||||
|
||||
s_tPrintFiFo.TxBuf[s_tPrintFiFo.Write] = _ch;
|
||||
if (++s_tPrintFiFo.Write >= PRINT_FIFO_SIZE)
|
||||
{
|
||||
s_tPrintFiFo.Write = 0;
|
||||
}
|
||||
s_tPrintFiFo.Count++;
|
||||
|
||||
if (s_tPrintFiFo.Count >= 512)
|
||||
{
|
||||
stime = 100; /* 如果已经快满了,则尽快启动一次发送 */
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_ch == 0x0A)
|
||||
{
|
||||
stime = 500; /* 如果遇到回车换行符号,则 0.5ms 后启动硬件传输 */
|
||||
}
|
||||
else
|
||||
{
|
||||
stime = 5000; /* 5ms后启动硬件传输 */
|
||||
}
|
||||
}
|
||||
bsp_StartHardTimer(3, stime, print_send);
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: MODH_PrintBuf
|
||||
* 功能说明: 打印的字符填入FIFO
|
||||
* 形 参: _ch : 输入字符
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void MODH_PrintBuf(uint8_t *_buf, uint16_t _len)
|
||||
{
|
||||
uint16_t i;
|
||||
uint8_t ch;
|
||||
uint8_t fCR = 0;
|
||||
uint32_t stime;
|
||||
|
||||
for (i = 0; i < _len; i++)
|
||||
{
|
||||
ch = _buf[i];
|
||||
s_tPrintFiFo.TxBuf[s_tPrintFiFo.Write] = ch;
|
||||
if (++s_tPrintFiFo.Write >= PRINT_FIFO_SIZE)
|
||||
{
|
||||
s_tPrintFiFo.Write = 0;
|
||||
}
|
||||
s_tPrintFiFo.Count++;
|
||||
|
||||
if (ch == 0x0A)
|
||||
{
|
||||
fCR = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (s_tPrintFiFo.Count >= 512)
|
||||
{
|
||||
stime = 100; /* 如果已经快满了,则尽快启动一次发送 */
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fCR == 1)
|
||||
{
|
||||
print_send();
|
||||
stime = 500; /* 如果遇到回车换行符号,则 0.5ms 后启动硬件传输 */
|
||||
}
|
||||
else
|
||||
{
|
||||
stime = 5000; /* 5ms后启动硬件传输 */
|
||||
}
|
||||
}
|
||||
|
||||
bsp_StartHardTimer(3, stime, print_send);
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: print_send
|
||||
* 功能说明: 物理层发送数据
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
static void print_send(void)
|
||||
{
|
||||
udp_tx_len = 0;
|
||||
while (1)
|
||||
{
|
||||
if (s_tPrintFiFo.Read == s_tPrintFiFo.Write)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
udp_tx_buf[udp_tx_len] = s_tPrintFiFo.TxBuf[s_tPrintFiFo.Read];
|
||||
if (++s_tPrintFiFo.Read >= PRINT_FIFO_SIZE)
|
||||
{
|
||||
s_tPrintFiFo.Read = 0;
|
||||
}
|
||||
s_tPrintFiFo.Count--;
|
||||
|
||||
if (++udp_tx_len >= UDP_TX_SIZE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
udp_print_send(udp_tx_buf, udp_tx_len);
|
||||
}
|
||||
|
||||
extern uint8_t USBCom_SendBuf(int _Port, uint8_t *_Buf, uint16_t _Len);
|
||||
extern void lua_udp_SendBuf(uint8_t *_buf, uint16_t _len, uint16_t _port);
|
||||
|
||||
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/
|
36
User/app/inc/net_udp.h → User/modbus/modbus_print.h
Executable file → Normal file
36
User/app/inc/net_udp.h → User/modbus/modbus_print.h
Executable file → Normal file
@ -1,18 +1,18 @@
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* 模块名称 : UDP搜索模块
|
||||
* 文件名称 : net_udp.h
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
#include "bsp.h"
|
||||
|
||||
#ifndef _NET_UDP_H
|
||||
#define _NET_UDP_H
|
||||
|
||||
void UDP_server_init(void);
|
||||
|
||||
#endif
|
||||
|
||||
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
*
|
||||
* 模块名称 : MODBUS发送print数据
|
||||
* 文件名称 : modbus_print.h
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
#ifndef __MODBUS_PRINT_H
|
||||
#define __MODBUS_PRINT_H
|
||||
|
||||
void MODH_Send61H(uint8_t _Ch, uint8_t *_TxBuf, uint16_t _TxLen);
|
||||
void MODH_PrintByte(char _ch);
|
||||
void MODH_PrintBuf(uint8_t *_buf, uint16_t _len);
|
||||
|
||||
#endif
|
||||
|
||||
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/
|
@ -377,7 +377,19 @@ AI : 示波器 CH1 均值, mV单位
|
||||
#define REG03_NET_SYSTEM_IP_L 0xFF13 /* 管理系统IP地址低位 */
|
||||
#define REG03_NET_SYSTEM_PORT 0xFF14 /* 远程服务器端口 */
|
||||
|
||||
#define REG03_RESET_TO_BOOT 0xFF7F /* 特殊寄存器,复位进入BOOT */
|
||||
#define REG03_RESET_TO_BOOT 0xFF7F /* 特殊寄存器,复位进入BOOT
|
||||
1 - 复位进入APP
|
||||
2 - 复位进入BOOT
|
||||
3 - 进入DAP
|
||||
4 - 进入U盘模式
|
||||
5 - 进入APP联机界面00
|
||||
*/
|
||||
#define JUMP_TO_APP 1
|
||||
#define JUMP_TO_BOOT 2
|
||||
#define JUMP_TO_DAP 3
|
||||
#define JUMP_TO_EMMC 4
|
||||
#define JUMP_TO_LINK 5
|
||||
|
||||
|
||||
/* BOOT 程序用的寄存器 */
|
||||
#define REG03_BOOT_CPU_ID0 0xFF80
|
||||
@ -392,10 +404,14 @@ AI : 示波器 CH1 均值, mV单位
|
||||
#define REG03_BOOT_PROG_TYPE 0xFF88 /* APP程序类型: 0 = CPU内部Flash ; 1 = QSPI Flash */
|
||||
#define REG03_BOOT_PROG_ADDR 0xFF89 /* APP程序地址 32位 */
|
||||
#define REG03_BOOT_PROG_SIZE 0xFF8B /* APP程序长度 32位 */
|
||||
|
||||
/* 系统控制参数
|
||||
1 - 通知开始升级,设备开始擦除flash. 根据前面2个寄存器决定擦除空间
|
||||
2 - 通知设备程序下载完毕
|
||||
3 - 通知系统复位
|
||||
|
||||
4 - 进入U盘模式
|
||||
5 - 退出U盘模式(需要RJ45)
|
||||
*/
|
||||
#define REG03_BOOT_SYSTEM 0xFF8D
|
||||
|
||||
|
@ -11,11 +11,7 @@
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
#include "bsp.h"
|
||||
#include "param.h"
|
||||
#include "modbus_reg_addr.h"
|
||||
#include "modbus_register.h"
|
||||
#include "lua_if.h"
|
||||
#include "Includes.h"
|
||||
|
||||
uint8_t fSaveReq_06H = 0; /* 保存基本参数请求,用于06H和10H写寄存器函数 */
|
||||
uint8_t fResetReq_06H = 0; /* 需要复位CPU,因为网络参数变化 */
|
||||
@ -1009,6 +1005,7 @@ static uint8_t ReadCalibRegValue_03H(uint16_t _reg_addr, uint16_t *_reg_value)
|
||||
* 返 回 值: 1表示OK 0表示错误
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
extern void JumpToDAPLink(void);
|
||||
uint8_t WriteRegValue_06H(uint16_t reg_addr, uint16_t reg_value)
|
||||
{
|
||||
uint8_t IPAddr[4];
|
||||
@ -1483,20 +1480,30 @@ uint8_t WriteRegValue_06H(uint16_t reg_addr, uint16_t reg_value)
|
||||
}
|
||||
break;
|
||||
|
||||
/*********************************************************/
|
||||
|
||||
/*********************************************************/
|
||||
case REG03_RESET_TO_BOOT:
|
||||
if (reg_value == 2)
|
||||
if (reg_value == JUMP_TO_APP) /* 复位进入APP */
|
||||
{
|
||||
*(uint32_t *)0x20000000 = 0;
|
||||
NVIC_SystemReset(); /* 复位CPU */
|
||||
}
|
||||
else if (reg_value == JUMP_TO_BOOT) /* 复位进入BOOT 升级 */
|
||||
{
|
||||
/* 复位进入BOOT 升级 */
|
||||
|
||||
*(uint32_t *)0x20000000 = 0x5AA51234;
|
||||
NVIC_SystemReset(); /* 复位CPU */
|
||||
}
|
||||
else if (reg_value == 1)
|
||||
else if (reg_value == JUMP_TO_DAP) /* 进入DAP */
|
||||
{
|
||||
/* 复位进入APP */
|
||||
*(uint32_t *)0x20000000 = 0;
|
||||
NVIC_SystemReset(); /* 复位CPU */
|
||||
JumpToDAPLink();
|
||||
}
|
||||
else if (reg_value == JUMP_TO_EMMC) /* 进入U盘模式 */
|
||||
{
|
||||
g_MainStatus = MS_USB_EMMC;
|
||||
}
|
||||
else if (reg_value == JUMP_TO_LINK) /* 进入APP联机 */
|
||||
{
|
||||
g_MainStatus = MS_LINK_MODE;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -36,7 +36,6 @@ static void MODS_10H(void);
|
||||
static void MODS_0FH(void);
|
||||
|
||||
static void MODS_65H(void);
|
||||
static void MODS_60H(void);
|
||||
|
||||
extern void MODS_64H(void);
|
||||
extern void MODS_66H(void);
|
||||
@ -44,7 +43,6 @@ extern void MODS_66H(void);
|
||||
void MODS_ReciveNew(uint8_t _byte);
|
||||
|
||||
MODS_T g_tModS;
|
||||
MOD_WAVE_T g_tModWave;
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
@ -102,56 +100,6 @@ err_ret:
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: MODS_ReciveNew
|
||||
* 功能说明: 串口接收中断服务程序会调用本函数。当收到一个字节时,执行一次本函数。
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
//void MODS_ReciveNew(uint8_t _byte)
|
||||
//{
|
||||
// /*
|
||||
// 3.5个字符的时间间隔,只是用在RTU模式下面,因为RTU模式没有开始符和结束符,
|
||||
// 两个数据包之间只能靠时间间隔来区分,Modbus定义在不同的波特率下,间隔时间是不一样的,
|
||||
// 所以就是3.5个字符的时间,波特率高,这个时间间隔就小,波特率低,这个时间间隔相应就大
|
||||
|
||||
// 4800 = 7.297ms
|
||||
// 9600 = 3.646ms
|
||||
// 19200 = 1.771ms
|
||||
// 38400 = 0.885ms
|
||||
// */
|
||||
// uint32_t timeout;
|
||||
//
|
||||
// g_rtu_timeout = 0;
|
||||
//
|
||||
// timeout = 35000000 / g_tParam.Baud; /* 计算超时时间,单位us */
|
||||
//
|
||||
// /* 硬件定时中断,定时精度us 硬件定时器1用于ADC, 定时器2用于Modbus */
|
||||
// bsp_StartHardTimer(2, timeout, (void *)MODS_RxTimeOut);
|
||||
|
||||
// if (g_tModS.RxCount < RX_BUF_SIZE)
|
||||
// {
|
||||
// g_tModS.RxBuf[g_tModS.RxCount++] = _byte;
|
||||
// }
|
||||
//}
|
||||
|
||||
///*
|
||||
//*********************************************************************************************************
|
||||
//* 函 数 名: MODS_RxTimeOut
|
||||
//* 功能说明: 超过3.5个字符时间后执行本函数。 设置全局变量 g_rtu_timeout = 1; 通知主程序开始解码。
|
||||
//* 形 参: 无
|
||||
//* 返 回 值: 无
|
||||
//*********************************************************************************************************
|
||||
//*/
|
||||
//static void MODS_RxTimeOut(void)
|
||||
//{
|
||||
// g_rtu_timeout = 1;
|
||||
//}
|
||||
#endif
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: MODS_SendWithCRC
|
||||
@ -253,10 +201,6 @@ static void MODS_AnalyzeApp(void)
|
||||
MODS_0FH(); /* 强制多个线圈(对应D01/D02/D03) */
|
||||
break;
|
||||
|
||||
case 0x60: /* 读取波形数据专用功能码 */
|
||||
MODS_60H();
|
||||
break;
|
||||
|
||||
case 0x64: /* 文件下载 */
|
||||
MODS_64H();
|
||||
break;
|
||||
@ -1058,8 +1002,6 @@ fail:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: MODS_65H
|
||||
@ -1119,248 +1061,4 @@ err_ret:
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: MODS_60H
|
||||
* 功能说明: PC机读取波形数据(浮点格式)
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
static void MODS_60H(void)
|
||||
{
|
||||
/*
|
||||
PC发送 60H
|
||||
01 ; 从机地址
|
||||
60 ; 功能码
|
||||
00 : 00表示PC下发,01表示设备应答 (仅仅用于人工分析)
|
||||
01 00 00 00 : 通道号使能标志 32bit,bit0表示CH1,bit1表示CH2
|
||||
00 00 04 00: 每个通道样本个数
|
||||
01 00 : 每通信包样本长度. 单位为1个样本。
|
||||
00 00 00 00 : 通道数据偏移 (样本单位,用于重发)
|
||||
CC CC : CRC16
|
||||
|
||||
从机首先应答: 60H -
|
||||
|
||||
01 ; 从机地址
|
||||
60 ; 功能码
|
||||
01 : 00表示PC下发,01表示设备应答 (仅仅用于人工分析)
|
||||
01 00 00 00 : 通道号使能标志 32bit,bit0表示CH1,bit1表示CH2
|
||||
00 00 04 00 : 每个通道样本个数
|
||||
01 00 : 每通信包样本长度. 单位为1个样本。
|
||||
00 00 00 00 : 通道数据偏移 (样本单位,用于重发)
|
||||
CCCC : CRC16
|
||||
|
||||
从机应答: (然后开始多包连续应答)
|
||||
01 ; 从机地址
|
||||
61 ; 功能码
|
||||
00 ; 通道号,00表示通道1,01表示通道2,
|
||||
00 00 00 00 : 偏移地址(样本单位)
|
||||
01 00 : 本包数据长度。样本单位。每个样本4字节。0x100表示1024字节。
|
||||
..... : 数据体
|
||||
CCCC : CRC16
|
||||
*/
|
||||
// uint16_t lual_len; /* 程序长度 */
|
||||
|
||||
g_tModS.RspCode = RSP_OK;
|
||||
|
||||
if (g_tModS.RxCount != 19)
|
||||
{
|
||||
g_tModS.RspCode = RSP_ERR_VALUE; /* 数据值域错误 */
|
||||
goto err_ret;
|
||||
}
|
||||
|
||||
if (g_tModS.RxBuf[2] != 00)
|
||||
{
|
||||
g_tModS.RspCode = RSP_ERR_VALUE; /* 数据值域错误 */
|
||||
goto err_ret;
|
||||
}
|
||||
|
||||
g_tModWave.ChEn = BEBufToUint32(&g_tModS.RxBuf[3]);
|
||||
g_tModWave.SampleSize = BEBufToUint32(&g_tModS.RxBuf[7]);
|
||||
g_tModWave.PackageSize = BEBufToUint16(&g_tModS.RxBuf[11]);
|
||||
g_tModWave.SampleOffset = BEBufToUint32(&g_tModS.RxBuf[13]);
|
||||
|
||||
g_tModWave.TransPos = 0; /* 传输的位置计数 */
|
||||
g_tModWave.StartTrans = 1; /* 开始传输的标志 */
|
||||
|
||||
err_ret:
|
||||
if (g_tModS.RxBuf[0] != 0x00) /* 00广播地址不应答, FF地址应答g_tParam.Addr485 */
|
||||
{
|
||||
if (g_tModS.RspCode == RSP_OK) /* 正确应答 */
|
||||
{
|
||||
g_tModS.TxCount = 0;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tParam.Addr485; /* 本机地址 */
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x60; /* 功能码 */
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tModS.RxBuf[2];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tModS.RxBuf[3];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tModS.RxBuf[4];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tModS.RxBuf[5];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tModS.RxBuf[6];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tModS.RxBuf[7];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tModS.RxBuf[8];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tModS.RxBuf[9];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tModS.RxBuf[10];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tModS.RxBuf[11];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tModS.RxBuf[12];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tModS.RxBuf[13];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tModS.RxBuf[14];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tModS.RxBuf[15];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tModS.RxBuf[16];
|
||||
|
||||
MODS_SendWithCRC();
|
||||
}
|
||||
else
|
||||
{
|
||||
MODS_SendAckErr(g_tModS.RspCode); /* 告诉主机命令错误 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: Send_61H
|
||||
* 功能说明: 传输波形。 自动连续多包传输。废弃,不稳定。
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void Send_61H(uint8_t _Ch, uint32_t _Offset, uint16_t _PackageLen)
|
||||
{
|
||||
/*
|
||||
从机应答: (然后开始多包连续应答)
|
||||
01 ; 从机地址
|
||||
61 ; 功能码
|
||||
00 ; 通道号,00表示通道1,01表示通道2,
|
||||
00 00 00 00 : 偏移地址(样本单位)
|
||||
01 00 : 本包数据长度。样本单位。每个样本4字节。0x100表示1024字节。
|
||||
..... : 数据体
|
||||
CRC16
|
||||
*/
|
||||
uint16_t i;
|
||||
uint8_t *p;
|
||||
|
||||
g_tModS.TxCount = 0;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = g_tParam.Addr485; /* 本机地址 */
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = 0x61; /* 功能码 */
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = _Ch;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = _Offset >> 24;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = _Offset >> 16;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = _Offset >> 8;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = _Offset;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = _PackageLen >> 8;
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = _PackageLen;
|
||||
|
||||
if (_Ch == 0)
|
||||
{
|
||||
for (i = 0; i < _PackageLen; i++)
|
||||
{
|
||||
p = (uint8_t *)&g_Ch1WaveBuf[_Offset + i];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = p[3];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = p[2];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = p[1];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = p[0];
|
||||
}
|
||||
}
|
||||
else if (_Ch == 1)
|
||||
{
|
||||
for (i = 0; i < _PackageLen; i++)
|
||||
{
|
||||
p = (uint8_t *)&g_Ch2WaveBuf[_Offset + i];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = p[3];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = p[2];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = p[1];
|
||||
g_tModS.TxBuf[g_tModS.TxCount++] = p[0];
|
||||
}
|
||||
}
|
||||
|
||||
MODS_SendWithCRC();
|
||||
|
||||
// USBCom_SendBufNow(0, g_tModS.TxBuf, g_tModS.TxCount);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: TransWaveTask
|
||||
* 功能说明: 传输波形任务。 插入bsp_Idle运行. 废弃
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
void TransWaveTask(void)
|
||||
{
|
||||
static uint32_t s_TransPos = 0;
|
||||
static uint8_t s_ChPos = 0;
|
||||
|
||||
if (g_tModWave.StartTrans == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
while (g_tModWave.StartTrans != 0)
|
||||
{
|
||||
lwip_pro(); /* 以太网协议栈轮询 */
|
||||
|
||||
wifi_task();
|
||||
|
||||
switch (g_tModWave.StartTrans)
|
||||
{
|
||||
case 1:
|
||||
s_ChPos = 0;
|
||||
s_TransPos = g_tModWave.SampleOffset;
|
||||
g_tModWave.StartTrans++;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (g_tModWave.ChEn & (1 << s_ChPos))
|
||||
{
|
||||
g_tModWave.StartTrans++;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_ChPos++;
|
||||
|
||||
if (s_ChPos >= 2)
|
||||
{
|
||||
g_tModWave.StartTrans = 100; /* 传输完毕 */
|
||||
}
|
||||
else
|
||||
{
|
||||
g_tModWave.StartTrans++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
Send_61H(s_ChPos, s_TransPos, g_tModWave.PackageSize);
|
||||
g_tModWave.StartTrans++;
|
||||
break;
|
||||
|
||||
case 4: /* 等待发送完毕 - 暂时未做 */
|
||||
g_tModWave.StartTrans++;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
s_TransPos += g_tModWave.PackageSize;
|
||||
if (s_TransPos >= g_tModWave.SampleSize)
|
||||
{
|
||||
s_ChPos++;
|
||||
s_TransPos = g_tModWave.SampleOffset;
|
||||
g_tModWave.StartTrans = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_tModWave.StartTrans = 3;
|
||||
}
|
||||
break;
|
||||
|
||||
case 100:
|
||||
g_tModWave.StartTrans = 0; /* 传输结束 */
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t *RxBuf;
|
||||
uint8_t *RxBuf; /* 注意是指针,没有分配内存 */
|
||||
uint16_t RxCount;
|
||||
uint8_t RxStatus;
|
||||
uint8_t RxNewFlag;
|
||||
@ -44,20 +44,6 @@ typedef struct
|
||||
uint8_t TCP_Flag;
|
||||
} MODS_T;
|
||||
|
||||
/* 传递波形数据的通信结构 60H功能码专用 */
|
||||
typedef struct
|
||||
{
|
||||
/* 保存PC机的指令参数 */
|
||||
uint32_t ChEn; /* bit0 表示CH1, bit1表示CH2 */
|
||||
uint32_t SampleSize; /* 每个通道样本个数 */
|
||||
uint16_t PackageSize; /* 每通信包样本长度. 单位为1个样本 */
|
||||
uint32_t SampleOffset;
|
||||
|
||||
/* 通信过程中,控制进度 */
|
||||
uint32_t TransPos; /* 样本缓冲区的当前位置 */
|
||||
uint8_t StartTrans; /* 开始传输波形的标志 */
|
||||
} MOD_WAVE_T;
|
||||
|
||||
void uart_rx_isr(void); /* 在 stm8s_it.c 中调用 */
|
||||
uint8_t AnalyzeCmd(uint8_t *_DispBuf);
|
||||
uint8_t MODS_Poll(uint8_t *_buf, uint16_t _len);
|
||||
@ -66,7 +52,6 @@ void MODS_SendWithCRC(void);
|
||||
void MODS_SendAckOk(void);
|
||||
|
||||
extern MODS_T g_tModS;
|
||||
extern MOD_WAVE_T g_tModWave;
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -55,7 +55,7 @@ void MODS_66H(void)
|
||||
主机发送: 小程序数据
|
||||
01 ; 站号
|
||||
66 ; 功能码
|
||||
0000 ; 子功能,
|
||||
0000 ; 子功能
|
||||
- 0表示读内存
|
||||
- 1表示写内存
|
||||
0000 0000 : 偏移地址 4字节
|
||||
|
@ -437,12 +437,31 @@ error_t target_flash_init(uint32_t flash_start, unsigned long clk, unsigned long
|
||||
/* 这个函数暂时未用到 */
|
||||
error_t target_flash_uninit(void)
|
||||
{
|
||||
#if 1
|
||||
g_tProg.FLMFuncTimeout = 500; /* 超时 */
|
||||
|
||||
if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
|
||||
{
|
||||
if (0 == MUL_swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.uninit, 0, 0, 0, 0)) {
|
||||
return ERROR_INIT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (0 == swd_flash_syscall_exec(&flash_algo.sys_call_s, flash_algo.uninit, 0, 0, 0, 0)) {
|
||||
return ERROR_INIT;
|
||||
}
|
||||
}
|
||||
return ERROR_SUCCESS;
|
||||
#else
|
||||
g_tProg.FLMFuncTimeout = 200; /* 函数执行超时 */
|
||||
|
||||
swd_set_target_state_hw(RESET_RUN);
|
||||
|
||||
swd_off();
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
error_t target_flash_program_page(uint32_t addr, const uint8_t *buf, uint32_t size)
|
||||
@ -554,6 +573,12 @@ error_t target_flash_verify_page(uint32_t addr, const uint8_t *buf, uint32_t siz
|
||||
{
|
||||
write_size = g_tFLM.Device.szDev;
|
||||
}
|
||||
|
||||
/* 2020-12-14 修复bug */
|
||||
if (write_size > size)
|
||||
{
|
||||
write_size = size;
|
||||
}
|
||||
|
||||
if (g_gMulSwd.MultiMode > 0) /* 多路模式 */
|
||||
{
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* Copyright (C), 2019-2030, 安富莱电子 www.armfly.com
|
||||
*
|
||||
* 本文件为安富莱电子原创,仅供学习使用,禁止在同类产品中商用.
|
||||
* 本文件为安富莱电子原创,仅供学习使用,禁止在同类产品中商用. 如需使用,需要得到我们的授权.
|
||||
*
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
@ -245,7 +245,13 @@ uint8_t ELF_ParseFile(char *_path)
|
||||
|
||||
/* 解析器件信息 */
|
||||
{
|
||||
bytes = ReadFileToMem(_path, g_tFLM.Func[IDX_FlashDevice].Offset + 52, FsReadBuf, sizeof(FlashDevice_T));
|
||||
|
||||
#if 0 /* 2020-12-13,调试苏州国芯 CCM4208时修改 */
|
||||
bytes = ReadFileToMem(_path, g_tFLM.Func[IDX_FlashDevice].Offset + 52, FsReadBuf, sizeof(FlashDevice_T));
|
||||
#else
|
||||
bytes = ReadFileToMem(_path, g_tFLM.Load[1].Offset, FsReadBuf, sizeof(FlashDevice_T));
|
||||
#endif
|
||||
|
||||
memcpy((char *)&g_tFLM.Device, FsReadBuf, sizeof(FlashDevice_T));
|
||||
}
|
||||
|
||||
|
@ -3,12 +3,13 @@
|
||||
*
|
||||
* 模块名称 : 编程器接口文件
|
||||
* 文件名称 : prog_if.c
|
||||
* 版 本 : V1.0
|
||||
* 版 本 : V1.1
|
||||
* 说 明 :
|
||||
*
|
||||
* 修改记录 :
|
||||
* 版本号 日期 作者 说明
|
||||
* V1.0 2019-03-19 armfly 正式发布
|
||||
* V1.1 2020-12-12 armfly 修正算法执行的缺陷,Init()和UnInit()按正常规范执行.
|
||||
*
|
||||
* Copyright (C), 2019-2030, 安富莱电子 www.armfly.com
|
||||
*
|
||||
@ -175,7 +176,18 @@ uint16_t PG_SWD_ProgFile(char *_Path, uint32_t _FlashAddr, uint32_t _EndAddr, ui
|
||||
flm_check_blank = target_flash_check_blank;
|
||||
}
|
||||
else /* 如果FLM没有查空函数,则加载通用的算法代码(flash常量数组) */
|
||||
{
|
||||
{
|
||||
/* 2020-12-14 执行init函数用于校验的, 用于QSPI Flash内存映射模式 */
|
||||
#if 0
|
||||
err_t = target_flash_init(_FlashAddr, 0, FLM_INIT_VERIFY);
|
||||
if (err_t != ERROR_SUCCESS)
|
||||
{
|
||||
PG_PrintText("error: target_flash_init(FLM_INIT_VERIFY) for check_blank");
|
||||
err = 1;
|
||||
goto quit;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* 装载算法代码到目标机内存 */
|
||||
LoadCheckBlankAlgoToTarget();
|
||||
|
||||
@ -244,8 +256,6 @@ uint16_t PG_SWD_ProgFile(char *_Path, uint32_t _FlashAddr, uint32_t _EndAddr, ui
|
||||
{
|
||||
/* 恢复芯片厂家的FLM算法代码到目标机内存 */
|
||||
LoadAlgoToTarget();
|
||||
|
||||
|
||||
}
|
||||
|
||||
PG_PrintPercent(100, _FlashAddr);
|
||||
@ -684,6 +694,27 @@ uint16_t PG_SWD_ProgFile(char *_Path, uint32_t _FlashAddr, uint32_t _EndAddr, ui
|
||||
}
|
||||
|
||||
/* 第3步 ******************** 校验 (fix区未完全校验)**********************/
|
||||
|
||||
#if 1 /* 2020-12-13 加入,V1.43 */
|
||||
/* 执行Uninit函数 */
|
||||
err_t = target_flash_uninit();
|
||||
if (err_t != ERROR_SUCCESS)
|
||||
{
|
||||
PG_PrintText("error: target_flash_uninit()");
|
||||
err = 1;
|
||||
goto quit;
|
||||
}
|
||||
|
||||
/* 装载算法并执行init函数 */
|
||||
err_t = target_flash_init(_FlashAddr, 0, FLM_INIT_VERIFY);
|
||||
if (err_t != ERROR_SUCCESS)
|
||||
{
|
||||
PG_PrintText("error: target_flash_init(FLM_INIT_VERIFY)");
|
||||
err = 1;
|
||||
goto quit;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
2020-05-22 记录: STM32F207RCT6,256K Flash
|
||||
FLM_CRC32 150ms
|
||||
@ -770,7 +801,14 @@ uint16_t PG_SWD_ProgFile(char *_Path, uint32_t _FlashAddr, uint32_t _EndAddr, ui
|
||||
if (PageSize >= sizeof(FsReadBuf))
|
||||
{
|
||||
PageSize = sizeof(FsReadBuf);
|
||||
}
|
||||
}
|
||||
|
||||
/* 2020-12-13 FLM有verify校验函数, page_size 按照FLM中来,针对SPI FLASH, QSPI_flash */
|
||||
if (flash_algo.verify > 0 && g_tProg.VerifyMode == VERIFY_AUTO)
|
||||
{
|
||||
PageSize = g_tFLM.Device.szPage;
|
||||
}
|
||||
|
||||
addr = _FlashAddr - g_tFLM.Device.DevAdr; /* 求相对地址, 方便后面计算 */
|
||||
for (; FileOffset < FileLen; )
|
||||
{
|
||||
|
@ -51,7 +51,7 @@
|
||||
#define CMD_BE 0xC7 /* 批量擦除命令 */
|
||||
|
||||
|
||||
#define CMD_AAI 0xAD /* AAI 连续编程指令(FOR SST25VF016B) */
|
||||
//#define CMD_AAI 0xAD /* AAI 连续编程指令(FOR SST25VF016B) */
|
||||
#define CMD_ERASE_CHIP 0xC7 /* CHIP擦除命令, 镁光的片子只支持C7,很多芯片同时支持60和C7 */
|
||||
#define CMD_PAGE_PROG 0x02 /* page编程256字节 */
|
||||
|
||||
@ -980,8 +980,11 @@ uint8_t W25Q_DetectIC(uint32_t *_id)
|
||||
}
|
||||
else if (g_tW25Q.ReadIDCmd == 0x90 || g_tW25Q.ReadIDCmd == 0xAB) /* SST */
|
||||
{
|
||||
txbuf[0] = g_tW25Q.ReadIDCmd;
|
||||
W25Q_SendAndReadData(txbuf, 1, rxbuf, 2);
|
||||
txbuf[0] = g_tW25Q.ReadIDCmd;
|
||||
txbuf[1] = 0;
|
||||
txbuf[2] = 0;
|
||||
txbuf[3] = 0;
|
||||
W25Q_SendAndReadData(txbuf, 4, rxbuf, 2);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
@ -1014,67 +1017,6 @@ uint8_t W25Q_WriteBuf(uint32_t _Addr, uint8_t *_Buf, uint16_t _Len)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: W25Q_ReadBuf
|
||||
* 功能说明: 读取连续多个字节数据. APROM。 LDROM的数据地址 + 0x10000
|
||||
* 形 参: _Addr : 3个字节的地址。整数值
|
||||
* _Buf : 目标缓冲区
|
||||
* _Len : 字节长度
|
||||
* 返 回 值: 1表示成功,0表示失败
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
uint8_t W25Q_ReadBuf(uint32_t _Addr, uint8_t *_Buf, uint16_t _Len)
|
||||
{
|
||||
uint8_t txbuf[5];
|
||||
|
||||
if (g_tW25Q.ReadMode == 0) /* 单线 */
|
||||
{
|
||||
if (_Addr > 16 * 1024 * 1024)
|
||||
{
|
||||
txbuf[0] = 0x13; /* 4字节地址,读 */
|
||||
txbuf[1] = _Addr >> 24;
|
||||
txbuf[2] = _Addr >> 16;
|
||||
txbuf[3] = _Addr >> 8;
|
||||
txbuf[4] = _Addr;
|
||||
|
||||
W25Q_SendAndReadData(txbuf, 5, _Buf, _Len);
|
||||
}
|
||||
else
|
||||
{
|
||||
txbuf[0] = 0x03; /* 3字节地址,读 */
|
||||
txbuf[1] = _Addr >> 16;
|
||||
txbuf[2] = _Addr >> 8;
|
||||
txbuf[3] = _Addr;
|
||||
W25Q_SendAndReadData(txbuf, 4, _Buf, _Len);
|
||||
}
|
||||
}
|
||||
else if (g_tW25Q.ReadMode == 1) /* 双线 */
|
||||
{
|
||||
if (_Addr > 16 * 1024 * 1024)
|
||||
{
|
||||
txbuf[0] = 0x3C; /* 4字节地址,读 Read daul output */
|
||||
txbuf[1] = _Addr >> 24;
|
||||
txbuf[2] = _Addr >> 16;
|
||||
txbuf[3] = _Addr >> 8;
|
||||
txbuf[4] = _Addr;
|
||||
|
||||
W25Q_SendAndReadDataDaul(txbuf, 5, _Buf, _Len);
|
||||
}
|
||||
else
|
||||
{
|
||||
txbuf[0] = 0x3B; /* 3字节地址,读 Read daul output */
|
||||
txbuf[1] = _Addr >> 16;
|
||||
txbuf[2] = _Addr >> 8;
|
||||
txbuf[3] = _Addr;
|
||||
txbuf[4] = 0; /* 空闲字节 */
|
||||
W25Q_SendAndReadDataDaul(txbuf, 5, _Buf, _Len);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: W25Q_CheckBlank
|
||||
@ -1089,6 +1031,13 @@ uint8_t W25Q_CheckBlank(uint32_t _Addr, uint32_t _Len)
|
||||
uint8_t txbuf[5];
|
||||
uint8_t re;
|
||||
|
||||
if (g_tW25Q.Capacity > 16 * 1024 * 1024)
|
||||
{
|
||||
/* 进入四字节地址模式 */
|
||||
txbuf[0] = 0xB7;
|
||||
W25Q_SendData(txbuf, 1);
|
||||
}
|
||||
|
||||
if (g_tW25Q.ReadMode == 0) /* 单线 */
|
||||
{
|
||||
if (_Addr > 16 * 1024 * 1024)
|
||||
@ -1211,7 +1160,7 @@ void W25Q_WriteStatus(uint8_t _value)
|
||||
*/
|
||||
void W25Q_UnlockBlock(void)
|
||||
{
|
||||
if (g_tW25Q.UnlockCmd > 0x00)
|
||||
if (g_tW25Q.UnlockCmd > 0x00) // SST26 是0x98指令全局解锁保护
|
||||
{
|
||||
uint8_t txbuf[1];
|
||||
|
||||
@ -1220,16 +1169,19 @@ void W25Q_UnlockBlock(void)
|
||||
txbuf[0] = g_tW25Q.UnlockCmd;
|
||||
W25Q_SendData(txbuf, 1);
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// W25Q_WriteDisable();
|
||||
//
|
||||
// W25Q_WaitBusy(200);
|
||||
//
|
||||
// W25Q_WriteStatusEnable();
|
||||
//
|
||||
// W25Q_WriteStatus(0); /* 解除所有BLOCK的写保护 */
|
||||
// }
|
||||
else // 0x00 表示写状态寄存器00
|
||||
{
|
||||
if (g_tW25Q.AutoAddrInc > 0) // SST25 特殊,缺省是保护,未启用AAI
|
||||
{
|
||||
W25Q_WriteEnable();
|
||||
|
||||
W25Q_WaitBusy(200);
|
||||
|
||||
W25Q_WriteStatusEnable();
|
||||
|
||||
W25Q_WriteStatus(0x00); /* 解除所有BLOCK的写保护 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1408,7 +1360,14 @@ uint8_t W25Q_FLASH_ProgramBuf(uint32_t _Addr, uint8_t *_Buff, uint32_t _Size)
|
||||
{
|
||||
uint8_t txbuf[5];
|
||||
uint32_t i;
|
||||
|
||||
|
||||
if (g_tW25Q.Capacity > 16 * 1024 * 1024)
|
||||
{
|
||||
/* 进入四字节地址模式 */
|
||||
txbuf[0] = 0xB7;
|
||||
W25Q_SendData(txbuf, 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < _Size / 256; i++)
|
||||
{
|
||||
W25Q_WriteEnable();
|
||||
@ -1441,44 +1400,68 @@ uint8_t W25Q_FLASH_ProgramBuf(uint32_t _Addr, uint8_t *_Buff, uint32_t _Size)
|
||||
_Buff += 256;
|
||||
}
|
||||
}
|
||||
else /* 地址递增模式 SST25 */
|
||||
else /* 地址递增模式 SST25VF020 以下单字节 040以上双字节 */
|
||||
{
|
||||
uint8_t txbuf[6];
|
||||
uint32_t i;
|
||||
|
||||
W25Q_WriteEnable();
|
||||
|
||||
// /* 允许SO输出忙状态 */
|
||||
// txbuf[0] = 0x70;
|
||||
// W25Q_SendData(txbuf, 1);
|
||||
|
||||
txbuf[0] = CMD_AAI;
|
||||
txbuf[1] = _Addr >> 16;
|
||||
txbuf[2] = _Addr >> 8;
|
||||
txbuf[3] = _Addr >> 0;
|
||||
txbuf[4] = *_Buff++;
|
||||
txbuf[5] = *_Buff++;
|
||||
W25Q_SendData(txbuf, 6); /* 发送完毕拉高CS */
|
||||
|
||||
//---- 等so
|
||||
if (W25Q_WaitBusy(g_tW25Q.ProgPageTimeout) == 0)
|
||||
if (g_tW25Q.AutoAddrInc == 0xAF) /* 单字节AAI */
|
||||
{
|
||||
return 0; /* 超时异常 */
|
||||
}
|
||||
|
||||
for (i = 0; i < (_Size - 2) / 2; i++)
|
||||
{
|
||||
txbuf[0] = CMD_AAI;
|
||||
txbuf[1] = *_Buff++;
|
||||
txbuf[2] = *_Buff++;
|
||||
W25Q_SendData(txbuf, 3); /* 发送完毕拉高CS */
|
||||
|
||||
txbuf[0] = g_tW25Q.AutoAddrInc;
|
||||
txbuf[1] = _Addr >> 16;
|
||||
txbuf[2] = _Addr >> 8;
|
||||
txbuf[3] = _Addr >> 0;
|
||||
txbuf[4] = *_Buff++;
|
||||
W25Q_SendData(txbuf, 5); /* 发送完毕拉高CS */
|
||||
|
||||
if (W25Q_WaitBusy(g_tW25Q.ProgPageTimeout) == 0)
|
||||
{
|
||||
return 0; /* 超时异常 */
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < (_Size - 1) / 1; i++)
|
||||
{
|
||||
txbuf[0] = g_tW25Q.AutoAddrInc;
|
||||
txbuf[1] = *_Buff++;
|
||||
W25Q_SendData(txbuf, 2); /* 发送完毕拉高CS */
|
||||
|
||||
if (W25Q_WaitBusy(g_tW25Q.ProgPageTimeout) == 0)
|
||||
{
|
||||
return 0; /* 超时异常 */
|
||||
}
|
||||
}
|
||||
}
|
||||
else /* 0xAD, 双字节AAI */
|
||||
{
|
||||
txbuf[0] = g_tW25Q.AutoAddrInc;
|
||||
txbuf[1] = _Addr >> 16;
|
||||
txbuf[2] = _Addr >> 8;
|
||||
txbuf[3] = _Addr >> 0;
|
||||
txbuf[4] = *_Buff++;
|
||||
txbuf[5] = *_Buff++;
|
||||
W25Q_SendData(txbuf, 6); /* 发送完毕拉高CS */
|
||||
|
||||
if (W25Q_WaitBusy(g_tW25Q.ProgPageTimeout) == 0)
|
||||
{
|
||||
return 0; /* 超时异常 */
|
||||
}
|
||||
|
||||
for (i = 0; i < (_Size - 2) / 2; i++)
|
||||
{
|
||||
txbuf[0] = g_tW25Q.AutoAddrInc;
|
||||
txbuf[1] = *_Buff++;
|
||||
txbuf[2] = *_Buff++;
|
||||
W25Q_SendData(txbuf, 3); /* 发送完毕拉高CS */
|
||||
|
||||
if (W25Q_WaitBusy(g_tW25Q.ProgPageTimeout) == 0)
|
||||
{
|
||||
return 0; /* 超时异常 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 退出AAI
|
||||
W25Q_WriteDisable();
|
||||
|
||||
@ -1490,4 +1473,73 @@ uint8_t W25Q_FLASH_ProgramBuf(uint32_t _Addr, uint8_t *_Buff, uint32_t _Size)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************************************
|
||||
* 函 数 名: W25Q_ReadBuf
|
||||
* 功能说明: 读取连续多个字节数据. APROM。 LDROM的数据地址 + 0x10000
|
||||
* 形 参: _Addr : 3个字节的地址。整数值
|
||||
* _Buf : 目标缓冲区
|
||||
* _Len : 字节长度
|
||||
* 返 回 值: 1表示成功,0表示失败
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
uint8_t W25Q_ReadBuf(uint32_t _Addr, uint8_t *_Buf, uint16_t _Len)
|
||||
{
|
||||
uint8_t txbuf[5];
|
||||
|
||||
if (g_tW25Q.Capacity > 16 * 1024 * 1024)
|
||||
{
|
||||
/* 进入四字节地址模式 */
|
||||
txbuf[0] = 0xB7;
|
||||
W25Q_SendData(txbuf, 1);
|
||||
}
|
||||
|
||||
if (g_tW25Q.ReadMode == 0) /* 单线 */
|
||||
{
|
||||
if (g_tW25Q.Capacity > 16 * 1024 * 1024)
|
||||
{
|
||||
txbuf[0] = 0x03; /* 4字节地址,读 */
|
||||
txbuf[1] = _Addr >> 24;
|
||||
txbuf[2] = _Addr >> 16;
|
||||
txbuf[3] = _Addr >> 8;
|
||||
txbuf[4] = _Addr;
|
||||
|
||||
W25Q_SendAndReadData(txbuf, 5, _Buf, _Len);
|
||||
}
|
||||
else
|
||||
{
|
||||
txbuf[0] = 0x03; /* 3字节地址,读 */
|
||||
txbuf[1] = _Addr >> 16;
|
||||
txbuf[2] = _Addr >> 8;
|
||||
txbuf[3] = _Addr;
|
||||
W25Q_SendAndReadData(txbuf, 4, _Buf, _Len);
|
||||
}
|
||||
}
|
||||
else if (g_tW25Q.ReadMode == 1) /* 双线 */
|
||||
{
|
||||
if (g_tW25Q.Capacity > 16 * 1024 * 1024)
|
||||
{
|
||||
txbuf[0] = 0x3B; /* 4字节地址,读 Read daul output */
|
||||
txbuf[1] = _Addr >> 24;
|
||||
txbuf[2] = _Addr >> 16;
|
||||
txbuf[3] = _Addr >> 8;
|
||||
txbuf[4] = _Addr;
|
||||
txbuf[5] = 0; /* 空闲字节 */
|
||||
W25Q_SendAndReadDataDaul(txbuf, 6, _Buf, _Len);
|
||||
}
|
||||
else
|
||||
{
|
||||
txbuf[0] = 0x3B; /* 3字节地址,读 Read daul output */
|
||||
txbuf[1] = _Addr >> 16;
|
||||
txbuf[2] = _Addr >> 8;
|
||||
txbuf[3] = _Addr;
|
||||
txbuf[4] = 0; /* 空闲字节 */
|
||||
W25Q_SendAndReadDataDaul(txbuf, 5, _Buf, _Len);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "bsp.h"
|
||||
#include "usbd_user.h"
|
||||
#include "modbus_slave.h"
|
||||
#include "status_usb_uart.h" /* 用来虚拟串口收发数据计数 */
|
||||
|
||||
uint8_t g_ModbusRxBuf[RX_BUF_SIZE];
|
||||
uint16_t g_ModbusRxLen = 0;
|
||||
@ -192,6 +193,22 @@ static int8_t CDC_Itf_Control(uint8_t cmd, uint8_t * pbuf, uint16_t length)
|
||||
LineCoding.paritytype = pbuf[5];
|
||||
LineCoding.datatype = pbuf[6];
|
||||
|
||||
if (s_NowCom >= COM_USB1) /* PC通信返回 */
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
BEEP_Start(5,5,1);
|
||||
g_tUasUart.PcTxCount = 0;
|
||||
g_tUasUart.DevTxCount = 0;
|
||||
|
||||
g_tUasUart.Connected = 1; /* 打开串口 */
|
||||
g_tUasUart.DataBit = LineCoding.datatype;
|
||||
g_tUasUart.StopBit = LineCoding.format;
|
||||
g_tUasUart.Parity = LineCoding.paritytype;
|
||||
g_tUasUart.Baud = LineCoding.bitrate;
|
||||
g_tUasUart.Changed = 1;
|
||||
|
||||
/* Set the new configuration */
|
||||
ComPort_Config();
|
||||
break;
|
||||
@ -208,6 +225,14 @@ static int8_t CDC_Itf_Control(uint8_t cmd, uint8_t * pbuf, uint16_t length)
|
||||
|
||||
case CDC_SET_CONTROL_LINE_STATE:
|
||||
/* Add your code here */
|
||||
if (s_NowCom >= COM_USB1) /* PC通信返回 */
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// g_tUasUart.Connected = 0; /* 关闭串口 */
|
||||
// g_tUasUart.Changed = 1;
|
||||
|
||||
break;
|
||||
|
||||
case CDC_SEND_BREAK:
|
||||
@ -255,6 +280,10 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef * htim)
|
||||
USBD_CDC_SetTxBuffer(&USBD_Device, (uint8_t *) & UserTxBuffer[buffptr],
|
||||
buffsize);
|
||||
|
||||
g_tUasUart.DevTxCount += buffsize; /* 用于虚拟串口界面显示计数值 */
|
||||
g_tUasUart.Changed = 1;
|
||||
|
||||
|
||||
if (USBD_CDC_TransmitPacket(&USBD_Device) == USBD_OK)
|
||||
{
|
||||
UserTxBufPtrOut += buffsize;
|
||||
@ -336,11 +365,20 @@ static int8_t CDC_Itf_Receive(uint8_t * Buf, uint32_t *Len)
|
||||
{
|
||||
SCB_CleanDCache_by_Addr((uint32_t *)Buf, *Len);
|
||||
|
||||
if (s_NowCom == COM_USB1) /* */
|
||||
if (s_NowCom == COM_USB1) /* PC通信 */
|
||||
{
|
||||
uint32_t len;
|
||||
|
||||
len = *Len;
|
||||
len = *Len;
|
||||
|
||||
#if 0
|
||||
{
|
||||
uint8_t buf[128];
|
||||
|
||||
sprintf((char *)buf, "PC->H7 %u, %02X %02X %02X, len = %d\r\n", bsp_GetRunTime(), Buf[0], Buf[1], Buf[2], len);
|
||||
comSendBuf(COM_RS485, buf, strlen(buf));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (g_ModbusRxLen + len <= RX_BUF_SIZE)
|
||||
{
|
||||
@ -364,8 +402,11 @@ static int8_t CDC_Itf_Receive(uint8_t * Buf, uint32_t *Len)
|
||||
* (transmitting data over Tx line) */
|
||||
USBD_CDC_ReceivePacket(&USBD_Device);
|
||||
}
|
||||
else if (s_NowCom == COM1)
|
||||
else if (s_NowCom == COM1) /* 虚拟串口 */
|
||||
{
|
||||
g_tUasUart.PcTxCount += *Len; /* 用于虚拟串口界面显示计数值 */
|
||||
g_tUasUart.Changed = 1;
|
||||
|
||||
RS485_SendBefor();
|
||||
comSetCallbackSendOver(COM1, Uart1TxCpltCallback);
|
||||
comSendBuf(COM1, Buf, *Len);
|
||||
@ -397,14 +438,8 @@ static void ComPort_Config(void)
|
||||
uint32_t StopBits;
|
||||
uint32_t Parity;
|
||||
uint32_t WordLength;
|
||||
uint32_t BaudRate;
|
||||
uint32_t BaudRate;
|
||||
|
||||
|
||||
if (s_NowCom >= COM_USB1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* set the Stop bit */
|
||||
switch (LineCoding.format)
|
||||
{
|
||||
@ -460,6 +495,7 @@ static void ComPort_Config(void)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
BaudRate = LineCoding.bitrate;
|
||||
|
||||
bsp_SetUartParam(s_NowCom, BaudRate, Parity, WordLength, StopBits);
|
||||
@ -521,6 +557,15 @@ static void TIM_Config(void)
|
||||
*/
|
||||
uint8_t USBCom_SendBufNow(int _Port, uint8_t *_Buf, uint16_t _Len)
|
||||
{
|
||||
#if 0
|
||||
{
|
||||
uint8_t buf[128];
|
||||
|
||||
sprintf((char *)buf, "H7->PC %u, %02X %02X %02X, len = %d\r\n\r\n", bsp_GetRunTime(), _Buf[0], _Buf[1], _Buf[2], _Len);
|
||||
comSendBuf(COM_RS485, buf, strlen(buf));
|
||||
}
|
||||
#endif
|
||||
|
||||
memcpy(UserTxBuffer, _Buf, _Len);
|
||||
USBD_CDC_SetTxBuffer(&USBD_Device, UserTxBuffer, _Len);
|
||||
if (USBD_CDC_TransmitPacket(&USBD_Device) == USBD_OK)
|
||||
|
@ -164,7 +164,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef * hpcd)
|
||||
__HAL_RCC_USB1_OTG_HS_CLK_ENABLE();
|
||||
|
||||
/* Set USBHS Interrupt to the lowest priority */
|
||||
HAL_NVIC_SetPriority(OTG_HS_IRQn, 0, 0);
|
||||
HAL_NVIC_SetPriority(OTG_HS_IRQn, 1, 0);
|
||||
|
||||
/* Enable USBHS Interrupt */
|
||||
HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
|
||||
|
Loading…
x
Reference in New Issue
Block a user