From bec0ee4184602315e1f57aea2dd80bcc95c6f443 Mon Sep 17 00:00:00 2001 From: NeoZng Date: Wed, 12 Jul 2023 20:34:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=8A=A8=E9=80=92?= =?UTF-8?q?=E5=BD=92=E6=9F=A5=E6=89=BE=E6=BA=90=E6=96=87=E4=BB=B6=E5=92=8C?= =?UTF-8?q?=E5=A4=B4=E6=96=87=E4=BB=B6=E7=9A=84makefile=E8=A7=84=E5=88=99?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0log=E5=85=B3=E9=97=AD=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=88makefile=E4=B8=AD=E7=9A=84=E5=AE=8F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 5 +- Makefile.upgrade | 193 +++++++++++++++++++++++++++++++++++++++ VSCode+Ozone使用方法.md | 7 +- bsp/log/bsp_log.h | 7 ++ modules/BMI088/bmi088.md | 2 - 5 files changed, 205 insertions(+), 9 deletions(-) create mode 100644 Makefile.upgrade diff --git a/Makefile b/Makefile index 97979fb..920f1fc 100644 --- a/Makefile +++ b/Makefile @@ -210,10 +210,7 @@ C_DEFS = \ -DUSE_HAL_DRIVER \ -DSTM32F407xx \ -DARM_MATH_CM4 \ --DARM_MATH_MATRIX_CHECK \ --DARM_MATH_ROUNDING \ --DARM_MATH_LOOPUNROLL \ --DISABLEFLOAT16 +-DDISABLE_LOG_SYSTEM # AS includes AS_INCLUDES = \ diff --git a/Makefile.upgrade b/Makefile.upgrade new file mode 100644 index 0000000..e55cc4f --- /dev/null +++ b/Makefile.upgrade @@ -0,0 +1,193 @@ +########################################################################################################################## +# File automatically-generated by tool: [projectgenerator] version: [3.18.0-B7] date: [Thu Apr 13 18:20:17 CST 2023] +########################################################################################################################## + +# ------------------------------------------------ +# Generic Makefile (based on gcc) +# +# ChangeLog : +# 2017-02-10 - Several enhancements + project update mode +# 2015-07-22 - first version +# ------------------------------------------------ + + +###################################### +# target +###################################### +TARGET = basic_framework + + +###################################### +# building variables +###################################### +# debug build? +DEBUG = 1 +# optimization +OPT = -Og + + +####################################### +# paths +####################################### +# Build path +BUILD_DIR = build + +###################################### +# source +###################################### +# 快速递归搜索当前目录下的.c文件,需在msys2环境下使用(Windows下),linux/macOS则可以直接使用 +# 如果一定要在powershell或cmd下使用,请自行修改查找子目录的命令find为对应值 +PROJ_DIR = Src \ +Inc \ +application \ +modules \ +bsp \ +Drivers \ +Middlewares +ALL_DIRS := $(foreach dire, $(PROJ_DIR), $(shell find $(dire) -maxdepth 10 -type d)) +C_SOURCES := $(foreach dire, $(ALL_DIRS), $(wildcard $(dire)/*.c)) + +# ASM sources +ASM_SOURCES = \ +startup_stm32f407xx.s \ +Middlewares/Third_Party/SEGGER/RTT/SEGGER_RTT_ASM_ARMv7M.s + + +####################################### +# binaries +####################################### +PREFIX = arm-none-eabi- +# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx) +# either it can be added to the PATH environment variable. +ifdef GCC_PATH +CC = $(GCC_PATH)/$(PREFIX)gcc +AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp +CP = $(GCC_PATH)/$(PREFIX)objcopy +SZ = $(GCC_PATH)/$(PREFIX)size +else +CC = $(PREFIX)gcc +AS = $(PREFIX)gcc -x assembler-with-cpp +CP = $(PREFIX)objcopy +SZ = $(PREFIX)size +endif +HEX = $(CP) -O ihex +BIN = $(CP) -O binary -S + +####################################### +# CFLAGS +####################################### +# cpu +CPU = -mcpu=cortex-m4 + +# fpu +FPU = -mfpu=fpv4-sp-d16 + +# float-abi +FLOAT-ABI = -mfloat-abi=hard + +# mcu +MCU = $(CPU) -mthumb -mthumb-interwork $(FPU) $(FLOAT-ABI) + +# macros for gcc +# AS defines +AS_DEFS = + +# C defines +C_DEFS = \ +-DUSE_HAL_DRIVER \ +-DSTM32F407xx \ +-DARM_MATH_CM4 \ +-DDISABLE_LOG_SYSTEM # 关闭日志系统 + +# AS includes +AS_INCLUDES = \ +-IInc + +# C includes +# 快速递归添加包含目录 +C_INCLUDES := $(addprefix -I,$(ALL_DIRS)) + + +# compile gcc flags +ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -fdata-sections -ffunction-sections + +CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -fdata-sections -ffunction-sections -fmessage-length=0 + +ifeq ($(DEBUG), 1) +CFLAGS += -g -gdwarf-2 +endif + + +# Generate dependency information +CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" + + +####################################### +# LDFLAGS +####################################### +# link script +LDSCRIPT = STM32F407IGHx_FLASH.ld + +# libraries +LIBS = -lc -lm -lnosys \ +-l:libCMSISDSP.a # 若想要自行编译CMSIS-DSP库,请参考https://github.com/ARM-software/CMSIS-DSP +LIBDIR = \ +-LMiddlewares/ST/ARM/DSP/Lib +LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections -flto + +# default action: build all +all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin + + +####################################### +# build the application +####################################### +# list of objects +OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o))) +vpath %.c $(sort $(dir $(C_SOURCES))) +# list of ASM program objects +OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o))) +vpath %.s $(sort $(dir $(ASM_SOURCES))) + +$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR) + @$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@ + +$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR) + @$(AS) -c $(CFLAGS) $< -o $@ + +$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile + @$(CC) $(OBJECTS) $(LDFLAGS) -o $@ + $(SZ) $@ + +$(BUILD_DIR)/%.hex: $(BUILD_DIR)/%.elf | $(BUILD_DIR) + $(HEX) $< $@ + +$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) + $(BIN) $< $@ + +$(BUILD_DIR): + @mkdir $@ + + +####################################### +# clean up +####################################### +clean: + rd $(BUILD_DIR) /s/q + + +####################################### +# dependencies +####################################### +-include $(wildcard $(BUILD_DIR)/*.d) + + +####################################### +# download directl without debugging +####################################### +download_dap: + openocd -f openocd_dap.cfg -c init -c halt -c "flash write_image erase $(BUILD_DIR)/$(TARGET).bin 0x08000000" -c reset -c shutdown +download_jlink: + JFlash -openprj'stm32.jflash' -open'$(BUILD_DIR)/$(TARGET).hex',0x8000000 -auto -startapp -exit + +# *** EOF *** \ No newline at end of file diff --git a/VSCode+Ozone使用方法.md b/VSCode+Ozone使用方法.md index f443fd6..5adb94d 100644 --- a/VSCode+Ozone使用方法.md +++ b/VSCode+Ozone使用方法.md @@ -383,6 +383,9 @@ Makefile的大部分内容在CubeMX初始化的时候就会帮你生成。如果 > 和KEIL新增文件的方式很相似,但是更方便。 + +- **另外**,如果你使用的时linux/Unix like/MacOS,则可以直接使用根目录下的Makefile.upgrade(复制替换到Makefile中),我们在其中定义了递归添加源文件和头文件目录的规则,不再需要手动添加新增的源文件和头文件路径。如果你使用windows+mingw/Msys2,则需要在mingw环境下执行编译指令,否则报错(因为makefile中使用了一些shell指令是cmd和powershell不支持的,后续考虑在makefile中添加os判断规则以自动替换目录查找指令) + ### 简单的调试配置 > 在VSCode中调试不能像Keil一样查看变量动态变化,但是支持以外的所有操作,如查看外设和反汇编代码,设置断点触发方式等。 @@ -785,9 +788,7 @@ AS_DEFS = # 汇编的一些宏定义 C_DEFS = \ # C语言的宏定义 -DUSE_HAL_DRIVER \ # 使用HAL库.HAL库的许多头文件和源文件里会判断是否定义了这个宏 -DSTM32F407xx \ # HAL库会根据使用的MCU的不同进行条件编译,这是一个很好的封装技术 --DARM_MATH_CM4 \ # 启用ARM MATH运算库,我们在卡尔曼滤波和最小二乘法的时候会用到矩阵运算 --DARM_MATH_MATRIX_CHECK \ # 启用矩阵乘法库 --DARM_MATH_ROUNDING # 对数学库的输出结果进行取整防止溢出? +-DARM_MATH_CM4 # 启用ARM MATH运算库,我们在卡尔曼滤波和最小二乘法的时候会用到矩阵运算 # AS includes AS_INCLUDES = -IHAL_N_Middlewares/Inc diff --git a/bsp/log/bsp_log.h b/bsp/log/bsp_log.h index 002be77..8f66681 100644 --- a/bsp/log/bsp_log.h +++ b/bsp/log/bsp_log.h @@ -35,13 +35,20 @@ void BSPLogInit(); /** * 有颜色格式日志输出,建议使用这些宏来输出日志 * @attention 注意这些接口不支持浮点格式化输出,若有需要,请使用Float2Str()函数进行转换后再打印 + * @note 在release版本上车使用时,与makefile中添加的宏DISABLE_LOG_SYSTEM一起使用,可以关闭日志系统 */ +#if DISABLE_LOG_SYSTEM +#define LOGINFO(format, ...) __unused +#define LOGWARNING(format, ...) __unused +#define LOGERROR(format, ...) __unused +#else // information level #define LOGINFO(format, ...) LOG_PROTO("I:", RTT_CTRL_TEXT_BRIGHT_GREEN, format, ##__VA_ARGS__) // warning level #define LOGWARNING(format, ...) LOG_PROTO("W:", RTT_CTRL_TEXT_BRIGHT_YELLOW, format, ##__VA_ARGS__) // error level #define LOGERROR(format, ...) LOG_PROTO("E:", RTT_CTRL_TEXT_BRIGHT_RED, format, ##__VA_ARGS__) +#endif // DISABLE_LOG_SYSTEM /** * @brief 通过segger RTT打印日志,支持格式化输出,格式化输出的实现参考printf. diff --git a/modules/BMI088/bmi088.md b/modules/BMI088/bmi088.md index 88a42a2..7dbd80f 100644 --- a/modules/BMI088/bmi088.md +++ b/modules/BMI088/bmi088.md @@ -1,7 +1,5 @@ # BMI088 -**注意,此模块待测试** - ## 示例 ```c