From 05377fe3a337ab23d0a1b397cc04e4cec8eff96a Mon Sep 17 00:00:00 2001 From: FINALxxx <3085378853@qq.com> Date: Tue, 14 Apr 2026 15:35:23 +0800 Subject: [PATCH 01/12] fix: fix info display --- board/StarrySkyC2/build_conf.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/board/StarrySkyC2/build_conf.mk b/board/StarrySkyC2/build_conf.mk index be468a2..85fde8a 100644 --- a/board/StarrySkyC2/build_conf.mk +++ b/board/StarrySkyC2/build_conf.mk @@ -43,7 +43,7 @@ DRIVER_SUBDIRS := $(notdir $(shell find $(DRIVER_DIR) -mindepth 1 -maxdepth 1 -t $(foreach subdir,$(DRIVER_SUBDIRS), \ $(eval CONFIG_NAME := $(shell echo $(subdir) | tr '[:lower:]' '[:upper:]')) \ - $(info Include drivers: $(CONFIG_NAME)) \ + $(if $(VERBOSE),$(info Include drivers: $(CONFIG_NAME))) \ $(eval $(call driver_template,$(CONFIG_NAME),$(subdir))) \ ) From ac6552f8c719dce61b83b10f64aa08408938022c Mon Sep 17 00:00:00 2001 From: FINALxxx <3085378853@qq.com> Date: Mon, 20 Apr 2026 08:45:34 +0800 Subject: [PATCH 02/12] fix: delete start.S and fix some typos for c2 --- bin/ecos-set_board | 4 ++-- board/StarrySkyC2/Makefile | 2 +- board/StarrySkyC2/driver.kconfig | 4 ++-- board/StarrySkyC2/{start.S => start.s} | 0 4 files changed, 5 insertions(+), 5 deletions(-) rename board/StarrySkyC2/{start.S => start.s} (100%) diff --git a/bin/ecos-set_board b/bin/ecos-set_board index 11db87f..6fdfb72 100755 --- a/bin/ecos-set_board +++ b/bin/ecos-set_board @@ -109,7 +109,7 @@ set_board() { local board_file="board.h" local make_file="Makefile" local lds_file="sections.lds" - local start_file="start.S" + local start_file="start.s" local board_source_path="$SDK_ROOT/board/StarrySkyC2/$board_file" local make_source_path="$SDK_ROOT/board/StarrySkyC2/$make_file" @@ -119,7 +119,7 @@ set_board() { local board_target_path="./board.h" local make_target_path="./Makefile" local lds_target_path="./sections.lds" - local start_target_path="./start.S" + local start_target_path="./start.s" if [[ ! -f "$board_source_path" ]]; then err "Board config file not found: $board_source_path" diff --git a/board/StarrySkyC2/Makefile b/board/StarrySkyC2/Makefile index 99ddae4..833b35e 100644 --- a/board/StarrySkyC2/Makefile +++ b/board/StarrySkyC2/Makefile @@ -23,7 +23,7 @@ CFLAGS := -mabi=ilp32 \ -nostdlib # 必要的源文件列表 -SRC_PATH := ./start.S ./main.c +SRC_PATH := ./start.s ./main.c CFLAGS += -I./configs # 必要的链接脚本路径 diff --git a/board/StarrySkyC2/driver.kconfig b/board/StarrySkyC2/driver.kconfig index bfd5238..a996e89 100644 --- a/board/StarrySkyC2/driver.kconfig +++ b/board/StarrySkyC2/driver.kconfig @@ -12,10 +12,10 @@ menu "Peripheral Drivers" Enable GPIO driver for pin control config DRIVER_HP_UART - bool "UART Driver Support" + bool "HP_UART Driver Support" default y help - Enable UART driver for serial communication + Enable HP_UART driver for serial communication # config DRIVER_SPI # bool "SPI Driver Support" diff --git a/board/StarrySkyC2/start.S b/board/StarrySkyC2/start.s similarity index 100% rename from board/StarrySkyC2/start.S rename to board/StarrySkyC2/start.s From 2d7dbd53fba45a47a12756835499a25b393bc807 Mon Sep 17 00:00:00 2001 From: FINALxxx <3085378853@qq.com> Date: Mon, 20 Apr 2026 08:58:16 +0800 Subject: [PATCH 03/12] fix: rename start.s to start.S and fix relative logic --- bin/ecos-set_board | 4 ++-- board/StarrySkyC2/Makefile | 2 +- board/StarrySkyC2/{start.s => start.S} | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename board/StarrySkyC2/{start.s => start.S} (100%) diff --git a/bin/ecos-set_board b/bin/ecos-set_board index 6fdfb72..11db87f 100755 --- a/bin/ecos-set_board +++ b/bin/ecos-set_board @@ -109,7 +109,7 @@ set_board() { local board_file="board.h" local make_file="Makefile" local lds_file="sections.lds" - local start_file="start.s" + local start_file="start.S" local board_source_path="$SDK_ROOT/board/StarrySkyC2/$board_file" local make_source_path="$SDK_ROOT/board/StarrySkyC2/$make_file" @@ -119,7 +119,7 @@ set_board() { local board_target_path="./board.h" local make_target_path="./Makefile" local lds_target_path="./sections.lds" - local start_target_path="./start.s" + local start_target_path="./start.S" if [[ ! -f "$board_source_path" ]]; then err "Board config file not found: $board_source_path" diff --git a/board/StarrySkyC2/Makefile b/board/StarrySkyC2/Makefile index 833b35e..99ddae4 100644 --- a/board/StarrySkyC2/Makefile +++ b/board/StarrySkyC2/Makefile @@ -23,7 +23,7 @@ CFLAGS := -mabi=ilp32 \ -nostdlib # 必要的源文件列表 -SRC_PATH := ./start.s ./main.c +SRC_PATH := ./start.S ./main.c CFLAGS += -I./configs # 必要的链接脚本路径 diff --git a/board/StarrySkyC2/start.s b/board/StarrySkyC2/start.S similarity index 100% rename from board/StarrySkyC2/start.s rename to board/StarrySkyC2/start.S From dba05c686159d52d15c581c54ca19c6154038c41 Mon Sep 17 00:00:00 2001 From: FINALxxx <3085378853@qq.com> Date: Tue, 21 Apr 2026 11:32:57 +0800 Subject: [PATCH 04/12] feat(StarrySkyC2): add isolated project --- bin/ecos | 31 +++--- bin/ecos-completion.zsh | 0 bin/ecos-init_project | 72 +++++++++++- bin/ecos-set_board_isolated | 163 ++++++++++++++++++++++++++++ board/StarrySkyC2/Makefile_isolated | 107 ++++++++++++++++++ docs/isolated_project.md | 0 6 files changed, 355 insertions(+), 18 deletions(-) mode change 100644 => 100755 bin/ecos-completion.zsh create mode 100755 bin/ecos-set_board_isolated create mode 100644 board/StarrySkyC2/Makefile_isolated create mode 100644 docs/isolated_project.md diff --git a/bin/ecos b/bin/ecos index d71ebbe..9ffa464 100755 --- a/bin/ecos +++ b/bin/ecos @@ -19,23 +19,28 @@ show_help() { echo "Usage: ecos [options]" echo "" echo "Available commands:" - echo " set_board Set the board configuration" - echo " init_project |list Initialize a project or list available projects" - echo " flash Flash the compiled firmware to the device" - echo " monitor Open serial monitor using minicom" - echo " help Show this help message" + echo " set_board Set the board configuration" + echo " init_project |list Initialize a project or list available projects" + echo " flash Flash the compiled firmware to the device" + echo " monitor Open serial monitor using minicom" + echo " help Show this help message" echo "" echo "Board list:" - echo " c1 StarrySky C1 board" - echo " c2 StarrySky C2 board" - echo " l3 StarrySky L3 board" + echo " c1 StarrySky C1 board" + echo " c2 StarrySky C2 board" + echo " l3 StarrySky L3 board" + echo "" + echo "Isolated:" + echo " Isolated project gathers all the resource so that you can compile your project without SDK" + echo " But the riscv-toolchain is still indispensable" echo "" echo "Examples:" - echo " ecos set_board c1 Set the board to StarrySky C1" - echo " ecos init_project hello Initialize a new project named 'hello'" - echo " ecos init_project list List all available project templates" - echo " ecos flash Flash the compiled firmware to the device" - echo " ecos monitor Open the default serial port at 115200 baud" + echo " ecos set_board c1 Set the board to StarrySky C1" + echo " ecos init_project hello Initialize a new project named 'hello'" + echo " ecos init_project list List all available project templates" + echo " ecos init_project hello -isolated Initialize a new isolated project named 'hello'" + echo " ecos flash Flash the compiled firmware to the device" + echo " ecos monitor Open the default serial port at 115200 baud" echo "" } diff --git a/bin/ecos-completion.zsh b/bin/ecos-completion.zsh old mode 100644 new mode 100755 diff --git a/bin/ecos-init_project b/bin/ecos-init_project index e977025..529acd0 100755 --- a/bin/ecos-init_project +++ b/bin/ecos-init_project @@ -8,9 +8,10 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SDK_ROOT="$(dirname "$SCRIPT_DIR")" # Color output -log() { echo -e "\033[1;32m[ECOS]\033[0m $*"; } -warn() { echo -e "\033[1;33m[WARN]\033[0m $*"; } -err() { echo -e "\033[1;31m[ERROR]\033[0m $*"; } +log() { echo -e "\033[1;32m[ECOS]\033[0m $*"; } +warn() { echo -e "\033[1;33m[WARN]\033[0m $*"; } +err() { echo -e "\033[1;31m[ERROR]\033[0m $*"; } +tips() { echo -e "\033[1;94m[ECOS]\033[0m $*"; } echo_available_templates() { log "Available project templates:" @@ -98,6 +99,55 @@ init_project() { log "Project '$new_project_name' created successfully in './$new_project_name'" } +init_project_isolated() { + local isolated_project_name="${1:-HelloWorld}" + local target_board="${2:-c2}" + local LibraryDir="$isolated_project_name/Library" + local StartupDir="$isolated_project_name/Startup" + local UserDir="$isolated_project_name/User" + local HardwareDir="$isolated_project_name/Hardware" + local SystemDir="$isolated_project_name/System" + + # Check if project directory exists + if [[ -d "$isolated_project_name" ]]; then + err "Project directory already exists: $isolated_project_name" + exit 1 + fi + + # Copy project source must needed from sdk + log "Initializing project '$isolated_project_name' isolated..." + mkdir -p "$LibraryDir" + mkdir -p "$StartupDir" + mkdir -p "$UserDir" + mkdir -p "$HardwareDir" + mkdir -p "$SystemDir" + + find "$SDK_ROOT/components/libc" -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' -exec cp {} "$LibraryDir" \; + find "$SDK_ROOT/components/libgcc" -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' -exec cp {} "$LibraryDir" \; + find "$SDK_ROOT/hal" -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' -exec cp {} "$LibraryDir" \; + + # due to diversity of the device drivers, copy its whole structure + find "$SDK_ROOT/devices" -maxdepth 1 -mindepth 1 -type d -exec cp -r {} "$HardwareDir" \; + cp "$SDK_ROOT/docs/isolated_project.md" "$isolated_project_name" + + + cd "$isolated_project_name" + # Initialize project config file + local board_to_set="${target_board:-c2}" + echo "BOARD=${board_to_set}" > ".ecos-project" + log "Initialized project: $isolated_project_name" + log "Config file: .ecos-project" + + # Set default board + ecos set_board_isolated "${board_to_set}" + + # Create configs directory and copy scripts + mkdir -p configs + cp -r "$SDK_ROOT/tools/scripts/" "." + log "Project '$isolated_project_name' created successfully in './$isolated_project_name'" + tips "Please set menuconfig once before your project isolation" +} + # Main entry point for the subcommand if [[ $# -eq 0 ]]; then err "Missing project name or 'list' argument" @@ -107,12 +157,16 @@ if [[ $# -eq 0 ]]; then echo "Example: ecos init_project hello" echo " ecos init_project hello -name my_new_hello" echo " ecos init_project hello -name my_new_hello -target l3" + echo " ecos init_project my_project -isolated" + echo " ecos init_project my_project -isolated -target c2" + echo " ecos init_project my_project -isolated -name my_new_project -target c2" exit 1 fi template_name="" new_project_name="" target_board="" +isIsolated=false while [[ $# -gt 0 ]]; do case "$1" in @@ -124,10 +178,14 @@ while [[ $# -gt 0 ]]; do target_board="$2" shift 2 ;; + -isolated) + isIsolated=true + shift 1 + ;; *) if [[ -z "$template_name" ]]; then template_name="$1" - shift + shift 1 else err "Unknown argument: $1" exit 1 @@ -141,4 +199,8 @@ if [[ -z "$template_name" ]]; then exit 1 fi -init_project "$template_name" "${new_project_name:-$template_name}" "${target_board:-c1}" +if [[ "${isIsolated:-false}" == false ]]; then + init_project "$template_name" "${new_project_name:-$template_name}" "${target_board:-c2}" +else + init_project_isolated "${new_project_name:-$template_name}" "${target_board:-c2}" +fi diff --git a/bin/ecos-set_board_isolated b/bin/ecos-set_board_isolated new file mode 100755 index 0000000..9077645 --- /dev/null +++ b/bin/ecos-set_board_isolated @@ -0,0 +1,163 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ECOS `set_board` subcommand +# Sets the board configuration for the project + +# WARN: only C2 was checked!!! +# TODO: support C1 / L3 + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SDK_ROOT="$(dirname "$SCRIPT_DIR")" + +# Color output +log() { echo -e "\033[1;32m[ECOS]\033[0m $*"; } +warn() { echo -e "\033[1;33m[WARN]\033[0m $*"; } +err() { echo -e "\033[1;31m[ERROR]\033[0m $*"; } + +board_name="" +project_type="" + +# Check if inside a project directory +check_project_dir() { + if [[ ! -f "Makefile" ]] && [[ ! -f ".ecos-project" ]]; then + err "Not an ECOS project directory." + err "Run this command in a directory containing a Makefile or .ecos-project file." + exit 1 + fi +} + +get_config() { + source .ecos-project + + board_name="${BOARD}" + project_type="${TYPE:-}" + + echo "Project type: $project_type" + echo "Board name: $board_name" +} + +rewrite_config() { + echo "BOARD=$target_board_name" > ".ecos-project" + echo "TYPE=$project_type" >> ".ecos-project" +} +# Set board configuration +set_board() { + local target_board_name="$1" + + check_project_dir + rewrite_config + get_config + + if [[ "$project_type" == "asm" ]]; then + rm -f Makefile + log "Removed Makefile for assembly project." + log "Board configuration set to: $target_board_name" + cp "$SDK_ROOT/board/${target_board_name}/Makefile_asm" "./Makefile" + exit 0 + fi + + case "$target_board_name" in + "c1") + warn "TODO" + exit 1 + ;; + "c2") + local board_file="board.h" + local make_file="Makefile_isolated" + local lds_file="sections.lds" + local start_file="start.S" + + local board_source_path="$SDK_ROOT/board/StarrySkyC2/$board_file" + local make_source_path="$SDK_ROOT/board/StarrySkyC2/$make_file" + local lds_source_path="$SDK_ROOT/board/StarrySkyC2/$lds_file" + local start_source_path="$SDK_ROOT/board/StarrySkyC2/$start_file" + local driver_source_path="$SDK_ROOT/board/StarrySkyC2/driver" + local main_source_path="$SDK_ROOT/templates/hello/c2" + + local board_target_path="./Library/board.h" + local make_target_path="./Makefile" + local lds_target_path="./Startup/sections.lds" + local start_target_path="./Startup/start.S" + local driver_target_path="./Library" + local main_target_path="./User" + + if [[ ! -f "$board_source_path" ]]; then + err "Board config file not found: $board_source_path" + exit 1 + fi + + # Copy Board config file + cp "$board_source_path" "$board_target_path" + log "Set board configuration to: starrysky_c2" + log "Config file: $board_target_path" + + # Copy Makefile + cp "$make_source_path" "$make_target_path" + log "Set Makefile: $make_target_path" + + # Copy Linker Script + if [[ -f "$lds_source_path" ]]; then + cp "$lds_source_path" "$lds_target_path" + log "Set Linker Script: $lds_target_path" + else + warn "Linker script not found for C2: $lds_source_path" + fi + + # Copy Startup code + if [[ -f "$start_source_path" ]]; then + cp "$start_source_path" "$start_target_path" + log "Set startup code: $start_target_path" + else + warn "Startup code not found for C2: $start_source_path" + fi + + # Copy Drivers + if [[ -d "$driver_source_path" ]]; then + find "$driver_source_path" -type f -regex '.*\.\(c\|h\|cpp\|hpp\)$' -exec cp {} "$driver_target_path" \; + log "Set drivers: $driver_target_path" + else + warn "Drivers not found for C2: $driver_source_path" + fi + + # Copy Main files + if [[ -d "$main_source_path" ]]; then + find "$main_source_path" -type f -name "main.*" -exec cp {} "$main_target_path" \; + log "Set drivers: $main_target_path" + else + warn "Drivers not found for C2: $main_source_path" + fi + + # Update project config file if it exists + if [[ -f ".ecos-project" ]]; then + if grep -q "BOARD=" ".ecos-project"; then + sed -i "s/BOARD=.*/BOARD=$target_board_name/" ".ecos-project" + else + echo "BOARD=$target_board_name" >> ".ecos-project" + fi + log "Updated project configuration file." + fi + ;; + "l3") + warn "TODO" + exit 1 + ;; + *) + err "Unsupported board: $board_name" + echo "" + echo "Supported boards:" + # echo " c1 StarrySky C1 board" + echo " c2 StarrySky C2 board" + # echo " l3 StarrySky L3 board" + exit 1 + ;; + esac +} + +# Main entry point for the subcommand +if [[ $# -eq 0 ]]; then + err "Missing board name argument for isolated project." + exit 1 +fi + +set_board "$1" \ No newline at end of file diff --git a/board/StarrySkyC2/Makefile_isolated b/board/StarrySkyC2/Makefile_isolated new file mode 100644 index 0000000..eb49582 --- /dev/null +++ b/board/StarrySkyC2/Makefile_isolated @@ -0,0 +1,107 @@ +# retroSoC 固件构建脚本 +# 用于编译基于RISC-V架构的嵌入式固件 + +# RISC-V 交叉编译工具链前缀 +CROSS=riscv64-unknown-elf- +BUILD_DIR := build +PROJECT_PATH := $(shell pwd) +CATEGORY := StarrySkyC2 + +# 包含配置文件 +-include configs/.config + +# 编译器标志配置 +# -mabi=ilp32: 使用ILP32 ABI +# -march=rv32im: RV32I基础指令集 + M乘除法扩展 +# -ffreestanding: 独立环境编译 +# -nostdlib: 不链接标准库 +CFLAGS := -mabi=ilp32 \ + -march=rv32im \ + -Wl,-Bstatic,-T,$(BUILD_DIR)/retrosoc_sections.lds,--strip-debug \ + -Wl,-Map=$(BUILD_DIR)/$(FIRMWARE_NAME).map,--cref \ + -ffreestanding \ + -nostdlib + +# 根据配置文件设置链接选项 +ifdef CONFIG_LINK_RAM_REGION_SRAM +LDFLAGS += -DCONFIG_LINK_RAM_REGION_SRAM +CFLAGS += -DCONFIG_LINK_RAM_REGION_SRAM +endif + +ifdef CONFIG_LINK_RAM_REGION_PSRAM +LDFLAGS += -DCONFIG_LINK_RAM_REGION_PSRAM +CFLAGS += -DCONFIG_LINK_RAM_REGION_PSRAM +endif + +# 根据配置文件添加编译优化选项 +ifdef CONFIG_BUILD_OPT_FLAGS +CFLAGS += $(subst ",,$(CONFIG_BUILD_OPT_FLAGS)) +endif + +# 根据配置文件添加调试选项 +ifdef CONFIG_BUILD_DEBUG +CFLAGS += -g -DDEBUG +endif + +# 根据配置文件添加详细输出选项 +ifdef CONFIG_BUILD_VERBOSE +VERBOSE := 1 +endif + +# 固件名称 - 从配置文件读取,如果未定义则使用默认值 +ifdef CONFIG_FIRMWARE_NAME +FIRMWARE_NAME := $(subst ",,$(CONFIG_FIRMWARE_NAME)) +else +FIRMWARE_NAME := main +endif + +# find包含目录 +INCLUDE_DIRS := Library Startup User System # Hardware需要等devices调整好api后再加入编译目录 + +# 源文件列表 +SRC_PATH := $(shell find $(INCLUDE_DIRS) -type f -name "*.s") +SRC_PATH += $(shell find $(INCLUDE_DIRS) -type f -name "*.c") + +CFLAGS += -I./configs +CFLAGS += $(addprefix -I,$(shell find $(INCLUDE_DIRS) -type d)) + +# 链接脚本路径 +LDS_PATH := $(shell find $(INCLUDE_DIRS) -type f -name "sections.lds") + +# 包含内存报告工具 +-include ./scripts/mem_report.mk + +# 主要构建目标:生成固件的所有格式文件 +$(FIRMWARE_NAME): + @echo "Building $(FIRMWARE_NAME)..." + @mkdir -p $(BUILD_DIR) + @$(CROSS)cpp -P -o $(BUILD_DIR)/retrosoc_sections.lds $(LDS_PATH) + @$(CROSS)gcc $(CFLAGS) -I./ -o $(BUILD_DIR)/$@ $(SRC_PATH) + @echo "Linking $(FIRMWARE_NAME)..." + @$(CROSS)objcopy -O verilog $(BUILD_DIR)/$@ $(BUILD_DIR)/$(FIRMWARE_NAME).hex + @echo "Post-processing $(FIRMWARE_NAME).hex..." + @sed -i 's/@30000000/@00000000/g' $(BUILD_DIR)/$(FIRMWARE_NAME).hex + @echo "Generating $(FIRMWARE_NAME).bin..." + @$(CROSS)objcopy -O binary $(BUILD_DIR)/$@ $(BUILD_DIR)/$(FIRMWARE_NAME).bin + @echo "Generating $(FIRMWARE_NAME).txt..." + @$(CROSS)objdump -d $(BUILD_DIR)/$@ > $(BUILD_DIR)/$(FIRMWARE_NAME).txt + $(call show_mem_usage, $(BUILD_DIR)/$@) + @echo "Done." + +# 清理构建产物 +clean: + rm -rf $(BUILD_DIR) + +clean_config: + rm -rf configs/generated configs/config configs/.config configs/.config.old + +clean_all: + rm -rf $(BUILD_DIR) + rm -rf configs/generated configs/config configs/.config configs/.config.old + rm -rf $(PROJECT_PATH)/tools/fixdep/build + rm -rf $(PROJECT_PATH)/tools/kconfig/build + + +-include scripts/config.mk +# 声明伪目标 +.PHONY: $(FIRMWARE_NAME).elf clean diff --git a/docs/isolated_project.md b/docs/isolated_project.md new file mode 100644 index 0000000..e69de29 From a74c2dd387bbc94198305b2cf2065b2a731fbcde Mon Sep 17 00:00:00 2001 From: FINALxxx <3085378853@qq.com> Date: Tue, 21 Apr 2026 12:17:04 +0800 Subject: [PATCH 05/12] fix(StarrySkyL3_1): fix kconfig debug info display --- board/StarrySkyL3_1/build_conf.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/board/StarrySkyL3_1/build_conf.mk b/board/StarrySkyL3_1/build_conf.mk index 8f9a60e..69f39de 100644 --- a/board/StarrySkyL3_1/build_conf.mk +++ b/board/StarrySkyL3_1/build_conf.mk @@ -43,7 +43,7 @@ DRIVER_SUBDIRS := $(notdir $(shell find $(DRIVER_DIR) -mindepth 1 -maxdepth 1 -t $(foreach subdir,$(DRIVER_SUBDIRS), \ $(eval CONFIG_NAME := $(shell echo $(subdir) | tr '[:lower:]' '[:upper:]')) \ - $(info Include drivers: $(CONFIG_NAME)) \ + $(if $(VERBOSE),$(info Include drivers: $(CONFIG_NAME))) \ $(eval $(call driver_template,$(CONFIG_NAME),$(subdir))) \ ) From 4702fa64c115730ec2a88cdc2f7a589d2fa6e54a Mon Sep 17 00:00:00 2001 From: FINALxxx <3085378853@qq.com> Date: Tue, 21 Apr 2026 14:35:19 +0800 Subject: [PATCH 06/12] fix(C2/L3_1): fix kconfig --- board/StarrySkyC2/board.kconfig | 58 ++++++++++------------------ board/StarrySkyL3_1/board.kconfig | 64 +++++++++++++++---------------- docs/menuconfig.md | 7 +++- 3 files changed, 56 insertions(+), 73 deletions(-) diff --git a/board/StarrySkyC2/board.kconfig b/board/StarrySkyC2/board.kconfig index 2f12b33..f685cb7 100644 --- a/board/StarrySkyC2/board.kconfig +++ b/board/StarrySkyC2/board.kconfig @@ -1,12 +1,12 @@ -menu "Target Hardware Configuration" +menu "System Read-Only Information" choice bool "Target SoC Platform" default STARRYSKY_C2 - config STARRYSKY_C2 - bool "StarrySky_C2 Platform" - help - StarrySky_C2 RISC-V based embedded platform + config STARRYSKY_C2 + bool "StarrySky_C2 Platform" + help + StarrySky_C2 RISC-V based embedded platform endchoice choice @@ -19,39 +19,6 @@ menu "Target Hardware Configuration" Code executes from PSRAM. endchoice - # config BOARD_NAME - # string - # default "starrysky_c2" - - # config ARCH_RISCV32 - # bool - # default y -endmenu - -menu "System Configuration" - config CPU_FREQ_MHZ - int "CPU Frequency (MHz)" - default 72 - range 1 200 - config UART_BAUD_RATE - int "UART Baud Rate" - default 115200 - range 1 1000000 - config PSRAM_NUM - int "Number of PSRAM Chips" - default 1 - range 1 4 - # config PSRAM_SCLK_MIN_FREQ_MHZ - # int "PSRAM SCLK Minimum Frequency (MHz)" - # default 12 - # range 1 200 - # config PSRAM_SCLK_MAX_FREQ_MHZ - # int "PSRAM SCLK Maximum Frequency (MHz)" - # default 133 - # range 1 200 -endmenu - -menu "Memory Configuration" config BOARD_RAM_TYPE_NAME string "RAM Type Name" default "PSRAM" @@ -70,3 +37,18 @@ menu "Memory Configuration" help Total available FLASH size in Kilobytes endmenu + +menu "System Configuration" + config CPU_FREQ_MHZ + int "CPU Frequency (MHz)" + default 72 + range 1 200 + config UART_BAUD_RATE + int "UART Baud Rate" + default 115200 + range 1 1000000 + config PSRAM_NUM + int "Number of PSRAM Chips" + default 1 + range 1 4 +endmenu diff --git a/board/StarrySkyL3_1/board.kconfig b/board/StarrySkyL3_1/board.kconfig index 0e9e6ad..cb0fcb5 100644 --- a/board/StarrySkyL3_1/board.kconfig +++ b/board/StarrySkyL3_1/board.kconfig @@ -1,4 +1,4 @@ -menu "Target Hardware Configuration" +menu "System Read-Only Information" choice bool "Target SoC Platform" default STARRYSKY_L3_1 @@ -9,23 +9,23 @@ menu "Target Hardware Configuration" StarrySky_L3_1 RISC-V based embedded platform endchoice - choice - bool "Memory Region Selection" - default LINK_TARGET_XIP + config BOARD_RAM_TYPE_NAME + string "MEM Type Name" + default "MEM" + help + The type of memory used on the board as MEM (e.g. SRAM, PSRAM, SDRAM, MEM) - config LINK_TARGET_XIP - bool "XIP Mode (ROM for Code, MEM for Data)" - help - Execute In Place. Code and read-only data are stored and executed - directly from ROM (Flash). Writable data (.data, .bss) and Stack - are placed in MEM (RAM). + config BOARD_RAM_SIZE_KB + int "MEM Size (in KB)" + default 131072 + help + Total available MEM (RAM) size in Kilobytes - config LINK_TARGET_MEM - bool "MEM Mode (All in MEM)" - help - Code and data are entirely loaded into MEM (RAM) by the Bootloader - before execution. Provides maximum performance. - endchoice + config BOARD_FLASH_SIZE_KB + int "ROM Size (in KB)" + default 16384 + help + Total available ROM (FLASH) size in Kilobytes endmenu menu "System Configuration" @@ -43,24 +43,22 @@ menu "System Configuration" int "UART Baud Rate" default 115200 range 1 1000000 -endmenu -menu "Memory Configuration" - config BOARD_RAM_TYPE_NAME - string "MEM Type Name" - default "MEM" - help - The type of memory used on the board as MEM (e.g. SRAM, PSRAM, SDRAM, MEM) + choice + bool "Memory Region Selection" + default LINK_TARGET_XIP - config BOARD_RAM_SIZE_KB - int "MEM Size (in KB)" - default 131072 - help - Total available MEM (RAM) size in Kilobytes + config LINK_TARGET_XIP + bool "XIP Mode (ROM for Code, MEM for Data)" + help + Execute In Place. Code and read-only data are stored and executed + directly from ROM (Flash). Writable data (.data, .bss) and Stack + are placed in MEM (RAM). - config BOARD_FLASH_SIZE_KB - int "ROM Size (in KB)" - default 16384 - help - Total available ROM (FLASH) size in Kilobytes + config LINK_TARGET_MEM + bool "MEM Mode (All in MEM)" + help + Code and data are entirely loaded into MEM (RAM) by the Bootloader + before execution. Provides maximum performance. + endchoice endmenu diff --git a/docs/menuconfig.md b/docs/menuconfig.md index 57f1ee4..90417ce 100644 --- a/docs/menuconfig.md +++ b/docs/menuconfig.md @@ -1,14 +1,17 @@ # SDK配置 ## Menuconfig分类 -### Target Hardware Configuration +### System Read-Only Information 存放与板卡型号有关的只读信息 ### System Configuration 存放与板卡型号有关的可配置信息 ### Peripheral Drivers -存放与外设相关的可配置信息 +存放与Driver相关的可配置信息 + +### External Devices +存放与Device相关的可配置信息 ### Build Configuration 存放与编译链接相关的可配置信息 From 74fd6629b23e9ff51b4b14f9a45a5dfa69749254 Mon Sep 17 00:00:00 2001 From: FINALxxx <3085378853@qq.com> Date: Tue, 21 Apr 2026 15:14:36 +0800 Subject: [PATCH 07/12] fix(C2): fix isolated project --- board/StarrySkyC2/Makefile_isolated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/board/StarrySkyC2/Makefile_isolated b/board/StarrySkyC2/Makefile_isolated index eb49582..4c9925f 100644 --- a/board/StarrySkyC2/Makefile_isolated +++ b/board/StarrySkyC2/Makefile_isolated @@ -59,7 +59,7 @@ endif INCLUDE_DIRS := Library Startup User System # Hardware需要等devices调整好api后再加入编译目录 # 源文件列表 -SRC_PATH := $(shell find $(INCLUDE_DIRS) -type f -name "*.s") +SRC_PATH := $(shell find $(INCLUDE_DIRS) -type f -name "*.S") SRC_PATH += $(shell find $(INCLUDE_DIRS) -type f -name "*.c") CFLAGS += -I./configs From daa8956c6692e44083d17d6b177c20a496064b5c Mon Sep 17 00:00:00 2001 From: FINALxxx <3085378853@qq.com> Date: Tue, 21 Apr 2026 15:38:01 +0800 Subject: [PATCH 08/12] fix(C2): add weak delay_ms in timer --- board/StarrySkyC2/driver/timer/timer.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/board/StarrySkyC2/driver/timer/timer.c b/board/StarrySkyC2/driver/timer/timer.c index adec0cb..8db3c86 100644 --- a/board/StarrySkyC2/driver/timer/timer.c +++ b/board/StarrySkyC2/driver/timer/timer.c @@ -2,6 +2,12 @@ #include "generated/autoconf.h" #include "board.h" +// 提供一个弱定义的延时函数,供 devices 外设驱动默认调用。 +// 用户可以在自己的应用代码(如 main.c)中重写这个函数,提供更精准的实现。 +__attribute__((weak)) void delay_ms(uint32_t val) { + hal_delay_ms(0, val); +} + uint8_t hal_delay_us(uint8_t timer_id, uint32_t val){ if (timer_id == 0){ REG_TIM_0_CONFIG = (uint32_t)0x0100; From 1c1d2734b53692a726018a2dedc011ca377f6c8b Mon Sep 17 00:00:00 2001 From: FINALxxx <3085378853@qq.com> Date: Wed, 22 Apr 2026 11:21:30 +0800 Subject: [PATCH 09/12] feat(C2/libc): fix build_conf.mk and add assert.h --- board/StarrySkyC2/Makefile_isolated | 2 +- board/StarrySkyC2/build_conf.mk | 9 --------- board/StarrySkyC2/driver/gpio/gpio.c | 4 ++++ board/StarrySkyC2/driver/i2c/i2c.c | 5 ----- components/libc/include/assert.h | 20 ++++++++++++++++++++ hal/sys_uart/hal_sys_uart.h | 5 +++-- 6 files changed, 28 insertions(+), 17 deletions(-) create mode 100644 components/libc/include/assert.h diff --git a/board/StarrySkyC2/Makefile_isolated b/board/StarrySkyC2/Makefile_isolated index 4c9925f..8e38b05 100644 --- a/board/StarrySkyC2/Makefile_isolated +++ b/board/StarrySkyC2/Makefile_isolated @@ -56,7 +56,7 @@ FIRMWARE_NAME := main endif # find包含目录 -INCLUDE_DIRS := Library Startup User System # Hardware需要等devices调整好api后再加入编译目录 +INCLUDE_DIRS := Library Startup User System Hardware # Hardware需要等devices调整好api后再加入编译目录 # 源文件列表 SRC_PATH := $(shell find $(INCLUDE_DIRS) -type f -name "*.S") diff --git a/board/StarrySkyC2/build_conf.mk b/board/StarrySkyC2/build_conf.mk index 3974d9b..e8b312c 100644 --- a/board/StarrySkyC2/build_conf.mk +++ b/board/StarrySkyC2/build_conf.mk @@ -35,7 +35,6 @@ endif define driver_template ifdef CONFIG_DRIVER_$(1) SRC_PATH += $(shell find $(ECOS_SDK_HOME)/board/StarrySkyC2/driver/$(2) -name "*.c") - SRC_PATH += $(shell find $(ECOS_SDK_HOME)/hal/$(2) -name "*.c") # 新增 CFLAGS += $(addprefix -I,$(shell find $(ECOS_SDK_HOME)/hal/$(2) -type d)) endif endef @@ -57,12 +56,4 @@ endif ifdef CONFIG_LINK_LIBGCC SRC_PATH += $(shell find $(ECOS_SDK_HOME)/components/libgcc/src -name "*.[cS]") CFLAGS += -I$(ECOS_SDK_HOME)/components/libgcc/include -endif - -# 新加的修改 - -ifdef CONFIG_DRIVER_HP_UART - # 确保 HP_UART 的头文件路径被添加 - CFLAGS += -I$(ECOS_SDK_HOME)/hal/hp_uart - $(info Manually added HP_UART HAL include: -I$(ECOS_SDK_HOME)/hal/hp_uart) endif \ No newline at end of file diff --git a/board/StarrySkyC2/driver/gpio/gpio.c b/board/StarrySkyC2/driver/gpio/gpio.c index 59b51a0..63d721a 100644 --- a/board/StarrySkyC2/driver/gpio/gpio.c +++ b/board/StarrySkyC2/driver/gpio/gpio.c @@ -3,6 +3,8 @@ #include "board.h" #include #include "generated/autoconf.h" +#include "hal_sys_uart.h" +#include "assert.h" void gpio_hal_input_enable(uint8_t gpio_id, uint8_t gpio_num){ @@ -36,8 +38,10 @@ uint8_t gpio_hal_get_level(uint8_t gpio_id, uint8_t gpio_num){ void gpio_hal_set_fcfg(uint8_t gpio_id, uint8_t gpio_num, uint8_t val){ // StarrySkyC2 does not implement FCFG + assert(0,"[Warn] StarrySkyC2 does not implement FCFG\n"); } void gpio_hal_set_mux(uint8_t gpio_id, uint8_t gpio_num, uint8_t val){ // StarrySkyC2 does not implement PINMUX + assert(0,"[Warn] StarrySkyC2 does not implement FCFG\n"); } \ No newline at end of file diff --git a/board/StarrySkyC2/driver/i2c/i2c.c b/board/StarrySkyC2/driver/i2c/i2c.c index 1e9d750..7a1e31b 100644 --- a/board/StarrySkyC2/driver/i2c/i2c.c +++ b/board/StarrySkyC2/driver/i2c/i2c.c @@ -65,11 +65,6 @@ int hal_i2c_init(hal_i2c_port_t port, const hal_i2c_config_t *config){ if (port >= HAL_I2C_PORT_MAX || !config) return -1; -#ifdef CONFIG_STARRYSKY_C2 - hal_gpio_set_function(GPIO_NUM_29, GPIO_FUNCTION_1); - hal_gpio_set_function(GPIO_NUM_30, GPIO_FUNCTION_1); -#endif - REG_I2C_0_CTRL = 0; REG_I2C_0_PSCR = config->pscr; REG_I2C_0_CTRL = 0x80; diff --git a/components/libc/include/assert.h b/components/libc/include/assert.h new file mode 100644 index 0000000..5766e07 --- /dev/null +++ b/components/libc/include/assert.h @@ -0,0 +1,20 @@ +#ifndef __ASSERT_H__ +#define __ASSERT_H__ + +#include +#include "stdio.h" + +#ifndef CONFIG_BUILD_DEBUG + #define assert(expr, info) ((void)0) +#else + #define assert(expr, info) \ + ({ \ + typeof(expr) result = (expr); \ + if (!(expr)) { \ + printf("(%s:%d) %s", __FILE__, __LINE__,(info)); \ + } \ + result; \ + }) +#endif + +#endif diff --git a/hal/sys_uart/hal_sys_uart.h b/hal/sys_uart/hal_sys_uart.h index 5365b40..8d68042 100644 --- a/hal/sys_uart/hal_sys_uart.h +++ b/hal/sys_uart/hal_sys_uart.h @@ -2,7 +2,7 @@ #define __HAL_SYS_UART_H__ #include - +#include "stdio.h" /** * @brief 初始化系统串口 * @@ -23,4 +23,5 @@ void hal_sys_putchar(char c); */ void hal_sys_putstr(char *str); -#endif \ No newline at end of file +#endif + From 55fd47accea2dd6ad99b004e2a8a2a1d81ca66f2 Mon Sep 17 00:00:00 2001 From: FINALxxx <3085378853@qq.com> Date: Wed, 22 Apr 2026 15:16:37 +0800 Subject: [PATCH 10/12] fix: fix kconfig --- board/StarrySkyC2/build_conf.mk | 22 +++++++++++++++++++- board/StarrySkyC2/driver.kconfig | 34 +++++++++++++++++++++++-------- board/StarrySkyL3_1/build_conf.mk | 2 +- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/board/StarrySkyC2/build_conf.mk b/board/StarrySkyC2/build_conf.mk index e8b312c..e05a30c 100644 --- a/board/StarrySkyC2/build_conf.mk +++ b/board/StarrySkyC2/build_conf.mk @@ -22,6 +22,7 @@ endif # 根据配置文件添加详细输出选项 ifdef CONFIG_BUILD_VERBOSE VERBOSE := 1 +LDFLAGS += --verbose endif # 固件名称 - 从配置文件读取,如果未定义则使用默认值 @@ -43,7 +44,7 @@ DRIVER_SUBDIRS := $(notdir $(shell find $(DRIVER_DIR) -mindepth 1 -maxdepth 1 -t $(foreach subdir,$(DRIVER_SUBDIRS), \ $(eval CONFIG_NAME := $(shell echo $(subdir) | tr '[:lower:]' '[:upper:]')) \ - $(if $(VERBOSE),$(info Include drivers: $(CONFIG_NAME))) \ + $(if $(VERBOSE),$(info Auto-load drivers: $(CONFIG_NAME))) \ $(eval $(call driver_template,$(CONFIG_NAME),$(subdir))) \ ) @@ -56,4 +57,23 @@ endif ifdef CONFIG_LINK_LIBGCC SRC_PATH += $(shell find $(ECOS_SDK_HOME)/components/libgcc/src -name "*.[cS]") CFLAGS += -I$(ECOS_SDK_HOME)/components/libgcc/include +endif + +# 自动包含所有的 devices 组件的头文件(方便代码补全) +CFLAGS += $(addprefix -I,$(shell find $(ECOS_SDK_HOME)/devices/*/include -type d 2>/dev/null)) + +ifdef CONFIG_DEVICE_ST7735 +SRC_PATH += $(shell find $(ECOS_SDK_HOME)/devices/st7735/src -name "*.c") +endif + +ifdef CONFIG_DEVICE_ST7789 +SRC_PATH += $(shell find $(ECOS_SDK_HOME)/devices/st7789/src -name "*.c") +endif + +ifdef CONFIG_DEVICE_SGP30 +SRC_PATH += $(shell find $(ECOS_SDK_HOME)/devices/gy_sgp30/src -name "*.c") +endif + +ifdef CONFIG_DEVICE_PCF8563 +SRC_PATH += $(shell find $(ECOS_SDK_HOME)/devices/pcf8563/src -name "*.c") endif \ No newline at end of file diff --git a/board/StarrySkyC2/driver.kconfig b/board/StarrySkyC2/driver.kconfig index 2d0b403..2915705 100644 --- a/board/StarrySkyC2/driver.kconfig +++ b/board/StarrySkyC2/driver.kconfig @@ -17,11 +17,11 @@ menu "Peripheral Drivers" help Enable HP_UART driver for serial communication - config DRIVER_SPI - bool "SPI Driver Support" + config DRIVER_QSPI + bool "QSPI Driver Support" default y help - Enable SPI driver for serial peripheral interface + Enable QSPI driver for serial peripheral interface config DRIVER_I2C bool "I2C Driver Support" @@ -29,11 +29,11 @@ menu "Peripheral Drivers" help Enable I2C driver for inter-integrated circuit - # config DRIVER_PWM - # bool "PWM Driver Support" - # default y - # help - # Enable PWM driver for pulse width modulation + config DRIVER_PWM + bool "PWM Driver Support" + default y + help + Enable PWM driver for pulse width modulation config DRIVER_TIMER bool "Timer Driver Support" @@ -41,3 +41,21 @@ menu "Peripheral Drivers" help Enable timer driver for timing functions endmenu + +menu "External Devices" + config DEVICE_ST7735 + bool "ST7735 LCD Support" + default y + + config DEVICE_ST7789 + bool "ST7789 LCD Support" + default y + + config DEVICE_SGP30 + bool "SGP30 Gas Sensor Support" + default y + + config DEVICE_PCF8563 + bool "PCF8563 RTC Support" + default y +endmenu diff --git a/board/StarrySkyL3_1/build_conf.mk b/board/StarrySkyL3_1/build_conf.mk index 69f39de..06a98c5 100644 --- a/board/StarrySkyL3_1/build_conf.mk +++ b/board/StarrySkyL3_1/build_conf.mk @@ -43,7 +43,7 @@ DRIVER_SUBDIRS := $(notdir $(shell find $(DRIVER_DIR) -mindepth 1 -maxdepth 1 -t $(foreach subdir,$(DRIVER_SUBDIRS), \ $(eval CONFIG_NAME := $(shell echo $(subdir) | tr '[:lower:]' '[:upper:]')) \ - $(if $(VERBOSE),$(info Include drivers: $(CONFIG_NAME))) \ + $(if $(VERBOSE),$(info Auto-load drivers: $(CONFIG_NAME))) \ $(eval $(call driver_template,$(CONFIG_NAME),$(subdir))) \ ) From 8dcfd6adc12f8a2c43bf47425719dbeaeb0cba92 Mon Sep 17 00:00:00 2001 From: FINALxxx <3085378853@qq.com> Date: Wed, 22 Apr 2026 16:42:11 +0800 Subject: [PATCH 11/12] fix(C2): fix gpio with read-edit-write method --- board/StarrySkyC2/driver/gpio/gpio.c | 21 ++++++++++++++------- hal/gpio/hal_gpio.h | 6 ++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/board/StarrySkyC2/driver/gpio/gpio.c b/board/StarrySkyC2/driver/gpio/gpio.c index 63d721a..2d47fc9 100644 --- a/board/StarrySkyC2/driver/gpio/gpio.c +++ b/board/StarrySkyC2/driver/gpio/gpio.c @@ -7,33 +7,40 @@ #include "assert.h" +static uint32_t ddr,dr; // 不可重入的变量 void gpio_hal_input_enable(uint8_t gpio_id, uint8_t gpio_num){ - REG_GPIO_0_DDR |= (0x01 << gpio_num); + ddr |= (1 << gpio_num); } void gpio_hal_output_enable(uint8_t gpio_id, uint8_t gpio_num){ - REG_GPIO_0_DDR &= ~(0x01 << gpio_num); + ddr &= ~(1 << gpio_num); } void gpio_hal_set_level(uint8_t gpio_id, uint8_t gpio_num, uint8_t level){ - if (level == GPIO_LEVEL_HIGH) { - REG_GPIO_0_DR |= (1 << gpio_num); + dr |= (1 << gpio_num); } else { - REG_GPIO_0_DR &= ~(1 << gpio_num); + dr &= ~(1 << gpio_num); } } - uint8_t gpio_hal_get_level(uint8_t gpio_id, uint8_t gpio_num){ - return (REG_GPIO_0_DR & (1 << gpio_num)) ? 1 :0; + return (dr & (1 << gpio_num)) ? 1 :0; +} + +void gpio_hal_update(){ + REG_GPIO_0_DDR = ddr; + REG_GPIO_0_DR = dr; + hal_delay_ms(0,5); + ddr = REG_GPIO_0_DDR; + dr = REG_GPIO_0_DR; } void gpio_hal_set_fcfg(uint8_t gpio_id, uint8_t gpio_num, uint8_t val){ diff --git a/hal/gpio/hal_gpio.h b/hal/gpio/hal_gpio.h index 2a744ae..48574cc 100644 --- a/hal/gpio/hal_gpio.h +++ b/hal/gpio/hal_gpio.h @@ -36,6 +36,12 @@ void gpio_hal_set_level(uint8_t gpio_id, uint8_t gpio_num, uint8_t level); */ uint8_t gpio_hal_get_level(uint8_t gpio_id, uint8_t gpio_num); +/** + * @brief 更新GPIO端口,需要在设置电平后调用、获取电平前调用 + * + */ +void gpio_hal_update(); + /** * @brief 设置指定GPIO的FCFG (Function Configuration) * From 732aac26cd1bd61ca3f323e0f5d2756143376b0e Mon Sep 17 00:00:00 2001 From: FINALxxx <3085378853@qq.com> Date: Thu, 23 Apr 2026 16:28:21 +0800 Subject: [PATCH 12/12] fix(C2): fix gpio left-shift 16bit when reading in software --- board/StarrySkyC2/driver/gpio/gpio.c | 15 ++++++++++----- hal/gpio/hal_gpio.h | 10 ++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/board/StarrySkyC2/driver/gpio/gpio.c b/board/StarrySkyC2/driver/gpio/gpio.c index 2d47fc9..cde2d74 100644 --- a/board/StarrySkyC2/driver/gpio/gpio.c +++ b/board/StarrySkyC2/driver/gpio/gpio.c @@ -7,7 +7,7 @@ #include "assert.h" -static uint32_t ddr,dr; // 不可重入的变量 +static volatile uint32_t ddr,dr,rdr; // 不可重入的变量 void gpio_hal_input_enable(uint8_t gpio_id, uint8_t gpio_num){ ddr |= (1 << gpio_num); @@ -32,15 +32,20 @@ void gpio_hal_set_level(uint8_t gpio_id, uint8_t gpio_num, uint8_t level){ } uint8_t gpio_hal_get_level(uint8_t gpio_id, uint8_t gpio_num){ - return (dr & (1 << gpio_num)) ? 1 :0; + return (dr & (1 << gpio_num)) ? 1 : 0; } -void gpio_hal_update(){ +void gpio_hal_read_update(){ + rdr = REG_GPIO_0_DR; + dr = dr | rdr; // 读取时,之前写的部分会左移到高16bit,现在读的部分在低16bit + gpio_hal_write_update(); + hal_delay_ms(0,5); +} + +void gpio_hal_write_update(){ REG_GPIO_0_DDR = ddr; REG_GPIO_0_DR = dr; hal_delay_ms(0,5); - ddr = REG_GPIO_0_DDR; - dr = REG_GPIO_0_DR; } void gpio_hal_set_fcfg(uint8_t gpio_id, uint8_t gpio_num, uint8_t val){ diff --git a/hal/gpio/hal_gpio.h b/hal/gpio/hal_gpio.h index 48574cc..b8f375f 100644 --- a/hal/gpio/hal_gpio.h +++ b/hal/gpio/hal_gpio.h @@ -37,10 +37,16 @@ void gpio_hal_set_level(uint8_t gpio_id, uint8_t gpio_num, uint8_t level); uint8_t gpio_hal_get_level(uint8_t gpio_id, uint8_t gpio_num); /** - * @brief 更新GPIO端口,需要在设置电平后调用、获取电平前调用 + * @brief GPIO端口写操作更新,需要在设置电平后调用 * */ -void gpio_hal_update(); +void gpio_hal_read_update(); + +/** + * @brief GPIO端口读操作更新,需要在获取电平前调用 + * + */ +void gpio_hal_write_update(); /** * @brief 设置指定GPIO的FCFG (Function Configuration)