Skip to content

Commit 9aaee91

Browse files
committed
arch/arm/src/stm32h7/stm32_fdcan_sock: fix clock, ILS register and extended ID filter
Fix three issues in the STM32H7 FDCAN SocketCAN driver: 1. Clock configuration: Allow board.h to override STM32_FDCANCLK. Previously the driver hardcoded STM32_HSE_FREQUENCY, ignoring any board-specific clock configuration. 2. ILS register bug: Fix putreg32 call that was writing FDCAN_ILS_TCL constant instead of the computed regval, causing interrupt routing issues. 3. Extended ID filter size: Increase n_extid from 64 to 128. Despite the reference manual (RM0433) suggesting 64 max, testing shows that 128 is required for reliable extended ID frame reception. With 64, some extended ID frames were silently dropped. Signed-off-by: Vinicius May <vmay.sweden@gmail.com>
1 parent 5024a67 commit 9aaee91

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

arch/arm/src/stm32h7/stm32_fdcan_sock.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,11 @@
142142

143143
/* CAN Clock Configuration **************************************************/
144144

145-
#define STM32_FDCANCLK STM32_HSE_FREQUENCY
145+
#ifndef STM32_FDCANCLK
146+
# define STM32_FDCANCLK STM32_HSE_FREQUENCY
147+
#endif
146148
#define CLK_FREQ STM32_FDCANCLK
149+
147150
#define PRESDIV_MAX 256
148151

149152
/* Interrupts ***************************************************************/
@@ -2062,6 +2065,10 @@ int fdcan_initialize(struct fdcan_driver_s *priv)
20622065

20632066
fdcan_setconfig(priv->base, 1);
20642067

2068+
/* Clear Message RAM */
2069+
2070+
memset((void *)STM32_CANRAM_BASE, 0, 2560 * 4);
2071+
20652072
/* Disable interrupts while we configure the hardware */
20662073

20672074
putreg32(0, priv->base + STM32_FDCAN_IE_OFFSET);
@@ -2183,7 +2190,7 @@ int fdcan_initialize(struct fdcan_driver_s *priv)
21832190

21842191
regval = getreg32(priv->base + STM32_FDCAN_ILS_OFFSET);
21852192
regval |= FDCAN_ILS_TCL;
2186-
putreg32(FDCAN_ILS_TCL, priv->base + STM32_FDCAN_ILS_OFFSET);
2193+
putreg32(regval, priv->base + STM32_FDCAN_ILS_OFFSET);
21872194

21882195
/* Enable Tx buffer transmission interrupts
21892196
* Note: Still need fdcan_enable_interrupts() to set ILE (IR line enable)
@@ -2247,9 +2254,13 @@ int fdcan_initialize(struct fdcan_driver_s *priv)
22472254
*
22482255
* Discussion:
22492256
* https://community.st.com/s/question/0D73W000001nzqFSAQ
2257+
*
2258+
* vmay23
2259+
* Using 64 --> some messages are being received but some are not
2260+
* Using 128 --> according to the tests, everything is working fine
22502261
*/
22512262

2252-
const uint8_t n_extid = 64;
2263+
const uint8_t n_extid = 128;
22532264
priv->message_ram.filt_extid_addr = gl_ram_base + ram_offset * WORD_LENGTH;
22542265

22552266
regval = (n_extid << FDCAN_XIDFC_LSE_SHIFT) & FDCAN_XIDFC_LSE_MASK;
@@ -2284,7 +2295,9 @@ int fdcan_initialize(struct fdcan_driver_s *priv)
22842295

22852296
regval = (ram_offset << FDCAN_RXF0C_F0SA_SHIFT) & FDCAN_RXF0C_F0SA_MASK;
22862297
regval |= (NUM_RX_FIFO0 << FDCAN_RXF0C_F0S_SHIFT) & FDCAN_RXF0C_F0S_MASK;
2298+
22872299
putreg32(regval, priv->base + STM32_FDCAN_RXF0C_OFFSET);
2300+
22882301
ram_offset += NUM_RX_FIFO0 * FIFO_ELEMENT_SIZE;
22892302

22902303
/* Not using Rx FIFO1 */

0 commit comments

Comments
 (0)