From f5d5f53914d46dfccdd21399e44f8af71a8f345a Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 11 Jun 2022 18:19:53 -0400 Subject: [PATCH] stm32: Add support for disabling the canbus filter Signed-off-by: Kevin O'Connor --- src/Kconfig | 3 +++ src/stm32/can.c | 20 +++++++++++++------- src/stm32/fdcan.c | 2 ++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Kconfig b/src/Kconfig index eba05243..79cb4182 100644 --- a/src/Kconfig +++ b/src/Kconfig @@ -83,6 +83,9 @@ config CANSERIAL config CANBUS_FREQUENCY int "CAN bus speed" if LOW_LEVEL_OPTIONS && CANSERIAL default 500000 +config CANBUS_FILTER + bool + default y if CANSERIAL # Support setting gpio state at startup config INITIAL_PINS diff --git a/src/stm32/can.c b/src/stm32/can.c index 9cd72209..6e50cea9 100644 --- a/src/stm32/can.c +++ b/src/stm32/can.c @@ -136,13 +136,19 @@ canbus_set_filter(uint32_t id) /* Initialisation mode for the filter */ SOC_CAN->FA1R = 0; - uint32_t mask = CAN_TI0R_STID | CAN_TI0R_IDE | CAN_TI0R_RTR; - SOC_CAN->sFilterRegister[0].FR1 = CANBUS_ID_ADMIN << CAN_RI0R_STID_Pos; - SOC_CAN->sFilterRegister[0].FR2 = mask; - SOC_CAN->sFilterRegister[1].FR1 = (id + 1) << CAN_RI0R_STID_Pos; - SOC_CAN->sFilterRegister[1].FR2 = mask; - SOC_CAN->sFilterRegister[2].FR1 = id << CAN_RI0R_STID_Pos; - SOC_CAN->sFilterRegister[2].FR2 = mask; + if (CONFIG_CANBUS_FILTER) { + uint32_t mask = CAN_TI0R_STID | CAN_TI0R_IDE | CAN_TI0R_RTR; + SOC_CAN->sFilterRegister[0].FR1 = CANBUS_ID_ADMIN << CAN_RI0R_STID_Pos; + SOC_CAN->sFilterRegister[0].FR2 = mask; + SOC_CAN->sFilterRegister[1].FR1 = (id + 1) << CAN_RI0R_STID_Pos; + SOC_CAN->sFilterRegister[1].FR2 = mask; + SOC_CAN->sFilterRegister[2].FR1 = id << CAN_RI0R_STID_Pos; + SOC_CAN->sFilterRegister[2].FR2 = mask; + } else { + SOC_CAN->sFilterRegister[0].FR1 = 0; + SOC_CAN->sFilterRegister[0].FR2 = 0; + id = 0; + } /* 32-bit scale for the filter */ SOC_CAN->FS1R = (1<<0) | (1<<1) | (1<<2); diff --git a/src/stm32/fdcan.c b/src/stm32/fdcan.c index cf2cc276..3af9ffa8 100755 --- a/src/stm32/fdcan.c +++ b/src/stm32/fdcan.c @@ -113,6 +113,8 @@ can_filter(uint32_t index, uint32_t id) void canbus_set_filter(uint32_t id) { + if (!CONFIG_CANBUS_FILTER) + return; /* Request initialisation */ SOC_CAN->CCCR |= FDCAN_CCCR_INIT; /* Wait the acknowledge */