Skip to content

Commit

Permalink
[fix] 1.修复了stm32f103c8t6最小系统板的编译和运行问题
Browse files Browse the repository at this point in the history
Signed-off-by: jiayuanwen <[email protected]>
  • Loading branch information
mio22440 committed Oct 11, 2023
1 parent 0a73461 commit 496688e
Show file tree
Hide file tree
Showing 33 changed files with 297 additions and 191 deletions.
54 changes: 54 additions & 0 deletions Build/arch_config/riscv_rv32.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
include $(BUILD_DIR)/compiler_configs/riscv_embed_gcc/riscv_none_embed_gcc.config

# c语言文件编译参数
CFLAGS += -march=rv32imac
CFLAGS += -mabi=ilp32
CFLAGS += -msmall-data-limit=8
CFLAGS += -msave-restore
CFLAGS += -Os
CFLAGS += -fmessage-length=0
CFLAGS += -fsigned-char
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
CFLAGS += -fno-common
CFLAGS += -Wunused
CFLAGS += -Wuninitialized
CFLAGS += -std=gnu99
# CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"

#汇编文件编译参数
ASMFLAGS += -march=rv32imac
ASMFLAGS += -mabi=ilp32
ASMFLAGS += -msmall-data-limit=8
ASMFLAGS += -msave-restore
ASMFLAGS += -Os
ASMFLAGS += -fmessage-length=0
ASMFLAGS += -fsigned-char
ASMFLAGS += -ffunction-sections
ASMFLAGS += -fdata-sections
ASMFLAGS += -fno-common
ASMFLAGS += -Wunused
ASMFLAGS += -Wuninitialized
ASMFLAGS += -x assembler-with-cpp
# ASMFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -c -o "$@" "$<"

#链接参数
CLINK_FLAGS += -march=rv32imac
CLINK_FLAGS += -mabi=ilp32
CLINK_FLAGS += -msmall-data-limit=8
CLINK_FLAGS += -msave-restore
CLINK_FLAGS += -Os
CLINK_FLAGS += -fmessage-length=0
CLINK_FLAGS += -fsigned-char
CLINK_FLAGS += -ffunction-sections
CLINK_FLAGS += -fdata-sections
CLINK_FLAGS += -fno-common
CLINK_FLAGS += -Wunused
CLINK_FLAGS += -Wuninitialized
CLINK_FLAGS += -nostartfiles
CLINK_FLAGS += -Xlinker --gc-sections --specs=nano.specs --specs=nosys.specs

#芯片架构(会用在硬件平台相关的编译控制上,如bsp)
CATOS_BOARD_ARCH = riscv-rv32

.EXPORT_ALL_VARIABLES:
2 changes: 1 addition & 1 deletion Build/compiler_configs/arm_none_gcc/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ifdef obj-y
#编译文件
$(OBJ_OUT_DIR)/%.o: $(CUR_DIR)/%.c
ifeq ($(compile_enable_detail), n)
@echo "compile $<"
@echo "compile $(notdir $<)"
@$(CC) $(CINCLUDE_FILE_FLAG) $(CFLAGS) -o $@ -c $<
else
$(CC) $(CINCLUDE_FILE_FLAG) $(CFLAGS) -o $@ -c $<
Expand Down
24 changes: 24 additions & 0 deletions Build/compiler_configs/riscv_embed_gcc/riscv_none_embed_gcc.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#编译命令指定
#TOOLCHAIN_DIR = $(shell pwd)
CROSS_COMPILE = $(BUILD_DIR)/../../../riscv_embed_gcc/bin/riscv-none-embed-

CC = $(CROSS_COMPILE)gcc
AS = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
LD = $(CROSS_COMPILE)gcc
CP = $(CROSS_COMPILE)objcopy
SZ = $(CROSS_COMPILE)size

#添加参数使LD输出.map文件:-Wl,-Map=xx.map
LIST_MAP_FILE = -Wl,-Map

#规则目录指定
RULE_DIR = $(BUILD_DIR)/compiler_configs/riscv_embed_gcc

#最终目标文件名
MAP_NAME := $(PROJECT).map
ELF_NAME := $(PROJECT).elf
BIN_NAME := $(PROJECT).bin
HEX_NAME := $(PROJECT).hex

.EXPORT_ALL_VARIABLES:
80 changes: 80 additions & 0 deletions Build/compiler_configs/riscv_embed_gcc/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#当前目录
CUR_DIR = $(shell pwd)

#目标名(当前目录的目录名(不带完整前缀))
TARGET := $(lastword $(subst /, ,$(CUR_DIR)))
#输出目录
#OBJ_OUT_DIR = $(CUR_DIR)
OBJ_OUT_DIR = $(subst $(TOP_DIR),$(RELATIVE_PATH)/$(OBJ_DIR),$(CUR_DIR))
#给obj目标添加输出目录作为前缀
OBJ_TARGET = $(patsubst %,$(OBJ_OUT_DIR)/%,$(obj-y))
#要创建的输出目录,并排序
OBJ_Y_DIR = $(sort $(dir $(OBJ_TARGET)))
#c文件编译包含目录
CINCLUDE_FILE_FLAG := $(addprefix -I$(RELATIVE_PATH)/,$(CINCLUDE_FILE))

#设置为伪目标,否则检测到文件或目录存在就不会执行命令
.PHONY: print_cat_compile_info $(subdir-y) $(TARGET)

all: print_cat_compile_info $(OBJ_Y_DIR) $(TARGET)

#在子makefile里声明编译前需要打印的信息,VERIFY_MSG = xxx
print_cat_compile_info:
ifdef CAT_COMPILE_INFO
#这里echo要先输出一个空格,换行才能对齐
@echo " $(CAT_COMPILE_INFO)"
endif

#创建输出目录
$(OBJ_Y_DIR):
@echo "\n-->make$(OBJ_Y_DIR)"
@if [ ! -d "$@" ];then $(MK_DIR) $@ ;fi;


#让all目标间接依赖OBJ_TARGET,又由于OBJ_TARGET的.o没有给出,
#就会和$(OBJ_OUT_DIR)/%.o匹配
#############!!note1:subdir-y必须在OBJ_TARGET之后,因为subdir-y的编译
#需要增加RELATIVE_PATH的层数
$(TARGET): $(OBJ_TARGET) $(subdir-y)

ifdef obj-y
#编译文件
$(OBJ_OUT_DIR)/%.o: $(CUR_DIR)/%.c
ifeq ($(compile_enable_detail), n)
@echo "compile $<"
@$(CC) $(CINCLUDE_FILE_FLAG) $(CFLAGS) -o $@ -c $<
else
$(CC) $(CINCLUDE_FILE_FLAG) $(CFLAGS) -o $@ -c $<
endif

$(OBJ_OUT_DIR)/%.o: $(CUR_DIR)/%.s
ifeq ($(compile_enable_detail), n)
@echo "compile $<"
@$(AS) $(ASMINCLUDE_FILE_FLAG) $(ASMFLAGS) -o $@ -c $<
else
$(AS) $(ASMINCLUDE_FILE_FLAG) $(ASMFLAGS) -o $@ -c $<
endif


$(OBJ_OUT_DIR)/%.o: $(CUR_DIR)/%.S
ifeq ($(compile_enable_detail), n)
@echo "compile $<"
@$(AS) $(ASMINCLUDE_FILE_FLAG) $(ASMFLAGS) -o $@ -c $<
else
$(AS) $(ASMINCLUDE_FILE_FLAG) $(ASMFLAGS) -o $@ -c $<
endif

endif #ifdef obj-y

#更改相对路径,以便目录层级创建
#############!!note2:添加../必须放在这里,放前面的话生成的obj会再往上一个目录...
#就不在目标的output目录了
ifdef subdir-y
RELATIVE_PATH := $(addprefix ../,$(RELATIVE_PATH))
endif

#编译子目录
$(subdir-y):
$(MAKE) -C $@

export CINCLUDE_FILE
4 changes: 4 additions & 0 deletions workspace/Makefile_content
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ CAT_COMPILE_INFO += OUT_ELF = $(TEXT_COLOR_GREEN)$(OUT_ELF)$(TEXT_COLOR_END)\n
CAT_COMPILE_INFO += compile_enable_detail = $(TEXT_COLOR_GREEN)$(compile_enable_detail)$(TEXT_COLOR_END)\n


include projects/$(PROJECT)/include_paths.mk

CINCLUDE_FILE += projects/$(PROJECT)/user


subdir-y += catOS
subdir-y += projects
Expand Down
19 changes: 0 additions & 19 deletions workspace/catOS/Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@

CINCLUDE_FILE += catOS/bsp/interface
CINCLUDE_FILE += catOS/bsp/interface/drivers
CINCLUDE_FILE += catOS/bsp/arch/$(CATOS_BOARD_ARCH)/$(CATOS_BOARD_BSP)/drivers


CINCLUDE_FILE += catOS/include

CINCLUDE_FILE += catOS/src/component/cat_device
CINCLUDE_FILE += catOS/src/component/cat_shell
CINCLUDE_FILE += catOS/src/component/cat_stdio
CINCLUDE_FILE += catOS/src/component/cat_string

CINCLUDE_FILE += catOS/src/core/idle_task
CINCLUDE_FILE += catOS/src/core/init
CINCLUDE_FILE += catOS/src/core/interrupt
CINCLUDE_FILE += catOS/src/core/schedule
CINCLUDE_FILE += catOS/src/core/support

CINCLUDE_FILE += user

subdir-y += bsp
subdir-y += src
Expand Down
5 changes: 0 additions & 5 deletions workspace/catOS/bsp/Libraries/STM32F1xx_HAL_Driver/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@

CINCLUDE_FILE += catOS/bsp/Libraries/CMSIS/Include
CINCLUDE_FILE += catOS/bsp/Libraries/CMSIS/Device/ST/STM32F1xx/Include
CINCLUDE_FILE += catOS/bsp/Libraries/STM32F1xx_HAL_Driver/Inc
CINCLUDE_FILE += catOS/bsp/Libraries/STM32F1xx_HAL_Driver

subdir-y += Src

obj-y += stm32f1xx_it.o
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@

CINCLUDE_FILE += user

CINCLUDE_FILE += catOS/bsp/$(CATOS_BOARD_BSP)/Libraries/CMSIS/Include
CINCLUDE_FILE += catOS/bsp/$(CATOS_BOARD_BSP)/Libraries/CMSIS/Device/ST/STM32F1xx/Include
CINCLUDE_FILE += catOS/bsp/$(CATOS_BOARD_BSP)/Libraries/STM32F1xx_HAL_Driver/Inc


#HAL_LIB_DRIVER
obj-y += stm32f1xx_hal_adc.o
Expand Down
2 changes: 0 additions & 2 deletions workspace/catOS/bsp/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#VERIFY_MSG = catOS/port:$(RELATIVE_PATH)***** making catOS port dir *****

CINCLUDE_FILE += catOS/bsp/Libraries

subdir-y += arch
subdir-y += Libraries

Expand Down
3 changes: 2 additions & 1 deletion workspace/catOS/bsp/arch/cortex_m3/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#VERIFY_MSG = catOS/port:$(RELATIVE_PATH)***** making catOS port dir *****

subdir-y += $(CATOS_BOARD_BSP)
subdir-y += board
subdir-y += libcpu

include $(RULE_DIR)/rules.mk
5 changes: 5 additions & 0 deletions workspace/catOS/bsp/arch/cortex_m3/board/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#VERIFY_MSG = catOS/port:$(RELATIVE_PATH)***** making catOS port dir *****

subdir-y += $(CATOS_BOARD_BSP)

include $(RULE_DIR)/rules.mk
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@

#INCLUDE DIR FOR "stm32f103vet6_min"
CINCLUDE_FILE += catOS/bsp/Libraries/CMSIS/Include
CINCLUDE_FILE += catOS/bsp/Libraries/CMSIS/Device/ST/STM32F1xx/Include
CINCLUDE_FILE += catOS/bsp/Libraries/STM32F1xx_HAL_Driver/Inc
CINCLUDE_FILE += catOS/bsp/Libraries/STM32F1xx_HAL_Driver

CINCLUDE_FILE += catOS/bsp/arch/$(CATOS_BOARD_ARCH)/$(CATOS_BOARD_BSP)/drivers/uart
CINCLUDE_FILE += catOS/bsp/interface
CINCLUDE_FILE += catOS/include
CINCLUDE_FILE += catOS/src/core/interrupt
CINCLUDE_FILE += catOS/src/core/schedule

#subdir
subdir-y += drivers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void cat_pin_device_init(void)
#endif
}

cat_uint8_t cat_pin_init(cat_uint32_t pin_num, cat_uint8_t mode)
cat_err_t cat_pin_init(cat_uint32_t pin_num, cat_uint8_t mode)
{
cat_uint8_t ret = CAT_ERROR;
stm32f103vet6_fire_pin_t *p = &(pin_map[0]);
Expand Down Expand Up @@ -82,25 +82,22 @@ cat_uint8_t cat_pin_init(cat_uint32_t pin_num, cat_uint8_t mode)
return ret;
}

cat_uint8_t cat_pin_set_mode(cat_uint32_t pin_num, cat_uint8_t mode)
void cat_pin_set_mode(cat_uint32_t pin_num, cat_uint8_t mode)
{
cat_uint8_t ret = CAT_ERROR;
CAT_KPRINTF("[pin] set mode now not support, abort!\r\n");
return ret;
}


cat_int8_t cat_pin_read(cat_uint32_t pin_num)
cat_uint8_t cat_pin_read(cat_uint32_t pin_num)
{
cat_int8_t ret = CAT_ERROR;
CAT_KPRINTF("[pin] read func now not support, abort!\r\n");
return ret;
}


cat_uint8_t cat_pin_write(cat_uint32_t pin_num, cat_uint8_t val)
void cat_pin_write(cat_uint32_t pin_num, cat_uint8_t val)
{
cat_uint8_t ret = CAT_EINVAL;
stm32f103vet6_fire_pin_t *p = &(pin_map[0]);

/* 遍历pin_map数组 */
Expand All @@ -110,14 +107,11 @@ cat_uint8_t cat_pin_write(cat_uint32_t pin_num, cat_uint8_t val)
{
HAL_GPIO_WritePin(p->port, p->gpio_pin, (GPIO_PinState)val);

ret = CAT_EOK;

/* 写入结束结束循环 */
break;
} /* if */
} /* for */

return ret;
}

#if (CATOS_ENABLE_CAT_SHELL == 1)
Expand Down Expand Up @@ -151,7 +145,7 @@ void *do_write_pin(void *arg)
CAT_KPRINTF("[pin] pin=%d, val=%d\r\n", pin_num, val);

/* 调用pin_write函数写入 */
ret = cat_pin_write(pin_num, val);
cat_pin_write(pin_num, val);
if(ret != CAT_EOK)
{
CAT_SYS_PRINTF("[pin] fail to write !!\r\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


obj-y += catos_start.o
obj-y += port_asm.o
# obj-y += port_asm.o
obj-y += port.o

include $(RULE_DIR)/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ LoopFillZerobss:
/* bl __libc_init_array */
/* Call the application's entry point.*/
/* 调用catos入口函数,并在完成初始化后跳转至用户主函数 */
bl catos_init
bl main
bx lr
.size Reset_Handler, .-Reset_Handler

Expand Down
Loading

0 comments on commit 496688e

Please sign in to comment.