Skip to content

Commit d5b9e74

Browse files
JiafeiPankartben
authored andcommitted
boards: imx8mp_evk: a53: enable FlexCAN on the board
Added dts nodes of FlexCAN1 and FlexCAN2 in SoC dts. Added dts nodes and overlay in imx8mp_evk board. Signed-off-by: Jiafei Pan <Jiafei.Pan@nxp.com>
1 parent 298cfda commit d5b9e74

File tree

8 files changed

+164
-4
lines changed

8 files changed

+164
-4
lines changed

boards/nxp/imx8mp_evk/Kconfig.defconfig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2024 NXP
1+
# Copyright 2024-2025 NXP
22
# SPDX-License-Identifier: Apache-2.0
33

44
if BOARD_IMX8MP_EVK
@@ -39,6 +39,15 @@ endif # NET_SOCKETS_SERVICE
3939

4040
endif # NETWORKING
4141

42+
if CAN && GPIO_PCA6416
43+
44+
# For FlexCAN2, SAI5 PDM/CAN2 IOMUX select is controlled by IO expandor PCA6416
45+
# IO port, so CAN transceiver must be initialized after PCA6416 initialization
46+
config CAN_TRANSCEIVER_INIT_PRIORITY
47+
default 75
48+
49+
endif # CAN && GPIO_PCA6416
50+
4251
endif # BOARD_IMX8MP_EVK_MIMX8ML8_A53 || BOARD_IMX8MP_EVK_MIMX8ML8_A53_SMP
4352

4453
endif # BOARD_IMX8MP_EVK

boards/nxp/imx8mp_evk/doc/index.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,25 @@ display the following console output:
180180
thread_b: Hello World from cpu 0 on mimx8mp_evk!
181181
thread_a: Hello World from cpu 0 on mimx8mp_evk!
182182
183+
CAN bus (FlexCAN) (A53)
184+
=======================
185+
The FlexCAN controller is a CAN 2.0B controller that supports both standard
186+
and extended frames. The FlexCAN controller has two independent FlexCAN
187+
modules, FlexCAN1 and FlexCAN2. By default, FlexCAN1 is enabled in the device
188+
tree. To enable FlexCAN2, you need to add the following overlay to the
189+
device tree:
190+
:zephyr_file:`boards/nxp/imx8mp_evk/dts/flexcan2.overlay`.
191+
192+
For example, building the :zephyr:code-sample:`hello_world` sample with the CAN shell and
193+
CAN statistics enabled, and using the FlexCAN1 controller, you can use the following
194+
configuration:
195+
196+
.. zephyr-app-commands::
197+
:zephyr-app: samples/hello_world
198+
:board: imx8mp_evk/mimx8ml8/a53
199+
:gen-args: -DCONFIG_SHELL=y -DCONFIG_CAN=y -DCONFIG_CAN_SHELL=y -DCONFIG_STATS=y -DCONFIG_CAN_STATS=y
200+
:goals: build
201+
183202
Programming and Debugging (M7)
184203
******************************
185204

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* DTS binding overlay for enabling FlexCAN2
5+
*/
6+
7+
/ {
8+
chosen {
9+
zephyr,canbus = &flexcan2;
10+
};
11+
};
12+
13+
&can_phy2 {
14+
status = "okay";
15+
};
16+
17+
&flexcan2 {
18+
status = "okay";
19+
};
20+
21+
&gpio4 {
22+
status = "okay";
23+
};

boards/nxp/imx8mp_evk/imx8mp_evk-pinctrl.dtsi

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@
77
#include <nxp/nxp_imx/mimx8ml8dvnlz-pinctrl.dtsi>
88

99
&pinctrl {
10+
flexcan1_default: flexcan1_default {
11+
group0 {
12+
pinmux = <&iomuxc_spdif_rx_can_rx_can1_rx>,
13+
<&iomuxc_spdif_tx_can_tx_can1_tx>;
14+
bias-pull-up;
15+
slew-rate = "fast";
16+
drive-strength = "x2";
17+
};
18+
};
19+
20+
flexcan2_default: flexcan2_default {
21+
group0 {
22+
pinmux = <&iomuxc_sai5_mclk_can_rx_can2_rx>,
23+
<&iomuxc_sai5_rxd3_can_tx_can2_tx>;
24+
bias-pull-up;
25+
slew-rate = "fast";
26+
drive-strength = "x2";
27+
};
28+
};
29+
1030
sai3_default: sai3_default {
1131
group0 {
1232
pinmux = <&iomuxc_sai3_txfs_sai_tx_sync_sai3_tx_sync>,

boards/nxp/imx8mp_evk/imx8mp_evk_mimx8ml8_a53.dts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
compatible = "fsl,mimx8mp";
1717

1818
chosen {
19+
zephyr,canbus = &flexcan1;
1920
zephyr,console = &uart4;
2021
zephyr,shell-uart = &uart4;
2122
/* sram node actually locates at DDR DRAM */
@@ -38,6 +39,23 @@
3839
reg = <0xc0000000 DT_SIZE_M(1)>;
3940
};
4041

42+
can_phy1: can-phy1{
43+
compatible = "nxp,tja1048", "can-transceiver-gpio";
44+
enable-gpios = <&gpio_exp1 2 GPIO_ACTIVE_LOW>;
45+
standby-gpios = <&gpio5 5 GPIO_ACTIVE_LOW>;
46+
max-bitrate = <8000000>;
47+
#phy-cells = <0>;
48+
status = "okay";
49+
};
50+
51+
can_phy2: can-phy2{
52+
compatible = "nxp,tja1048", "can-transceiver-gpio";
53+
enable-gpios = <&gpio_exp1 3 GPIO_ACTIVE_HIGH>;
54+
standby-gpios = <&gpio4 27 GPIO_ACTIVE_LOW>;
55+
max-bitrate = <8000000>;
56+
#phy-cells = <0>;
57+
status = "disabled";
58+
};
4159
};
4260

4361
&enet {
@@ -64,6 +82,20 @@
6482
};
6583
};
6684

85+
&flexcan1 {
86+
pinctrl-0 = <&flexcan1_default>;
87+
pinctrl-names = "default";
88+
phys = <&can_phy1>;
89+
status = "okay";
90+
};
91+
92+
&flexcan2 {
93+
pinctrl-0 = <&flexcan2_default>;
94+
pinctrl-names = "default";
95+
phys = <&can_phy2>;
96+
status = "disabled";
97+
};
98+
6799
&uart4 {
68100
status = "okay";
69101
current-speed = <115200>;
@@ -91,3 +123,7 @@
91123
&gpio1 {
92124
status = "okay";
93125
};
126+
127+
&gpio5 {
128+
status = "okay";
129+
};

boards/nxp/imx8mp_evk/imx8mp_evk_mimx8ml8_a53.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ toolchain:
1313
- cross-compile
1414
ram: 1024
1515
supported:
16-
- uart
17-
- net
16+
- can
1817
- gpio
1918
- i2c
19+
- net
20+
- uart
2021
testing:
2122
ignore_tags:
2223
- bluetooth

dts/arm64/nxp/nxp_mimx8mp_a53.dtsi

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2022,2024 NXP
2+
* Copyright 2020-2022, 2024-2025 NXP
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -189,6 +189,34 @@
189189
status = "disabled";
190190
};
191191

192+
flexcan1: can@308c0000 {
193+
compatible = "nxp,flexcan-fd", "nxp,flexcan";
194+
reg = <0x308c0000 DT_SIZE_K(64)>;
195+
interrupt-parent= <&gic>;
196+
interrupts = <GIC_SPI 142 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>,
197+
<GIC_SPI 143 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
198+
interrupt-names = "common", "error";
199+
clocks = <&ccm IMX_CCM_CAN1_CLK 0x68 14>;
200+
clk-source = <0>;
201+
rdc = <(RDC_DOMAIN_PERM(A53_DOMAIN_ID, RDC_DOMAIN_PERM_RW)|\
202+
RDC_DOMAIN_PERM(M7_DOMAIN_ID, RDC_DOMAIN_PERM_RW))>;
203+
status = "disabled";
204+
};
205+
206+
flexcan2: can@308d0000 {
207+
compatible = "nxp,flexcan-fd", "nxp,flexcan";
208+
reg = <0x308d0000 DT_SIZE_K(64)>;
209+
interrupt-parent= <&gic>;
210+
interrupts = <GIC_SPI 144 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>,
211+
<GIC_SPI 145 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
212+
interrupt-names = "common", "error";
213+
clocks = <&ccm IMX_CCM_CAN2_CLK 0x68 14>;
214+
clk-source = <0>;
215+
rdc = <(RDC_DOMAIN_PERM(A53_DOMAIN_ID, RDC_DOMAIN_PERM_RW)|\
216+
RDC_DOMAIN_PERM(M7_DOMAIN_ID, RDC_DOMAIN_PERM_RW))>;
217+
status = "disabled";
218+
};
219+
192220
i2c1: i2c@30a20000 {
193221
compatible = "nxp,ii2c";
194222
#address-cells = <1>;

soc/nxp/imx/imx8m/a53/soc.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ static void soc_rdc_init(void)
5151
periphConfig.policy = RDC_DT_VAL(i2c3);
5252
RDC_SetPeriphAccessConfig(rdc_inst, &periphConfig);
5353
#endif
54+
55+
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcan1)) && DT_NODE_HAS_PROP(DT_NODELABEL(flexcan1), rdc)
56+
periphConfig.periph = kRDC_Periph_CAN_FD1;
57+
periphConfig.policy = RDC_DT_VAL(flexcan1);
58+
RDC_SetPeriphAccessConfig(rdc_inst, &periphConfig);
59+
#endif
60+
61+
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcan2)) && DT_NODE_HAS_PROP(DT_NODELABEL(flexcan2), rdc)
62+
periphConfig.periph = kRDC_Periph_CAN_FD2;
63+
periphConfig.policy = RDC_DT_VAL(flexcan2);
64+
RDC_SetPeriphAccessConfig(rdc_inst, &periphConfig);
65+
#endif
5466
}
5567
#else
5668

@@ -67,6 +79,18 @@ __weak void soc_clock_init(void)
6779
CLOCK_SetRootDivider(kCLOCK_RootI2c3, 1U, 10U);
6880
CLOCK_EnableClock(kCLOCK_I2c3);
6981
#endif
82+
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcan1))
83+
/* Set FLEXCAN1 source to SYSTEM PLL1 800MHZ */
84+
CLOCK_SetRootMux(kCLOCK_RootFlexCan1, kCLOCK_FlexCanRootmuxSysPll1);
85+
/* Set root clock to 800MHZ / 10 = 80MHZ */
86+
CLOCK_SetRootDivider(kCLOCK_RootFlexCan1, 2U, 5U);
87+
#endif
88+
#if DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(flexcan2))
89+
/* Set FLEXCAN2 source to SYSTEM PLL1 800MHZ */
90+
CLOCK_SetRootMux(kCLOCK_RootFlexCan2, kCLOCK_FlexCanRootmuxSysPll1);
91+
/* Set root clock to 800MHZ / 10 = 80MHZ */
92+
CLOCK_SetRootDivider(kCLOCK_RootFlexCan2, 2U, 5U);
93+
#endif
7094
}
7195

7296
void soc_prep_hook(void)

0 commit comments

Comments
 (0)