Micro with two Ethernet ports or alternative solution? - Page 1
Forum section: electronics / projects

author: ricko_uk
author_rank: Super Contributor
timestamp: August 20, 2023, 12:33:06 pm
content: Hi,I need to design a custom PCB with a microcontroller and two Ethernet ports. The micro controls a custom printer (print head and motors) and is has three functions:- connect via the first ethernet to a PC to receive data- connect via the second ethernet to a smart display (to show the label image to be printed)- control the motors and print head to print the imageDigikey and other distributors don't show how many ethernet ports a micro has, so after filtering as much as possible I still get 680 results of possible micros that I would have to check one by one which would take ages. Does anybody know a micro (preferably by ST) with 2 ethernet ports?Alternatively what is the easiest and simplest solution especially from a firmware point of view (considering I never written any code for ethernet, know nothing about it and will have to learn from scratch)? Would a ethernet switch IC be preferred? Or two external UART/SPI to ethernet converters?Thank you

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: August 20, 2023, 01:21:03 pm
content: "Easiest" would probably be two W5500 chips or similar.If you said what you actually want to do wit the ethernet, that might give you more useful replies.

author: Terry Bites
author_rank: Super Contributor
timestamp: August 20, 2023, 01:22:01 pm
content: https://thepihut.com/products/dual-gigabit-ethernet-base-board-for-raspberry-pi-compute-module-4

author: ricko_uk
author_rank: Super Contributor
timestamp: August 20, 2023, 01:45:34 pm
content: Thank you both,The micro controls a custom printer (print head and motors) and is has three functions:- connect via the first ethernet to a PC to receive data- connect via the second ethernet to a smart display (to show the label image to be printed)- control the motors and print head to print the imageOP also updated.Thank you

author: kripton2035
author_rank: Super Contributor
timestamp: August 20, 2023, 01:51:46 pm
content: you could use a network (ethernet) and only have one ethernet port on your board.the board, the pc and the display just have to be on the same network...just saying.

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: August 20, 2023, 01:56:05 pm
content: Quote from: kripton2035 on August 20, 2023, 01:51:46 pmIf it's going to be connected to different PC environments than having the display on the same network could cause a lot of headaches.Assuming bandwidth isn't a big issue, then the 2 x W5500 option may be a good route, as it frees up most constraints on choice of MCU, and also you have the same interface to learn for both ports ( vs. using internal plus external).

author: bson
author_rank: Unknown
timestamp: August 20, 2023, 07:12:52 pm
content: You can have have two PHYs on the controller, each one with a different MAC address. This prevents IP address hashing in the controller, but since switched networks aren't collision domains you will still only see your own traffic and can do IP address lookups in software. Unless you're going to be forwarding (which it doesn't sound like) all you have to do is make sure the IP address in the header makes sense for the MAC address in the frame, or send back an ICMP dest unreachable error if not. For a modest amount of traffic this is a trivial overhead.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: August 20, 2023, 07:28:43 pm
content: My first though would also be 2x W5500 or one and native onboard ethernet for the other.Maybe it is a viable option to use one of those chips as used in ethernet switches or routers. Such chips can support 4 or more ports, are designed for a high workload and are configurable via some microcontroller interface.If you microcontroller has an USB interface, then maybe you can add an USB to Ethernet dongle, but most uC's are USB device only (though that seems to be changing slowly). But it's probably more difficult to omplement then a W5500.

author: Perkele
author_rank: Regular Contributor
timestamp: August 20, 2023, 07:54:43 pm
content: First solution:One micro with one Ethernet port handling the comms. Connected to a 5-port switch.Other micro handling time-critical stuff (motors) and talking to the first micro via shared memory or some local bus (I2C, SPI, serial, raw USB HID in the worst case).Or for some reason if you want to avoid having a PC connected directly to this network, use a board with two Ethernet ports.Second solution:Offload complex stuff onto something where all the networking issues are already ironed-out (an RTOS or Yocto Linux) and keep your time-critical code on a simple micro connected over a local bus.If this is a commercial product, sooner or later someone will come with a brilliant idea to add Wi-Fi or Bluetooth.

author: ConKbot
author_rank: Super Contributor
timestamp: August 20, 2023, 09:55:16 pm
content: KSZ9893 from Microchip is a 3 port, layer 2 switch. 2 ports have PHYs so they go right to a connector. 3rd port has an RGMII interface that can act as a PHY or MAC, so you can put it in PHY mode, hook it up to RGMII on a micro, and then have 2 ports.Caveat is that it's kind of a mess. I've tried implementing one with a phy hung off the 3rd port, and testing worked fine with desktop PCs. But hang it off of the embedded system (Nvidia TX2) and it does nothing but give enumeration problems with the onboard PHYs. Maybe power sequence related, the datasheet gives a sequence. The appnote examples don't sequence in power, just use the PCIE card power however it arrives. But NVidia has had more than their share of problems with the TX2 module, so I wouldn't hold them blameless, as their widget is the only one I've found with enumeration issues. Vs a dozen other desktop and laptop PCs that had no issues.Don't go betting the farm on it working if you think it sounds suitable.

author: rstofer
author_rank: Super Contributor
timestamp: August 20, 2023, 11:33:27 pm
content: I would take a look at the micro library and see if Ethernet is implemented and then look at Berkeley Sockets and find code for that - it's built on top of Ethernet.I would need a host socket to drive the display and the display would have to look for the IP/Socket at startup. I would need second client socket to connect to the PC. The PC wouldl have to make a connection to the controller IP/Socket.The physical part would just be a switch with one cable from the MCU (connecting on 2 logical sockets), one cable to the display and one cable from the PC. Actually, all these cables could connect to any switch as long as the IP address is static. I'm not sure I would want to implement DHCP.Look at the mbed library for the LPC1768. It has all you need for software and the hardware is as simple as creating a daughter card with a MagJack.https://os.mbed.com/platforms/mbed-LPC1768/I did a project with that device where I took SPI input from an FPGA, manipulated it and sent it out via Berkeley Sockets to a laserjet printer. The code is simple and it's been working for years...

author: ricko_uk
author_rank: Super Contributor
timestamp: August 21, 2023, 02:45:36 pm
content: Thank you all!

author: Scrts
author_rank: Frequent Contributor
timestamp: August 21, 2023, 03:18:01 pm
content: Both printer and display can be used over Ethernet with standard TCP/UDP connection? If so - do not overcomplicate your design. Use a microcontroller with a single Ethernet and use off-the-shelf network switch.

author: Siwastaja
author_rank: Super Contributor
timestamp: August 21, 2023, 03:45:03 pm
content: Unless there is a strong reason to prevent the display from being exposed / available to the user network, +1 to network switch. If it has to be integrated on the same PCB, then just off-the-shelf network switch IC.If the display has to be hidden in a completely isolated network, then +1 for the 2xW5500 solution. These chips are relatively easy to use.

author: ejeffrey
author_rank: Super Contributor
timestamp: August 21, 2023, 06:06:48 pm
content: If the host PC has to be in charge of addressing (e.g. running DHCP) for it's network, using a switch may cause problems with the controller locating the display.If the controller is going to run DHCP or the addressing is fixed, using an off the shelf switch is almost certainly the easiest solution.

author: ajb
author_rank: Super Contributor
timestamp: August 21, 2023, 07:00:27 pm
content: It should be possible to use a small switch IC that supports VLAN tagging to isolate the two connections. There are a few 3-8 port switch ASICs from Micrel/Microchip in particular that are readily available and should work, and allow VLAN tagging to be configured via the SMI or SPI/I2C. You'd configure the display-facing and PC-facing ports for two different VLANs and configure the MCU-facing port for both of those VLANs, which would allow the MCU can talk to the PC and the display, but the PC and display can only talk to the MCU. For traffic originating from the MCU, you'd ideally want to have that tagged for the correct VLAN before transmitting, but I'm not sure how well supported that is under various embedded IP stacks. It might involve creating two separate local netifs for the separate VLANs, which would probably be the easiest way to provide logical isolation in the firmware anyway. You could use a dev board of your choice with an on-board PHY and an external off-the-shelf lightly managed switch to test the firmware side of things before committing to hardware.

author: sd
author_rank: Unknown
timestamp: August 21, 2023, 07:10:13 pm
content: https://www.nxp.com/products/product-selector:PRODUCT-SELECTOR?category=c731_c1770_c1508&filter=%7B%22filters%22%3A%7B%22h81%22%3A%7B%22min%22%3A2%2C%22max%22%3A3%2C%22type%22%3A%22dual_range%22%7D%7D%7DTI probably has quite a few as well.

author: NiHaoMike
author_rank: Super Contributor
timestamp: August 22, 2023, 02:44:24 am
content: Take a look at the chips used in cheap routers, it's very common to find some with several Ethernet ports. Nowadays, even the cheapest ones have a substantial amount of compute power.