Skip to content

Commit b913fa6

Browse files
committed
drivers: can: m_can variant for STM32H7
* New m_can driver variant for STM32H7, as it uses the complete m_can register set. * Fix definitions for CAN_MCAN_RXF0S_F0FL, CAN_MCAN_TXEFC_EFSA_POS. Signed-off-by: Jeremy Wood <[email protected]>
1 parent c025abd commit b913fa6

File tree

7 files changed

+365
-22
lines changed

7 files changed

+365
-22
lines changed

drivers/can/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ zephyr_library_sources_ifdef(CONFIG_CAN_MCUX_FLEXCAN can_mcux_flexcan.c)
1111
zephyr_library_sources_ifdef(CONFIG_CAN_SAM can_sam.c)
1212
zephyr_library_sources_ifdef(CONFIG_CAN_STM32 can_stm32.c)
1313
zephyr_library_sources_ifdef(CONFIG_CAN_STM32FD can_stm32fd.c)
14+
zephyr_library_sources_ifdef(CONFIG_CAN_STM32H7 can_stm32h7.c)
1415
zephyr_library_sources_ifdef(CONFIG_CAN_RCAR can_rcar.c)
1516

1617
zephyr_library_sources_ifdef(CONFIG_USERSPACE can_handlers.c)

drivers/can/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ config CAN_AUTO_BUS_OFF_RECOVERY
9696
source "drivers/can/Kconfig.sam"
9797
source "drivers/can/Kconfig.stm32"
9898
source "drivers/can/Kconfig.stm32fd"
99+
source "drivers/can/Kconfig.stm32h7"
99100
source "drivers/can/Kconfig.mcux"
100101
source "drivers/can/Kconfig.mcp2515"
101102
source "drivers/can/Kconfig.mcan"

drivers/can/Kconfig.mcan

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ config CAN_MCAN
1010
help
1111
Enable Bosch m_can driver.
1212
This driver supports the Bosch m_can IP. This IP is built into the
13-
STM32G4, STM32G0 and the Microchip SAM controllers with CAN-FD.
13+
STM32G4, STM32G0, STM32H7, and the Microchip SAM controllers with
14+
CAN-FD.
1415

1516
if CAN_MCAN
1617

drivers/can/Kconfig.stm32h7

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# STM32H7 FD-CAN configuration options
2+
3+
# Copyright (c) 2022 Blue Clover
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
DT_COMPAT_STM32_H7 := st,stm32h7-fdcan
7+
8+
config CAN_STM32H7
9+
bool "STM32H7 FDCAN driver"
10+
default $(dt_compat_enabled,$(DT_COMPAT_STM32_H7))
11+
select CAN_MCAN
12+
select USE_STM32_LL_RCC
13+
14+
if CAN_STM32H7
15+
16+
config CAN_MAX_STD_ID_FILTER
17+
int "Maximum number of std ID filters"
18+
default 28
19+
range 0 28
20+
help
21+
Defines the maximum number of filters with standard ID (11-bit)
22+
that can be attached.
23+
24+
config CAN_MAX_EXT_ID_FILTER
25+
int "Maximum number of ext ID filters"
26+
default 8
27+
range 0 8
28+
help
29+
Defines the maximum number of filters with extended ID (29-bit)
30+
that can be attached.
31+
32+
endif #CAN_STM32H7

drivers/can/can_mcan.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,14 @@ int can_mcan_init(const struct device *dev, const struct can_mcan_config *cfg,
297297
(can->crel & CAN_MCAN_CREL_DAY) >> CAN_MCAN_CREL_DAY_POS);
298298

299299
#ifndef CONFIG_CAN_STM32FD
300+
uint32_t mrba = 0;
301+
#ifdef CONFIG_CAN_STM32H7
302+
mrba = (uint32_t)msg_ram;
303+
#endif
300304
#ifdef CONFIG_CAN_MCUX_MCAN
301-
uint32_t mrba = (uint32_t)msg_ram & CAN_MCAN_MRBA_BA_MSK;
302-
305+
mrba = (uint32_t)msg_ram & CAN_MCAN_MRBA_BA_MSK;
303306
can->mrba = mrba;
307+
#endif
304308
can->sidfc = (((uint32_t)msg_ram->std_filt - mrba) & CAN_MCAN_SIDFC_FLSSA_MSK) |
305309
(ARRAY_SIZE(msg_ram->std_filt) << CAN_MCAN_SIDFC_LSS_POS);
306310
can->xidfc = (((uint32_t)msg_ram->ext_filt - mrba) & CAN_MCAN_XIDFC_FLESA_MSK) |
@@ -312,24 +316,8 @@ int can_mcan_init(const struct device *dev, const struct can_mcan_config *cfg,
312316
can->rxbc = (((uint32_t)msg_ram->rx_buffer - mrba) & CAN_MCAN_RXBC_RBSA);
313317
can->txefc = (((uint32_t)msg_ram->tx_event_fifo - mrba) & CAN_MCAN_TXEFC_EFSA_MSK) |
314318
(ARRAY_SIZE(msg_ram->tx_event_fifo) << CAN_MCAN_TXEFC_EFS_POS);
315-
can->txbc = (((uint32_t)msg_ram->tx_buffer - mrba) & CAN_MCAN_TXBC_TBSA_MSK) |
316-
(ARRAY_SIZE(msg_ram->tx_buffer) << CAN_MCAN_TXBC_TFQS_POS);
317-
#else /* CONFIG_CAN_MCUX_MCAN */
318-
can->sidfc = ((uint32_t)msg_ram->std_filt & CAN_MCAN_SIDFC_FLSSA_MSK) |
319-
(ARRAY_SIZE(msg_ram->std_filt) << CAN_MCAN_SIDFC_LSS_POS);
320-
can->xidfc = ((uint32_t)msg_ram->ext_filt & CAN_MCAN_XIDFC_FLESA_MSK) |
321-
(ARRAY_SIZE(msg_ram->ext_filt) << CAN_MCAN_XIDFC_LSS_POS);
322-
can->rxf0c = ((uint32_t)msg_ram->rx_fifo0 & CAN_MCAN_RXF0C_F0SA) |
323-
(ARRAY_SIZE(msg_ram->rx_fifo0) << CAN_MCAN_RXF0C_F0S_POS);
324-
can->rxf1c = ((uint32_t)msg_ram->rx_fifo1 & CAN_MCAN_RXF1C_F1SA) |
325-
(ARRAY_SIZE(msg_ram->rx_fifo1) << CAN_MCAN_RXF1C_F1S_POS);
326-
can->rxbc = ((uint32_t)msg_ram->rx_buffer & CAN_MCAN_RXBC_RBSA);
327-
can->txefc = ((uint32_t)msg_ram->tx_event_fifo & CAN_MCAN_TXEFC_EFSA_MSK) |
328-
(ARRAY_SIZE(msg_ram->tx_event_fifo) <<
329-
CAN_MCAN_TXEFC_EFS_POS);
330-
can->txbc = ((uint32_t)msg_ram->tx_buffer & CAN_MCAN_TXBC_TBSA) |
331-
(ARRAY_SIZE(msg_ram->tx_buffer) << CAN_MCAN_TXBC_TFQS_POS);
332-
#endif /* !CONFIG_CAN_MCUX_MCAN */
319+
can->txbc = (((uint32_t)msg_ram->tx_buffer - mrba) & CAN_MCAN_TXBC_TBSA) |
320+
(ARRAY_SIZE(msg_ram->tx_buffer) << CAN_MCAN_TXBC_TFQS_POS);
333321

334322
if (sizeof(msg_ram->tx_buffer[0].data) <= 24) {
335323
can->txesc = (sizeof(msg_ram->tx_buffer[0].data) - 8) / 4;

drivers/can/can_mcan_int.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@
10841084

10851085
/* Rx FIFO 0 Fill Level */
10861086
#define CAN_MCAN_RXF0S_F0FL_POS (0U)
1087-
#define CAN_MCAN_RXF0S_F0FL_MSK (0x3FUL << CAN_MCAN_RXF0S_F0FL_POS)
1087+
#define CAN_MCAN_RXF0S_F0FL_MSK (0x7FUL << CAN_MCAN_RXF0S_F0FL_POS)
10881088
#define CAN_MCAN_RXF0S_F0FL CAN_MCAN_RXF0S_F0FL_MSK
10891089
/* Rx FIFO 0 Get Index */
10901090
#define CAN_MCAN_RXF0S_F0GI_POS (8U)

0 commit comments

Comments
 (0)