soc: arm: add support for nuvoton numaker m46x series

Add initial support for nuvoton numaker m46x SoC series including
basic init.

Signed-off-by: cyliang tw <cyliang@nuvoton.com>
diff --git a/dts/arm/nuvoton/m46x.dtsi b/dts/arm/nuvoton/m46x.dtsi
new file mode 100644
index 0000000..c87995e
--- /dev/null
+++ b/dts/arm/nuvoton/m46x.dtsi
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2023 Nuvoton Technology Corporation.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <arm/armv7-m.dtsi>
+#include <mem.h>
+
+/ {
+	cpus {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		cpu@0 {
+			device_type = "cpu";
+			compatible = "arm,cortex-m4f";
+			reg = <0>;
+		};
+	};
+
+	sram0: memory@20000000 {
+		compatible = "mmio-sram";
+		reg = <0x20000000 DT_SIZE_K(512)>;
+	};
+
+	flash0: flash@0 {
+		compatible = "soc-nv-flash";
+		reg = <0 DT_SIZE_K(1024)>;
+		erase-block-size = <4096>;
+		write-block-size = <4>;
+	};
+
+	sysclk: system-clock {
+		compatible = "fixed-clock";
+		clock-frequency = <200000000>;
+		#clock-cells = <0>;
+	};
+};
+
+&nvic {
+	arm,num-irq-priority-bits = <4>;
+};
diff --git a/modules/Kconfig.nuvoton b/modules/Kconfig.nuvoton
index cdf94bf..4413c29 100644
--- a/modules/Kconfig.nuvoton
+++ b/modules/Kconfig.nuvoton
@@ -12,9 +12,59 @@
 	depends on HAS_NUMICRO_HAL
 
 config HAS_NUMICRO_UART
-	bool
+	bool "NuMicro UART"
 	help
 	  Enable Nuvoton Universal asynchronous receiver transmitter HAL
 	  module driver
 
 endmenu
+
+config HAS_NUMAKER_HAL
+	bool
+	select HAS_CMSIS_CORE
+	depends on SOC_FAMILY_NUMAKER
+
+menu "Nuvoton NuMaker drivers"
+	depends on HAS_NUMAKER_HAL
+	config HAS_NUMAKER_UART
+		bool "NuMaker UART"
+		help
+		  Enable Nuvoton Universal asynchronous receiver transmitter HAL
+		  module driver
+	config HAS_NUMAKER_GPIO
+		bool "NuMaker GPIO"
+		help
+		  Enable Nuvoton gpio HAL module driver
+	config HAS_NUMAKER_FMC
+		bool "NuMaker FMC"
+		help
+		  Enable Nuvoton FMC HAL module driver
+	config HAS_NUMAKER_I2C
+		bool "NuMaker I2C"
+		help
+		  Enable Nuvoton I2C HAL module driver
+	config HAS_NUMAKER_SPI
+		bool "NuMaker SPI"
+		help
+		  Enable Nuvoton SPI HAL module driver
+	config HAS_NUMAKER_PWM
+		bool "NuMaker PWM"
+		help
+		  Enable Nuvoton PWM HAL module driver
+	config HAS_NUMAKER_USBD
+		bool "NuMaker USB 1.1 device controller"
+		help
+		  Enable Nuvoton USB 1.1 device controller HAL module driver
+	config HAS_NUMAKER_HSUSBD
+		bool "NuMaker high-speed USB 2.0 device controller"
+		help
+		  Enable Nuvoton high-speed USB 2.0 device controller HAL module driver
+	config HAS_NUMAKER_ETH
+		bool "NuMaker ETH"
+		help
+		  Enable Nuvoton ETH EMAC HAL module driver
+	config HAS_NUMAKER_CANFD
+		bool "NuMaker CAN FD"
+		help
+		  Enable Nuvoton CAN FD HAL module driver
+endmenu
diff --git a/soc/arm/nuvoton_numaker/CMakeLists.txt b/soc/arm/nuvoton_numaker/CMakeLists.txt
new file mode 100644
index 0000000..ba7e2ec
--- /dev/null
+++ b/soc/arm/nuvoton_numaker/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Copyright (c) 2023 Nuvoton Technology Corporation.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+# This is for access to pinctrl macros
+zephyr_include_directories(common)
+
+add_subdirectory(${SOC_SERIES})
diff --git a/soc/arm/nuvoton_numaker/Kconfig b/soc/arm/nuvoton_numaker/Kconfig
new file mode 100644
index 0000000..e9b668e
--- /dev/null
+++ b/soc/arm/nuvoton_numaker/Kconfig
@@ -0,0 +1,18 @@
+# Copyright (c) 2023 Nuvoton Technology Corporation.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+
+config SOC_FAMILY_NUMAKER
+	select PLATFORM_SPECIFIC_INIT
+	bool
+
+if SOC_FAMILY_NUMAKER
+
+config SOC_FAMILY
+	string
+	default "nuvoton_numaker"
+
+source "soc/arm/nuvoton_numaker/*/Kconfig.soc"
+
+endif # SOC_FAMILY_NUMAKER
diff --git a/soc/arm/nuvoton_numaker/Kconfig.defconfig b/soc/arm/nuvoton_numaker/Kconfig.defconfig
new file mode 100644
index 0000000..bcccdaa
--- /dev/null
+++ b/soc/arm/nuvoton_numaker/Kconfig.defconfig
@@ -0,0 +1,5 @@
+# Copyright (c) 2023 Nuvoton Technology Corporation.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+source "soc/arm/nuvoton_numaker/*/Kconfig.defconfig.series"
diff --git a/soc/arm/nuvoton_numaker/Kconfig.soc b/soc/arm/nuvoton_numaker/Kconfig.soc
new file mode 100644
index 0000000..8e3ff44
--- /dev/null
+++ b/soc/arm/nuvoton_numaker/Kconfig.soc
@@ -0,0 +1,5 @@
+# Copyright (c) 2023 Nuvoton Technology Corporation.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+source "soc/arm/nuvoton_numaker/*/Kconfig.series"
diff --git a/soc/arm/nuvoton_numaker/m46x/CMakeLists.txt b/soc/arm/nuvoton_numaker/m46x/CMakeLists.txt
new file mode 100644
index 0000000..6b2126d
--- /dev/null
+++ b/soc/arm/nuvoton_numaker/m46x/CMakeLists.txt
@@ -0,0 +1,5 @@
+# Copyright (c) 2023 Nuvoton Technology Corporation.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+zephyr_sources(soc.c)
diff --git a/soc/arm/nuvoton_numaker/m46x/Kconfig.defconfig.m467 b/soc/arm/nuvoton_numaker/m46x/Kconfig.defconfig.m467
new file mode 100644
index 0000000..ff94f5d
--- /dev/null
+++ b/soc/arm/nuvoton_numaker/m46x/Kconfig.defconfig.m467
@@ -0,0 +1,10 @@
+# Copyright (c) 2023 Nuvoton Technology Corporation.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+if SOC_M467
+
+config NUM_IRQS
+	default 127
+
+endif # SOC_M467
diff --git a/soc/arm/nuvoton_numaker/m46x/Kconfig.defconfig.series b/soc/arm/nuvoton_numaker/m46x/Kconfig.defconfig.series
new file mode 100644
index 0000000..8bf1440
--- /dev/null
+++ b/soc/arm/nuvoton_numaker/m46x/Kconfig.defconfig.series
@@ -0,0 +1,12 @@
+# Copyright (c) 2023 Nuvoton Technology Corporation.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+if SOC_SERIES_M46X
+
+source "soc/arm/nuvoton_numaker/m46x/Kconfig.defconfig.m46*"
+
+config SOC_SERIES
+	default "m46x"
+
+endif # SOC_SERIES_M46X
diff --git a/soc/arm/nuvoton_numaker/m46x/Kconfig.series b/soc/arm/nuvoton_numaker/m46x/Kconfig.series
new file mode 100644
index 0000000..61e877f
--- /dev/null
+++ b/soc/arm/nuvoton_numaker/m46x/Kconfig.series
@@ -0,0 +1,15 @@
+# Copyright (c) 2023 Nuvoton Technology Corporation.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+config SOC_SERIES_M46X
+	bool "Nuvoton M46X Series MCU"
+	select ARM
+	select CPU_CORTEX_M4
+	select CPU_CORTEX_M_HAS_DWT
+	select CPU_HAS_FPU
+	select CPU_HAS_ARM_MPU
+	select CORTEX_M_SYSTICK
+	select SOC_FAMILY_NUMAKER
+	help
+	  Enable support for Nuvoton M46X MCU series
diff --git a/soc/arm/nuvoton_numaker/m46x/Kconfig.soc b/soc/arm/nuvoton_numaker/m46x/Kconfig.soc
new file mode 100644
index 0000000..898d23b
--- /dev/null
+++ b/soc/arm/nuvoton_numaker/m46x/Kconfig.soc
@@ -0,0 +1,13 @@
+# Copyright (c) 2023 Nuvoton Technology Corporation.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+choice
+	prompt "Nuvoton M46X MCU Selection"
+	depends on SOC_SERIES_M46X
+
+config SOC_M467
+	bool "M467"
+	select HAS_NUMAKER_HAL
+
+endchoice
diff --git a/soc/arm/nuvoton_numaker/m46x/linker.ld b/soc/arm/nuvoton_numaker/m46x/linker.ld
new file mode 100644
index 0000000..b9a8077
--- /dev/null
+++ b/soc/arm/nuvoton_numaker/m46x/linker.ld
@@ -0,0 +1,7 @@
+/*
+ * Copyright (c) 2023 Nuvoton Technology Corporation.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <zephyr/arch/arm/aarch32/cortex_m/scripts/linker.ld>
diff --git a/soc/arm/nuvoton_numaker/m46x/soc.c b/soc/arm/nuvoton_numaker/m46x/soc.c
new file mode 100644
index 0000000..5637007
--- /dev/null
+++ b/soc/arm/nuvoton_numaker/m46x/soc.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2023 Nuvoton Technology Corporation.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include <zephyr/devicetree.h>
+/* Hardware and starter kit includes. */
+#include <NuMicro.h>
+
+void z_arm_platform_init(void)
+{
+	SystemInit();
+
+	/* Unlock protected registers */
+	SYS_UnlockReg();
+
+	/*
+	 * -------------------
+	 * Init System Clock
+	 * -------------------
+	 */
+
+	CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
+	/* Wait for HXT clock ready */
+	CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);
+
+	CLK_EnableXtalRC(CLK_PWRCTL_LXTEN_Msk);
+	/* Wait for LXT clock ready */
+	CLK_WaitClockReady(CLK_STATUS_LXTSTB_Msk);
+
+	/* Enable 12 MHz high-speed internal RC oscillator (HIRC) */
+	CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);
+	/* Wait for HIRC clock ready */
+	CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);
+
+	/* Enable 10 KHz low-speed internal RC oscillator (LIRC) */
+	CLK_EnableXtalRC(CLK_PWRCTL_LIRCEN_Msk);
+	/* Wait for LIRC clock ready */
+	CLK_WaitClockReady(CLK_STATUS_LIRCSTB_Msk);
+
+	CLK_EnableXtalRC(CLK_PWRCTL_HIRC48EN_Msk);
+	/* Wait for HIRC48 clock ready */
+	CLK_WaitClockReady(CLK_STATUS_HIRC48STB_Msk);
+
+	/* Set PCLK0 and PCLK1 to HCLK/2 */
+	CLK->PCLKDIV = (CLK_PCLKDIV_APB0DIV_DIV2 | CLK_PCLKDIV_APB1DIV_DIV2);
+
+	/* Set core clock to 200MHz */
+	CLK_SetCoreClock(200000000);
+
+	/*
+	 * Update System Core Clock
+	 * User can use SystemCoreClockUpdate() to calculate SystemCoreClock.
+	 */
+	SystemCoreClockUpdate();
+
+	/* Lock protected registers */
+	SYS_LockReg();
+}
diff --git a/soc/arm/nuvoton_numaker/m46x/soc.h b/soc/arm/nuvoton_numaker/m46x/soc.h
new file mode 100644
index 0000000..dcb21b3
--- /dev/null
+++ b/soc/arm/nuvoton_numaker/m46x/soc.h
@@ -0,0 +1,13 @@
+/*
+ * Copyright (c) 2023 Nuvoton Technology Corporation.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#ifndef ZEPHYR_SOC_ARM_NUVOTON_M46X_SOC_H_
+#define ZEPHYR_SOC_ARM_NUVOTON_M46X_SOC_H_
+
+/* Hardware and starter kit includes. */
+#include <NuMicro.h>
+
+#endif /* ZEPHYR_SOC_ARM_NUVOTON_M46X_SOC_H_*/