Skip to content

Commit 54f041f

Browse files
authored
HSLink-Pro: 2.3.2 (#30)
1 parent c720deb commit 54f041f

File tree

31 files changed

+1601
-111
lines changed

31 files changed

+1601
-111
lines changed

.github/workflows/HSLinkPro-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
export HPM_SDK_TOOLCHAIN_VARIANT=gcc
5050
export PYTHON_EXECUTABLE=~/HPM_PYTHON/bin/python3
5151
52-
cmake -GNinja -DBOARD=hpm5301evklite -DHPM_BUILD_TYPE=flash_xip -DCMAKE_BUILD_TYPE=release -Dpython_exec="~/HPM_PYTHON/bin/python3" -DCUSTOM_TARGET_TRIPLET=riscv-none-elf -DRV_ARCH="rv32imac_zicsr_zifencei" . -B=./build
52+
cmake -GNinja -DBOARD=hslinkpro -DHPM_BUILD_TYPE=flash_xip -DCMAKE_BUILD_TYPE=release -Dpython_exec="~/HPM_PYTHON/bin/python3" -DCUSTOM_TARGET_TRIPLET=riscv-none-elf -DRV_ARCH="rv32imac_zicsr_zifencei" . -B=./build
5353
cmake --build ./build
5454
5555
- name: Build APP
@@ -60,7 +60,7 @@ jobs:
6060
export HPM_SDK_TOOLCHAIN_VARIANT=gcc
6161
export PYTHON_EXECUTABLE=~/HPM_PYTHON/bin/python3
6262
63-
cmake -GNinja -DBOARD=hpm5301evklite -DHPM_BUILD_TYPE=flash_uf2 -DCMAKE_BUILD_TYPE=release -Dpython_exec="~/HPM_PYTHON/bin/python3" -DCUSTOM_TARGET_TRIPLET=riscv-none-elf -DRV_ARCH="rv32imac_zicsr_zifencei" . -B=./build
63+
cmake -GNinja -DBOARD=hslinkpro -DHPM_BUILD_TYPE=flash_uf2 -DCMAKE_BUILD_TYPE=release -Dpython_exec="~/HPM_PYTHON/bin/python3" -DCUSTOM_TARGET_TRIPLET=riscv-none-elf -DRV_ARCH="rv32imac_zicsr_zifencei" . -B=./build
6464
cmake --build ./build
6565
6666
- name: Merge Bin

.gitmodules

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
[submodule "CherryRB"]
55
path = CherryRB
66
url = https://github.com/cherry-embedded/CherryRB.git
7-
[submodule "projects/HSLink-Pro/WS2812"]
8-
path = projects/HSLink-Pro/WS2812
7+
[submodule "projects/HSLink-Pro/third_party_components/WS2812"]
8+
path = projects/HSLink-Pro/third_party_components/WS2812
99
url = https://github.com/HalfSweet/HPM_WS2812.git
10-
[submodule "projects/HSLink-Pro/src/tlsf"]
11-
path = projects/HSLink-Pro/src/tlsf
10+
[submodule "projects/HSLink-Pro/third_party_components/tlsf/tlsf"]
11+
path = projects/HSLink-Pro/third_party_components/tlsf/tlsf
1212
url = https://github.com/mattconte/tlsf.git
13-
[submodule "projects/HSLink-Pro/src/rapidjson"]
14-
path = projects/HSLink-Pro/src/rapidjson
15-
url = https://github.com/Tencent/rapidjson.git
13+
[submodule "projects/HSLink-Pro/third_party_components/rapidjson/rapidjson"]
14+
path = projects/HSLink-Pro/third_party_components/rapidjson/rapidjson
15+
url = https://github.com/Tencent/rapidjson.git

projects/HSLink-Pro/WS2812

Lines changed: 0 additions & 1 deletion
This file was deleted.

projects/HSLink-Pro/bootloader/CMakeLists.txt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cmake_minimum_required(VERSION 3.13)
22

33
set(APP_NAME HSLink-Pro-Bootloader)
4+
set(BOARD_SEARCH_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../common)
45

56
set(CONFIG_DMA_MGR 1)
67

@@ -15,12 +16,9 @@ find_package(hpm-sdk REQUIRED HINTS $ENV{HPM_SDK_BASE})
1516

1617
project(HSLink-Pro-Bootloader)
1718

18-
add_subdirectory(../WS2812 ${CMAKE_CURRENT_BINARY_DIR}/ws2812)
19-
20-
sdk_compile_definitions(
21-
# -DBOARD_SHOW_CLOCK=0
22-
-DBOARD_SHOW_BANNER=0
23-
)
19+
#sdk_compile_definitions(-DCONFIG_WS2812=1)
20+
#sdk_compile_definitions(-DWS2812_USE_SPI=0)
21+
#add_subdirectory(../third_party_components/WS2812 ${CMAKE_CURRENT_BINARY_DIR}/ws2812)
2422

2523
sdk_app_src(src/main.c)
2624
sdk_app_src(src/msc_bootuf2.c)

projects/HSLink-Pro/bootloader/bootuf2/bootuf2.c

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
#include "bootuf2.h"
88
#include "usbd_core.h"
99

10-
char file_INFO[] = {
10+
const char file_INFO[] = {
1111
"CherryUSB UF2 BOOT\r\n"
1212
"Model: " CONFIG_PRODUCT "\r\n"
1313
"Board-ID: " CONFIG_BOARD "\r\n"
14+
"Bootloader Reason: " DEFAULT_REASON
1415
};
1516

1617
const char file_IDEX[] = {
@@ -37,11 +38,18 @@ const char file_JOIN[] = {
3738

3839
const char file_ID__[12] = BOOTUF2_FAMILYID_ARRAY;
3940

41+
enum {
42+
FILE_ID = 0,
43+
FILE_INFO = 1,
44+
FILE_INDEX = 2,
45+
FILE_JOIN = 3,
46+
};
47+
4048
static struct bootuf2_FILE files[] = {
41-
[0] = { .Name = file_ID__, .Content = NULL, .FileSize = 0 },
42-
[1] = { .Name = "INFO_UF2TXT", .Content = file_INFO, .FileSize = sizeof(file_INFO) - 1 },
43-
[2] = { .Name = "INDEX HTM", .Content = file_IDEX, .FileSize = sizeof(file_IDEX) - 1 },
44-
[3] = { .Name = "JOIN HTM", .Content = file_JOIN, .FileSize = sizeof(file_JOIN) - 1 },
49+
[FILE_ID] = { .Name = file_ID__, .Content = NULL, .FileSize = 0 },
50+
[FILE_INFO] = { .Name = "INFO_UF2TXT", .Content = NULL, .FileSize = 0 }, // will be added when init
51+
[FILE_INDEX] = { .Name = "INDEX HTM", .Content = file_IDEX, .FileSize = sizeof(file_IDEX) - 1 },
52+
[FILE_JOIN] = { .Name = "JOIN HTM", .Content = file_JOIN, .FileSize = sizeof(file_JOIN) - 1 },
4553
};
4654

4755
struct bootuf2_data {
@@ -245,11 +253,74 @@ int bootuf2_flash_write_internal(struct bootuf2_data *ctx, struct bootuf2_BLOCK
245253

246254
return 0;
247255
}
248-
256+
static void replaceSubstring(char *str, const char *oldWord, const char *newWord) {
257+
char *result; // 存放新字符串的缓冲区
258+
char *pos, *temp;
259+
int count = 0;
260+
int oldLen = strlen(oldWord);
261+
int newLen = strlen(newWord);
262+
263+
// 1. 统计 oldWord 在 str 中出现的次数
264+
temp = str;
265+
while ((pos = strstr(temp, oldWord)) != NULL) {
266+
count++;
267+
temp = pos + oldLen;
268+
}
269+
270+
// 2. 分配足够大小的缓冲区(注意:如果 newLen < oldLen,分配空间会小于原始字符串大小,
271+
// 但为了代码简单,这里直接分配原始串长度加上扩展部分)
272+
result = (char *) malloc(strlen(str) + count * (newLen - oldLen) + 1);
273+
if (result == NULL) {
274+
// 内存分配失败,直接返回
275+
return;
276+
}
277+
278+
// 3. 进行字符串替换构造新的结果字符串
279+
temp = str; // 临时指针,指向原字符串
280+
char *r = result; // 指向新字符串的写入位置
281+
282+
while ((pos = strstr(temp, oldWord)) != NULL) {
283+
// 复制 pos 之前的部分
284+
int len = pos - temp;
285+
memcpy(r, temp, len);
286+
r += len;
287+
288+
// 将 newWord 复制到结果中
289+
memcpy(r, newWord, newLen);
290+
r += newLen;
291+
292+
// 更新 temp 指针,跳过被替换的 oldWord
293+
temp = pos + oldLen;
294+
}
295+
// 复制剩下的部分
296+
strcpy(r, temp);
297+
298+
// 4. 将结果拷贝回原来的字符串中
299+
strcpy(str, result);
300+
free(result);
301+
}
302+
void bootuf2_SetReason(const char* reason) {
303+
if (files[FILE_INFO].Content != NULL) {
304+
free(files[FILE_INFO].Content);
305+
}
306+
307+
// modify it to show why we keep in bootloader mode
308+
// because of file_INFO is a string in .data section, we need to copy it and modify it
309+
char* const file_INFO_ = (char*)malloc(strlen(file_INFO) + 100);
310+
memset(file_INFO_, 0, strlen(file_INFO) + 100);
311+
strcpy(file_INFO_, file_INFO);
312+
replaceSubstring(file_INFO_, DEFAULT_REASON, reason);
313+
files[FILE_INFO].Content = file_INFO_;
314+
files[FILE_INFO].FileSize = strlen(file_INFO_);
315+
}
249316
void bootuf2_init(void)
250317
{
251318
struct bootuf2_data *ctx;
252319

320+
if (files[FILE_INFO].Content == NULL) {
321+
bootuf2_SetReason("DEFAULT_REASON");
322+
}
323+
253324
ctx = &bootuf2_disk;
254325

255326
fcalculate_cluster(ctx);

projects/HSLink-Pro/bootloader/bootuf2/bootuf2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct bootuf2_ENTRY
102102
struct bootuf2_FILE
103103
{
104104
const char *const Name;
105-
const void *const Content;
105+
void * Content;
106106
uint32_t FileSize;
107107
uint16_t ClusterBeg;
108108
uint16_t ClusterEnd;

projects/HSLink-Pro/bootloader/bootuf2/bootuf2_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define CONFIG_BOARD "HSLink Pro"
1111
#define CONFIG_BOOTUF2_INDEX_URL "https://github.com/cherry-embedded/CherryDAP"
1212
#define CONFIG_BOOTUF2_JOIN_URL "http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=NXGLdOOrFypXfBoAmh_eLwmcAZ2doqxJ&authKey=CDerxhytwBfYn1jHcfmBwOOl2B73vRxGmPJ0utVTFrnjfwfTikpzJbYUUPhyicmK&noverify=0&group_code=975779851"
13+
#define DEFAULT_REASON "DEFAULT_REASON_DEFAULT_REASON_DEFAULT_REASON\r\n"
1314

1415
#define CONFIG_BOOTUF2_CACHE_SIZE 4096
1516
#define CONFIG_BOOTUF2_SECTOR_SIZE 512

0 commit comments

Comments
 (0)