From 522d6a45458edbfbc0039037a8157fc18a79d136 Mon Sep 17 00:00:00 2001 From: tuxmonkey Date: Tue, 24 Feb 2026 16:43:57 +0800 Subject: [PATCH] CAN CAN NEED --- User_Code/bsp/fdcan/bsp_fdcan.c | 3 ++- User_Code/bsp/fdcan/bsp_fdcan.h | 17 ++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/User_Code/bsp/fdcan/bsp_fdcan.c b/User_Code/bsp/fdcan/bsp_fdcan.c index 66edefe..d388907 100644 --- a/User_Code/bsp/fdcan/bsp_fdcan.c +++ b/User_Code/bsp/fdcan/bsp_fdcan.c @@ -4,6 +4,7 @@ #include "stdlib.h" #include "bsp_dwt.h" #include "bsp_log.h" +//说是fdcan实际上就是配置成了经典的CAN /* can instance ptrs storage, used for recv callback */ // 在CAN产生接收中断会遍历数组,选出hcan和rxid与发生中断的实例相同的那个,调用其回调函数 @@ -251,7 +252,7 @@ void CANSetDLC(FDCANInstance *_instance, uint8_t length) LOGERROR("[bsp_can] CAN DLC error! check your code or wild pointer"); } - _instance->txconf.DataLength = length; + _instance->txconf.DataLength = DLC_LookUp_Table[length]; } /* -----------------------belows are callback definitions--------------------------*/ diff --git a/User_Code/bsp/fdcan/bsp_fdcan.h b/User_Code/bsp/fdcan/bsp_fdcan.h index 7ee5a74..cb15357 100644 --- a/User_Code/bsp/fdcan/bsp_fdcan.h +++ b/User_Code/bsp/fdcan/bsp_fdcan.h @@ -1,5 +1,5 @@ -#ifndef BSP_CAN_H -#define BSP_CAN_H +#ifndef BSP_FDCAN_H +#define BSP_FDCAN_H //在此选择CAN类型,两者只能选择一个!!! #define FDCAN //G系列和H7系列使用FDCAN @@ -34,7 +34,18 @@ // 如果只有1个CAN,还需要把bsp_can.c中所有的hcan2变量改为hcan1(别担心,主要是总线和FIFO的负载均衡,不影响功能) #endif - +// 定义查找表 +static const uint32_t DLC_LookUp_Table[9] = { + FDCAN_DLC_BYTES_0, + FDCAN_DLC_BYTES_1, + FDCAN_DLC_BYTES_2, + FDCAN_DLC_BYTES_3, + FDCAN_DLC_BYTES_4, + FDCAN_DLC_BYTES_5, + FDCAN_DLC_BYTES_6, + FDCAN_DLC_BYTES_7, + FDCAN_DLC_BYTES_8 +}; /* can instance typedef, every module registered to CAN should have this variable */ #pragma pack(1)