diff --git a/boards/nuvoton/numaker_m55m1/Kconfig.defconfig b/boards/nuvoton/numaker_m55m1/Kconfig.defconfig new file mode 100644 index 00000000000..923a86f8dfc --- /dev/null +++ b/boards/nuvoton/numaker_m55m1/Kconfig.defconfig @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Nuvoton NuMaker M55M1 board configuration +# +# Copyright (c) 2025 Nuvoton Technology Corporation. + +if BOARD_NUMAKER_M55M1 + +if NETWORKING + +config NET_L2_ETHERNET + default y if !MODEM + +endif # NETWORKING + +endif # BOARD_NUMAKER_M55M1 diff --git a/boards/nuvoton/numaker_m55m1/numaker_m55m1-pinctrl.dtsi b/boards/nuvoton/numaker_m55m1/numaker_m55m1-pinctrl.dtsi index 4bfa3d95c67..9139b82417e 100644 --- a/boards/nuvoton/numaker_m55m1/numaker_m55m1-pinctrl.dtsi +++ b/boards/nuvoton/numaker_m55m1/numaker_m55m1-pinctrl.dtsi @@ -24,4 +24,23 @@ ; }; }; + + /* EMAC multi-function pins for MDIO, TX, REFCLK, RX pins */ + emac_default: emac_default { + group0 { + pinmux = , + , + , + , + , + , + ; + }; + group1 { + pinmux = , + , + ; + slew-rate = "fast"; + }; + }; }; diff --git a/boards/nuvoton/numaker_m55m1/numaker_m55m1.dts b/boards/nuvoton/numaker_m55m1/numaker_m55m1.dts index 9025b25b149..edfb4bcc0a6 100644 --- a/boards/nuvoton/numaker_m55m1/numaker_m55m1.dts +++ b/boards/nuvoton/numaker_m55m1/numaker_m55m1.dts @@ -86,3 +86,9 @@ pinctrl-names = "default"; status = "okay"; }; + +&emac { + pinctrl-0 = <&emac_default>; + pinctrl-names = "default"; + status = "okay"; +}; diff --git a/doc/releases/migration-guide-4.2.rst b/doc/releases/migration-guide-4.2.rst index 9477c1ec213..4096653591b 100644 --- a/doc/releases/migration-guide-4.2.rst +++ b/doc/releases/migration-guide-4.2.rst @@ -133,6 +133,9 @@ Ethernet kconfig options: :kconfig:option:`CONFIG_ETH_NATIVE_POSIX` and its related options have been deprecated in favor of :kconfig:option:`CONFIG_ETH_NATIVE_TAP` (:github:`86578`). +* NuMaker Ethernet driver ``eth_numaker.c`` now supports ``gen_random_mac``, + and the EMAC data flash feature has been removed (:github:`87953`). + Enhanced Serial Peripheral Interface (eSPI) =========================================== diff --git a/drivers/ethernet/Kconfig.numaker b/drivers/ethernet/Kconfig.numaker index a21462bac74..3a40c1d81af 100644 --- a/drivers/ethernet/Kconfig.numaker +++ b/drivers/ethernet/Kconfig.numaker @@ -9,6 +9,7 @@ config ETH_NUMAKER select HAS_NUMAKER_ETH select PINCTRL depends on DT_HAS_NUVOTON_NUMAKER_ETHERNET_ENABLED + select NOCACHE_MEMORY if ARCH_HAS_NOCACHE_MEMORY_SUPPORT help This option enables the Ethernet driver for Nuvoton NuMaker family of processors. diff --git a/drivers/ethernet/eth_numaker.c b/drivers/ethernet/eth_numaker.c index 77577943f23..80b807e8f8b 100644 --- a/drivers/ethernet/eth_numaker.c +++ b/drivers/ethernet/eth_numaker.c @@ -21,22 +21,31 @@ #ifdef CONFIG_SOC_M467 #include +#else +#include #endif LOG_MODULE_REGISTER(eth_numaker, CONFIG_ETHERNET_LOG_LEVEL); /* Device EMAC Interface port */ #define NUMAKER_GMAC_INTF 0 -/* 2KB Data Flash at 0xFF800 */ -#define NUMAKER_DATA_FLASH (0xFF800U) + #define NUMAKER_MASK_32 (0xFFFFFFFFU) #define NUMAKER_MII_CONFIG (ADVERTISE_CSMA | ADVERTISE_10HALF | ADVERTISE_10FULL | \ ADVERTISE_100HALF | ADVERTISE_100FULL) #define NUMAKER_MII_LINKED (BMSR_ANEGCOMPLETE | BMSR_LSTATUS) extern synopGMACdevice GMACdev[GMAC_CNT]; + +#ifdef CONFIG_NOCACHE_MEMORY +DmaDesc tx_desc[GMAC_CNT][TRANSMIT_DESC_SIZE] __nocache __aligned(64); +DmaDesc rx_desc[GMAC_CNT][RECEIVE_DESC_SIZE] __nocache __aligned(64); +struct sk_buff tx_buf[GMAC_CNT][TRANSMIT_DESC_SIZE] __nocache __aligned(64); +struct sk_buff rx_buf[GMAC_CNT][RECEIVE_DESC_SIZE] __nocache __aligned(64); +#else extern struct sk_buff tx_buf[GMAC_CNT][TRANSMIT_DESC_SIZE]; extern struct sk_buff rx_buf[GMAC_CNT][RECEIVE_DESC_SIZE]; +#endif static uint32_t eth_phy_addr; @@ -167,33 +176,31 @@ static int reset_phy(synopGMACdevice *gmacdev) static void m_numaker_read_mac_addr(char *mac) { +#if DT_INST_PROP(0, zephyr_random_mac_address) + gen_random_mac(mac, NUMAKER_OUI_B0, NUMAKER_OUI_B1, NUMAKER_OUI_B2); +#else uint32_t uid1; - /* Fetch word 0 of data flash */ - uint32_t word0 = *(uint32_t *)(NUMAKER_DATA_FLASH + 0x04U); + uint32_t word0; /* - * Fetch word 1 of data flash * we only want bottom 16 bits of word1 (MAC bits 32-47) * and bit 9 forced to 1, bit 8 forced to 0 * Locally administered MAC, reduced conflicts * http://en.wikipedia.org/wiki/MAC_address */ - uint32_t word1 = *(uint32_t *)NUMAKER_DATA_FLASH; - - /* Not burn any mac address at the beginning of data flash */ - if (word0 == NUMAKER_MASK_32) { - /* Generate a semi-unique MAC address from the UUID */ - SYS_UnlockReg(); - /* Enable FMC ISP function */ - FMC_Open(); - uid1 = FMC_ReadUID(1); - word1 = (uid1 & 0x003FFFFF) | ((uid1 & 0x030000) << 6) >> 8; - word0 = ((FMC_ReadUID(0) >> 4) << 20) | ((uid1 & 0xFF) << 12) | - (FMC_ReadUID(2) & 0xFFF); - /* Disable FMC ISP function */ - FMC_Close(); - /* Lock protected registers */ - SYS_LockReg(); - } + uint32_t word1; + + /* Generate a semi-unique MAC address from the UUID */ + SYS_UnlockReg(); + /* Enable FMC ISP function */ + FMC_Open(); + uid1 = FMC_ReadUID(1); + word1 = (uid1 & 0x003FFFFF) | ((uid1 & 0x030000) << 6) >> 8; + word0 = ((FMC_ReadUID(0) >> 4) << 20) | ((uid1 & 0xFF) << 12) | + (FMC_ReadUID(2) & 0xFFF); + /* Disable FMC ISP function */ + FMC_Close(); + /* Lock protected registers */ + SYS_LockReg(); word1 |= 0x00000200; word1 &= 0x0000FEFF; @@ -204,7 +211,7 @@ static void m_numaker_read_mac_addr(char *mac) mac[3] = (word0 & 0x00ff0000) >> 16; mac[4] = (word0 & 0x0000ff00) >> 8; mac[5] = (word0 & 0x000000ff); - +#endif LOG_INF("mac address %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); } diff --git a/drivers/ethernet/eth_numaker_priv.h b/drivers/ethernet/eth_numaker_priv.h index e3bec804b98..283081dd47c 100644 --- a/drivers/ethernet/eth_numaker_priv.h +++ b/drivers/ethernet/eth_numaker_priv.h @@ -15,4 +15,9 @@ #define NU_ETH_MTU_SIZE 1500 +/* NuMaker chip's OUI*/ +#define NUMAKER_OUI_B0 0xDA +#define NUMAKER_OUI_B1 0x00 +#define NUMAKER_OUI_B2 0x53 + #endif /* ZEPHYR_DRIVERS_ETHERNET_ETH_NUMAKER_PRIV_H_ */ diff --git a/dts/arm/nuvoton/m55m1x.dtsi b/dts/arm/nuvoton/m55m1x.dtsi index bb3a6f0858a..d0d17060552 100644 --- a/dts/arm/nuvoton/m55m1x.dtsi +++ b/dts/arm/nuvoton/m55m1x.dtsi @@ -335,6 +335,16 @@ #size-cells = <0>; status = "disabled"; }; + + emac: ethernet@40208000 { + compatible = "nuvoton,numaker-ethernet"; + reg = <0x40208000 0x2000>; + interrupts = <63 0>; + resets = <&rst NUMAKER_SYS_EMAC0RST>; + phy-addr = <0>; + clocks = <&pcc NUMAKER_EMAC0_MODULE 0 0>; + status = "disabled"; + }; }; }; diff --git a/west.yml b/west.yml index 82b19138a5f..b5ba95f2405 100644 --- a/west.yml +++ b/west.yml @@ -198,7 +198,7 @@ manifest: groups: - hal - name: hal_nuvoton - revision: 8eec051270fe45c3f9a1a12de60220e1ab26b579 + revision: be1042dc8a96ebe9ea4c5d714f07c617539106d6 path: modules/hal/nuvoton groups: - hal