清除所有的legacy support,增加编译时的内存使用预测和Werror选项,统一命名。

This commit is contained in:
NeoZng 2023-07-14 17:24:44 +08:00
parent 8943bdfe5c
commit 3faa9f1f8f
24 changed files with 94 additions and 234 deletions

File diff suppressed because one or more lines are too long

View File

@ -109,9 +109,6 @@ Middlewares/Third_Party/SEGGER/RTT/SEGGER_RTT_printf.c \
Middlewares/Third_Party/SEGGER/RTT/SEGGER_RTT.c \
bsp/dwt/bsp_dwt.c \
bsp/pwm/bsp_pwm.c \
bsp/bsp_legacy_support/bsp_temperature.c \
bsp/bsp_legacy_support/bsp_buzzer.c \
bsp/bsp_legacy_support/bsp_led.c \
bsp/gpio/bsp_gpio.c \
bsp/spi/bsp_spi.c \
bsp/iic/bsp_iic.c \
@ -120,7 +117,6 @@ bsp/usart/bsp_usart.c \
bsp/usb/bsp_usb.c \
bsp/log/bsp_log.c \
bsp/flash/bsp_flash.c \
bsp/bsp_init.c \
modules/algorithm/controller.c \
modules/algorithm/kalman_filter.c \
modules/algorithm/QuaternionEKF.c \
@ -132,7 +128,6 @@ modules/imu/BMI088driver.c \
modules/imu/BMI088Middleware.c \
modules/imu/ins_task.c \
modules/ist8310/ist8310.c \
modules/led_task/led_task.c \
modules/led/led.c \
modules/master_machine/master_process.c \
modules/master_machine/seasky_protocol.c \
@ -247,14 +242,12 @@ C_INCLUDES = \
-Ibsp/log \
-Ibsp/flash \
-Ibsp/pwm \
-Ibsp/bsp_legacy_support \
-Ibsp \
-Imodules/algorithm \
-Imodules/BMI088 \
-Imodules/imu \
-Imodules/ist8310 \
-Imodules/led \
-Imodules/led_task \
-Imodules/master_machine \
-Imodules/motor/DJImotor \
-Imodules/motor/LKmotor \
@ -271,13 +264,14 @@ C_INCLUDES = \
-Imodules/daemon \
-Imodules/vofa \
-Imodules/alarm \
-Imodules
-Imodules \
-IMiddlewares/ST/ARM/DSP/Inc
# 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
CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -fdata-sections -ffunction-sections -fmessage-length=0 -Werror
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
@ -299,7 +293,7 @@ LIBS = -lc -lm -lnosys \
-l:libCMSISDSP.a
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
LDFLAGS = $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections -flto -Wl,--no-warn-rwx-segments -Wl,--print-memory-usage
# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).bin

View File

@ -54,13 +54,13 @@ osThreadId defaultTaskHandle;
/* USER CODE END FunctionPrototypes */
void StartDefaultTask(void const *argument);
void StartDefaultTask(void const * argument);
extern void MX_USB_DEVICE_Init(void);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
/* GetIdleTaskMemory prototype (linked to static allocation support) */
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize);
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );
/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
static StaticTask_t xIdleTaskTCBBuffer;
@ -80,8 +80,7 @@ void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, StackTyp
* @param None
* @retval None
*/
void MX_FREERTOS_Init(void)
{
void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN Init */
/* USER CODE END Init */
@ -111,6 +110,7 @@ void MX_FREERTOS_Init(void)
/* add threads, ... */
/* USER CODE END RTOS_THREADS */
}
/* USER CODE BEGIN Header_StartDefaultTask */
@ -120,10 +120,10 @@ void MX_FREERTOS_Init(void)
* @retval None
*/
/* USER CODE END Header_StartDefaultTask */
void StartDefaultTask(void const *argument)
void StartDefaultTask(void const * argument)
{
/* init code for USB_DEVICE */
MX_USB_DEVICE_Init(); // 默认usb启动任务的位置
MX_USB_DEVICE_Init();
/* USER CODE BEGIN StartDefaultTask */
osThreadTerminate(NULL); // 避免空置和切换占用cpu
/* USER CODE END StartDefaultTask */

View File

@ -6,7 +6,7 @@
// 编译warning,提醒开发者修改机器人参数
#ifndef ROBOT_DEF_PARAM_WARNING
#define ROBOT_DEF_PARAM_WARNING
#warning check if you have configured the parameters in robot_def.h, IF NOT, please refer to the comments AND DO IT, otherwise the robot will have FATAL ERRORS!!!
#pragma message "check if you have configured the parameters in robot_def.h, IF NOT, please refer to the comments AND DO IT, otherwise the robot will have FATAL ERRORS!!!"
#endif // !ROBOT_DEF_PARAM_WARNING
#if defined(ONE_BOARD) || defined(CHASSIS_BOARD)

View File

@ -89,7 +89,7 @@ void StartMOTORTASK(void const *argument)
void StartDAEMONTASK(void const *argument)
{
static float daemon_dt, daemon_start;
buzzer_init();
BuzzerInit();
LOGINFO("[freeRTOS] Daemon Task Start");
while (1)
{

View File

@ -1,17 +0,0 @@
#include "bsp_init.h"
#include "bsp_log.h"
#include "bsp_dwt.h"
#include "bsp_usb.h"
#include "bsp_led.h"
#include "bsp_temperature.h"
// CAN和串口会在注册实例的时候自动初始化,不注册不初始化
void BSPInit()
{
DWT_Init(168);
BSPLogInit();
// legacy support待删除,将在实现了led/tempctrl/buzzer的module之后移动到app层进行XXXRegister()
LEDInit();
IMUTempInit();
}

View File

@ -1,13 +1,24 @@
#ifndef BSP_INIT_h
#define BSP_INIT_h
#include "bsp_init.h"
#include "bsp_log.h"
#include "bsp_dwt.h"
#include "bsp_usb.h"
/**
* @brief bsp层初始化统一入口,bsp组件,
* ,RobotoInit()
*
* @note CAN和串口会在注册实例的时候自动初始化,
*/
void BSPInit();
//
void BSPInit()
{
DWT_Init(168);
BSPLogInit();
}
#endif // !BSP_INIT_h

View File

@ -1,29 +0,0 @@
#include "bsp_led.h"
#include "main.h"
#warning this is a legacy support file, please use the new version
extern TIM_HandleTypeDef htim5;
static uint8_t tmp_output_level = 0;
void LEDInit()
{
HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_2);
HAL_TIM_PWM_Start(&htim5, TIM_CHANNEL_3);
}
void FlowRGBShow(uint32_t aRGB)
{
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;
__HAL_TIM_SetCompare(&htim5, TIM_CHANNEL_1, blue);
__HAL_TIM_SetCompare(&htim5, TIM_CHANNEL_2, green);
__HAL_TIM_SetCompare(&htim5, TIM_CHANNEL_3, red);
}

View File

@ -1,9 +0,0 @@
#ifndef BSP_LED_H
#define BSP_LED_H
#include <stdint.h>
void LEDInit();
extern void FlowRGBShow(uint32_t aRGB);
#endif

View File

@ -1,15 +0,0 @@
#include "bsp_temperature.h"
#warning this is a legacy support file, please use the new version
extern TIM_HandleTypeDef htim10;
void IMUTempInit()
{
HAL_TIM_PWM_Start(&htim10, TIM_CHANNEL_1);
}
void IMUPWMSet(uint16_t pwm)
{
__HAL_TIM_SetCompare(&htim10, TIM_CHANNEL_1, pwm);
}

View File

@ -1,10 +0,0 @@
#ifndef __BSP_IMU_PWM_H
#define __BSP_IMU_PWM_H
#include "stdint.h"
#include "tim.h"
void IMUTempInit();
extern void IMUPWMSet(uint16_t pwm);
#endif

View File

@ -1,5 +0,0 @@
# legacy bsp
这些bsp实现将在v0.1删除,因为他们实际上都是用pwm实现的,应当放在module层,以彻底隔离bsp和CubeMX的初始化代码.现已提供了bsp_pwm的实现.
之后在修改CubeMX的初始化配置之后就不再需要修改bsp的内容了,所有的修改都会通过app层的初始化配置`xxx_Init_Config_s`来实现.

View File

@ -2,6 +2,7 @@
#include "buzzer.h"
#include "bsp_dwt.h"
#include "string.h"
static PWMInstance *buzzer;
static uint8_t idx;
static BuzzzerInstance *buzzer_list[BUZZER_DEVICE_CNT] = {0};
@ -10,11 +11,11 @@ static BuzzzerInstance *buzzer_list[BUZZER_DEVICE_CNT] = {0};
* @brief
*
*/
void buzzer_init()
void BuzzerInit()
{
PWM_Init_Config_s buzzer_config = {
.htim = &htim4,
.channel= TIM_CHANNEL_3,
.channel = TIM_CHANNEL_3,
.dutyratio = 0,
.period = 0.001,
};
@ -36,7 +37,6 @@ BuzzzerInstance *BuzzerRegister(Buzzer_config_s *config)
buzzer_list[config->alarm_level] = buzzer_temp;
return buzzer_temp;
}
void AlarmSetStatus(BuzzzerInstance *buzzer, AlarmState_e state)
@ -50,11 +50,11 @@ void BuzzerTask()
for (size_t i = 0; i < BUZZER_DEVICE_CNT; ++i)
{
buzz = buzzer_list[i];
if(buzz->alarm_level > ALARM_LEVEL_LOW)
if (buzz->alarm_level > ALARM_LEVEL_LOW)
{
continue;
}
if(buzz->alarm_state == ALARM_OFF)
if (buzz->alarm_state == ALARM_OFF)
{
PWMSetDutyRatio(buzzer, 0);
}
@ -64,34 +64,28 @@ void BuzzerTask()
switch (buzz->octave)
{
case OCTAVE_1:
PWMSetPeriod(buzzer, (float)1/DoFreq);
PWMSetPeriod(buzzer, (float)1 / DoFreq);
break;
case OCTAVE_2:
PWMSetPeriod(buzzer, (float)1/ReFreq);
PWMSetPeriod(buzzer, (float)1 / ReFreq);
break;
case OCTAVE_3:
PWMSetPeriod(buzzer, (float)1/MiFreq);
PWMSetPeriod(buzzer, (float)1 / MiFreq);
break;
case OCTAVE_4:
PWMSetPeriod(buzzer, (float)1/FaFreq);
PWMSetPeriod(buzzer, (float)1 / FaFreq);
break;
case OCTAVE_5:
PWMSetPeriod(buzzer, (float)1/SoFreq);
PWMSetPeriod(buzzer, (float)1 / SoFreq);
break;
case OCTAVE_6:
PWMSetPeriod(buzzer, (float)1/LaFreq);
PWMSetPeriod(buzzer, (float)1 / LaFreq);
break;
case OCTAVE_7:
PWMSetPeriod(buzzer, (float)1/SiFreq);
PWMSetPeriod(buzzer, (float)1 / SiFreq);
break;
}
break;
}
}
}

View File

@ -53,7 +53,7 @@ typedef struct
}BuzzzerInstance;
void buzzer_init();
void BuzzerInit();
void BuzzerTask();
BuzzzerInstance *BuzzerRegister(Buzzer_config_s *config);
void AlarmSetStatus(BuzzzerInstance *buzzer, AlarmState_e state);

View File

@ -5,7 +5,7 @@
#include "bsp_log.h"
#include <math.h>
#warning this is a legacy support. test the new BMI088 module as soon as possible.
#pragma message "this is a legacy support. test the new BMI088 module as soon as possible."
float BMI088_ACCEL_SEN = BMI088_ACCEL_6G_SEN;
float BMI088_GYRO_SEN = BMI088_GYRO_2000_SEN;

View File

@ -14,8 +14,8 @@
#include "ins_task.h"
#include "controller.h"
#include "QuaternionEKF.h"
#include "bsp_temperature.h"
#include "spi.h"
#include "tim.h"
#include "user_lib.h"
#include "general_def.h"
#include "master_process.h"
@ -35,6 +35,11 @@ static float RefTemp = 40; // 恒温设定温度
static void IMU_Param_Correction(IMU_Param_t *param, float gyro[3], float accel[3]);
static void IMUPWMSet(uint16_t pwm)
{
__HAL_TIM_SetCompare(&htim10, TIM_CHANNEL_1, pwm);
}
/**
* @brief
*
@ -79,6 +84,8 @@ attitude_t *INS_Init(void)
else
return (attitude_t *)&INS.Gyro;
HAL_TIM_PWM_Start(&htim10, TIM_CHANNEL_1);
while (BMI088Init(&hspi1, 1) != BMI088_NO_ERROR)
;
IMU_Param.scale[X] = 1;

View File

@ -34,6 +34,13 @@ void LEDSwitch(LEDInstance *_led, uint8_t led_switch)
}
}
void LEDShow()
void LEDShow(uint32_t aRGB)
{
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;
}

3
modules/led/led.md Normal file
View File

@ -0,0 +1,3 @@
TO BE DONE
请勿使用

View File

@ -1,8 +0,0 @@
# led_task
<p align='right'>neozng1@hnu.edu.cn</p>
> TODO:
> 1. 预计添加不同错误标志,将错误类型和灯的闪烁频率或颜色等对应起来,方便调试
这是legacy support,后续将使用bsp_pwm进行重构

View File

@ -1,59 +0,0 @@
/**
* @file led_task.c
* @author DJI RM
* @author modified by NeoZeng neozng1@hnu.edu.cn
* @brief
* @version 0.1
* @date 2022-11-30
*
* @copyright Copyright (c) 2022
*
*/
#warning this is a legacy support file, please build the new 'led' module as soon as possible
#include "led_task.h"
#include <stdint.h>
#include "bsp_led.h"
#include "main.h"
#define RGB_FLOW_COLOR_CHANGE_TIME 1000
#define RGB_FLOW_COLOR_LENGHT 6
// 蓝 -> 绿(灭) -> 红 -> 蓝(灭) -> 绿 -> 红(灭) -> 蓝
uint32_t RGB_flow_color[RGB_FLOW_COLOR_LENGHT + 1] = {0xFF0000FF, 0x0000FF00, 0xFFFF0000, 0x000000FF, 0xFF00FF00, 0x00FF0000, 0xFF0000FF};
void led_RGB_flow_task()
{
static float delta_alpha, delta_red, delta_green, delta_blue;
static float alpha, red, green, blue;
static uint32_t aRGB;
for (size_t i = 0; i < RGB_FLOW_COLOR_LENGHT; ++i)
{
alpha = (RGB_flow_color[i] & 0xFF000000) >> 24;
red = ((RGB_flow_color[i] & 0x00FF0000) >> 16);
green = ((RGB_flow_color[i] & 0x0000FF00) >> 8);
blue = ((RGB_flow_color[i] & 0x000000FF) >> 0);
delta_alpha = (float)((RGB_flow_color[i + 1] & 0xFF000000) >> 24) - (float)((RGB_flow_color[i] & 0xFF000000) >> 24);
delta_red = (float)((RGB_flow_color[i + 1] & 0x00FF0000) >> 16) - (float)((RGB_flow_color[i] & 0x00FF0000) >> 16);
delta_green = (float)((RGB_flow_color[i + 1] & 0x0000FF00) >> 8) - (float)((RGB_flow_color[i] & 0x0000FF00) >> 8);
delta_blue = (float)((RGB_flow_color[i + 1] & 0x000000FF) >> 0) - (float)((RGB_flow_color[i] & 0x000000FF) >> 0);
delta_alpha /= RGB_FLOW_COLOR_CHANGE_TIME;
delta_red /= RGB_FLOW_COLOR_CHANGE_TIME;
delta_green /= RGB_FLOW_COLOR_CHANGE_TIME;
delta_blue /= RGB_FLOW_COLOR_CHANGE_TIME;
for (size_t j = 0; j < RGB_FLOW_COLOR_CHANGE_TIME; ++j)
{
alpha += delta_alpha;
red += delta_red;
green += delta_green;
blue += delta_blue;
aRGB = ((uint32_t)(alpha)) << 24 | ((uint32_t)(red)) << 16 | ((uint32_t)(green)) << 8 | ((uint32_t)(blue)) << 0;
FlowRGBShow(aRGB);
}
}
}

View File

@ -1,7 +0,0 @@
#ifndef LED_TRIGGER_TASK_H
#define LED_TRIGGER_TASK_H
void led_RGB_flow_task();
#endif

View File

@ -1,14 +1,13 @@
# MUST & MUSTNOTMUSTNOT
## 禁止过度摸鱼
提供工作效率!
## 禁止在临界区使用延时,这会导致因中断关闭使得定时器无法进入中断更新时间,进而卡死系统
除非你使用的是基于计数寄存器差值的延时方法,或阻塞式的for延时。
**若有必要,应该使用`bsp_dwt.h`提供的接口。
## 禁止摸鱼
提供工作效率!
## 禁止图方便直接将电机/电调连接在开发板的xt30接口上否则电机的反电动势可能烧毁开发板
后续考虑增加一个xt30转接器其上实现隔离电路再连接开发板充当分电板。
@ -18,3 +17,7 @@
用于调试的条件编译和若有可能log输出也是必须的。
另外“treat your user as idot
## NO WARNING
makefile中已经启用了`-Werror`选项所有的warning都会被视为error别妄图带着warning通过编译