Five Port Fast Ethernet Managed Switch

This project is the complete design of a 5 port fast Ethernet switch, based on the Micrel KSZ8995M switch IC with integrated PHY and an ATMega168 8-bit microcontroller.

The hardware was originally developed in 2009, because I needed a compact, VLAN capable switch to expand the functionality of an NSLU2, which has just a single Ethernet port and that I was using as router for my home network.

Features

  • Complete VLAN support
  • Auto MDIX on all ports
  • Programmable port rate limiting
  • Integrated MIB counters
  • TTL UART interface for external access of switch configuration


Hardware

The main component of the Ethernet switch is… (surprise) the Switch! This project is based on a Micrel KSZ8995MA, which is a 5 port switch, managed, with 5 integrated auto-MDIX capable PHYs.
The device is available from major IC distributors in a 128 pin PQFP package, which can be easily hand-soldered if you have a good hand and the right tools.
If you work on electronic designs, you can also request the IC as a sample from Micrel itself… just don’t abuse the sample service!

The switch requires three power rails: 3.3V for the digital I/O, 2.5 (or 3.3V) for the analog I/O and 1.8V for the core.
As current requirements are pretty low, to keep the design simple and compact, the power supply has been designed with simple LM317 linear regulators and a series diode for the 2.5V.
During the assembly of the PCB, the regulators have been changed to a mix of LD1117 and LD33 (as you can see from the photos), as I had these devices readily available and they fitted on the LM317 pads.

If you are redesigning the the power section, I suggest to use two LD1117 with a proper thermal pad, or a buck converter.

The switch IC has the basic configuration bits exposed as pinstrap on some 0R shortable jumper.
To use the switch in unmanaged mode just don’t short any pinstrap, to use it in SPI salve mode so that it can be configured from the microcontroller short the jumpers as in the picture.

The switch IC is managed by the small Atmel ATMega168 microcontroller using the a TTL UART port on the host side, and an SPI port on the switch side.
Please note that to interface the TTL UART port with a standard RS232 port, you need a TTL-to-232 level shifter.

The board has an AVR910 compatible 2×3 2.54mm programming header for the microcontroller.

As for the Ethernet ports, there are five connectors with integrated magnetic. You can find compatible connectors from many manufacturers, just double check the integrated LEDs polarity (I designed for Pulse but found out that Halos are different).

Software

The firmware for the microcontroller implements a simple command-line interface to access the internal registers of the switch IC.
The interface can be used with a serial emulator application, like minicom, configured as 38400 bps, 8 data bit, 1 stop bit and no parity.

Available commands are:

  • help: print available commands
  • rd offset count: read registers
  • wr offset values…: write registers
  • status: print port status
  • sm_show and dm_show: print internal MAC tables
  • vlan_show: display current VLAN table
  • vlan_set addr valid membership fid vid: set vlan entry
  • mib_show offset count: show mib records

Refer to commands.c source file and switch IC documentation for further details.

Instructions to build and flash the firmware are provided in the README file in the repository.

If you need to store a specific configuration, you can hardcode that in the main function, before the “start switch” command, such as in the “start_mode_A()” function, disabled by default in the main.c file.

Files

All project files, including schematic, layout and firmware source for the microcontroller, can be found on GitHub.


The schematics in PDF version can be downloaded from here.

Happy switching!

Advertisements

58 Responses to Five Port Fast Ethernet Managed Switch

  1. You are my first (and only) beta tester!

  2. Giordano says:

    a great project! – GM

  3. Paolo says:

    Ciao, complimenti per il lavoro!! sono un neofita e ti vorrei rivolgere una domanda: con quale criterio hai dimensionato numero e capacità dei condensatori di filtro che si vedono nella parta bassa dello schema?
    Ciao e ancora complimenti!

    • Ciao, grazie per i complimenti!

      Se stai parlando dei condensatori di filtraggio sulle rail di alimentazione, sono arbitrariamente fissati a 100nF e sono uno per ogni pin di alimentazione. Anche nel layout in teoria vanno piazzati uno vicino a ogni pin di alimentazione, sempre che sia possibile, sulle schede a due layer a volte diventa complicato.

      Lo scopo e’ compensare i “tiri” di corrente della logica digitale e la conseguente propagazione di disturbi sulle alimentazioni (si dice…), di fatto anche se non li monti tutti la scheda funziona benone lo stesso ma potresti avere problemi in condizioni particolari.

      Se invece parli dei gruppi 50Ohm-50Ohm-100nF, si tratta delle reti di polarizzazione dei tasformatori ethernet, e il disegno dipende dal tipo di pilotaggio del trasformatore da parte del PHY (in questo caso dei PHY integrati nello switch), chiaramente devi riferirti ai reference design e documentazione dei relativi integrati per capire come piazzarli.

      Ciao!

      • Paolo says:

        Si, parlavo dei condensatori sulle tre linee di alimentazione. ho visto che dedichi attenzione all’alimentazione del pin 123 (+1.8VPLL). deriva dalla tua esperienza diretta? o sono io che non riesco ad interpretare bene il data sheet del componente micrel?
        Ciao, e grazie per la disponibilità

      • Beh, generalmente le alimentazioni dei PLL hanno quel circuito di filtraggio addizionale, non a caso il pin ha un nome diverso dagli altri alla stessa tensione. Il circuito comunque e’ preso dal reference design e il datasheet non indica necessariamente questi accorgimenti, che a volte vengono indicati in documentazione addizionale e a volte vengono lasciate a discrezione del progettista.

        Ciao.

  4. Paolo says:

    Ciao Fabio,
    ne vorrei costruire uno! come connettori ho dei magjack SI-50158 con trasformatori ethernet integrati. pensi che la rete 50ohm+50ohm+100nF (sul reference design le chiamano terminazioni) possa andare bene anche per questo connettore o devo valutare qualche dato in particolare che non conosco?
    Ciao e grazie per la disponibilità

    • La polarizzazione va benone, dato che dipende dal PHY non cambia col trasformatore.

      Per i connettori invece mi pare che i MagJack che hai indicato abbiano un footprint differente (sono a contatti inferiori, tab superiore e led superiori), al contrario nel mio progetto ci sono dei Pulse serie J0026 o equivalenti, che hanno tab e led sul lato inferiore. Il footprint chiaramente e’ diverso.

      Una volta beccato il footprint, il disegno dei trasformatori non dovrebbe farte molta differenza.

      Occhio anche alla polarita’ dei led, come scrivo nel post ho dovuto modificare degli Halo per renderli compatibili.

      Saluti!

  5. Paolo says:

    Ciao, Fabio
    sono arrivato alla definizione dei piani di massa. vorrei chiederti come mai hai splittato i piani di massa dedicandone uno ai connettori RJ45? come calcoli il valore dell’induttanza di collegamento tra i due piani? quali sono i benefici rispetto ad un solo piano di massa?
    Ciao e grazie per la pazienza :-)

    • Ciao Paolo,

      ancora una volta lo split e’ preso con fede dal reference. I miei colleghi piu’ saggi mi dicono che la separazione dei piani puo’ tornare utile per intervenire se fosse necessario filtrare rumore o altro in applicazioni strane.

      Tieni conto che quel piano viene direttamente collegato agli shield di eventuali cavi shielded/foiled collegati allo switch, e in questo caso ci sono diverse possibilita’ di filtraggio per riportare lo shield a massa evitando problemi da disturbi o ground-loop, problema che comunque non si ha usando cavi UTP, ovvero la maggiorparte dei cavi usati per applicazioni Fast Ethernet.

      Per un prototipo che vive su un tavolo di un ufficio quindi non ha nessuna utilita’, nei miei montaggi infatti ho usato ferriti “di recupero” o zero-ohm a seconda della disponibilita’ senza notare differenze di funzionamento apprezzabili.

      Puoi comunque tenerlo e poi metterlo in corto col signal ground nei prototipi. Se noti fenomeni strani (lock/reset dello switch) usando cavi shielded o chassis metallici hai gia’ un punto di intervento… di piu’ non ti so dire purtroppo!

      Ciao!

  6. Pingback: Making Time Lapse Video with IP Cameras « fabiobaltieri

  7. Norberto Jimenez says:

    Hi Fabio.

    Nice job man..! I ran into your project just because I am trying to do something similar (originally using a Broadcom BCM5352EKQMG and a PIC controller). Unfortunatelly, there is almost no information at all about this chip on internet, just a light “datasheet” (?)).

    I’d like to consult the following with you: I want to combine in my PCB the switch itself and other PIC based application (mainly sensors) and want to “internally connect” this application to one of the switch ports. That way I will have 4 ports for external use and my application will be connected by default. Ok, do you see any conflict in doing this “internal connection” with an ENC2BJ60 (from microchip) face to face , I mean, without the magnetics?

    My mail is [removed, less spam :-)] . You can reach me there if you want to.

    Thanks,

    Norberto (form Mexico City)

    • Hi Norberto!

      Good luck with the Broadcom! They are one of the best network ICs manufacturer, but there is almost zero documentation for their stuff. That’s probably because they don’t care about minor market or hobbyist projects. That’s actually a common situation, and Micrel here is a pleasant exception… Too bad they don’t have gigabit Ethernet switches!

      As for your question, what you’re trying to do is transformerless coupling between two PHYs, which is actually commonly done in backplanes and similar application. Unfortunately the generic answer is no, unless you have some specific documentation from the vendor on how this configuration can be supported, as it depends on how the transformer driver inside the PHY is designed.

      I know for sure that you can do that between some Micrel devices by connecting TX/RX pairs with a specific R-C network, but as you have an ENC28J60 on the other side I would suggest you to use a single transformer anyway between the two.

      Apart from that, you may want to read the application note for “Capacitive Coupling Ethernet Transceivers” from Micrel here:

      http://www.micrel.com/_PDF/Ethernet/app-notes/an-120.pdf

      and “Transformerless Ethernet Designs” from Vitesse here:

      https://www.vitesse.com/products/download.php?fid=3484&number=VSC8244

      Both are vendor specific documents but contains some interesting information about the problems involved.

      Hope you find this stuff useful!

      Fabio

    • Jamie says:

      You might have better luck with the Atheros AR8327-AL1A gigabit switch chip and a PIC. Parts are easy to source on Alibaba and the datasheet is findable on findable on Google and Baidu

  8. This looks like a very nice start for my needs. In a project I have to split ethernet from one to two lines. Would it be hard to change the software to use it for 3 ports instead of 5?
    Regards,
    Mischa

    • Hi Mischa,

      you could just redesign it without two of the five ports, but check the Micrel website, they have plenty of 3 port switches with VLAN capability that I think would suit your needs!

    • lodeameije says:

      Hi Mischa, did you ever did this? Was it compact? I am having the same needs!

  9. Franz says:

    Hi Fabio,

    thanks for sharing this great project!

    I have an application where I need a customized 4-port 100MBit switch with passive PoE capability via the spare RJ-45 pins. For early prototypes I modified cheap switches but it takes too long for 100pcs :-) Therefore I would like to learn how many hours you roughly spent to design the board?

    Kind regards,
    Franz

    • Hi Franz! It was a long time ago but I think it took me 4 or 5 nights to do the layout of this one. I actually redesigned a v2 (which I never published) and I think it took me one full day to modify the schematics and do the layout from scratch… Hard to count the hours since I do this stuff in my spare time, but it depends on how confident you are with the CAD.

  10. Franz says:

    Wow, that sounds very fast. It’s long time since I used EDA software. I’m trying to learn about the requirements to outsource a small batch production of such a customized board.

    If you don’t mind I would like to ask you about the missing steps to assemble 100pcs of such a custom PCB.

    This is my description of the process:

    1) Design schematic + PCB Layout
    2) Send PCB Layout (Gerber files) to a PCB manufacturer and receive empty PCBs
    3) Source components (on reels) from different suppliers
    4) Send empty PCBs, Gerber files, BOM list and reels to a PCB assembler
    5) Get assembled PCBs and hope that you and the factory didn’t make mistakes :-)

    PS: I think I saw the v2 schematics in your Github account, right?

    Many thanks,
    Franz

    • Sounds about right, the details varies depending on how the assembly house is used to work, some of them buys the components on their own so you just need to send them the BOM. They may also ask for the coordinate file for the pick and place machine in some specific format, and you almost certainly need to add some fiducial marker on the board, but apart from that it should be a very simple board to assemble. You’re right on the rev2, the files are on github, but keep in mind that I’ve never built one! :-) It should be a nice upgrade of the first design, using a mini USB port for power and control.

  11. Franz says:

    I also learnt that every company has a checklist what they can and can’t process. Like:

    – Via in pads
    – Too small holes
    – Too small parts
    – How the parts are packaged (tray, tube, tape/reel)

    Seems I’m on the right track towards my first custom board :-)

    Thanks again,
    Franz

    • That’s true but I doubt you’ll hit on any tech limitation on a design like this since all components are pretty standard and easy to handle (there is a QFN in rev2, but nothing too fancy)… Of course checking with the fab and assembly house for their limits would not hurt for sure. :-)

  12. Franz says:

    May I contact you on Linkedin? I don’t want to bore you with more questions but instead would like to introduce you to our crazy wireless-mesh startup :-)

  13. Eddie says:

    Thanks Fabio! I’ve been looking for a reference design for a small switch for an embedded project for quite a while and this looks perfect. Question: if I only need an un-managed switch (just for a couple of IP cameras), can I skip the ATMega168 by appropriate strapping (or not strapping) of some jumpers. I don’t think I’ll ever need management for this and every bit of space I can shave off is welcome.

    Thanks for getting me started!
    Eddie

    • Hi Eddie, sure thing! You just need to flip the configuration pinstrap correctly (the PS0/PS1) and the switch will start in forwarding mode with the default (unmanaged) configuration. Not sure how it comes up if you leave the pins open but you can figure it out from the datasheet.

      Have fun!

      • Eddie says:

        Great! Looks perfect. If I get a decent design working I’ll report back.

        Keep up the excellent work on this, Fabio!

  14. pawanbahl says:

    Dear Fabio, I need a switch to put on buses with IP surveillance cameras. I need M12 connectors. Most such switches are super expensive. I came across this post by you and i feel it could be a wonderful fit. before i get started on the modifications, i just wanted to know- did you run it in a live applications ultimately. Any bugs and issues we may need to take care of? Any later version you may have for me to get started on instead.
    Thanks! and good work. Most helpful.

    Best
    Pawandeep.

    • Hey Pawandeep, I’m using one of these at home almost continuously since I made it in 2011 and it never let me down… I’ve actually learned about that switch IC (the KSZ8995MA) from its use in an automotive application, and I’m not aware of any problem with it from the field. Make sure to get the -I variant for the industrial temperature range (-40 to +85 C)… AFAIK this used to be one of the few industrial switch ICs commonly available from major supply chains (DigiKey: http://www.digikey.com/product-detail/en/KSZ8995MAI/576-2126-ND/1027614).

      Cheers!

    • Oh, about the second version question: I’ve redone the layout from scratch some year ago but I’ve never built the new version… If I were to deploy these in a non DIY project I would completely redesign it from scratch anyway, with a proper DC/DC supply in place of the LDOs (at least for the first stage) and a 4 layer PCB using proper high speed design practices – my dual layer design is ok for DIY and proven to be surprisingly reliable, but I’m sure EMC and signal integrity are sub-optimal.

      • pawanbahl says:

        Emc would not be a concern if it is being packed in a metallic enclosure. Nevertheless, if you can agree on being a guide we can jointly take up the development of a multilayer board for a good managed switch. I can contribute with better regulators, pcb designing (validation by you) and prototyping. I would not be too good with firmware though.

      • Hey, thanks for asking but I’m not really into putting more effort in this project. Feel free to post a link to the project though if you end up sharing it! For the firmware part, if you just need the switch in unmanaged mode you don’t need the micro at all.

      • pawanbahl says:

        Thanks fabio. That was helpful. I get the gist of how to build it.

  15. TomRitchey says:

    Hi Fabio,

    Thanks for sharing your design, it was very helpful.

    But i have problem. The Micrel KSZ8995M throughput don’t exceed 3.3Mb/s :( Do you have any idea why? Or had a similar problem?

    Cheers,

    Tom

    • Hey Tom,
      never had any performance problem with the switch (I built three of these), it was always able to saturate the 100Mbps link. Are you running in default unmanaged mode? (I think there are some ratelimit register)

      • TomRitchey says:

        Hi Fabio,

        Thanks for quick reply, sorry I couldn’t do that too (i was little busy ;)

        Turns out it was connected devices problem, not switch itself.

        Again, thanks for sharing your design.

        Keep up the good work,
        Tom

  16. Arun says:

    Thank you for sharing your knowledge about this project. I am interested in building one for an embedded design I am doing. I need an unmanaged switch. If I am going use the device as an unmanaged switch can I eliminate the CPU and associated circuitry and will the switch run on its own after power up?

    • Hey Arun, yeah totally, just double check on the datasheet for the various pinstrap but this runs happily in unmanaged mode without any micro or EEPROM.

  17. Hello Fabio,

    I need to do the same thing as Arun. I have already built the circuit but can’t seem to get it to work. Would you be able to look at my schematic and see if there are any major issues? Please let me know.

    Btw, thanks for putting this tutorial together.

    Here’s my email: –cut–

    -Elmer

    • Hey Elmer, glad you found it useful! :-)

      You could start by doing some initial check before even looking at the schematics:
      – are all power supplies up to specs?
      – is the crystal oscillating?
      – do you get the initialization blinks on the switch when you apply power? (that would indicate that the internal logic is working somehow)

      If the three above you should be at a good point already…

      • Fabio,

        Thanks for getting back to me.

        I found an error in the power supply circuit so I’m bypassing them and giving the chip the three power rails (3.3, 2.5 and 1.8) it needs from a power supply. The crystal is oscillating, I hooked it up to an oscilloscope and saw the 25 MHz sine wave. Unfortunately, I didn’t put any LEDs for the switch. Maybe I can connect them to multimeter check the output voltage. What kind voltages should I expect at the LED outputs?

        -Elmer

      • The LED pins are open drain, so if you did not install any LED, unless you put a pullup you are not going to see anything. I think it’s worth giving it a try and hack a pullup to one of the LED pins and check with the scope. All LEDs blinks when you reset the chip and then they stay in high impedence until the corresponding Ethernet port finished negotiation. After that one of the LED pulls down for link-up and blinks on activity, and the other pulls down on 100MBps link (by default).

        About the pinstrapping, I remember that on my design leaving the solder bridges open was enough to put the switch in standalone mode. Did you drive the PS0/1 and SCONF0/1 pins in any way?

      • Oh you could also check if the switch is trying to read the configuration EEPROM at bootup, look for activity on the SCL/SDA pins.

  18. Neil du Toit says:

    Hi Fabio,

    This is the first time I’m going to be working with any type of networking chips and I only do it as a hobby.

    When using the KSZ8995M in switch mode, none of the jumpers are shorted, so that then means it is not set to SPI slave mode from my understanding.

    Does that then mean that the ATMega chip can be ommited if it is only going to be used in switch mode?

    Thank you

    • Yeah that is correct! In that mode it looks up for an I2C EEPROM and if that’s not present it just works with default settings as an unmanaged switch.

  19. Huan Hoang says:

    Hi Fabio,

    Thanks for sharing your great work.

    May I ask why is it that the center tap connections are connected to 2.5V instead of 3.3V. I have built a similar board, I found out that connecting the center taps to 2.5V works but not to 3.3V.

    Regards,
    Huan

    • Hi! I don’t really remember the details and can’t find the electrical datasheet now that everything is under Microchip, but from what I remember some of the analog rails of the chip could work at either 2.5V or 3.3V (and it looks like in the current revisions it’s 3.3V only). I suspect that the center tap just has to be a the same level as VDDAT, so maybe you mixed 2.5V on the chip and 3.3V on the tap. Either way… I probably just copied the reference design. :-)

      • Ed Williams says:

        Another cool thing: The chip that is the successor to the 8995 has this web page:

        http://www.microchip.com/wwwproducts/en/KSZ8895

        and if you go down to the Design Guides section and download the guide:
        KSZ8895MQX_RQX_DP_V1.3.zip

        In the resulting folder you’ll find:
        App Note-Migration from 8995 to 8895.pdf

        which shows that a lot of passive components needed for the 8995 design (caps and whatever on the ethernet tx/rx wires) have been incorporated into the 8895 chip so it’s even easier to use! Hooray!

      • Oh that’s pretty cool, it should also saves quite some power when the port is not used, on-chip termination is a pretty common feature on modern transceivers as well, cool to see it here. Should update this design. :-)

    • Ed Williams says:

      Hi Fabio, While I at first cringed to see Micrel go under the Microchip name, it looks like they are actually setting up better documentation and resources such as free samples(!!!). It looks not only better, but maybe MUCH better for us users/experimenters.

      Info / Feature Matrix and data sheets for their Ethernet Switch chips are here:
      http://www.microchip.com/ParamChartSearch/chart.aspx?branchID=1633

      Extensive Applicatiion Notes, Design Guides, etc for the KSZ8895 (the still-in-production pretty much equivalent of the 8995 which they say is retiring) can be found here:
      http://www.microchip.com/wwwproducts/en/KSZ8895

      Their extensive documentation as well as new reference designs and such is a hopeful sign.

      THANKS AGAIN for your terrific work on this. I hope it is gratifying for you that so many people are still using this as their first path to making their own switches. You can probably now just point newbies like me and Huan Hoang to the Microchip docs, but thanks for taking a machete and hacking out the trail for us to follow!

      Happy Trails!

      • Yeah I was just used to the old website. :-) Also I’m happy to see some gigabit p/n in the switch category (KSZ87**), that may be an interesting followup design!

  20. metin says:

    Hi Fabio,i wanna use this switch in layer 2 controlled mode with an ARM CPU which has an Ethernet MAC. How should it be connected to the KS8995MA? I mean the MII interface of MAC of CPU shoul be connected to P5 interface of KS8995MA or SW interface?

    Thanks.

    • Hi! Yeah that should work just fine, I think that’s the main purpose of this switch, and I’ve seen it used in this mode in some commercial router already. There’s even a Linux kernel driver to control the switch via MDIO in that mode.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s