diff --git a/.DS_Store b/.DS_Store index 7169f00..2690b1b 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/bsp/fdcan/fdcan.c b/bsp/fdcan/fdcan.c index 6c6221f..481548d 100644 --- a/bsp/fdcan/fdcan.c +++ b/bsp/fdcan/fdcan.c @@ -21,19 +21,19 @@ #define FDCAN1_FILTER_CONFIG_TABLE(X) \ X(0, FDCAN_STANDARD_ID, FDCAN_FILTER_MASK, 0x000 , 0x000 , 0) \ X(1, FDCAN_EXTENDED_ID, FDCAN_FILTER_MASK, 0x00000000, 0x00000000, 0) - #define FDCAN1_GLOBAL_FILTER FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE/* 全局过滤器参数(用于 HAL_FDCAN_ConfigGlobalFilter) */ + #define FDCAN1_GLOBAL_FILTER FDCAN_ACCEPT_IN_RX_FIFO0, FDCAN_ACCEPT_IN_RX_FIFO0, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE #endif #ifdef FDCAN2_EN #define FDCAN2_FILTER_CONFIG_TABLE(X) \ X(0, FDCAN_STANDARD_ID, FDCAN_FILTER_MASK, 0x000 , 0x000 , 0) \ X(1, FDCAN_EXTENDED_ID, FDCAN_FILTER_MASK, 0x00000000, 0x00000000, 0) - #define FDCAN2_GLOBAL_FILTER FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE/* 全局过滤器参数(用于 HAL_FDCAN_ConfigGlobalFilter) */ + #define FDCAN2_GLOBAL_FILTER FDCAN_ACCEPT_IN_RX_FIFO1, FDCAN_ACCEPT_IN_RX_FIFO1, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE #endif #ifdef FDCAN3_EN #define FDCAN3_FILTER_CONFIG_TABLE(X) \ X(0, FDCAN_STANDARD_ID, FDCAN_FILTER_MASK, 0x000 , 0x000 , 0) \ X(1, FDCAN_EXTENDED_ID, FDCAN_FILTER_MASK, 0x00000000, 0x00000000, 0) - #define FDCAN3_GLOBAL_FILTER FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE/* 全局过滤器参数(用于 HAL_FDCAN_ConfigGlobalFilter) */ + #define FDCAN3_GLOBAL_FILTER FDCAN_ACCEPT_IN_RX_FIFO1, FDCAN_ACCEPT_IN_RX_FIFO1, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE #endif /* ====宏展开实现==== */ diff --git a/component/freertos_cli/FreeRTOS_CLI.h b/component/freertos_cli/FreeRTOS_CLI.h index e6d8266..a3f792f 100644 --- a/component/freertos_cli/FreeRTOS_CLI.h +++ b/component/freertos_cli/FreeRTOS_CLI.h @@ -28,6 +28,9 @@ #ifndef COMMAND_INTERPRETER_H #define COMMAND_INTERPRETER_H +#include +#include "FreeRTOS.h" + /* This config should be defined in FreeRTOSConfig.h. But due to the limition of CubeMX I put it here. */ #define configCOMMAND_INT_MAX_OUTPUT_SIZE 512 diff --git a/component/limiter/limiter.c b/component/limiter/limiter.c index 71e4bf1..b7e8138 100644 --- a/component/limiter/limiter.c +++ b/component/limiter/limiter.c @@ -105,3 +105,8 @@ float HeatLimit_ShootFreq(float heat, float heat_limit, float cooling_rate, else return (heat_percent > 0.7f) ? stable_freq : 3.0f * stable_freq; } + + +/* USER CODE BEGIN */ + +/* USER CODE END */ \ No newline at end of file diff --git a/component/limiter/limiter.h b/component/limiter/limiter.h index d0aa92a..5853c73 100644 --- a/component/limiter/limiter.h +++ b/component/limiter/limiter.h @@ -61,3 +61,7 @@ float PowerLimit_TargetPower(float power_limit, float power_buffer); */ float HeatLimit_ShootFreq(float heat, float heat_limit, float cooling_rate, float heat_increase, bool is_big); + +/* USER CODE BEGIN */ + +/* USER CODE END */ \ No newline at end of file diff --git a/device/mrobot/mrobot.c b/device/mrobot/mrobot.c index e96471a..3a77112 100644 --- a/device/mrobot/mrobot.c +++ b/device/mrobot/mrobot.c @@ -120,7 +120,7 @@ static void send_string(const char *str) { if (str == NULL || *str == '\0') return; ctx.tx_complete = false; - BSP_UART_Transmit(MROBOT_UART_PORT, (uint8_t *)str, strlen(str), true); + BSP_UART_Transmit(BSP_UART_MROBOT, (uint8_t *)str, strlen(str), true); while (!ctx.tx_complete) { osDelay(1); } } @@ -151,7 +151,7 @@ static void uart_rx_callback(void) { if (ch == 'q' || ch == 'Q' || ch == 27) { ctx.htop_exit = true; } - BSP_UART_Receive(MROBOT_UART_PORT, &ctx.uart_rx_char, 1, false); + BSP_UART_Receive(BSP_UART_MROBOT, &ctx.uart_rx_char, 1, false); return; } @@ -160,19 +160,20 @@ static void uart_rx_callback(void) { if (ctx.cmd_index > 0) { ctx.cmd_buffer[ctx.cmd_index] = '\0'; ctx.cmd_ready = true; - BSP_UART_Transmit(MROBOT_UART_PORT, (uint8_t *)"\r\n", 2, false); + BSP_UART_Transmit(BSP_UART_MROBOT, (uint8_t *)"\r\n", 2, false); } } else if (ch == 127 || ch == 8) { /* 退格键 */ if (ctx.cmd_index > 0) { ctx.cmd_index--; - BSP_UART_Transmit(MROBOT_UART_PORT, (uint8_t *)ANSI_BACKSPACE, 3, false); + BSP_UART_Transmit(BSP_UART_MROBOT, (uint8_t *)ANSI_BACKSPACE, 3, false); } } else if (ch >= 32 && ch < 127 && ctx.cmd_index < sizeof(ctx.cmd_buffer) - 1) { ctx.cmd_buffer[ctx.cmd_index++] = ch; - BSP_UART_Transmit(MROBOT_UART_PORT, &ch, 1, false); + /* 回显:使用静态变量地址,避免异步发送时局部变量已失效 */ + BSP_UART_Transmit(BSP_UART_MROBOT, &ctx.uart_rx_char, 1, false); } - BSP_UART_Receive(MROBOT_UART_PORT, &ctx.uart_rx_char, 1, false); + BSP_UART_Receive(BSP_UART_MROBOT, &ctx.uart_rx_char, 1, false); } /* ========================================================================== */ @@ -483,9 +484,8 @@ void MRobot_Init(void) { /* 创建互斥锁 */ ctx.mutex = xSemaphoreCreateMutex(); - /* 初始化状态 */ - memset(ctx.devices, 0, sizeof(ctx.devices)); - ctx.device_count = 0; + /* 初始化状态(保留已注册的设备) */ + // 注意:不清除 devices 和 device_count,因为其他任务可能已经注册了设备 ctx.custom_cmd_count = 0; ctx.state = MROBOT_STATE_IDLE; strcpy(ctx.current_path, "/"); @@ -500,11 +500,11 @@ void MRobot_Init(void) { } /* 注册 UART 回调 */ - BSP_UART_RegisterCallback(MROBOT_UART_PORT, BSP_UART_RX_CPLT_CB, uart_rx_callback); - BSP_UART_RegisterCallback(MROBOT_UART_PORT, BSP_UART_TX_CPLT_CB, uart_tx_callback); + BSP_UART_RegisterCallback(BSP_UART_MROBOT, BSP_UART_RX_CPLT_CB, uart_rx_callback); + BSP_UART_RegisterCallback(BSP_UART_MROBOT, BSP_UART_TX_CPLT_CB, uart_tx_callback); /* 启动 UART 接收 */ - BSP_UART_Receive(MROBOT_UART_PORT, &ctx.uart_rx_char, 1, false); + BSP_UART_Receive(BSP_UART_MROBOT, &ctx.uart_rx_char, 1, false); /* 等待用户按下回车 */ while (ctx.uart_rx_char != '\r' && ctx.uart_rx_char != '\n') { diff --git a/device/mrobot/mrobot.h b/device/mrobot/mrobot.h index 74c0875..69d8b3a 100644 --- a/device/mrobot/mrobot.h +++ b/device/mrobot/mrobot.h @@ -143,10 +143,6 @@ extern "C" { #define MROBOT_HTOP_REFRESH_MS 200 /* htop 刷新间隔 (ms) */ #endif -#ifndef MROBOT_UART_PORT -#define MROBOT_UART_PORT BSP_UART_VOFA /* 默认 UART 端口 */ -#endif - #ifndef MROBOT_USER_NAME #define MROBOT_USER_NAME "root" /* CLI 用户名 */ #endif diff --git a/task/task.c.template b/task/task.c.template index e238fa2..807631e 100644 --- a/task/task.c.template +++ b/task/task.c.template @@ -18,6 +18,9 @@ /* USER STRUCT END */ /* Private function --------------------------------------------------------- */ +/* USER PRIVATE CODE BEGIN */ + +/* USER PRIVATE CODE END */ /* Exported functions ------------------------------------------------------- */ void {{task_function}}(void *argument) { (void)argument; /* 未使用argument,消除警告 */ diff --git a/task/template_task/cli.c b/task/template_task/cli.c new file mode 100644 index 0000000..29ae053 --- /dev/null +++ b/task/template_task/cli.c @@ -0,0 +1,52 @@ +/* + cli Task + +*/ + +/* Includes ----------------------------------------------------------------- */ +#include "task/user_task.h" +/* USER INCLUDE BEGIN */ +#include "device/mrobot.h" +/* USER INCLUDE END */ + +/* Private typedef ---------------------------------------------------------- */ +/* Private define ----------------------------------------------------------- */ +/* Private macro ------------------------------------------------------------ */ +/* Private variables -------------------------------------------------------- */ +/* USER STRUCT BEGIN */ + +/* USER STRUCT END */ + +/* Private function --------------------------------------------------------- */ +/* USER PRIVATE CODE BEGIN */ +/** + * @brief hello 命令回调 + * @note 命令回调必须返回 0 (pdFALSE) 表示完成,返回非0会继续调用 + */ +static long Cli_Hello(char *buffer, size_t size, const char *cmd) { + (void)cmd; /* 未使用cmd,消除警告 */ + MRobot_Snprintf(buffer, size, "Ciallo~(∠・ω< )⌒★\r\n"); + return 0; /* 返回0表示命令执行完成 */ +} +/* USER PRIVATE CODE END */ +/* Exported functions ------------------------------------------------------- */ +void Task_cli(void *argument) { + (void)argument; /* 未使用argument,消除警告 */ + + + osDelay(CLI_INIT_DELAY); /* 延时一段时间再开启任务 */ + + /* USER CODE INIT BEGIN */ + /* 初始化 MRobot CLI 系统 */ + MRobot_Init(); + MRobot_RegisterCommand("hello", " --hello: 打印问候语\r\n", Cli_Hello, -1); + /* USER CODE INIT END */ + + while (1) { + /* USER CODE BEGIN */ + /* 运行 MRobot 主循环 */ + MRobot_Run(); + /* USER CODE END */ + } + +} \ No newline at end of file diff --git a/task/template_task/task.yaml b/task/template_task/task.yaml index 5a6d279..2d63f85 100644 --- a/task/template_task/task.yaml +++ b/task/template_task/task.yaml @@ -1,7 +1,7 @@ atti_esti: name: "atti_esti" frequency: 1000 - delay: 100 + delay: 0 stack: 512 freq_control: false description: | @@ -16,3 +16,13 @@ atti_esti: - 陀螺仪使用前需要校准,校准结果保存在bmi088_cali结构体中 - 无磁力计版本,适用于干净的电磁环境 - 需要配置PWM通道用于IMU加热控制 +cli: + name: "cli" + frequency: 500 + delay: 0 + stack: 1024 + freq_control: false + description: | + 命令行接口任务 + 通过串口实现的虚拟终端,配合putty食用更佳 + 需要freertos_cli组件支持,还有mrobot设备驱动 \ No newline at end of file