Skip to content

Commit c7816f0

Browse files
committed
V2.6.0增加ESP32串口下载程序功能
1 parent b81986a commit c7816f0

27 files changed

+6114
-129
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@
22

33
RYCOM是一款开源的串口调试助手,使用QT设计,C++编写,可在Windows、Linux、MacOS操作系统上使用。支持STM32串口下载程序。
44
# RYCOM
5+
#### 20250202 RYCOM 2.6.0.exe
6+
7+
- 1.添加ESP32系列芯片串口下载程序,支持从0x0开始下载合并后的单个.bin;
8+
- 2.支持bootloader.bin,partition-table.bin,app.bin分段下载;
9+
- 3.自动识别ESP32芯片信号和flash大小;
10+
- 4.ESP32串口下载使用方法https://rymcu.com/article/2203
11+
12+
#### 20240323 RYCOM 2.5.1.exe
13+
14+
- 1.修复重复点击Open按钮卡死bug。
15+
516
#### 20240320 RYCOM2.5.exe
17+
618
- 1.增加串口下载Flash擦除选项;
719
- 2.修复.Hex文件打开时下载地址错误;
820
- 3.修复指示灯bug及其他。

sources/HexToBin.cpp

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
#include "HexToBin.h"
2+
#include <stdio.h>
3+
#include <string.h>
4+
5+
QByteArray text;
6+
7+
/********************************************************************************
8+
input:
9+
c:单个字符('0'~'9' 'a'~'f', 'A'~'F')
10+
output:
11+
单个字符转化为单个字符
12+
********************************************************************************/
13+
static uint8_t HexCharToBinBinChar(char c)
14+
{
15+
if (c >= '0' && c <= '9')
16+
return c - '0';
17+
else if (c >= 'a' && c <= 'z')
18+
return c - 'a' + 10;
19+
else if (c >= 'A' && c <= 'Z')
20+
return c - 'A' + 10;
21+
return 0xff;
22+
}
23+
24+
/********************************************************************************
25+
input:
26+
p: 两个文本字符
27+
output:
28+
转化为1个字节
29+
********************************************************************************/
30+
static uint8_t Hex2Bin(const char *p)
31+
{
32+
uint8_t tmp = 0;
33+
tmp = HexCharToBinBinChar(p[0]);
34+
tmp <<= 4;
35+
tmp |= HexCharToBinBinChar(p[1]);
36+
return tmp;
37+
}
38+
39+
/********************************************************************************
40+
input:
41+
src: hex单行字符串
42+
p->type: 如果函数返回结果正确,这里就存着转化后的类型
43+
p->len: 如果函数运行正确,这里就存着转化后的bin数据长度
44+
p->data: 如果函数运行正确,长度并且不为0,该指针就只想转化后的数据
45+
p->addr[0]: 如果函数返回结果正确,这里就存着地址的低字节
46+
p->addr[1]: 如果函数返回结果正确,这里就存着地址的低字节
47+
output:
48+
返回hex格式流分析的结果
49+
********************************************************************************/
50+
static RESULT_STATUS HexFormatUncode(const char *src, BinFarmat *p)
51+
{
52+
uint8_t check = 0, tmp[4], binLen;
53+
uint16_t hexLen = strlen(src);
54+
uint16_t num = 0, offset = 0;
55+
if (hexLen > HEX_MAX_LENGTH) //数据内容过长
56+
return RES_DATA_TOO_LONG;
57+
if (hexLen < HEX_MIN_LEN)
58+
return RES_DATA_TOO_SHORT; //数据内容过短
59+
if (src[0] != ':')
60+
return RES_NO_COLON; //没有冒号
61+
if ((hexLen - 1) % 2 != 0)
62+
return RES_LENGTH_ERROR; //hexLen的长度应该为奇数
63+
binLen = (hexLen - 1) / 2; //bin总数据的长度,包括长度,地址,类型校验等内容
64+
while (num < 4)
65+
{
66+
offset = (num << 1) + 1;
67+
tmp[num] = Hex2Bin(src + offset);
68+
check += tmp[num];
69+
num++;
70+
}
71+
p->len = tmp[0]; //把解析的这些数据保存到结构体中
72+
p->addr = tmp[1];
73+
p->addr <<= 8;
74+
p->addr += tmp[2];
75+
p->type = tmp[3];
76+
while (num < binLen)
77+
{
78+
offset = (num << 1) + 1; //保存真正的bin格式数据流
79+
p->data[num - 4] = Hex2Bin(src + offset);
80+
check += p->data[num - 4];
81+
num++;
82+
}
83+
if (p->len != binLen - 5) //检查hex格式流的长度和数据的长度是否一致
84+
return RES_LENGTH_ERROR;
85+
if (check != 0) //检查校验是否通过
86+
return RES_CHECK_ERROR;
87+
return RES_OK;
88+
}
89+
90+
int insertsomething(QByteArray* desQByte,uint8_t* addr, int num )
91+
{
92+
QByteArray str="a";
93+
94+
for(int i=0;i<num;i++)
95+
{
96+
str[0] = *(addr+i);
97+
desQByte->append(str);
98+
}
99+
return num;
100+
}
101+
102+
RESULT_STATUS HexFile2BinFile(char *src, char *dest, uint32_t *addr)
103+
{
104+
FILE *src_file;// *dest_file;
105+
uint16_t addr_low = 0;
106+
uint32_t addr_hign = 0;
107+
char buffer_hex[600];
108+
uint8_t buffer_bin[255];
109+
BinFarmat gBinFor;
110+
RESULT_STATUS res;
111+
112+
//QByteArray tset;
113+
114+
gBinFor.data = buffer_bin;
115+
src_file = fopen(src, "r"); //以文本的形式打开一个hex文件
116+
if (!src_file)
117+
return RES_HEX_FILE_NOT_EXIST;
118+
//dest_file = fopen(dest, "wb"); //以二进制写的方式打开文件,文件不存在也没影响
119+
//if (!dest_file)
120+
//return RES_BIN_FILE_PATH_ERROR;
121+
fseek(src_file, 0, SEEK_SET); //定位到开头,准备开始读取数据
122+
char beginflag = 1;
123+
char secondline = 1;
124+
while (!feof(src_file))
125+
{
126+
fscanf(src_file, "%s\r\n", buffer_hex);
127+
128+
129+
130+
131+
//get the begin addr
132+
unsigned int Low,High,addr_temp = 0;
133+
134+
if(buffer_hex[2] == '2')
135+
{
136+
137+
for(char i=0;i<4;i++)
138+
{
139+
if(buffer_hex[6-i]>='0' && buffer_hex[6-i]<='9')
140+
{
141+
Low = buffer_hex[6-i]-'0';
142+
}
143+
else if(buffer_hex[6-i]>='a' && buffer_hex[6-i]<='f')
144+
{
145+
Low = buffer_hex[6-i]-'a'+10;
146+
}
147+
else if(buffer_hex[6-i]>='A' && buffer_hex[6-i]<='F')
148+
{
149+
Low = buffer_hex[6-i]-'A'+10;
150+
}
151+
else
152+
{
153+
Low = 0xFF;
154+
}
155+
156+
Low = Low<<(4*i);
157+
158+
if(buffer_hex[12-i]>='0' && buffer_hex[12-i]<='9')
159+
{
160+
High = buffer_hex[12-i]-'0';
161+
}
162+
else if(buffer_hex[12-i]='a' && buffer_hex[12-i]<='f')
163+
{
164+
High = buffer_hex[12-i]-'a'+10;
165+
}
166+
else if(buffer_hex[12-i]>='A' && buffer_hex[12-i]<='F')
167+
{
168+
High = buffer_hex[12-i]-'A'+10;
169+
}
170+
else
171+
{
172+
High = 0xFF;
173+
}
174+
175+
High = High<<(4*i+16);
176+
177+
addr_temp = addr_temp + Low + High;
178+
}
179+
//addr_temp= 0x08000000;
180+
if(beginflag)
181+
{
182+
*addr = addr_temp;//only frist time!
183+
beginflag = 0;
184+
}
185+
186+
}
187+
//get addr offset
188+
if(buffer_hex[1] == '1')
189+
{
190+
Low =0;
191+
for(char i=0;i<4;i++)
192+
{
193+
if(buffer_hex[6-i]>='0' && buffer_hex[6-i]<='9')
194+
{
195+
Low = buffer_hex[6-i]-'0';
196+
}
197+
else if(buffer_hex[6-i]>='a' && buffer_hex[6-i]<='f')
198+
{
199+
Low = buffer_hex[6-i]-'a'+10;
200+
}
201+
else if(buffer_hex[6-i]>='A' && buffer_hex[6-i]<='F')
202+
{
203+
Low = buffer_hex[6-i]-'A'+10;
204+
}
205+
else
206+
{
207+
Low = 0xFF;
208+
}
209+
210+
Low = Low<<(4*i);
211+
}
212+
//addr_temp= 0x08000000;
213+
if(secondline)
214+
{
215+
*addr = *addr+Low;//only frist time!
216+
secondline = 0;
217+
}
218+
219+
}
220+
221+
222+
//
223+
224+
225+
226+
227+
res = HexFormatUncode(buffer_hex, &gBinFor);
228+
if (res != RES_OK)
229+
{
230+
fclose(src_file);
231+
//fclose(dest_file);
232+
return res;
233+
}
234+
switch (gBinFor.type)
235+
{
236+
case 0: //数据记录
237+
addr_low = gBinFor.addr;
238+
//数据指针偏移
239+
// fseek(dest_file, addr_low + addr_hign, SEEK_SET);
240+
241+
242+
insertsomething(&text,(uint8_t*)gBinFor.data, gBinFor.len);
243+
244+
/*if (fwrite((const uint8_t*)gBinFor.data, gBinFor.len, 1, dest_file) != 1)
245+
{
246+
fclose(src_file);
247+
fclose(dest_file);
248+
return RES_WRITE_ERROR;
249+
}*/
250+
break;
251+
case 1: //数据结束
252+
fclose(src_file);
253+
//fclose(dest_file);
254+
return RES_OK;
255+
case 2:
256+
addr_hign = ((uint32_t)gBinFor.addr) << 2;
257+
break;
258+
case 4: //线性段地址
259+
addr_hign = ((uint32_t)gBinFor.addr) << 16;
260+
break;
261+
default:
262+
fclose(src_file);
263+
//fclose(dest_file);
264+
return RES_TYPE_ERROR;
265+
}
266+
}
267+
fclose(src_file);
268+
//fclose(dest_file);
269+
return RES_HEX_FILE_NO_END;
270+
}
271+

sources/HexToBin.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef HEX2BIN_H
2+
#define HEX2BIN_H
3+
4+
typedef unsigned char uint8_t;
5+
typedef unsigned short uint16_t;
6+
typedef unsigned int uint32_t;
7+
#include <QString>
8+
9+
extern QByteArray text;
10+
11+
#define HEX_MAX_LENGTH 521
12+
#define HEX_MIN_LEN 11
13+
14+
typedef enum {
15+
RES_OK = 0, //正确
16+
RES_DATA_TOO_LONG, //数据太长
17+
RES_DATA_TOO_SHORT, //数据太短
18+
RES_NO_COLON, //无标号
19+
RES_TYPE_ERROR, //类型出错,或许不存在
20+
RES_LENGTH_ERROR, //数据长度字段和内容的总长度不对应
21+
RES_CHECK_ERROR, //校验错误
22+
RES_HEX_FILE_NOT_EXIST, //HEX文件不存在
23+
RES_BIN_FILE_PATH_ERROR,//BIN文件路径可能不正确
24+
RES_WRITE_ERROR, //写数据出错
25+
RES_HEX_FILE_NO_END //hex文件没有结束符
26+
} RESULT_STATUS;
27+
28+
typedef struct {
29+
uint8_t len;
30+
uint8_t type;
31+
uint16_t addr;
32+
uint8_t *data;
33+
} BinFarmat;
34+
35+
RESULT_STATUS HexFile2BinFile(char *src, char *dest,uint32_t* addr);
36+
#endif

sources/RYCOM.pro

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,25 @@ RC_ICONS = rymculogo.ico
2828
SOURCES += \
2929
main.cpp \
3030
mainwindow.cpp \
31-
mycombobox.cpp
31+
mycombobox.cpp \
32+
ryisp.cpp \
33+
mycom.cpp \
34+
HexToBin.cpp \
35+
ry_ymodem.cpp \
36+
myfilewatcher.cpp \
37+
ryesp32isp.cpp
3238

3339
HEADERS += \
3440
mainwindow.h \
35-
mycombobox.h
41+
mycombobox.h \
42+
ryisp.h \
43+
mycom.h \
44+
HexToBin.h \
45+
HexToBin.h \
46+
ry_ymodem.h \
47+
myfilewatcher.h \
48+
ryesp32isp.h \
49+
esp32/esp32_protocol.h
3650

3751
FORMS += \
3852
mainwindow.ui

0 commit comments

Comments
 (0)