Skip to content

Commit 6df845e

Browse files
committed
realtek-rtl8305nb: Add usage.ato from ethernet-things branch
1 parent 996d02f commit 6df845e

1 file changed

Lines changed: 202 additions & 0 deletions

File tree

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
"Complete 5-port Ethernet switch using Realtek RTL8305NB"
2+
#pragma experiment("FOR_LOOP")
3+
#pragma experiment("BRIDGE_CONNECT")
4+
5+
import ElectricPower
6+
import Resistor
7+
8+
from "realtek-rtl8305nb.ato" import Realtek_RTL8305NB
9+
from "atopile/rj45-connectors/rj45-connectors.ato" import RJ45_Horizontal_TH_Magnetics
10+
from "atopile/espressif-esp32-c3/esp32_c3_mini.ato" import ESP32_C3_MINI_1_driver
11+
from "atopile/wiznet-w5500/wiznet-w5500.ato" import Wiznet_W5500
12+
from "atopile/usb-connectors/usb-connectors.ato" import USB2_0TypeCHorizontalConnector
13+
from "atopile/ti-tpsm863257/ti-tpsm863257.ato" import TPSM863257
14+
from "atopile/opsco-sk6805-side/opsco-sk6805-side.ato" import OPSCO_SK6805_SIDE
15+
from "atopile/diodes-inc-74lvc1t45dw-7/diodes-inc-74lvc1t45dw-7.ato" import Diodes_Inc_74LVC1T45DW_7
16+
from "atopile/saleae-header/saleae-header.ato" import SaleaeHeaderRightAngle_2
17+
from "atopile/logos/logos.ato" import atopile_logo_25x6mm
18+
from "atopile/indicator-leds/indicator-leds.ato" import LEDIndicatorGreen, LEDIndicatorYellow, LEDIndicatorRed, LEDIndicatorBlue
19+
20+
module Usage:
21+
"""
22+
Complete 5-port Ethernet switch example using RTL8305NB
23+
Creates a managed switch with 4 external RJ-45 ports and ESP32-C3 connected via W5500
24+
"""
25+
26+
# --- Main switch IC ---
27+
switch = new Realtek_RTL8305NB
28+
29+
# --- Management microcontroller ---
30+
esp32 = new ESP32_C3_MINI_1_driver
31+
"""
32+
ESP32-C3 for switch management, configuration, and monitoring
33+
Can implement web interface, SNMP, or custom management protocols
34+
"""
35+
36+
# --- SPI-to-Ethernet bridge ---
37+
w5500 = new Wiznet_W5500
38+
"""
39+
W5500 SPI-to-Ethernet controller
40+
Connects ESP32-C3 to the switch as a network node
41+
"""
42+
43+
# --- Power supply system ---
44+
# USB-C input connector
45+
usb_connector = new USB2_0TypeCHorizontalConnector
46+
"""
47+
USB-C connector for 5V power input
48+
"""
49+
50+
# 3.3V Buck converter (more efficient than LDO)
51+
buck = new TPSM863257
52+
"""
53+
TI TPSM863257 synchronous buck converter
54+
Converts 5V USB input to 3.3V with ~90% efficiency
55+
Much more efficient than LDO for high current applications
56+
"""
57+
58+
# Power rails
59+
power_5v = new ElectricPower
60+
power_3v3 = new ElectricPower
61+
"""
62+
5V from USB-C and regulated 3.3V for all components
63+
"""
64+
power_5v.required = True
65+
power_3v3.required = True
66+
assert power_5v.voltage within 5V +/- 5%
67+
assert power_3v3.voltage within 3.3V +/- 5%
68+
69+
atopile_logo = new atopile_logo_25x6mm
70+
71+
# Net name overrides for cleaner PCB layout
72+
power_5v.hv.override_net_name = "+5V"
73+
power_5v.lv.override_net_name = "GND"
74+
power_3v3.hv.override_net_name = "+3V3"
75+
esp32.i2c.scl.line.override_net_name = "I2C_SCL"
76+
esp32.i2c.sda.line.override_net_name = "I2C_SDA"
77+
esp32.spi.sclk.line.override_net_name = "SPI_SCLK"
78+
esp32.spi.mosi.line.override_net_name = "SPI_MOSI"
79+
esp32.spi.miso.line.override_net_name = "SPI_MISO"
80+
w5500.spi_cs.line.override_net_name = "SPI_CS"
81+
82+
# --- RJ-45 Ethernet connectors with integrated magnetics ---
83+
ethernet_ports = new RJ45_Horizontal_TH_Magnetics[4]
84+
"""
85+
4 x RJ-45 connectors with integrated magnetics for external ports
86+
Each connector includes transformer isolation and common-mode filtering
87+
Port 0 is used internally for ESP32-C3 via W5500
88+
"""
89+
90+
# --- Status LED with level shifter ---
91+
status_led = new OPSCO_SK6805_SIDE
92+
"""
93+
Addressable RGB LED for system status indication
94+
Can show power, network activity, error states, etc.
95+
"""
96+
97+
level_shifter = new Diodes_Inc_74LVC1T45DW_7
98+
"""
99+
3.3V to 5V level shifter for LED data signal
100+
Translates ESP32-C3 3.3V GPIO to 5V logic for SK6805
101+
"""
102+
103+
# --- Debug header ---
104+
debug_header = new SaleaeHeaderRightAngle_2
105+
"""
106+
Saleae logic analyzer debug header
107+
Monitors: SPI (SCLK, MOSI, MISO, CS), I2C (SCL, SDA), Reset, Loop indication
108+
"""
109+
110+
# --- Ethernet status LEDs ---
111+
link_led = new LEDIndicatorGreen
112+
"""
113+
Green link status LED for W5500-Switch connection
114+
Shows when Ethernet link is established
115+
"""
116+
117+
activity_led = new LEDIndicatorYellow
118+
"""
119+
Yellow activity LED for W5500-Switch connection
120+
Shows network traffic activity
121+
"""
122+
123+
# --- Power indicator LEDs ---
124+
power_5v_led = new LEDIndicatorRed
125+
"""
126+
Red power indicator LED for 5V rail
127+
Shows when 5V power is present and active
128+
"""
129+
130+
power_3v3_led = new LEDIndicatorBlue
131+
"""
132+
Blue power indicator LED for 3.3V rail
133+
Shows when 3.3V regulator output is active
134+
"""
135+
136+
# --- Connections ---
137+
# Power supply chain: USB-C → 5V → Buck Converter → 3.3V
138+
usb_connector.usb.usb_if.buspower ~ power_5v
139+
power_5v ~> buck ~> power_3v3
140+
141+
# Power all components
142+
switch.power_3v3 ~ power_3v3
143+
esp32.power ~ power_3v3
144+
w5500.power ~ power_3v3
145+
status_led.power ~ power_5v # LED needs 5V
146+
level_shifter.power_a ~ power_3v3 # 3.3V side (ESP32)
147+
level_shifter.power_b ~ power_5v # 5V side (LED)
148+
149+
150+
# USB data connection for ESP32-C3 programming and communication
151+
esp32.usb_if ~ usb_connector.usb.usb_if
152+
153+
# External Ethernet ports (4 ports for users)
154+
switch.ethernets[1] ~ ethernet_ports[0].ethernet # External port 1
155+
switch.ethernets[2] ~ ethernet_ports[1].ethernet # External port 2
156+
switch.ethernets[3] ~ ethernet_ports[2].ethernet # External port 3
157+
switch.ethernets[4] ~ ethernet_ports[3].ethernet # External port 4
158+
159+
# Internal management network (ESP32-C3 connected as network node)
160+
switch.ethernets[0] ~ w5500.ethernet # W5500 connects to switch port 0
161+
esp32.spi ~ w5500.spi # ESP32-C3 controls W5500 via SPI
162+
163+
# Status LEDs using bridge connect across power rails
164+
w5500.ethernet.led_link.line ~> link_led ~> power_3v3.lv # Green link status LED
165+
w5500.ethernet.led_speed.line ~> activity_led ~> power_3v3.lv # Yellow activity LED
166+
power_5v.hv ~> power_5v_led ~> power_5v.lv # Red 5V power indicator LED
167+
power_3v3.hv ~> power_3v3_led ~> power_3v3.lv # Blue 3.3V power indicator LED
168+
# GPIO assignments (avoiding conflicts with peripherals and strapping pins)
169+
esp32.gpio[3] ~ w5500.spi_cs # GPIO3: W5500 SPI chip select
170+
esp32.gpio[0] ~ w5500.interrupt # GPIO0: W5500 interrupt (ADC capable)
171+
esp32.gpio[1] ~ w5500.reset # GPIO1: W5500 reset (ADC capable)
172+
173+
# Switch management via MDIO (uses I2C peripheral: GPIO5=SDA, GPIO6=SCL)
174+
switch.i2c_mdio ~ esp32.i2c # ESP32 I2C manages switch directly via MDIO
175+
switch.reset ~ esp32.gpio[4] # GPIO4: Switch reset control
176+
switch.loop_indication ~ esp32.gpio[20] # GPIO20: Switch loop detection monitor
177+
178+
# Status LED connection via level shifter (3.3V → 5V)
179+
esp32.gpio[21] ~> level_shifter ~> status_led.data_in # GPIO21: LED data
180+
level_shifter.dir.line ~ power_3v3.hv # DIR = HIGH for A→B transmission
181+
182+
# I2C/MDIO pull-up resistors (required for proper signaling)
183+
i2c_pullups = new Resistor[2]
184+
for r in i2c_pullups:
185+
r.resistance = 4.7kohm +/- 5%
186+
r.package = "0402"
187+
188+
esp32.i2c.scl.line ~> i2c_pullups[0] ~> power_3v3.hv
189+
esp32.i2c.sda.line ~> i2c_pullups[1] ~> power_3v3.hv
190+
191+
# Debug header connections (for logic analyzer monitoring)
192+
# Header 0: SPI signals
193+
debug_header.headers[0].channels[0] ~ esp32.spi.sclk # SPI Clock (GPIO10)
194+
debug_header.headers[0].channels[1] ~ esp32.spi.mosi # SPI MOSI (GPIO7)
195+
debug_header.headers[0].channels[2] ~ esp32.spi.miso # SPI MISO (GPIO8)
196+
debug_header.headers[0].channels[3] ~ esp32.gpio[3] # SPI CS (GPIO3)
197+
198+
# Header 1: I2C and control signals
199+
debug_header.headers[1].channels[0] ~ esp32.i2c.scl # I2C SCL (GPIO6)
200+
debug_header.headers[1].channels[1] ~ esp32.i2c.sda # I2C SDA (GPIO5)
201+
debug_header.headers[1].channels[2] ~ esp32.gpio[4] # Switch reset (GPIO4)
202+
debug_header.headers[1].channels[3] ~ esp32.gpio[20] # Loop detection (GPIO20)

0 commit comments

Comments
 (0)