Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions boards/arm/mr_canhubk3/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ SIUL2 on-chip | pinctrl
| external interrupt controller
LPUART on-chip serial
QSPI on-chip flash
FLEXCAN on-chip can
============ ========== ================================

The default configuration can be found in the Kconfig file
Expand Down Expand Up @@ -107,6 +108,73 @@ P6.2 PTA9 LPUART2_TX
P6.3 PTA8 LPUART2_RX
========= ===== ============

CAN
===

CAN is provided through FLEXCAN interface with 6 instances.

=============== ======= =============== =============
Devicetree node Pin Pin Function Bus Connector
=============== ======= =============== =============
flexcan0 | PTA6 | PTA6_CAN0_RX P12/P13
| PTA7 | PTA7_CAN0_TX
flexcan1 | PTC9 | PTC9_CAN0_RX P14/P15
| PTC8 | PTC8_CAN0_TX
flexcan2 | PTE25 | PTE25_CAN0_RX P16/P17
| PTE24 | PTE24_CAN0_TX
flexcan3 | PTC29 | PTC29_CAN0_RX P18/019
| PTC28 | PTC28_CAN0_TX
flexcan4 | PTC31 | PTC31_CAN0_RX P20/P21
| PTC30 | PTC30_CAN0_TX
flexcan5 | PTC11 | PTC11_CAN0_RX P22/P23
| PTC10 | PTC10_CAN0_TX
=============== ======= =============== =============

.. note::
There is limitation by HAL SDK, so CAN only has support maximum 64 message buffers (MBs)
and support maximum 32 message buffers for concurrent active instances with 8 bytes
payload. We need to pay attention to configuration options:

1. :kconfig:option:`CONFIG_CAN_MAX_MB` must be less or equal than the
maximum number of message buffers that is according to the table below.

2. :kconfig:option:`CONFIG_CAN_MAX_FILTER` must be less or equal than
:kconfig:option:`CONFIG_CAN_MAX_MB`.

=============== ========== ================ ================
Devicetree node Payload Hardware support Software support
=============== ========== ================ ================
flexcan0 | 8 bytes | 96 MBs | 64 MBs
| 16 bytes | 63 MBs | 42 MBs
| 32 bytes | 36 MBs | 24 MBs
| 64 bytes | 21 MBs | 14 MBs
flexcan1 | 8 bytes | 64 MBs | 64 MBs
| 16 bytes | 42 MBs | 42 MBs
| 32 bytes | 24 MBs | 24 MBs
| 64 bytes | 14 MBs | 14 MBs
flexcan2 | 8 bytes | 64 MBs | 64 MBs
| 16 bytes | 42 MBs | 42 MBs
| 32 bytes | 24 MBs | 24 MBs
| 64 bytes | 14 MBs | 14 MBs
flexcan3 | 8 bytes | 32 MBs | 32 MBs
| 16 bytes | 21 MBs | 21 MBs
| 32 bytes | 12 MBs | 12 MBs
| 64 bytes | 7 MBs | 7 MBs
flexcan4 | 8 bytes | 32 MBs | 32 MBs
| 16 bytes | 21 MBs | 21 MBs
| 32 bytes | 12 MBs | 12 MBs
| 64 bytes | 7 MBs | 7 MBs
flexcan5 | 8 bytes | 32 MBs | 32 MBs
| 16 bytes | 21 MBs | 21 MBs
| 32 bytes | 12 MBs | 12 MBs
| 64 bytes | 7 MBs | 7 MBs
=============== ========== ================ ================

.. note::
A CAN bus usually requires 60 Ohm termination at both ends of the bus. This may be
accomplished using one of the included CAN termination boards. For more details, refer
to the section ``6.3 CAN Connectors`` in the Hardware User Manual of `NXP MR-CANHUBK3`_.

FS26 SBC Watchdog
=================

Expand Down
66 changes: 66 additions & 0 deletions boards/arm/mr_canhubk3/mr_canhubk3-pinctrl.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,70 @@
bias-pull-up;
};
};

flexcan0_default: flexcan0_default {
group1 {
pinmux = <PTA6_CAN0_RX>;
input-enable;
};
group2 {
pinmux = <PTA7_CAN0_TX>;
output-enable;
};
};

flexcan1_default: flexcan1_default {
group1 {
pinmux = <PTC9_CAN1_RX>;
input-enable;
};
group2 {
pinmux = <PTC8_CAN1_TX>;
output-enable;
};
};

flexcan2_default: flexcan2_default {
group1 {
pinmux = <PTE25_CAN2_RX>;
input-enable;
};
group2 {
pinmux = <PTE24_CAN2_TX>;
output-enable;
};
};

flexcan3_default: flexcan3_default {
group1 {
pinmux = <PTC29_CAN3_RX>;
input-enable;
};
group2 {
pinmux = <PTC28_CAN3_TX>;
output-enable;
};
};

flexcan4_default: flexcan4_default {
group1 {
pinmux = <PTC31_CAN4_RX>;
input-enable;
};
group2 {
pinmux = <PTC30_CAN4_TX>;
output-enable;
};
};

flexcan5_default: flexcan5_default {
group1 {
pinmux = <PTC11_CAN5_RX>;
input-enable;
};
group2 {
pinmux = <PTC10_CAN5_TX>;
output-enable;
};
};
};
140 changes: 140 additions & 0 deletions boards/arm/mr_canhubk3/mr_canhubk3.dts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
zephyr,console = &lpuart2;
zephyr,shell-uart = &lpuart2;
zephyr,flash-controller = &mx25l6433f;
zephyr,canbus = &flexcan0;
};

aliases {
Expand Down Expand Up @@ -59,6 +60,54 @@
gpios = <&gpioa_h 9 GPIO_ACTIVE_HIGH>;
};
};

can_phy0: can-phy0 {
compatible = "nxp,tja1443", "can-transceiver-gpio";
enable-gpios = <&gpioc_h 8 GPIO_ACTIVE_HIGH>;
standby-gpios = <&gpioc_h 5 GPIO_ACTIVE_LOW>;
max-bitrate = <5000000>;
#phy-cells = <0>;
};

can_phy1: can-phy1 {
compatible = "nxp,tja1443", "can-transceiver-gpio";
enable-gpios = <&gpiod_l 2 GPIO_ACTIVE_HIGH>;
standby-gpios = <&gpiod_h 7 GPIO_ACTIVE_LOW>;
max-bitrate = <5000000>;
#phy-cells = <0>;
};

can_phy2: can-phy2 {
compatible = "nxp,tja1463", "can-transceiver-gpio";
enable-gpios = <&gpiod_l 4 GPIO_ACTIVE_HIGH>;
standby-gpios = <&gpiod_h 6 GPIO_ACTIVE_LOW>;
max-bitrate = <8000000>;
#phy-cells = <0>;
};

can_phy3: can-phy3 {
compatible = "nxp,tja1463", "can-transceiver-gpio";
enable-gpios = <&gpiob_l 0 GPIO_ACTIVE_HIGH>;
standby-gpios = <&gpiob_l 1 GPIO_ACTIVE_LOW>;
max-bitrate = <8000000>;
#phy-cells = <0>;
};

can_phy4: can-phy4 {
compatible = "nxp,tja1153", "can-transceiver-gpio";
enable-gpios = <&gpioc_h 10 GPIO_ACTIVE_HIGH>;
standby-gpios = <&gpioc_h 9 GPIO_ACTIVE_LOW>;
max-bitrate = <2000000>;
#phy-cells = <0>;
};

can_phy5: can-phy5 {
compatible = "nxp,tja1153", "can-transceiver-gpio";
enable-gpios = <&gpioe_h 1 GPIO_ACTIVE_HIGH>;
standby-gpios = <&gpiod_h 14 GPIO_ACTIVE_LOW>;
max-bitrate = <2000000>;
#phy-cells = <0>;
};
};

&flash0 {
Expand Down Expand Up @@ -87,10 +136,28 @@
status = "okay";
};

/* Enable gpio to control the CAN transceivers */

&gpioc_h {
status = "okay";
};

&gpiod_l {
status = "okay";
};

&gpiod_h {
status = "okay";
};

&gpiob_l {
status = "okay";
};

&gpioe_h {
status = "okay";
};

&eirq0 {
pinctrl-0 = <&eirq0_default>;
pinctrl-names = "default";
Expand Down Expand Up @@ -168,3 +235,76 @@
};
};
};

&flexcan0 {
pinctrl-0 = <&flexcan0_default>;
pinctrl-names = "default";
phys = <&can_phy0>;
bus-speed = <125000>;
sample-point = <875>;
sjw = <1>;
bus-speed-data = <1000000>;
sample-point-data = <875>;
sjw-data = <1>;
status = "okay";
};

&flexcan1 {
pinctrl-0 = <&flexcan1_default>;
pinctrl-names = "default";
phys = <&can_phy1>;
bus-speed = <125000>;
sample-point = <875>;
sjw = <1>;
bus-speed-data = <1000000>;
sample-point-data = <875>;
sjw-data = <1>;
};

&flexcan2 {
pinctrl-0 = <&flexcan2_default>;
pinctrl-names = "default";
phys = <&can_phy2>;
bus-speed = <125000>;
sample-point = <875>;
sjw = <1>;
bus-speed-data = <1000000>;
sample-point-data = <875>;
sjw-data = <1>;
};

&flexcan3 {
pinctrl-0 = <&flexcan3_default>;
pinctrl-names = "default";
phys = <&can_phy3>;
bus-speed = <125000>;
sample-point = <875>;
sjw = <1>;
bus-speed-data = <1000000>;
sample-point-data = <875>;
sjw-data = <1>;
};

&flexcan4 {
pinctrl-0 = <&flexcan4_default>;
pinctrl-names = "default";
phys = <&can_phy4>;
bus-speed = <125000>;
sample-point = <875>;
sjw = <1>;
bus-speed-data = <1000000>;
sample-point-data = <875>;
sjw-data = <1>;
};

&flexcan5 {
pinctrl-0 = <&flexcan5_default>;
pinctrl-names = "default";
phys = <&can_phy5>;
bus-speed = <125000>;
sample-point = <875>;
sjw = <1>;
bus-speed-data = <1000000>;
sample-point-data = <875>;
sjw-data = <1>;
};
1 change: 1 addition & 0 deletions boards/arm/mr_canhubk3/mr_canhubk3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ toolchain:
supported:
- gpio
- uart
- can
1 change: 1 addition & 0 deletions boards/arm/mr_canhubk3/mr_canhubk3_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CONFIG_NOCACHE_MEMORY=y
# Drivers
CONFIG_PINCTRL=y
CONFIG_SERIAL=y
CONFIG_GPIO=y # Enable support for GPIO controlled CAN transceivers

# Serial console
CONFIG_CONSOLE=y
9 changes: 9 additions & 0 deletions drivers/can/Kconfig.mcux
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ config CAN_MCUX_FLEXCAN_FD
help
Enable support for CAN-FD capable NXP FlexCAN devices.

config CAN_MAX_MB
int "Maximum number of message buffers for concurrent active instances"
default 16
depends on SOC_SERIES_S32K3_M7
range 1 96
help
Defines maximum number of message buffers for concurrent active instances.

config CAN_MAX_FILTER
int "Maximum number of concurrent active RX filters"
default 5
range 1 15 if SOC_SERIES_KINETIS_KE1XF || SOC_SERIES_KINETIS_K6X
range 1 13 if SOC_SERIES_IMX_RT && CAN_MCUX_FLEXCAN_FD
range 1 63 if SOC_SERIES_IMX_RT
range 1 96 if SOC_SERIES_S32K3_M7
help
Defines maximum number of concurrent active RX filters

Expand Down
13 changes: 9 additions & 4 deletions drivers/can/can_mcux_flexcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,19 @@ LOG_MODULE_REGISTER(can_mcux_flexcan, CONFIG_CAN_LOG_LEVEL);
#define RX_START_IDX 0
#endif

/* The maximum number of message buffers for concurrent active instances */
#ifdef CONFIG_CAN_MAX_MB
#define MCUX_FLEXCAN_MAX_MB CONFIG_CAN_MAX_MB
#else
#define MCUX_FLEXCAN_MAX_MB FSL_FEATURE_FLEXCAN_HAS_MESSAGE_BUFFER_MAX_NUMBERn(0)
#endif

/*
* RX message buffers (filters) will take up the first N message
* buffers. The rest are available for TX use.
*/
#define MCUX_FLEXCAN_MAX_RX (CONFIG_CAN_MAX_FILTER + RX_START_IDX)
#define MCUX_FLEXCAN_MAX_TX \
(FSL_FEATURE_FLEXCAN_HAS_MESSAGE_BUFFER_MAX_NUMBERn(0) \
- MCUX_FLEXCAN_MAX_RX)
#define MCUX_FLEXCAN_MAX_TX (MCUX_FLEXCAN_MAX_MB - MCUX_FLEXCAN_MAX_RX)

/*
* Convert from RX message buffer index to allocated filter ID and
Expand Down Expand Up @@ -1246,7 +1251,7 @@ static int mcux_flexcan_init(const struct device *dev)
data->dev = dev;

FLEXCAN_GetDefaultConfig(&flexcan_config);
flexcan_config.maxMbNum = FSL_FEATURE_FLEXCAN_HAS_MESSAGE_BUFFER_MAX_NUMBERn(0);
flexcan_config.maxMbNum = MCUX_FLEXCAN_MAX_MB;
flexcan_config.clkSrc = config->clk_source;
flexcan_config.baudRate = clock_freq /
(1U + data->timing.prop_seg + data->timing.phase_seg1 +
Expand Down
Loading