Skip to content

Commit 77bea75

Browse files
committed
samples: net: dsa: Add KSZ8463MLI net shell sample
Provide a sample showing how the KSZ8463 is configured for the Cortex-M7 CPU on ST's Nucleo H755ZI-Q. The KSZ8463MLI evaluation board is assumed to be connected to spi1. The primary focus of the sample is illustrating a proper devicetree configuration. The software included does nothing. Instead, users are expected to use the net shell to manage the DSA interfaces. Signed-off-by: Vilhelm Engström <vilhelm.engstrom@tuta.io>
1 parent 67b4885 commit 77bea75

6 files changed

Lines changed: 407 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2026 Vilhelm Engström
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
cmake_minimum_required(VERSION 3.20.0)
6+
7+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
8+
project(dsa_ksz8463)
9+
10+
target_sources(app PRIVATE src/main.c)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.. zephyr:code-sample:: dsa_ksz8463ml
2+
:name: KSZ8463ML DSA sample
3+
:relevant-api: dsa_core
4+
5+
Configure the KSZ8463ML evaluation board and use net-shell to view the interfaces.
6+
7+
Overview
8+
********
9+
10+
A sample application configuring the Microchip KSZ8463ML MII-based 3-port Ethernet
11+
switch. The sample enables the net-shell, allowing users to view and manage the DSA
12+
interfaces.
13+
14+
Source code for the sample is available at
15+
:zephyr_file:`samples/net/ethernet/dsa_ksz8463ml`
16+
17+
Requirements
18+
************
19+
20+
- :ref:`networking_with_host`
21+
22+
Building and Running
23+
********************
24+
25+
The sample is built by running the following:
26+
27+
.. zephyr-app-commands::
28+
:zephyr-app: samples/net/ethernet/dsa_ksz8463ml
29+
:board: <board to use>
30+
:conf: prj.conf
31+
:goals: build
32+
:compact:
33+
34+
Using the Nucleo H755ZI-Q With the KSZ8463ML Evaluation Board
35+
=============================================================
36+
37+
The KSZ8463ML evaluation board uses a MII connector for connecting the MAC of port 3
38+
--- i.e. the host/CPU port --- to an external MAC. Using the evaluation board with
39+
the STM32 Nucleo H755ZI-Q, which comes with an integrated LAN8742A PHY connected via
40+
RMII, can therefore be done in one of two ways.
41+
42+
#. Desolder the LAN8742A PHY from the Nucleo board and connect the respective MII lines
43+
from the KSZ8463 directly to the extension connectors/through holes on the former
44+
#. Hook the KSZ8463ML evaluation board up to an external PHY and connect said PHY
45+
to the Nucleo board via Ethernet (untested).
46+
47+
Note that the strap-in configuration differs between the two options. See Section 3.1.1
48+
in the KSZ8463ML/RL user guide.
Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
/*
2+
* Copyright (c) 2026 Vilhelm Engström
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <st/h7/stm32h755zitx-pinctrl.dtsi>
8+
#include <zephyr/dt-bindings/pinctrl/stm32-pinctrl.h>
9+
#include <zephyr/dt-bindings/ethernet/dsa_tag_proto.h>
10+
11+
&mac {
12+
pinctrl-0 = <
13+
&eth_mii_col_pa3
14+
&eth_mii_crs_pa0
15+
&eth_mii_rx_clk_pa1
16+
&eth_mii_rx_dv_pa7
17+
&eth_mii_rx_er_pb10
18+
&eth_mii_rxd0_pc4
19+
&eth_mii_rxd1_pc5
20+
&eth_mii_rxd2_pb0
21+
&eth_mii_rxd3_pb1
22+
&eth_mii_tx_clk_pc3
23+
&eth_mii_tx_en_pb11
24+
&eth_mii_txd0_pb12
25+
&eth_mii_txd1_pb13
26+
&eth_mii_txd2_pc2
27+
&eth_mii_txd3_pb8
28+
&eth_mii_tx_er_pb2
29+
>;
30+
pinctrl-names = "default";
31+
32+
phy-handle = <&phy0>;
33+
34+
/* KSZ8463ML uses MII */
35+
phy-connection-type = "mii";
36+
37+
status = "okay";
38+
};
39+
40+
&mdio {
41+
pinctrl-0 = <
42+
&eth_mdc_pc1
43+
&eth_mdio_pa2
44+
>;
45+
pinctrl-names = "default";
46+
47+
status = "okay";
48+
49+
/* PHY for CPU port */
50+
phy0: ethernet-phy@0 {
51+
/* Know the capabilities of both the MAC transceiver and
52+
* the switch, no sense attempting to negotiate speeds
53+
*/
54+
compatible = "ethernet-phy-fixed-link";
55+
56+
/* KSZ8463 capped at 100Mbps, Full-Duplex */
57+
default-speeds = "100BASE Full-Duplex";
58+
59+
reg = <0>;
60+
status = "okay";
61+
};
62+
};
63+
64+
65+
&pinctrl {
66+
eth_mdc_pc1: eth_mdc_pc1 {
67+
pinmux = <
68+
STM32_PINMUX('C', 1, AF11) /* ETH_MDC */
69+
>;
70+
};
71+
72+
eth_mdio_pa2: eth_mdio_pa2 {
73+
pinmux = <
74+
STM32_PINMUX('A', 2, AF11) /* ETH_MDIO */
75+
>;
76+
};
77+
78+
eth_mii_col_pa3: eth_mii_col_pa3 {
79+
pinmux = <
80+
STM32_PINMUX('A', 3, AF11) /* ETH_MII_COL */
81+
>;
82+
};
83+
84+
eth_mii_crs_pa0: eth_mii_crs_pa0 {
85+
pinmux = <
86+
STM32_PINMUX('A', 0, AF11) /* ETH_MII_CRS */
87+
>;
88+
};
89+
90+
eth_mii_rx_clk_pa1: eth_mii_rx_clk_pa1 {
91+
pinmux = <
92+
STM32_PINMUX('A', 1, AF11) /* ETH_MII_RX_CLK */
93+
>;
94+
};
95+
96+
eth_mii_rx_dv_pa7: eth_mii_rx_dv_pa7 {
97+
pinmux = <
98+
STM32_PINMUX('A', 7, AF11) /* ETH_MII_RX_DV */
99+
>;
100+
};
101+
102+
eth_mii_rx_er_pb10: eth_mii_rx_er_pb10 {
103+
pinmux = <
104+
STM32_PINMUX('B', 10, AF11) /* ETH_MII_RX_ER */
105+
>;
106+
};
107+
108+
eth_mii_rxd0_pc4: eth_mii_rxd0_pc4 {
109+
pinmux = <
110+
STM32_PINMUX('C', 4, AF11) /* ETH_MII_RXD0 */
111+
>;
112+
};
113+
114+
eth_mii_rxd1_pc5: eth_mii_rxd1_pc5 {
115+
pinmux = <
116+
STM32_PINMUX('C', 5, AF11) /* ETH_MII_RXD1 */
117+
>;
118+
};
119+
120+
eth_mii_rxd2_pb0: eth_mii_rxd2_pb0 {
121+
pinmux = <
122+
STM32_PINMUX('B', 0, AF11) /* ETH_MII_RXD2 */
123+
>;
124+
};
125+
126+
eth_mii_rxd3_pb1: eth_mii_rxd3_pb1 {
127+
pinmux = <
128+
STM32_PINMUX('B', 1, AF11) /* ETH_MII_RXD3 */
129+
>;
130+
};
131+
132+
eth_mii_tx_clk_pc3: eth_mii_tx_clk_pc3 {
133+
pinmux = <
134+
STM32_PINMUX('C', 3, AF11) /* ETH_MII_TX_CLK */
135+
>;
136+
};
137+
138+
eth_mii_tx_en_pb11: eth_mii_tx_en_pb11 {
139+
pinmux = <
140+
STM32_PINMUX('B', 11, AF11) /* ETH_MII_TX_EN */
141+
>;
142+
};
143+
144+
eth_mii_tx_er_pb2: eth_mii_tx_er_pb2 {
145+
pinmux = <
146+
STM32_PINMUX('B', 2, AF11) /* ETH_TX_ER */
147+
>;
148+
};
149+
150+
eth_mii_txd0_pb12: eth_mii_txd0_pb12 {
151+
pinmux = <
152+
STM32_PINMUX('B', 12, AF11) /* ETH_MII_TXD0 */
153+
>;
154+
};
155+
156+
eth_mii_txd1_pb13: eth_mii_txd1_pb13 {
157+
pinmux = <
158+
STM32_PINMUX('B', 13, AF11) /* ETH_MII_TXD1 */
159+
>;
160+
};
161+
162+
eth_mii_txd2_pc2: eth_mii_txd2_pc2 {
163+
pinmux = <
164+
STM32_PINMUX('C', 2, AF11) /* ETH_MII_TXD2 */
165+
>;
166+
};
167+
168+
eth_mii_txd3_pb8: eth_mii_txd3_pb8 {
169+
pinmux = <
170+
STM32_PINMUX('B', 8, AF11) /* ETH_MII_TXD3 */
171+
>;
172+
};
173+
174+
spi1_nss_pa4: spi1_nss_pa4 {
175+
pinmux = <
176+
STM32_PINMUX('A', 4, AF5) /* SPI1_NSS */
177+
>;
178+
};
179+
180+
spi1_sck_pa5: spi1_sck_pa5 {
181+
pinmux = <
182+
STM32_PINMUX('A', 5, AF5) /* SPI1_SCK */
183+
>;
184+
};
185+
186+
spi1_miso_pa6: spi1_miso_pa6 {
187+
pinmux = <
188+
STM32_PINMUX('A', 6, AF5) /* SPI1_MISO */
189+
>;
190+
};
191+
192+
spi1_mosi_pa7: spi1_mosi_pa7 {
193+
pinmux = <
194+
STM32_PINMUX('A', 7, AF5) /* SPI1_MOSI */
195+
>;
196+
};
197+
198+
sw1_rst_pb3: sw1_rst_pb3 {
199+
pinmux = <
200+
STM32_PINMUX('B', 3, GPIO) /* GPIO */
201+
>;
202+
};
203+
204+
sw1_irq_pb5: sw1_irq_pb5 {
205+
pinmux = <
206+
STM32_PINMUX('B', 5, GPIO) /* GPIO */
207+
>;
208+
};
209+
};
210+
211+
/* For sys_rand_get */
212+
&rng {
213+
status = "okay";
214+
};
215+
216+
/* Switch connected to SPI bus 1 */
217+
&spi1 {
218+
cs-gpios = <&gpioa 4 GPIO_ACTIVE_LOW>;
219+
220+
pinctrl-0 = <
221+
&spi1_nss_pa4
222+
&spi1_sck_pa5
223+
&spi1_miso_pa6
224+
&spi1_mosi_pa7
225+
>;
226+
pinctrl-names = "default";
227+
228+
status = "okay";
229+
230+
sw1: ethernet-switch@0 {
231+
compatible = "microchip,ksz8463";
232+
233+
/* Chip-select 0 */
234+
reg = <0>;
235+
236+
#address-cells = <1>;
237+
#size-cells = <0>;
238+
239+
spi-max-frequency = <DT_FREQ_K(12500)>;
240+
241+
/* Hardware reset is active low */
242+
reset-gpios = <&gpiob 3 GPIO_ACTIVE_LOW>;
243+
244+
/* Interrupt output is active low */
245+
int-gpios = <&gpiob 5 GPIO_ACTIVE_LOW>;
246+
247+
/* Enable IGMP snooping */
248+
microchip,igmp-snoop-en;
249+
250+
/* Enable MLD snooping */
251+
microchip,mld-snoop-en;
252+
253+
status = "okay";
254+
255+
/* User port 1 */
256+
sw1_port1: port@0 {
257+
compatible = "zephyr,dsa-port";
258+
reg = <0>;
259+
260+
/* Use random MAC */
261+
zephyr,random-mac-address;
262+
263+
status = "okay";
264+
265+
/* Internal PHY */
266+
phy {
267+
compatible = "microchip,ksz8463-phy";
268+
269+
/* Fall back on 10BASE Half-Duplex on auto-negotiation failure */
270+
microchip,fixed-link-speed = "10BASE Half-Duplex";
271+
272+
status = "okay";
273+
};
274+
};
275+
276+
/* User port 2 */
277+
sw1_port2: port@1 {
278+
compatible = "zephyr,dsa-port";
279+
reg = <1>;
280+
281+
zephyr,random-mac-address;
282+
283+
status = "okay";
284+
285+
/* Internal PHY */
286+
phy {
287+
compatible = "microchip,ksz8463-phy";
288+
289+
/* Fall back on 100BASE Full-Duplex on auto-negotiation failure */
290+
microchip,fixed-link-speed = "100BASE Full-Duplex";
291+
292+
status = "okay";
293+
};
294+
};
295+
296+
/* CPU port */
297+
sw1_port3: port@2 {
298+
compatible = "zephyr,dsa-port";
299+
reg = <2>;
300+
301+
/* Port is connected to the STM MAC */
302+
ethernet = <&mac>;
303+
304+
/* KSZ8463ML uses MII */
305+
phy-connection-type = "mii";
306+
307+
/* Enable tail tagging */
308+
dsa-tag-protocol = <DSA_TAG_PROTO_KSZ8463>;
309+
310+
status = "okay";
311+
};
312+
};
313+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CONFIG_NETWORKING=y
2+
CONFIG_NET_DSA=y
3+
4+
CONFIG_SPI=y
5+
6+
CONFIG_SHELL=y
7+
CONFIG_NET_SHELL=y
8+
9+
# The KSZ8463 driver is automatically enabled whenever a node with compatible microchip,ksz8463 and
10+
# status okay is found in the dts.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2026 Vilhelm Engström
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/logging/log.h>
8+
LOG_MODULE_REGISTER(ksz8463ml_sample, LOG_LEVEL_DBG);
9+
10+
int main(void)
11+
{
12+
LOG_INF("Run 'net iface' in the shell to view the interfaces");
13+
return 0;
14+
}

0 commit comments

Comments
 (0)