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 c84b064a9da8011a6c99b89e17ea4458124d7469 Author: raiden00pl <[email protected]> AuthorDate: Wed Nov 25 21:53:56 2026 +0100 arch/arm/stm32: Fix the FDCAN v2 SocketCAN message RAM layout. The 128 extended filter elements are 2 words each, but only 1 word each was reserved, so the filter list overlapped RX FIFO0. Each interface got half of the RAM, which put FDCAN3 past its end. Split the RAM between the interfaces and check the layout at build time. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: raiden00pl <[email protected]> --- .../src/common/stm32/stm32_fdcan_mcan_v2_sock.c | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/arch/arm/src/common/stm32/stm32_fdcan_mcan_v2_sock.c b/arch/arm/src/common/stm32/stm32_fdcan_mcan_v2_sock.c index b039d761828..4a9f2fc60bb 100644 --- a/arch/arm/src/common/stm32/stm32_fdcan_mcan_v2_sock.c +++ b/arch/arm/src/common/stm32/stm32_fdcan_mcan_v2_sock.c @@ -127,6 +127,23 @@ # define NUM_TX_FIFO 32 /* 32 elements max for TX FIFO */ #endif +/* Message RAM of one interface: 128 standard filters (1 word), 128 + * extended filters (2 words), RX FIFO0 and the TX FIFO. + */ + +#ifdef CONFIG_STM32_FDCAN3 +# define FDCAN_NIFACES 3 +#else +# define FDCAN_NIFACES 2 +#endif + +#define FDCAN_RAM_WORDS (CANRAM_WORDS / FDCAN_NIFACES) + +#if 128 + 2 * 128 + (NUM_RX_FIFO0 + NUM_TX_FIFO) * FIFO_ELEMENT_SIZE > \ + FDCAN_RAM_WORDS +# error "FDCAN message RAM layout does not fit" +#endif + /* CAN Clock Configuration **************************************************/ #ifndef STM32_FDCANCLK @@ -1954,7 +1971,7 @@ int fdcan_initialize(struct fdcan_driver_s *priv) * overlapping region of RAM assigned to it by properly assigning the start * and end addresses for all regions of RAM. * - * We will give each interface half of the available RAM. + * Each enabled interface index gets an equal part of the RAM. * * Rx buffers are only used in conjunction with acceptance filters; we * don't have any specific need for this, so we will only use Rx FIFOs. @@ -1976,8 +1993,7 @@ int fdcan_initialize(struct fdcan_driver_s *priv) * and relative address (in words) used for configuration */ - const uint32_t iface_ram_base = - (CANRAM_WORDS / 2) * priv->iface_idx; + const uint32_t iface_ram_base = FDCAN_RAM_WORDS * priv->iface_idx; const uint32_t gl_ram_base = STM32_CANRAM_BASE; uint32_t ram_offset = iface_ram_base; @@ -2019,7 +2035,7 @@ int fdcan_initialize(struct fdcan_driver_s *priv) regval = (n_extid << FDCAN_XIDFC_LSE_SHIFT) & FDCAN_XIDFC_LSE_MASK; regval |= ram_offset << FDCAN_XIDFC_FLESA_SHIFT; putreg32(regval, priv->base + STM32_FDCAN_XIDFC_OFFSET); - ram_offset += n_extid; + ram_offset += 2 * n_extid; /* Extended filter elements are 2 words */ /* Set size of each element in the Rx/Tx buffers and FIFOs */
