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 f6081b8c58c22a4431d8fbd08874756c7bec4236 Author: Jari Nippula <[email protected]> AuthorDate: Mon Nov 2 09:13:50 2026 +0200 boards/arm/imxrt/imxrt1180-evk: enable NETC Configure NETC with 1 port enabled: ENETC1/PORT1 Assisted-by: ChatGPT:GPT-6.1 Signed-off-by: Jari Nippula <[email protected]> --- .../arm/imxrt/boards/imxrt1180-evk/index.rst | 103 +++++- boards/arm/imxrt/imxrt1180-evk/CMakeLists.txt | 23 ++ boards/arm/imxrt/imxrt1180-evk/Kconfig | 5 + .../arm/imxrt/imxrt1180-evk/configs/nsh/defconfig | 15 +- boards/arm/imxrt/imxrt1180-evk/include/board.h | 115 +++++++ boards/arm/imxrt/imxrt1180-evk/src/CMakeLists.txt | 54 ++++ boards/arm/imxrt/imxrt1180-evk/src/Makefile | 4 + boards/arm/imxrt/imxrt1180-evk/src/imxrt1180-evk.h | 4 + boards/arm/imxrt/imxrt1180-evk/src/imxrt_bringup.c | 8 + .../imxrt/imxrt1180-evk/src/imxrt_clockconfig_m7.c | 54 ++++ boards/arm/imxrt/imxrt1180-evk/src/imxrt_netc.c | 347 +++++++++++++++++++++ 11 files changed, 726 insertions(+), 6 deletions(-) diff --git a/Documentation/platforms/arm/imxrt/boards/imxrt1180-evk/index.rst b/Documentation/platforms/arm/imxrt/boards/imxrt1180-evk/index.rst index 72342a75d8d..3e5107618e7 100644 --- a/Documentation/platforms/arm/imxrt/boards/imxrt1180-evk/index.rst +++ b/Documentation/platforms/arm/imxrt/boards/imxrt1180-evk/index.rst @@ -43,9 +43,9 @@ Features The current NuttX configurations provide the serial console, USB device support, image generation, and multicore boot flow. The Cortex-M7 ``nsh`` -configuration also enables the onboard MicroSD socket through USDHC1. Other -on-board interfaces listed above are not enabled by the supplied -configurations. +configuration also enables the onboard MicroSD socket through USDHC1 and +NETC Ethernet on ETH1. Other on-board interfaces listed above are not +enabled by the supplied configurations. Buttons and LEDs ================ @@ -102,6 +102,98 @@ Consult the MIMXRT1180-EVK user manual (UM12021) and schematic, available from the NXP product page linked above, for the complete expansion-header pinout and any signal-sharing restrictions. +Ethernet +======== + +The Cortex-M7 board integration supports direct-PHY ENETC0 and the ENETC1 +switch through the NETC driver. The ``nsh`` configuration enables only +``CONFIG_IMXRT_NETC_ENETC1_PORT1`` (ETH1). NETC selects +``CONFIG_NET_PHYLIB``; board Kconfig selects the appropriate Realtek drivers. +Board bring-up configures the enabled ports' pins and resets before PHY +discovery and registers the network interfaces. Hardware acceptance, +including link negotiation and bidirectional traffic, is still required. + +================= ========== ============ ============ ============ +Attachment Board port PHY MDIO address Reset GPIO +================= ========== ============ ============ ============ +ENETC1 port 0 ETH0/J28 RTL8201FI 2 GPIO_AD_25 +ENETC1 port 1 ETH1 RTL8211FDI 5 GPIO_B1_13 +ENETC1 port 2 ETH2 RTL8211FDI 4 GPIO_AD_28 +ENETC1 port 3 ETH3 RTL8211FDI 7 GPIO_B2_01 +ENETC0 ETH4/J32 RTL8201FI 3 GPIO_AD_13 +================= ========== ============ ============ ============ + +Select additional switch ports with ``CONFIG_IMXRT_NETC_ENETC1_PORT0`` +through ``CONFIG_IMXRT_NETC_ENETC1_PORT3``, or the direct attachment with +``CONFIG_IMXRT_NETC_ENETC0``. The appropriate PHY drivers must also be +compiled. Board Kconfig selects +``CONFIG_NET_PHY_REALTEK_RTL8201F`` and +``CONFIG_NET_PHY_REALTEK_RTL8211F`` automatically: +RTL8201F for ENETC0 or ENETC1 port 0, and RTL8211F for ENETC1 ports 1--3. +No additional manual PHY selection is required when adding these ports. +Board code supplies each port's PHY address and interface mode; +PHYLIB matches the driver by the hardware PHY ID. +The board also selects the +``CONFIG_IMXRT_NETC_PHYINIT`` hardware-reset hook automatically. Ports 1--3 +use ``PHY_INTERFACE_RGMII_ID`` to enable both PHY-side clock delays. +ETH0 and ETH4 use ``PHY_INTERFACE_RMII`` with a 50 MHz reference supplied +by the MAC and SION enabled on the clock pad. Boards where the PHY supplies +the reference instead must select ``PHY_INTERFACE_RMII_PHY_CLK_OUT``. +GPIO_AD_16 for ETH0 (ENETC1/PORT0) and GPIO_AD_17 for +ETH4 (ENETC0) must remain inputs without internal pulls when their +respective ports are enabled, preserving the PHY-address straps. + +ENETC0's PHY reset shares GPIO_AD_13 with LPUART3 TX; do not enable both. +For ETH2/3, set J65/J72 and J63/J73 to 2-3 and do not enable SDRAM or +EtherCAT on their shared GPIO_EMC_B1 pads. + +The NETC root uses PLL3 PFD3 at 480 MHz divided by two for 240 MHz. +MAC1/2/3 use PLL1 DIV2 at 500 MHz divided by four for 125 MHz; +MAC0/4 divide it by ten for 50 MHz. The boot environment must supply the +PLL3 PFD3 source with fraction 18 and leave NETCMIX powered, released from +reset and deisolated, with TRDC access for the Cortex-M7 and NETC DMA. +The board's Cortex-M33 bootloader configures TRDC permissions for +Cortex-M7 access to NETC registers and NETC DMA access to memory. +A replacement bootloader must provide equivalent permissions. + +Both controllers use 16 TX and 16 RX descriptors by default. The ``nsh`` +configuration provides ``CONFIG_MM_IOB=y`` and 160 IOBs, the minimum pool +for the 16-descriptor TX selection. + +ENETC1 exposes one interface for all enabled switch ports. ENETC0 exposes a +separate interface and is not bridged to ENETC1. MAC addresses are locally +administered unicast addresses derived from the chip UID; ENETC0 differs +from ENETC1 in the low bit of the last byte. With only ENETC1 enabled, its +interface is ``eth0``. Enabling ENETC0 normally makes ENETC0 ``eth0`` and +ENETC1 ``eth1``; confirm the mapping with ``ifconfig``. + +Use separate subnets for two-interface tests and do not introduce loops +between switch ports. ``CONFIG_DEBUG_NET_ERROR`` enables PHY discovery +and NETC initialization error messages; ``CONFIG_NETDEV_PHY_IOCTL`` enables +PHY register diagnostics. + +NETC selects ``CONFIG_MDIO_BUS`` automatically. +Each used NETC MDIO endpoint has one registered bus shared by its PHYs; +PHYLIB owns discovery, initialization, auto-negotiation and link polling. +The NETC lower half implements Clause 22 MDIO access. PHYLIB's paged helpers +hold the bus lock across page selection, access and restoration. +Bus handles survive interface down/up, and MDIO timing is restored on each +transaction after a function reset. Initialization failure releases the +failing attachment's PHY devices and bus references. + +``board_netc_phyinit()`` performs initial reset pulses before PHY discovery. + +ENETC0 starts/stops its PHY with the interface, before disabling its MDIO +register window. External switch PHYs remain active while ENETC1 is down, +preserving port-to-port forwarding. NETC consumes PHYLIB state under the +PHY lock, applies each MAC mode, then reports carrier (any active switch +port for ENETC1). ``CONFIG_NET_PHYLIB_POLL_INTERVAL`` controls PHY polling; +``CONFIG_IMXRT_NETC_LINK_POLL_MS`` controls MAC updates and the TX watchdog. +Only full-duplex modes are advertised. Direct-interface PHY ioctls use +PHYLIB, including ethtool; switch MII ioctls retain the port selector in +``phy_id[9:8]`` and MDIO address in ``phy_id[4:0]``. Switch-wide ethtool +settings are not supported because the external ports negotiate separately. + Power Supply ============ @@ -248,8 +340,9 @@ nsh Runs NSH on the Cortex-M7. The output ``nuttx.bin`` is a raw XIP payload that must be programmed at offset ``0x80000`` and started by the ``bl`` configuration. NSH is available on LPUART1 at the MCU-Link virtual COM port. -This configuration also enables USB CDC/ACM, the ``ostest`` application, and -the onboard MicroSD socket via USDHC1. +This configuration also enables USB CDC/ACM, the ``ostest`` application, the +onboard MicroSD socket via USDHC1, and NETC Ethernet on ETH1 with static IPv4 +addressing and ``ping``. License Exceptions ================== diff --git a/boards/arm/imxrt/imxrt1180-evk/CMakeLists.txt b/boards/arm/imxrt/imxrt1180-evk/CMakeLists.txt new file mode 100644 index 00000000000..c3c7461fbbf --- /dev/null +++ b/boards/arm/imxrt/imxrt1180-evk/CMakeLists.txt @@ -0,0 +1,23 @@ +# ############################################################################## +# boards/arm/imxrt/imxrt1180-evk/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## + +add_subdirectory(src) diff --git a/boards/arm/imxrt/imxrt1180-evk/Kconfig b/boards/arm/imxrt/imxrt1180-evk/Kconfig index 88293b0b7e1..a59ba6026df 100644 --- a/boards/arm/imxrt/imxrt1180-evk/Kconfig +++ b/boards/arm/imxrt/imxrt1180-evk/Kconfig @@ -26,6 +26,11 @@ if ARCH_BOARD_IMXRT1180_EVK +config IMXRT_NETC + select IMXRT_NETC_PHYINIT + select NET_PHY_REALTEK_RTL8201F if IMXRT_NETC_ENETC0 || IMXRT_NETC_ENETC1_PORT0 + select NET_PHY_REALTEK_RTL8211F if IMXRT_NETC_ENETC1_PORT1 || IMXRT_NETC_ENETC1_PORT2 || IMXRT_NETC_ENETC1_PORT3 + config IMXRT_DMA_POOL_SIZE int "RT1180 USB DMA pool size" depends on ARCH_FAMILY_IMXRT118x && IMXRT_USBDEV && USBDEV_DMAMEMORY diff --git a/boards/arm/imxrt/imxrt1180-evk/configs/nsh/defconfig b/boards/arm/imxrt/imxrt1180-evk/configs/nsh/defconfig index b1edc074312..ddcf0be3d6c 100644 --- a/boards/arm/imxrt/imxrt1180-evk/configs/nsh/defconfig +++ b/boards/arm/imxrt/imxrt1180-evk/configs/nsh/defconfig @@ -53,6 +53,7 @@ CONFIG_IDLETHREAD_STACKSIZE=4096 CONFIG_IMXRT_EDMA=y CONFIG_IMXRT_GPIO_IRQ=y CONFIG_IMXRT_LPUART1=y +CONFIG_IMXRT_NETC_ENETC1_PORT1=y CONFIG_IMXRT_OCRAM_HEAP=y CONFIG_IMXRT_TCM_PRIMARY=y CONFIG_IMXRT_USBDEV=y @@ -65,7 +66,11 @@ CONFIG_INPUT=y CONFIG_INPUT_BUTTONS=y CONFIG_INPUT_BUTTONS_LOWER=y CONFIG_INTELHEX_BINARY=y +CONFIG_IOB_NBUFFERS=160 CONFIG_LIBC_LOCALTIME=y +CONFIG_LIBC_NETDB=y +CONFIG_LIBC_STRERROR=y +CONFIG_LIBC_STRERROR_ERRNUM=y CONFIG_LINE_MAX=64 CONFIG_LPUART1_RXDMA=y CONFIG_LPUART1_SERIAL_CONSOLE=y @@ -74,8 +79,14 @@ CONFIG_MKFATFS_BUFFER_ALIGNMENT=64 CONFIG_MMCSD=y CONFIG_MMCSD_SDIO=y CONFIG_MM_REGIONS=2 +CONFIG_NET=y +CONFIG_NETDEV_PHY_IOCTL=y +CONFIG_NET_ETH_PKTSIZE=1518 +CONFIG_NET_ICMP_SOCKET=y +CONFIG_NET_SOCKOPTS=y +CONFIG_NET_TCP=y +CONFIG_NET_UDP=y CONFIG_NSH_BUILTIN_APPS=y -CONFIG_NSH_DISABLE_IFUPDOWN=y CONFIG_NSH_FILEIOSIZE=512 CONFIG_NSH_READLINE=y CONFIG_PTHREAD_MUTEX_TYPES=y @@ -87,6 +98,7 @@ CONFIG_RR_INTERVAL=200 CONFIG_SCHED_BACKTRACE=y CONFIG_SCHED_EVENTS=y CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_LPWORK=y CONFIG_SCHED_SPORADIC=y CONFIG_SCHED_THREAD_LOCAL=y CONFIG_SCHED_WAITPID=y @@ -95,6 +107,7 @@ CONFIG_SIG_EVTHREAD=y CONFIG_START_MONTH=9 CONFIG_SYSTEM_CDCACM=y CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_PING=y CONFIG_TESTING_OSTEST=y CONFIG_TESTING_OSTEST_STACKSIZE=16384 CONFIG_TLS_NCLEANUP=4 diff --git a/boards/arm/imxrt/imxrt1180-evk/include/board.h b/boards/arm/imxrt/imxrt1180-evk/include/board.h index c1c0a080520..0cca2a5166f 100644 --- a/boards/arm/imxrt/imxrt1180-evk/include/board.h +++ b/boards/arm/imxrt/imxrt1180-evk/include/board.h @@ -215,6 +215,121 @@ #define BOARD_USDHC_SD4MODE_HS_PRESCALER USDHC_SYSCTL_SDCLKFS_DIV4 #define BOARD_USDHC_SD4MODE_HS_DIVISOR USDHC_SYSCTL_DVS_DIV(1) +/* NETC: SPF-50577 C4 sheets 6, 7 and 15-19. */ + +#define BOARD_NETC_PIN(p) IOMUX_PIN(IOMUXC_PAD_##p, IOMUXC_PAD_PULL_NONE, 0) + +#define GPIO_NETC_MDC IOMUX_PIN(IOMUXC_PAD_GPIO_AD_30_NETC_EMDC, \ + IOMUXC_PAD_DSE | IOMUXC_PAD_PUE, 0) +#define GPIO_NETC_MDIO IOMUX_PIN(IOMUXC_PAD_GPIO_AD_31_NETC_EMDIO, \ + IOMUXC_PAD_DSE | IOMUXC_PAD_PUE | \ + IOMUXC_PAD_ODE, 0) + +#define BOARD_ENET0_PORT0_PINS \ +{ \ + BOARD_NETC_PIN(GPIO_EMC_B2_13_NETC_PINMUX_ETH4_TXD00), \ + BOARD_NETC_PIN(GPIO_EMC_B2_14_NETC_PINMUX_ETH4_TXD01), \ + BOARD_NETC_PIN(GPIO_EMC_B2_15_NETC_PINMUX_ETH4_TX_EN), \ + IOMUX_PIN(IOMUXC_PAD_GPIO_EMC_B2_16_NETC_PINMUX_ETH4_TX_CLK, \ + IOMUXC_PAD_PULL_NONE, IOMUXC_MUX_SION_ON), \ + BOARD_NETC_PIN(GPIO_EMC_B2_17_NETC_PINMUX_ETH4_RXD00), \ + BOARD_NETC_PIN(GPIO_EMC_B2_18_NETC_PINMUX_ETH4_RXD01), \ + BOARD_NETC_PIN(GPIO_EMC_B2_19_NETC_PINMUX_ETH4_RX_DV), \ + BOARD_NETC_PIN(GPIO_EMC_B2_20_NETC_PINMUX_ETH4_RX_ER) \ +} + +#define BOARD_ENET1_PORT0_PINS \ +{ \ + BOARD_NETC_PIN(GPIO_EMC_B2_05_NETC_PINMUX_ETH0_TXD00), \ + BOARD_NETC_PIN(GPIO_EMC_B2_06_NETC_PINMUX_ETH0_TXD01), \ + BOARD_NETC_PIN(GPIO_EMC_B2_07_NETC_PINMUX_ETH0_TX_EN), \ + IOMUX_PIN(IOMUXC_PAD_GPIO_EMC_B2_08_NETC_PINMUX_ETH0_TX_CLK, \ + IOMUXC_PAD_PULL_NONE, IOMUXC_MUX_SION_ON), \ + BOARD_NETC_PIN(GPIO_EMC_B2_09_NETC_PINMUX_ETH0_RXD00), \ + BOARD_NETC_PIN(GPIO_EMC_B2_10_NETC_PINMUX_ETH0_RXD01), \ + BOARD_NETC_PIN(GPIO_EMC_B2_11_NETC_PINMUX_ETH0_RX_DV), \ + BOARD_NETC_PIN(GPIO_EMC_B2_12_NETC_PINMUX_ETH0_RX_ER) \ +} + +#define BOARD_ENET1_PORT1_PINS \ +{ \ + BOARD_NETC_PIN(GPIO_B1_00_NETC_PINMUX_ETH1_TXD00), \ + BOARD_NETC_PIN(GPIO_B1_01_NETC_PINMUX_ETH1_TXD01), \ + BOARD_NETC_PIN(GPIO_B1_02_NETC_PINMUX_ETH1_TX_EN), \ + BOARD_NETC_PIN(GPIO_B1_03_NETC_PINMUX_ETH1_TX_CLK), \ + BOARD_NETC_PIN(GPIO_B1_04_NETC_PINMUX_ETH1_RXD00), \ + BOARD_NETC_PIN(GPIO_B1_05_NETC_PINMUX_ETH1_RXD01), \ + BOARD_NETC_PIN(GPIO_B1_06_NETC_PINMUX_ETH1_RX_DV), \ + BOARD_NETC_PIN(GPIO_B1_07_NETC_PINMUX_ETH1_TXD02), \ + BOARD_NETC_PIN(GPIO_B1_08_NETC_PINMUX_ETH1_TXD03), \ + BOARD_NETC_PIN(GPIO_B1_09_NETC_PINMUX_ETH1_RXD02), \ + BOARD_NETC_PIN(GPIO_B1_10_NETC_PINMUX_ETH1_RXD03), \ + BOARD_NETC_PIN(GPIO_B1_11_NETC_PINMUX_ETH1_RX_CLK) \ +} + +#define BOARD_ENET1_PORT2_PINS \ +{ \ + BOARD_NETC_PIN(GPIO_EMC_B1_13_NETC_PINMUX_ETH2_RX_DV), \ + BOARD_NETC_PIN(GPIO_EMC_B1_16_NETC_PINMUX_ETH2_RXD00), \ + BOARD_NETC_PIN(GPIO_EMC_B1_17_NETC_PINMUX_ETH2_RXD01), \ + BOARD_NETC_PIN(GPIO_EMC_B1_21_NETC_PINMUX_ETH2_RX_CLK), \ + BOARD_NETC_PIN(GPIO_EMC_B1_22_NETC_PINMUX_ETH2_RXD02), \ + BOARD_NETC_PIN(GPIO_EMC_B1_23_NETC_PINMUX_ETH2_RXD03), \ + BOARD_NETC_PIN(GPIO_EMC_B1_24_NETC_PINMUX_ETH2_TXD03), \ + BOARD_NETC_PIN(GPIO_EMC_B1_25_NETC_PINMUX_ETH2_TXD02), \ + BOARD_NETC_PIN(GPIO_EMC_B1_26_NETC_PINMUX_ETH2_TXD01), \ + BOARD_NETC_PIN(GPIO_EMC_B1_27_NETC_PINMUX_ETH2_TXD00), \ + BOARD_NETC_PIN(GPIO_EMC_B1_28_NETC_PINMUX_ETH2_TX_EN), \ + BOARD_NETC_PIN(GPIO_EMC_B1_29_NETC_PINMUX_ETH2_TX_CLK) \ +} + +#define BOARD_ENET1_PORT3_PINS \ +{ \ + BOARD_NETC_PIN(GPIO_EMC_B1_00_NETC_PINMUX_ETH3_TXD03), \ + BOARD_NETC_PIN(GPIO_EMC_B1_01_NETC_PINMUX_ETH3_TXD02), \ + BOARD_NETC_PIN(GPIO_EMC_B1_02_NETC_PINMUX_ETH3_RX_CLK), \ + BOARD_NETC_PIN(GPIO_EMC_B1_03_NETC_PINMUX_ETH3_RXD03), \ + BOARD_NETC_PIN(GPIO_EMC_B1_04_NETC_PINMUX_ETH3_RXD02), \ + BOARD_NETC_PIN(GPIO_EMC_B1_05_NETC_PINMUX_ETH3_TXD00), \ + BOARD_NETC_PIN(GPIO_EMC_B1_06_NETC_PINMUX_ETH3_TXD01), \ + BOARD_NETC_PIN(GPIO_EMC_B1_07_NETC_PINMUX_ETH3_TX_EN), \ + BOARD_NETC_PIN(GPIO_EMC_B1_08_NETC_PINMUX_ETH3_TX_CLK), \ + BOARD_NETC_PIN(GPIO_EMC_B1_09_NETC_PINMUX_ETH3_RXD00), \ + BOARD_NETC_PIN(GPIO_EMC_B1_10_NETC_PINMUX_ETH3_RXD01), \ + BOARD_NETC_PIN(GPIO_EMC_B1_11_NETC_PINMUX_ETH3_RX_DV) \ +} + +#define IOMUX_NETC_RESET_DEFAULT (IOMUXC_PAD_ODE | IOMUXC_PAD_PULL_DOWN) + +#define GPIO_ENET0_PORT0_PHY_RESET \ + IOMUX_GPIO(IOMUXC_PAD_GPIO_AD_13_GPIO4_IO13, IOMUX_NETC_RESET_DEFAULT, \ + GPIO_OUTPUT | GPIO_OUTPUT_ONE | GPIO_PORT4 | GPIO_PIN13) +#define GPIO_ENET1_PORT0_PHY_RESET \ + IOMUX_GPIO(IOMUXC_PAD_GPIO_AD_25_GPIO4_IO25, IOMUX_NETC_RESET_DEFAULT, \ + GPIO_OUTPUT | GPIO_OUTPUT_ONE | GPIO_PORT4 | GPIO_PIN25) +#define GPIO_ENET1_PORT1_PHY_RESET \ + IOMUX_GPIO(IOMUXC_PAD_GPIO_B1_13_GPIO6_IO13, IOMUX_NETC_RESET_DEFAULT, \ + GPIO_OUTPUT | GPIO_OUTPUT_ONE | GPIO_PORT6 | GPIO_PIN13) +#define GPIO_ENET1_PORT2_PHY_RESET \ + IOMUX_GPIO(IOMUXC_PAD_GPIO_AD_28_GPIO4_IO28, IOMUX_NETC_RESET_DEFAULT, \ + GPIO_OUTPUT | GPIO_OUTPUT_ONE | GPIO_PORT4 | GPIO_PIN28) +#define GPIO_ENET1_PORT3_PHY_RESET \ + IOMUX_GPIO(IOMUXC_PAD_GPIO_B2_01_GPIO6_IO15, IOMUX_NETC_RESET_DEFAULT, \ + GPIO_OUTPUT | GPIO_OUTPUT_ONE | GPIO_PORT6 | GPIO_PIN15) + +/* Leave PHY0/4 LED1/PHYAD1 straps under control of the external pull-ups. */ + +#define GPIO_ENET0_PHYAD1 \ + IOMUX_GPIO(IOMUXC_PAD_GPIO_AD_16_GPIO4_IO16, 0, \ + GPIO_INPUT | GPIO_PORT4 | GPIO_PIN16) +#define GPIO_ENET4_PHYAD1 \ + IOMUX_GPIO(IOMUXC_PAD_GPIO_AD_17_GPIO4_IO17, 0, \ + GPIO_INPUT | GPIO_PORT4 | GPIO_PIN17) + +#if defined(CONFIG_IMXRT_NETC_ENETC0) && defined(CONFIG_IMXRT_LPUART3) +# error "ENETC0 PHY reset shares GPIO_AD_13 with LPUART3 TX" +#endif + /* Buttons ******************************************************************/ /* The MIMXRT1180-EVK has one general purpose user button, SW8 ("GPIO INT diff --git a/boards/arm/imxrt/imxrt1180-evk/src/CMakeLists.txt b/boards/arm/imxrt/imxrt1180-evk/src/CMakeLists.txt new file mode 100644 index 00000000000..201dfec8b4b --- /dev/null +++ b/boards/arm/imxrt/imxrt1180-evk/src/CMakeLists.txt @@ -0,0 +1,54 @@ +# ############################################################################## +# boards/arm/imxrt/imxrt1180-evk/src/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## + +set(SRCS imxrt_boot.c imxrt_bringup.c imxrt_appinit.c) + +if(CONFIG_IMXRT_NETC) + list(APPEND SRCS imxrt_netc.c) +endif() + +if(CONFIG_ARCH_CORTEXM33) + list(APPEND SRCS imxrt_clockconfig_m33.c imxrt_flash_headers.c) +else() + list(APPEND SRCS imxrt_clockconfig_m7.c) +endif() + +if(CONFIG_IMXRT1180_EVK_BOOTLOADER) + list(APPEND SRCS imxrt_bootloader.c) +endif() + +if(CONFIG_ARCH_BUTTONS) + list(APPEND SRCS imxrt_buttons.c) +endif() + +if(CONFIG_USBDEV_DMAMEMORY OR CONFIG_FAT_DMAMEMORY) + list(APPEND SRCS imxrt_dma_alloc.c) +endif() + +target_sources(board PRIVATE ${SRCS}) + +if(CONFIG_ARCH_CORTEXM33) + set_property(GLOBAL PROPERTY LD_SCRIPT + "${NUTTX_BOARD_DIR}/scripts/flash-m33.ld") +else() + set_property(GLOBAL PROPERTY LD_SCRIPT "${NUTTX_BOARD_DIR}/scripts/flash.ld") +endif() diff --git a/boards/arm/imxrt/imxrt1180-evk/src/Makefile b/boards/arm/imxrt/imxrt1180-evk/src/Makefile index b0ad8287aa7..e9a18b4fa78 100644 --- a/boards/arm/imxrt/imxrt1180-evk/src/Makefile +++ b/boards/arm/imxrt/imxrt1180-evk/src/Makefile @@ -28,6 +28,10 @@ ifeq ($(CONFIG_IMXRT_ADC),y) CSRCS += imxrt_adc.c endif +ifeq ($(CONFIG_IMXRT_NETC),y) +CSRCS += imxrt_netc.c +endif + ifeq ($(CONFIG_ARCH_CORTEXM33),y) CSRCS += imxrt_clockconfig_m33.c else diff --git a/boards/arm/imxrt/imxrt1180-evk/src/imxrt1180-evk.h b/boards/arm/imxrt/imxrt1180-evk/src/imxrt1180-evk.h index 610c1e50b5a..94c704abb5f 100644 --- a/boards/arm/imxrt/imxrt1180-evk/src/imxrt1180-evk.h +++ b/boards/arm/imxrt/imxrt1180-evk/src/imxrt1180-evk.h @@ -38,6 +38,10 @@ int imxrt_bringup(void); +#ifdef CONFIG_IMXRT_NETC +int imxrt_netc_boardinitialize(void); +#endif + #if defined(CONFIG_USBDEV_DMAMEMORY) || defined(CONFIG_FAT_DMAMEMORY) int imxrt_dma_alloc_init(void); #endif diff --git a/boards/arm/imxrt/imxrt1180-evk/src/imxrt_bringup.c b/boards/arm/imxrt/imxrt1180-evk/src/imxrt_bringup.c index 9aeaafafd82..e1c9fbe864f 100644 --- a/boards/arm/imxrt/imxrt1180-evk/src/imxrt_bringup.c +++ b/boards/arm/imxrt/imxrt1180-evk/src/imxrt_bringup.c @@ -137,5 +137,13 @@ int imxrt_bringup(void) } #endif +#ifdef CONFIG_IMXRT_NETC + ret = imxrt_netc_boardinitialize(); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: NETC initialization failed: %d\n", ret); + } +#endif + return ret; } diff --git a/boards/arm/imxrt/imxrt1180-evk/src/imxrt_clockconfig_m7.c b/boards/arm/imxrt/imxrt1180-evk/src/imxrt_clockconfig_m7.c index c7a446cc358..03a5f6f31d2 100644 --- a/boards/arm/imxrt/imxrt1180-evk/src/imxrt_clockconfig_m7.c +++ b/boards/arm/imxrt/imxrt1180-evk/src/imxrt_clockconfig_m7.c @@ -161,12 +161,66 @@ const struct clock_configuration_s g_initial_clkconfig = .ecat_clk_root = CCM_CLOCK_ROOT_DISABLE, .enet_clk_root = CCM_CLOCK_ROOT_DISABLE, .tmr_1588_clk_root = CCM_CLOCK_ROOT_DISABLE, +#ifdef CONFIG_IMXRT_NETC + .netc_clk_root = + { + .action = CCM_CLOCK_ROOT_CONFIGURE, + .div = 2, + .mux = SYS_PLL3_PFD3, + }, +#else .netc_clk_root = CCM_CLOCK_ROOT_IGNORE, +#endif +#ifdef CONFIG_IMXRT_NETC_ENETC1_PORT0 + .mac0_clk_root = + { + .action = CCM_CLOCK_ROOT_CONFIGURE, + .div = 10, + .mux = SYS_PLL1_DIV2, + }, +#else .mac0_clk_root = CCM_CLOCK_ROOT_DISABLE, +#endif +#ifdef CONFIG_IMXRT_NETC_ENETC1_PORT1 + .mac1_clk_root = + { + .action = CCM_CLOCK_ROOT_CONFIGURE, + .div = 4, + .mux = SYS_PLL1_DIV2, + }, +#else .mac1_clk_root = CCM_CLOCK_ROOT_DISABLE, +#endif +#ifdef CONFIG_IMXRT_NETC_ENETC1_PORT2 + .mac2_clk_root = + { + .action = CCM_CLOCK_ROOT_CONFIGURE, + .div = 4, + .mux = SYS_PLL1_DIV2, + }, +#else .mac2_clk_root = CCM_CLOCK_ROOT_DISABLE, +#endif +#ifdef CONFIG_IMXRT_NETC_ENETC1_PORT3 + .mac3_clk_root = + { + .action = CCM_CLOCK_ROOT_CONFIGURE, + .div = 4, + .mux = SYS_PLL1_DIV2, + }, +#else .mac3_clk_root = CCM_CLOCK_ROOT_DISABLE, +#endif +#ifdef CONFIG_IMXRT_NETC_ENETC0 + .mac4_clk_root = + { + .action = CCM_CLOCK_ROOT_CONFIGURE, + .div = 10, + .mux = SYS_PLL1_DIV2, + }, +#else .mac4_clk_root = CCM_CLOCK_ROOT_DISABLE, +#endif .serdes0_clk_root = CCM_CLOCK_ROOT_DISABLE, .serdes1_clk_root = CCM_CLOCK_ROOT_DISABLE, .serdes2_clk_root = CCM_CLOCK_ROOT_DISABLE, diff --git a/boards/arm/imxrt/imxrt1180-evk/src/imxrt_netc.c b/boards/arm/imxrt/imxrt1180-evk/src/imxrt_netc.c new file mode 100644 index 00000000000..827bcc1c3b0 --- /dev/null +++ b/boards/arm/imxrt/imxrt1180-evk/src/imxrt_netc.c @@ -0,0 +1,347 @@ +/**************************************************************************** + * boards/arm/imxrt/imxrt1180-evk/src/imxrt_netc.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <errno.h> +#include <stdint.h> +#include <string.h> +#include <sys/param.h> +#include <syslog.h> + +#include <nuttx/arch.h> +#include <nuttx/net/realtek_phy.h> + +#include "arm_internal.h" +#include "imxrt_clockconfig.h" +#include "imxrt_gpio.h" +#include "imxrt_netc.h" +#include "imxrt1180-evk.h" +#include "hardware/rt118x/imxrt118x_ocotp.h" +#include <arch/board/board.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define BOARD_RTL8201F_PHY(addr) \ + .phyaddr = (addr), \ + .interface = PHY_INTERFACE_RMII + +#define BOARD_RTL8211F_PHY(addr) \ + .phyaddr = (addr), \ + .interface = PHY_INTERFACE_RGMII_ID + +#define RTL8201F_RESET_DELAY_MS 10 +#define RTL8201F_RESET_POST_DELAY_MS 150 +#define RTL8211F_RESET_DELAY_MS 10 +#define RTL8211F_RESET_POST_DELAY_MS 50 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct imxrt_netc_board_port_s +{ + imxrt_pinset_t pins[12]; + imxrt_pinset_t reset; + unsigned int npins; + unsigned int reset_delay; + unsigned int reset_post_delay; +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct imxrt_netc_board_port_s +g_netc_ports[IMXRT_NETC_PHY_PORT_COUNT] = +{ + [0] = + { + .pins = BOARD_ENET1_PORT0_PINS, + .reset = GPIO_ENET1_PORT0_PHY_RESET, + .npins = 8, + .reset_delay = RTL8201F_RESET_DELAY_MS, + .reset_post_delay = RTL8201F_RESET_POST_DELAY_MS + }, + [1] = + { + .pins = BOARD_ENET1_PORT1_PINS, + .reset = GPIO_ENET1_PORT1_PHY_RESET, + .npins = 12, + .reset_delay = RTL8211F_RESET_DELAY_MS, + .reset_post_delay = RTL8211F_RESET_POST_DELAY_MS + }, + [2] = + { + .pins = BOARD_ENET1_PORT2_PINS, + .reset = GPIO_ENET1_PORT2_PHY_RESET, + .npins = 12, + .reset_delay = RTL8211F_RESET_DELAY_MS, + .reset_post_delay = RTL8211F_RESET_POST_DELAY_MS + }, + [3] = + { + .pins = BOARD_ENET1_PORT3_PINS, + .reset = GPIO_ENET1_PORT3_PHY_RESET, + .npins = 12, + .reset_delay = RTL8211F_RESET_DELAY_MS, + .reset_post_delay = RTL8211F_RESET_POST_DELAY_MS + }, + [4] = + { + .pins = BOARD_ENET0_PORT0_PINS, + .reset = GPIO_ENET0_PORT0_PHY_RESET, + .npins = 8, + .reset_delay = RTL8201F_RESET_DELAY_MS, + .reset_post_delay = RTL8201F_RESET_POST_DELAY_MS + } +}; + +static const struct imxrt_netc_config_s g_netc_config = +{ + .enetc = + { + [0] = + { + .msgintr = 2, +#ifdef CONFIG_IMXRT_NETC_ENETC0 + .enabled = true, + .ports = + { + [0] = + { + .enabled = true, + BOARD_RTL8201F_PHY(3) + } + } +#endif + }, + [1] = + { + .msgintr = 1, +#if defined(CONFIG_IMXRT_NETC_ENETC1_PORT0) || \ + defined(CONFIG_IMXRT_NETC_ENETC1_PORT1) || \ + defined(CONFIG_IMXRT_NETC_ENETC1_PORT2) || \ + defined(CONFIG_IMXRT_NETC_ENETC1_PORT3) + .enabled = true, +#endif + .ports = + { +#ifdef CONFIG_IMXRT_NETC_ENETC1_PORT0 + [0] = + { + .enabled = true, + BOARD_RTL8201F_PHY(2) + }, +#endif +#ifdef CONFIG_IMXRT_NETC_ENETC1_PORT1 + [1] = + { + .enabled = true, + BOARD_RTL8211F_PHY(5) + }, +#endif +#ifdef CONFIG_IMXRT_NETC_ENETC1_PORT2 + [2] = + { + .enabled = true, + BOARD_RTL8211F_PHY(4) + }, +#endif +#ifdef CONFIG_IMXRT_NETC_ENETC1_PORT3 + [3] = + { + .enabled = true, + BOARD_RTL8211F_PHY(7) + }, +#endif + } + } + } +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int board_netc_phyinit(unsigned int if_idx, + const struct imxrt_netc_port_s *config) +{ + const struct imxrt_netc_board_port_s *port; + uint16_t gpio; + unsigned int gpioport; + uint32_t mask; + int ret; + + /* config not used */ + + (void) config; + + DEBUGASSERT(if_idx < nitems(g_netc_ports)); + port = &g_netc_ports[if_idx]; + ret = imxrt_config_gpio(port->reset | GPIO_SION_ENABLE); + if (ret < 0) + { + syslog(LOG_ERR, "NETC: reset pin for port %u failed: %d\n", + if_idx, ret); + return ret; + } + + /* Enable input readback of the open-drain reset pad. */ + + gpio = IMXRT_PINSET_GPIO(port->reset); + gpioport = (gpio & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT; + mask = 1u << ((gpio & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT); + modifyreg32(IMXRT_GPIO_PIDR(gpioport), mask, 0); + + imxrt_gpio_write(port->reset, false); + up_mdelay(port->reset_delay); + imxrt_gpio_write(port->reset, true); + up_mdelay(port->reset_post_delay); + return OK; +} + +int imxrt_netc_boardinitialize(void) +{ + struct imxrt_netc_config_s config = g_netc_config; + const struct imxrt_netc_port_s *port; + uint32_t uidl; + uint32_t uidml; + unsigned int i; + unsigned int pin; + int ret; + + ret = imxrt_ccm_gate_on(CCM_LPCG_IOMUXC1, true); + if (ret < 0) + { + syslog(LOG_ERR, "NETC: IOMUXC1 clock failed: %d\n", ret); + return ret; + } + + ret = imxrt_clockall_gpio4(); + if (ret < 0) + { + syslog(LOG_ERR, "NETC: GPIO4 clock failed: %d\n", ret); + return ret; + } + + if (config.enetc[1].enabled) + { + ret = imxrt_clockall_gpio6(); + if (ret < 0) + { + syslog(LOG_ERR, "NETC: GPIO6 clock failed: %d\n", ret); + return ret; + } + } + + ret = imxrt_config_gpio(GPIO_NETC_MDC); + if (ret == OK) + { + ret = imxrt_config_gpio(GPIO_NETC_MDIO); + } + + if (ret < 0) + { + syslog(LOG_ERR, "NETC: MDIO pin configuration failed: %d\n", ret); + return ret; + } + +#ifdef CONFIG_IMXRT_NETC_ENETC0 + ret = imxrt_config_gpio(GPIO_ENET4_PHYAD1); + if (ret < 0) + { + syslog(LOG_ERR, "NETC: PHY4 strap pin configuration failed: %d\n", + ret); + return ret; + } +#endif + +#ifdef CONFIG_IMXRT_NETC_ENETC1_PORT0 + ret = imxrt_config_gpio(GPIO_ENET0_PHYAD1); + if (ret < 0) + { + syslog(LOG_ERR, "NETC: PHY0 strap pin configuration failed: %d\n", + ret); + return ret; + } +#endif + + for (i = 0; i < nitems(g_netc_ports); i++) + { + port = i == 4 ? &config.enetc[0].ports[0] : + &config.enetc[1].ports[i]; + if (!port->enabled) + { + continue; + } + + for (pin = 0; pin < g_netc_ports[i].npins; pin++) + { + ret = imxrt_config_gpio(g_netc_ports[i].pins[pin]); + if (ret < 0) + { + syslog(LOG_ERR, "NETC: port %u pin %u failed: %d\n", + i, pin, ret); + return ret; + } + } + } + + uidl = getreg32(IMXRT_OCOTP_UNIQUE_ID_MSB); + uidml = getreg32(IMXRT_OCOTP_UNIQUE_ID_LSB); + config.enetc[1].mac[0] = ((uidml >> 8) & 0xfe) | 0x02; + config.enetc[1].mac[1] = uidml; + config.enetc[1].mac[2] = uidl >> 24; + config.enetc[1].mac[3] = uidl >> 16; + config.enetc[1].mac[4] = uidl >> 8; + config.enetc[1].mac[5] = uidl; + memcpy(config.enetc[0].mac, config.enetc[1].mac, + sizeof(config.enetc[0].mac)); + config.enetc[0].mac[5] ^= 1; + +#ifdef CONFIG_NET_PHY_REALTEK_RTL8201F + ret = rtl8201f_register(); + if (ret < 0) + { + syslog(LOG_ERR, "NETC: RTL8201F registration failed: %d\n", ret); + return ret; + } +#endif + +#ifdef CONFIG_NET_PHY_REALTEK_RTL8211F + ret = rtl8211f_register(); + if (ret < 0) + { + syslog(LOG_ERR, "NETC: RTL8211F registration failed: %d\n", ret); + return ret; + } +#endif + + return imxrt_netc_initialize(&config); +}
