This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 2070a1c273c8544689fa747464daa1b78846acee Author: raiden00pl <[email protected]> AuthorDate: Thu Nov 26 09:16:13 2026 +0100 arch/arm/stm32: Fix the bxCAN CAN2 filter handling. The CAN2 filter banks are in the CAN1 register block. The CAN2SB update masked FMR with CAN_FMR_CAN2SB_MASK instead of its complement, which cleared FINIT before the filter banks were written, and closing CAN1 reset it through RCC, which stopped CAN2 reception. Clear only the CAN2SB field and, while CAN2 is set up, only stop CAN1. The SocketCAN driver gets the reset fix with its netdev lower half conversion. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: raiden00pl <[email protected]> --- arch/arm/src/common/stm32/stm32_can_bxcan.c | 19 ++++++++++++++++++- arch/arm/src/common/stm32/stm32_can_bxcan_sock.c | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/arm/src/common/stm32/stm32_can_bxcan.c b/arch/arm/src/common/stm32/stm32_can_bxcan.c index 15547417789..540b08f1ca8 100644 --- a/arch/arm/src/common/stm32/stm32_can_bxcan.c +++ b/arch/arm/src/common/stm32/stm32_can_bxcan.c @@ -105,6 +105,7 @@ struct stm32_can_s uint32_t base; /* Base address of the CAN control registers */ uint32_t fbase; /* Base address of the CAN filter registers */ uint32_t baud; /* Configured baud */ + bool active; /* Between setup and shutdown */ }; /**************************************************************************** @@ -624,6 +625,19 @@ static void stm32can_reset(struct can_dev_s *dev) #ifdef CONFIG_STM32_CAN1 if (priv->port == 1) { +#ifdef CONFIG_STM32_CAN2 + /* The CAN2 filter banks are in CAN1: only stop CAN1 */ + + if (g_can2priv.active) + { + stm32can_putreg(priv, STM32_CAN_IER_OFFSET, 0); + regval = stm32can_getreg(priv, STM32_CAN_MCR_OFFSET); + regval |= CAN_MCR_INRQ; + stm32can_putreg(priv, STM32_CAN_MCR_OFFSET, regval); + return; + } +#endif + regbit = CAN_RCC_CAN1RST; } else @@ -775,6 +789,7 @@ static int stm32can_setup(struct can_dev_s *dev) #ifdef CONFIG_CAN_ERRORS up_enable_irq(priv->cansce); #endif + priv->active = true; return OK; } @@ -799,6 +814,8 @@ static void stm32can_shutdown(struct can_dev_s *dev) caninfo("CAN%" PRIu8 "\n", priv->port); + priv->active = false; + /* Disable the RX FIFO 0/1, TX and SCE interrupts */ up_disable_irq(priv->canrx[0]); @@ -2319,7 +2336,7 @@ static int stm32can_filterinit(struct stm32_can_s *priv) defined(CONFIG_STM32_STM32F20XX) || \ defined(CONFIG_STM32_STM32F4XXX) regval = stm32can_getfreg(priv, STM32_CAN_FMR_OFFSET); - regval &= CAN_FMR_CAN2SB_MASK; + regval &= ~CAN_FMR_CAN2SB_MASK; regval |= (CAN_NFILTERS / 2) << CAN_FMR_CAN2SB_SHIFT; stm32can_putfreg(priv, STM32_CAN_FMR_OFFSET, regval); #endif diff --git a/arch/arm/src/common/stm32/stm32_can_bxcan_sock.c b/arch/arm/src/common/stm32/stm32_can_bxcan_sock.c index bd6507c24cf..40d8b751e00 100644 --- a/arch/arm/src/common/stm32/stm32_can_bxcan_sock.c +++ b/arch/arm/src/common/stm32/stm32_can_bxcan_sock.c @@ -2314,7 +2314,7 @@ static int stm32can_filterinit(struct stm32_can_s *priv) defined(CONFIG_STM32_STM32F20XX) || \ defined(CONFIG_STM32_STM32F4XXX) regval = stm32can_getfreg(priv, STM32_CAN_FMR_OFFSET); - regval &= CAN_FMR_CAN2SB_MASK; + regval &= ~CAN_FMR_CAN2SB_MASK; regval |= (CAN_NFILTERS / 2) << CAN_FMR_CAN2SB_SHIFT; stm32can_putfreg(priv, STM32_CAN_FMR_OFFSET, regval); #endif
