From 4c6892e4db0be45ccfaaf7cfb807eb4c8f2bb821 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Wed, 15 Apr 2026 16:37:33 +0200 Subject: [PATCH] mimxrt/machine_can: Define CAN_HW_MAX_FILTER and CAN_TX_QUEUE_LEN. These were define with default values, but port specific values can be used instead. Signed-off-by: robert-hh --- ports/mimxrt/machine_can.c | 5 +++-- ports/mimxrt/mpconfigport.h | 6 ------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/ports/mimxrt/machine_can.c b/ports/mimxrt/machine_can.c index c9d7a09a7c..b8bd82b7da 100644 --- a/ports/mimxrt/machine_can.c +++ b/ports/mimxrt/machine_can.c @@ -76,8 +76,9 @@ #define CAN_SJW_MAX ((CAN_CTRL1_RJW_MASK >> CAN_CTRL1_RJW_SHIFT) + 1) #define CAN_USE_UPSTREAM_TIMING (1) -#define CAN_IDFILTERNUM_MAX (((CAN_CTRL2_RFFN_MASK >> CAN_CTRL2_RFFN_SHIFT) + 1) * 8) +#define CAN_HW_MAX_FILTER (((CAN_CTRL2_RFFN_MASK >> CAN_CTRL2_RFFN_SHIFT) + 1) * 8) #define CAN_FILTER_MASK_NUM (64) +#define CAN_TX_QUEUE_LEN (64 - 7 - (CAN_HW_MAX_FILTER / 4)) // matches fsl_flexcan.c enum _flexcan_mb_code_tx #define kFLEXCAN_TxMbInactive (0x8) @@ -264,7 +265,7 @@ static void machine_can_port_init(machine_can_obj_t *self) { // Set the number of filters here. RFFN will be set accordingly. // This largest possible value is (CAN_CTRL2_RFFN_MASK >> CAN_CTRL2_RFFN_SHIFT) + 1) * 8. // If needed, lower these in steps of 8. - mp_uint_t idFilterNum = CAN_IDFILTERNUM_MAX; + mp_uint_t idFilterNum = CAN_HW_MAX_FILTER; port->flexcan_rx_fifo_config->idFilterNum = idFilterNum; port->flexcan_rx_fifo_config->idFilterType = kFLEXCAN_RxFifoFilterTypeA; port->flexcan_rx_fifo_config->priority = kFLEXCAN_RxFifoPrioHigh; diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index 338fd88760..bd9adf4664 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -110,12 +110,6 @@ uint32_t trng_random_u32(void); #ifndef MICROPY_HW_CAN_IS_RESERVED #define MICROPY_HW_CAN_IS_RESERVED(can_id) (false) #endif -#ifndef CAN_TX_QUEUE_LEN -#define CAN_TX_QUEUE_LEN (16) // Must be checked -#endif -#ifndef CAN_HW_MAX_FILTER -#define CAN_HW_MAX_FILTER (128) -#endif #ifndef MICROPY_PY_MACHINE_I2C_TARGET #define MICROPY_PY_MACHINE_I2C_TARGET (1) #define MICROPY_PY_MACHINE_I2C_TARGET_INCLUDEFILE "ports/mimxrt/machine_i2c_target.c"