From cb3aeb40637966207821d77878d649313f9efe5d Mon Sep 17 00:00:00 2001 From: NeoZng Date: Wed, 26 Jul 2023 14:31:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0cmakelists=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E9=9D=99=E6=80=81=E6=A3=80=E6=9F=A5warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/c-cpp.yml | 7 +- CMakeLists.txt | 115 +++++++++++++++++++++++++++++++++ bsp/can/bsp_can.c | 2 +- modules/BMI088/bmi088.c | 18 +++--- modules/alarm/buzzer.c | 4 +- modules/can_comm/can_comm.c | 2 +- modules/imu/BMI088driver.c | 14 +--- modules/ist8310/ist8310.c | 7 +- modules/led/led.c | 12 ++-- modules/motor/LKmotor/LK9025.c | 2 +- 10 files changed, 147 insertions(+), 36 deletions(-) create mode 100644 CMakeLists.txt diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 9145b4f..77afb9c 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -17,4 +17,9 @@ jobs: - uses: actions/checkout@v3 - name: make - run: make -j12 \ No newline at end of file + run: make -j12 + + - uses: seanmiddleditch/gha-setup-ninja@master + - name: ninja + run: cd build && cmake -G Ninja .. && ninja + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..7f7fc41 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,115 @@ +cmake_minimum_required(VERSION 3.16) +# 指定编译平台/架构与语言标准, 推荐指定Ninja为构建工具,可以加快编译速度(相比make) +set(CMAKE_SYSTEM_NAME Generic) +set(CMAKE_SYSTEM_PROCESSOR arm) +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +# 指定工具链 +set(CMAKE_C_COMPILER_FORCED TRUE) # skip compiler test +set(CMAKE_CXX_COMPILER_FORCED TRUE) +set(CMAKE_C_COMPILER arm-none-eabi-gcc) +set(CMAKE_ASM_COMPILER arm-none-eabi-gcc) +set(CMAKE_OBJCOPY arm-none-eabi-objcopy) +set(CMAKE_OBJDUMP arm-none-eabi-objdump) +set(SIZE arm-none-eabi-size) +set(CMAKE_AR arm-none-eabi-ar) +set(CMAKE_C_STANDARD 11) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# 指定工程名称和语言类型 +project(basic_framework C ASM) + +# 选择构建类型 +set(CMAKE_BUILD_TYPE Debug) # Debug Release RelWithDebInfo MinSizeRel + +# board specific settings, arch/fpu/instruction +set(MCU_FLAGS -mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16) +set(LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/STM32F407IGHx_FLASH.ld") # 指定链接脚本 +set(DSP_NAME "libCMSISDSP.a") # 指定DSP库名称 +link_directories(${CMAKE_SOURCE_DIR}/Middlewares/ST/ARM/DSP/Lib) + +# Generic compiler settings for optimization and basic link lib +add_compile_options(-pipe ${MCU_FLAGS} -Wall -Werror -fmessage-length=0 # basic options + -ffunction-sections -fdata-sections -fno-common # optimize options + ) +add_link_options(-pipe ${MCU_FLAGS} -T${LINKER_SCRIPT} -Wl,--no-warn-rwx-segments # close RWX warning + -lm -lc -lnosys # lib options + -Wl,--gc-sections -flto -specs=nano.specs -specs=nosys.specs # optimize options + -Wl,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map -Wl,--cref -Wl,--print-memory-usage # map options + ) # if your executable is too large , try option '-s' to strip symbols + +# add_compile_definitions() works for compile stage +# while add_definitions() works for both compile and link stage +add_definitions( + -DUSE_HAL_DRIVER + -DSTM32F407xx + -DARM_MATH_CM4 + ) # need -D to define macro + +# add inc +# 递归包含头文件的函数 +function(include_sub_directories_recursively root_dir) + if (IS_DIRECTORY ${root_dir}) # 当前路径是一个目录吗,是的话就加入到包含目录 + message("include dir: " ${root_dir}) + include_directories(${root_dir}) + endif() + + file(GLOB ALL_SUB RELATIVE ${root_dir} ${root_dir}/*) # 获得当前目录下的所有文件,让如ALL_SUB列表中 + foreach(sub ${ALL_SUB}) + if (IS_DIRECTORY ${root_dir}/${sub}) + include_sub_directories_recursively(${root_dir}/${sub}) # 对子目录递归调用,包含 + endif() + endforeach() +endfunction() +include_sub_directories_recursively(${CMAKE_SOURCE_DIR}/Drivers) +include_sub_directories_recursively(${CMAKE_SOURCE_DIR}/Middlewares) +include_sub_directories_recursively(${CMAKE_SOURCE_DIR}/bsp) +include_sub_directories_recursively(${CMAKE_SOURCE_DIR}/modules) +include_sub_directories_recursively(${CMAKE_SOURCE_DIR}/application) +include_sub_directories_recursively(${CMAKE_SOURCE_DIR}/Inc) + +# add source, only surfix .c +file(GLOB_RECURSE SOURCES + "Drivers/*.c" + "Src/*.c" + "Middlewares/*.c" + "bsp/*.c" + "modules/*.c" + "application/*.c" +) + +# 汇编文件路径 +# ENABLE_LANGUAGE(ASM) +set(ASM_SOURCES + startup_stm32f407xx.s + Middlewares/Third_Party/SEGGER/RTT/SEGGER_RTT_ASM_ARMv7M.s + ) +set_source_files_properties(${ASM_SOURCES} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp") + +# Build types +if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release") + message(STATUS "Maximum optimization for speed") + add_compile_options(-Ofast) +elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") + message(STATUS "Maximum optimization for speed, debug info included") + add_compile_options(-Ofast -g) +elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel") + message(STATUS "Maximum optimization for size") + add_compile_options(-Os) +else () + message(STATUS "Minimal optimization, debug info included") + add_compile_options(-Og -g -gdwarf-2) + add_definitions(-DESC_DEBUG) # ESC Debug +endif () + +# build binary and hex file +add_executable(${PROJECT_NAME}.elf ${SOURCES} ${ASM_SOURCES} ${LINKER_SCRIPT}) +target_link_libraries(${PROJECT_NAME}.elf ${DSP_NAME} m) # link DSP lib and math lib + +add_custom_command( + TARGET ${PROJECT_NAME}.elf POST_BUILD + COMMAND ${CMAKE_OBJCOPY} -Oihex $ ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex + COMMAND ${CMAKE_OBJCOPY} -Obinary $ ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin + COMMENT "Building hex & bin file..." + COMMENT "EXCUTABLE SIZE:" + COMMAND ${SIZE} ${PROJECT_NAME}.elf + ) \ No newline at end of file diff --git a/bsp/can/bsp_can.c b/bsp/can/bsp_can.c index 52d09e6..9e32a13 100644 --- a/bsp/can/bsp_can.c +++ b/bsp/can/bsp_can.c @@ -106,7 +106,7 @@ CANInstance *CANRegister(CAN_Init_Config_s *config) uint8_t CANTransmit(CANInstance *_instance, float timeout) { static uint32_t busy_count; - static float wait_time; + static volatile float wait_time __attribute__((unused)); // for cancel warning float dwt_start = DWT_GetTimeline_ms(); while (HAL_CAN_GetTxMailboxesFreeLevel(_instance->can_handle) == 0) // 等待邮箱空闲 { diff --git a/modules/BMI088/bmi088.c b/modules/BMI088/bmi088.c index ffd8bc6..04ffbdc 100644 --- a/modules/BMI088/bmi088.c +++ b/modules/BMI088/bmi088.c @@ -188,31 +188,31 @@ static uint8_t BMI088GyroInit(BMI088Instance *bmi088) */ static void BMI088AccSPIFinishCallback(SPIInstance *spi) { - static BMI088Instance *bmi088; - bmi088 = (BMI088Instance *)(spi->id); + // static BMI088Instance *bmi088; + // bmi088 = (BMI088Instance *)(spi->id); // 若第一次读取加速度,则在这里启动温度读取 // 如果使用异步姿态更新,此处唤醒量测更新的任务 } static void BMI088GyroSPIFinishCallback(SPIInstance *spi) { - static BMI088Instance *bmi088; - bmi088 = (BMI088Instance *)(spi->id); + // static BMI088Instance *bmi088; + // bmi088 = (BMI088Instance *)(spi->id); // 若不是异步,啥也不做;否则启动姿态的预测步(propagation) } static void BMI088AccINTCallback(GPIOInstance *gpio) { - static BMI088Instance *bmi088; - bmi088 = (BMI088Instance *)(gpio->id); + // static BMI088Instance *bmi088; + // bmi088 = (BMI088Instance *)(gpio->id); // 启动加速度计数据读取(和温度读取,如果有必要),并转换为实际值 // 读取完毕会调用BMI088AccSPIFinishCallback } static void BMI088GyroINTCallback(GPIOInstance *gpio) { - static BMI088Instance *bmi088; - bmi088 = (BMI088Instance *)(gpio->id); + // static BMI088Instance *bmi088; + // bmi088 = (BMI088Instance *)(gpio->id); // 启动陀螺仪数据读取,并转换为实际值 // 读取完毕会调用BMI088GyroSPIFinishCallback } @@ -258,6 +258,7 @@ uint8_t BMI088Acquire(BMI088Instance *bmi088, BMI088_Data_t *data_store) // 如果数据还没准备好,则返回空数据?或者返回上一次的数据?或者返回错误码? @todo if (bmi088->update_flag.imu_ready == 0) return 0; + return 1; } /* pre calibrate parameter to go here */ @@ -286,7 +287,6 @@ void BMI088CalibrateIMU(BMI088Instance *_bmi088) // 一次性参数用完就丢,不用static float startTime; // 开始标定时间,用于确定是否超时 uint16_t CaliTimes = 6000; // 标定次数(6s) - uint8_t buf[6] = {0}; // buffer float gyroMax[3], gyroMin[3]; // 保存标定过程中读取到的数据最大值判断是否满足标定环境 float gNormTemp, gNormMax, gNormMin; // 同上,计算矢量范数(模长) float gyroDiff[3], gNormDiff; // 每个轴的最大角速度跨度及其模长 diff --git a/modules/alarm/buzzer.c b/modules/alarm/buzzer.c index 02f80f1..3051ee4 100644 --- a/modules/alarm/buzzer.c +++ b/modules/alarm/buzzer.c @@ -4,7 +4,7 @@ #include "string.h" static PWMInstance *buzzer; -static uint8_t idx; +// static uint8_t idx; static BuzzzerInstance *buzzer_list[BUZZER_DEVICE_CNT] = {0}; /** @@ -84,6 +84,8 @@ void BuzzerTask() case OCTAVE_7: PWMSetPeriod(buzzer, (float)1 / SiFreq); break; + default: + break; } break; } diff --git a/modules/can_comm/can_comm.c b/modules/can_comm/can_comm.c index 415a67d..bb39c59 100644 --- a/modules/can_comm/can_comm.c +++ b/modules/can_comm/can_comm.c @@ -95,7 +95,7 @@ CANCommInstance *CANCommInit(CANComm_Init_Config_s *comm_config) ins->can_ins = CANRegister(&comm_config->can_config); Daemon_Init_Config_s daemon_config = { - .callback = NULL, + .callback = CANCommLostCallback, .owner_id = (void *)ins, .reload_count = comm_config->daemon_count, }; diff --git a/modules/imu/BMI088driver.c b/modules/imu/BMI088driver.c index 97a92bd..e681428 100644 --- a/modules/imu/BMI088driver.c +++ b/modules/imu/BMI088driver.c @@ -18,8 +18,6 @@ float gyroDiff[3], gNormDiff; uint8_t caliOffset = 1; int16_t caliCount = 0; -static uint32_t offset_cal_DWT_Count = 0; - IMU_Data_t BMI088; #if defined(BMI088_USE_SPI) @@ -333,17 +331,7 @@ void BMI088_Read(IMU_Data_t *bmi088) { static uint8_t buf[8] = {0}; static int16_t bmi088_raw_temp; - static float dt = 1.0; - static uint8_t first_read_flag = 0; - if (!first_read_flag) - { - first_read_flag = 1; - DWT_GetDeltaT(&offset_cal_DWT_Count); - } - else - { - dt = DWT_GetDeltaT(&offset_cal_DWT_Count) * 1000.0; - } + BMI088_accel_read_muli_reg(BMI088_ACCEL_XOUT_L, buf, 6); bmi088_raw_temp = (int16_t)((buf[1]) << 8) | buf[0]; diff --git a/modules/ist8310/ist8310.c b/modules/ist8310/ist8310.c index 8f22733..64abee2 100644 --- a/modules/ist8310/ist8310.c +++ b/modules/ist8310/ist8310.c @@ -1,7 +1,8 @@ #include "bsp_dwt.h" #include "ist8310.h" -#include "memory.h" -#include "stdlib.h" +#include "bsp_log.h" +#include +#include // 一般这个模块只有一个实例,所以直接保存在这里,实际上不保存也可以,application可以自己保存 static IST8310Instance *ist8310_instance = NULL; // 用于存储IST8310实例的指针 @@ -91,7 +92,7 @@ IST8310Instance *IST8310Init(IST8310_Init_Config_s *config) IICAccessMem(ist->iic, ist8310_write_reg_data_error[i][0], &check_who_i_am, 1, IIC_READ_MEM, 1); // 读回自身id if (check_who_i_am != ist8310_write_reg_data_error[i][1]) while (1) - ist8310_write_reg_data_error[i][2]; // 掉线/写入失败/未知错误,会返回对应的错误码 + LOGERROR("[ist8310] init error, code %d", ist8310_write_reg_data_error[i][2]); // 掉线/写入失败/未知错误,会返回对应的错误码 } ist8310_instance = ist; // 保存ist8310实例的指针 diff --git a/modules/led/led.c b/modules/led/led.c index 5b48f1e..276d86f 100644 --- a/modules/led/led.c +++ b/modules/led/led.c @@ -36,11 +36,11 @@ void LEDSwitch(LEDInstance *_led, uint8_t led_switch) void LEDShow(uint32_t aRGB) { - static uint8_t alpha; - static uint16_t red, green, blue; + // static uint8_t alpha; + // static uint16_t red, green, blue; - alpha = (aRGB & 0xFF000000) >> 24; - red = ((aRGB & 0x00FF0000) >> 16) * alpha; - green = ((aRGB & 0x0000FF00) >> 8) * alpha; - blue = ((aRGB & 0x000000FF) >> 0) * alpha; + // alpha = (aRGB & 0xFF000000) >> 24; + // red = ((aRGB & 0x00FF0000) >> 16) * alpha; + // green = ((aRGB & 0x0000FF00) >> 8) * alpha; + // blue = ((aRGB & 0x000000FF) >> 0) * alpha; } diff --git a/modules/motor/LKmotor/LK9025.c b/modules/motor/LKmotor/LK9025.c index 103faac..c9fadbc 100644 --- a/modules/motor/LKmotor/LK9025.c +++ b/modules/motor/LKmotor/LK9025.c @@ -80,7 +80,7 @@ LKMotorInstance *LKMotorInit(Motor_Init_Config_s *config) lkmotor_instance[idx++] = motor; Daemon_Init_Config_s daemon_config = { - .callback = NULL, + .callback = LKMotorLostCallback, .owner_id = motor, .reload_count = 5, // 50ms };