Author Topic: Ethernet interface for MCU  (Read 4238 times)

0 Members and 1 Guest are viewing this topic.

Offline ulixTopic starter

  • Regular Contributor
  • *
  • Posts: 118
  • Country: de
Ethernet interface for MCU
« on: January 01, 2025, 06:17:46 pm »
Hi Everyone,

I’m planning to transfer some data captured with an MSP430 MCU via LAN. Does anyone have any recommendations for modules to get started with LAN communication? I’ve seen a lot of ENC28J60 modules on AliExpress, but it seems that this chip is quite unreliable and buggy. Do any forum members have other or better recommendations?

Thanks a lot!
 

Online Siwastaja

  • Super Contributor
  • ***
  • Posts: 9481
  • Country: fi
Re: Ethernet interface for MCU
« Reply #1 on: January 01, 2025, 06:21:23 pm »
Wiznet (W5500, W6100) is The Easy Way and pretty good. Additionally to Ethernet MAC+PHY, it integrates TCP, IP, UDP and ARP on-chip, you need software implementations for DHCP and DNS if you need them, but they do have (seriously buggy, of course, but that's part of the deal) examples you can use.

Time-to-product was not too bad, and probably easier than trying to integrate lwip for example.

Compared to that, ENC28J60 only is MAC/PHY, so you need full TCP/IP software implementation if you want that.

What protocols are you expecting to use?
« Last Edit: January 01, 2025, 06:24:13 pm by Siwastaja »
 
The following users thanked this post: Smokey

Offline coppice

  • Super Contributor
  • ***
  • Posts: 10190
  • Country: gb
Re: Ethernet interface for MCU
« Reply #2 on: January 01, 2025, 06:24:14 pm »
Is the chip really buggy, or is there just a lot of buggy software trying to use it? I have no experience with this part, but I do have a lot of experience of people complaining about buggy hardware in the MCU world that is actually a buggy software problem. That said, there are plenty of real hardware bugs in the MCU world that never get fixed.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28522
  • Country: nl
    • NCT Developments
Re: Ethernet interface for MCU
« Reply #3 on: January 01, 2025, 06:29:18 pm »
I strongly second the suggestion for the W5500 or W6100 (the latter also supporting IPv6). Life just doesn't get any easier. The ENC28J60 supports 10Mbit only which might not even be supported by switches in the very near future. 100Mbit/s is also deemed obsolete and not all ethernet equipment supports 100Mbit/s these days, let alone 10Mbit/s.
« Last Edit: January 01, 2025, 06:31:42 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 
The following users thanked this post: ulix, Smokey

Offline phil from seattle

  • Super Contributor
  • ***
  • Posts: 1076
  • Country: us
Re: Ethernet interface for MCU
« Reply #4 on: January 01, 2025, 07:02:38 pm »
Another vote for the W5500. You can get complete modules that run off of SPI and a couple of extra pins. WIZ820io is a nice compact version that I have used a number of times.  $5 or less from China. $8ish on Amazon in the US.  Probably similar in the EU. 
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 10190
  • Country: gb
Re: Ethernet interface for MCU
« Reply #5 on: January 01, 2025, 08:02:04 pm »
To experiment quickly with the W6100 there are modules with the W6100 and an RP2040 MCU available from many places now. There appear to be load and go demo projects for that.
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 14131
  • Country: gb
    • Mike's Electric Stuff
Re: Ethernet interface for MCU
« Reply #6 on: January 01, 2025, 08:05:01 pm »
+1 for W5500. The thing I could do with them improving is support for longer (fragmented) UDP packets.
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 
The following users thanked this post: Smokey

Offline kripton2035

  • Super Contributor
  • ***
  • Posts: 2733
  • Country: fr
    • kripton2035 schematics repository
Re: Ethernet interface for MCU
« Reply #7 on: January 01, 2025, 09:56:15 pm »
https://www.aliexpress.com/item/1005006900921262.html
ESP32 with a LAN8270 on a small pcb, you can use it with arduino code.


or a W5500 like others said, mounted on a small pcb with the ethernet plug.
https://www.aliexpress.com/item/1005004679288698.html
« Last Edit: January 01, 2025, 09:57:48 pm by kripton2035 »
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28522
  • Country: nl
    • NCT Developments
Re: Ethernet interface for MCU
« Reply #8 on: January 01, 2025, 10:24:09 pm »
I would be careful with recommending random modules. The W5500 requires a careful PCB layout. It is doable on two layers if you are experienced. Otherwise use or try finding a board / module with 4 layers so power and ground are decoupled properly.
« Last Edit: January 01, 2025, 11:10:07 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline ejeffrey

  • Super Contributor
  • ***
  • Posts: 4065
  • Country: us
Re: Ethernet interface for MCU
« Reply #9 on: January 01, 2025, 11:01:41 pm »
I don't love having Ethernet or TCP/IP on small micros in the first place, but the wiznet chips are a pretty good way to do it.  It's easy to set up and mostly just works.
 

Offline fchk

  • Frequent Contributor
  • **
  • Posts: 288
  • Country: de
Re: Ethernet interface for MCU
« Reply #10 on: January 01, 2025, 11:28:10 pm »
Hi Everyone,

I’m planning to transfer some data captured with an MSP430 MCU via LAN.

Why MSP430? This is not an ideal platform for an Ethernet system. You are limited to SPI-NICs (Recommendation: Microchip KSZ8851SNL), these Wiznet chips or external bridges. MSP430 does not have enough RAM for a decent TCP implementation.

If you like to stick with TI, my suggestion is:
https://www.ti.com/product/TM4C1294NCPDT
There is also a suitable launchpad for this:
https://www.ti.com/tool/EK-TM4C1294XL

Much more power, good driver library, and there is still the TI-RTOS you can use.
 

Offline coppice

  • Super Contributor
  • ***
  • Posts: 10190
  • Country: gb
Re: Ethernet interface for MCU
« Reply #11 on: January 02, 2025, 12:01:23 am »
Hi Everyone,

I’m planning to transfer some data captured with an MSP430 MCU via LAN.

Why MSP430? This is not an ideal platform for an Ethernet system. You are limited to SPI-NICs (Recommendation: Microchip KSZ8851SNL), these Wiznet chips or external bridges. MSP430 does not have enough RAM for a decent TCP implementation.

If you like to stick with TI, my suggestion is:
https://www.ti.com/product/TM4C1294NCPDT
There is also a suitable launchpad for this:
https://www.ti.com/tool/EK-TM4C1294XL

Much more power, good driver library, and there is still the TI-RTOS you can use.
Great idea. because some random MCU is sure to have the mix of qualities that will suit the OP's application. I assume this is an add on to an existing application, or the MSP430 has just the right peripherals for some particular application.

 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28522
  • Country: nl
    • NCT Developments
Re: Ethernet interface for MCU
« Reply #12 on: January 02, 2025, 12:31:26 am »
Hi Everyone,

I’m planning to transfer some data captured with an MSP430 MCU via LAN.

Why MSP430? This is not an ideal platform for an Ethernet system. You are limited to SPI-NICs (Recommendation: Microchip KSZ8851SNL), these Wiznet chips or external bridges. MSP430 does not have enough RAM for a decent TCP implementation.
Actually that is a good thing! Running a TCP stack on a microcontroller is far from ideal. Even with a RTOS. I've been around the block a couple of times (including using Lwip) and the Wiznet chips are a really good solution. The BOM cost and part count don't increase (the Wiznet chips are cheaper from Digikey compared to the KSZ8851SNL) but the R&D time gets a massive reduction.
« Last Edit: January 02, 2025, 12:34:50 am by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 14131
  • Country: gb
    • Mike's Electric Stuff
Re: Ethernet interface for MCU
« Reply #13 on: January 02, 2025, 12:43:41 am »
BTW with the W5500 use a proper crystal oscillator, not a MEMS one - took me a couple of days to figure out why I was losing about 1% of receive packets.
 
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 14131
  • Country: gb
    • Mike's Electric Stuff
Re: Ethernet interface for MCU
« Reply #14 on: January 02, 2025, 01:58:40 am »
There's also the CH390 from WCH -
SPI or parallel port versions, internal unique MAC address, but no protocols built in. UDP ought to be easy enough - I don't know if they supply a software stack for it.
Parallel I/F might be useful if you need something faster than the W5500, and it comes in smaller package options like DFN20.
 
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline woofy

  • Frequent Contributor
  • **
  • Posts: 381
  • Country: gb
    • Woofys Place
Re: Ethernet interface for MCU
« Reply #15 on: January 02, 2025, 09:14:36 am »
I've kinda used the ENC28J60 in the past, its the same peripheral built in to the PIC18F67J60. Its ok but very old now, and its 10BASE-T only.
If your not absolutely stuck on the MPS430 then STM32+Mongoose is an easy way in.

Offline tellurium

  • Frequent Contributor
  • **
  • Posts: 288
  • Country: ua
Re: Ethernet interface for MCU
« Reply #16 on: January 03, 2025, 12:10:00 pm »
Actually that is a good thing! Running a TCP stack on a microcontroller is far from ideal. Even with a RTOS.

What's wrong with running TCP stack on a micro?
Here's Arduino Nano every, 8-bit, 6k RAM, 48k flash, running simple web server and MQTT client.
The stack is in software, using W5500 as ethernet frame sender/receiver.

Open source embedded network library https://github.com/cesanta/mongoose
TCP/IP stack + TLS1.3 + HTTP/WebSocket/MQTT in a single file
 

Offline qqclient

  • Newbie
  • Posts: 4
  • Country: cn
Re: Ethernet interface for MCU
« Reply #17 on: January 03, 2025, 04:36:45 pm »
have fun with CH32V307, CH32V208, CH579M, cost effective RISC-V or cortexM core MCU with Ethernet MAC+PHY and ,
for more, there are many examples, which style is similar to the STM standard lib, thats whats important.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28522
  • Country: nl
    • NCT Developments
Re: Ethernet interface for MCU
« Reply #18 on: January 03, 2025, 07:58:46 pm »
Actually that is a good thing! Running a TCP stack on a microcontroller is far from ideal. Even with a RTOS.

What's wrong with running TCP stack on a micro?
The part you cut away. Life gets a lot easier if you don't have to deal with ethernet packets coming in at random points in time in unspecified quantities. And hackers are quite crafty so having a dedicated chip in between which isolates your own code (which might do something safety related) from anything which deals with the network directly is a bonus.

Quote
Here's Arduino Nano every, 8-bit, 6k RAM, 48k flash, running simple web server and MQTT client.
I did far more with less 20 odd years ago. I get that you want to push your Mongoose product but frankly I'd go with Lwip because that has way more eyes going over it making it a safer bet in terms of security & reliability. But both make me unhappy looking at the source code (example: mapping structs onto void pointers which the compiler might choke on and/or give alignment issues depending on settings) which for me is also a reason to go for a Wiznet chip or similar product by lack of a better alternative.
« Last Edit: January 03, 2025, 09:28:52 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Online Siwastaja

  • Super Contributor
  • ***
  • Posts: 9481
  • Country: fi
Re: Ethernet interface for MCU
« Reply #19 on: January 04, 2025, 07:54:39 am »
And hackers are quite crafty so having a dedicated chip in between which isolates your own code (which might do something safety related) from anything which deals with the network directly is a bonus.

Well, with Wiznet you can't do that. It does not implement the full basic set of protocols required, and what's worse, the software DNS implementation they supply (that runs on customer MCU) has glaring security holes, for example it overindexes a stack-allocated buffer. You can of course implement or find something safer, but really that's textbook example of "false sense of security": thinking that Wiznet gives you a secure solution easily is dangerous.

So, while the idea of isolation is nice in theory, it would need a good implementation, which Wiznet is not. At least with Mongoose/lwip/whatever stack you can evaluate the code, with Wiznet the internal stack is what it is, and probably done by the same guys who did the DNS/DHCP implementations that are pure horror.

My excuse for not using Mongoose is that I haven't had time to try it. If it really is as good as tellurium makes it sound like, I would prefer it as a solution over an external locked-down chip. In the meantime, Wiznet chip simplifies my life.
« Last Edit: January 04, 2025, 08:07:52 am by Siwastaja »
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28522
  • Country: nl
    • NCT Developments
Re: Ethernet interface for MCU
« Reply #20 on: January 04, 2025, 10:20:16 am »
And hackers are quite crafty so having a dedicated chip in between which isolates your own code (which might do something safety related) from anything which deals with the network directly is a bonus.

Well, with Wiznet you can't do that. It does not implement the full basic set of protocols required, and what's worse, the software DNS implementation they supply (that runs on customer MCU) has glaring security holes, for example it overindexes a stack-allocated buffer. You can of course implement or find something safer, but really that's textbook example of "false sense of security": thinking that Wiznet gives you a secure solution easily is dangerous.
No, you are now going the 'glass half full' road while in reality the glass is still 90% full. The local MCU doesn't need to deal with the TCP / UDP stack and it can fortify the protocols running on top of TCP / UDP. That is a whole lot easier to do compared to analysing every nook and cranny of  TCP / UDP protocol stack and dealing with ethernet packets in realtime. Having the source code for a TCP / UDP protocol stack doesn't do you any good as implementing TCP/ UDP correctly and doing the verification is an art in itself. Talking about false sense of security  ;) There are many pitfalls due to all the features which got bolted on later and various levels of OS interoperability. Been there, done that. There is a very good reason there are so few TCP / UDP stacks out there! The Wiznet chip OTOH does provide a very clear interface between your own code and the network. To the point where I don't care how the Wiznet chips works internally. If the Wiznet chip locks up, just reset it. I still assume that the 'Wiznet' stack itself has been written & tested by people who know what they are doing as this can't be fixed after the chip has been sold. When dealing with code from China I typically see that the base architecture has been designed & implemented by people who know what they are doing but then the junior engineers come in to add / change extra features which are very poorely implemented.
« Last Edit: January 04, 2025, 10:29:40 am by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Online Siwastaja

  • Super Contributor
  • ***
  • Posts: 9481
  • Country: fi
Re: Ethernet interface for MCU
« Reply #21 on: January 04, 2025, 10:29:37 am »
No, you are now going the 'glass half full' road while in reality the glass is still 90% full.

No, just pointing out there is no magic here, and obvious false sense of security. It is true that DHCP+DNS is probably two orders of magnitude easier to do right and verify than the whole stack, but temptation to use readily provided example without verifying it is high, especially given the advice (e.g. in my post above) that using W5500/W6100 is really simple.

Besides, separation alone isn't nearly a sufficient level of protection. If the chip offered TLS, then that would be pretty significant, but because it does not, attacker can still use malformed payloads to trigger bugs in firmware. The attack surface is smaller, but not by orders of magnitude.

For a complete safe and secure implementation, you are still at mercy of libraries like mbedTLS, integrating them right, and doing your own code right. I claim that Wiznet chip does not offer significant improvement in time-to-market. If it feels like it does, you are very likely overlooking something and relying on the false sense of security it offers.
« Last Edit: January 04, 2025, 10:32:09 am by Siwastaja »
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 28522
  • Country: nl
    • NCT Developments
Re: Ethernet interface for MCU
« Reply #22 on: January 04, 2025, 10:47:04 am »
Have you tried using Lwip? I have and I can assure you that dealing with the Wiznet chip is easier and saves lots of time.

Using TLS opens up another can of worms as you will want to use a pre-emptive multitasking RTOS. Processing the keys during connection initialisation takes such a long time that your criticial tasks will be starved long before if you are using a single threaded super-loop / round robin scheduler. I have done some work on that as well in the past but realistically, if you application needs TLS, then you also need to be able to do firmware (security) updates as well. All in all, I'm not so sure a standard microcontroller is a good choice if you need TLS. I'd either run Linux or use a VPN router.
« Last Edit: January 04, 2025, 10:50:41 am by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Karel

  • Super Contributor
  • ***
  • Posts: 2279
  • Country: 00
Re: Ethernet interface for MCU
« Reply #23 on: January 04, 2025, 10:57:37 am »
Hi Everyone,

I’m planning to transfer some data captured with an MSP430 MCU via LAN. Does anyone have any recommendations for modules to get started with LAN communication? I’ve seen a lot of ENC28J60 modules on AliExpress, but it seems that this chip is quite unreliable and buggy. Do any forum members have other or better recommendations?

Thanks a lot!

I would use a Raspberry Pi as an " ethernet module".
Much easier to deal with and it's much more secure and stable.
 

Online Siwastaja

  • Super Contributor
  • ***
  • Posts: 9481
  • Country: fi
Re: Ethernet interface for MCU
« Reply #24 on: January 04, 2025, 01:05:24 pm »
Using TLS opens up another can of worms as you will want to use a pre-emptive multitasking RTOS.

Maybe you do, maybe not. For the current project I chose not to, and it has scaled up just fine even beyond initial expectations. That's because since I discovered how handy ARM pre-emptive prioritized interrupts are some 10 years ago, I have transitioned into fully interrupt-driven designs with normally empty while(1) loop (or calls to put CPU in sleep when power matters), basically wasting the "main thread" and running everything in interrupt context, triggered by timers or peripheral events. This has worked for me really well, and in TLS/Wiznet design currently I utilized that otherwise wasted main thread so that it handles networking and can deal with the blocking calls to existing networking code (e.g. mbedtls).

But I recognize it does not work for everyone, and adding another layer of blocking calls (concurrently to blocking networking calls) is not possible without adding an OS with a task scheduler. Then again, adding an OS is not a big deal, I just prefer not having it when I can survive without.
« Last Edit: January 04, 2025, 01:09:00 pm by Siwastaja »
 
The following users thanked this post: tellurium


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf