添加cmakelists的支持,修复了一些静态检查warning

This commit is contained in:
NeoZng 2023-07-26 14:31:49 +08:00
parent 668848a1e8
commit cb3aeb4063
10 changed files with 147 additions and 36 deletions

View File

@ -17,4 +17,9 @@ jobs:
- uses: actions/checkout@v3
- name: make
run: make -j12
run: make -j12
- uses: seanmiddleditch/gha-setup-ninja@master
- name: ninja
run: cd build && cmake -G Ninja .. && ninja

115
CMakeLists.txt Normal file
View File

@ -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<macro> 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 $<TARGET_FILE:${PROJECT_NAME}.elf> ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin
COMMENT "Building hex & bin file..."
COMMENT "EXCUTABLE SIZE:"
COMMAND ${SIZE} ${PROJECT_NAME}.elf
)

View File

@ -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) // 等待邮箱空闲
{

View File

@ -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; // 每个轴的最大角速度跨度及其模长

View File

@ -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;
}

View File

@ -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,
};

View File

@ -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];

View File

@ -1,7 +1,8 @@
#include "bsp_dwt.h"
#include "ist8310.h"
#include "memory.h"
#include "stdlib.h"
#include "bsp_log.h"
#include <memory.h>
#include <stdlib.h>
// 一般这个模块只有一个实例,所以直接保存在这里,实际上不保存也可以,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实例的指针

View File

@ -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;
}

View File

@ -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
};