The Ethernet of Things

The Pico-100BASE-TX library uses the Programmable I/O subsystem of the Raspberry Pi Pico 2 to bit bang a Fast Ethernet transmitter.

Nick Bild
2 days agoCommunication
Ethernet the hard way (📷: Steve Markgraf)

When selecting a new development board for your next project, one of the most important things to consider is the interfaces that it has available. Can it talk in SPI? How about UART or I2C? It is through these interfaces that the board will communicate with external devices, so if the sensor you want to use does not speak the same language as the development board, you are out of luck.

However, if you don’t mind doing your project in hard mode, there is another option that should always be kept in mind — bit banging. Just like it says on the tin, those free GPIO pins are for general purpose use, and that includes simulating standard communications protocols. As long as the GPIO pins can switch on and off fast enough to keep up with the specifications, there is nothing stopping you from coding up your own solution to replicate the signal pattern of any existing interface.

Some of these interfaces, like UART, are not too terribly difficult to replicate. But then there are the tough ones, like Fast Ethernet, which hardware hacker Steve Markgraf just wrote a bit-banging library for. The communication speed is quite fast, making it challenging for standard GPIO pins to keep up with, but Markgraf got some help in that department by using a Raspberry Pi Pico 2. Specialized hardware on this board can twiddle the pins at a blazing speed.

Markgraf’s new library, Pico-100BASE-TX, cleverly exploits the Programmable I/O (PIO) subsystem. Using this subsystem, it can stream data at roughly 11 MB/s, effectively creating a 100 Mbit/s Ethernet transmitter, entirely through bit banging. But if you want to receive signals as well, you will have to look elsewhere — the library has not implemented that capability.

With the speed problem solved, it was time to implement the protocol. 100BASE-TX Ethernet uses MLT-3 encoding, which cycles through three voltage levels (-1, 0, +1). It also relies on 4B5B encoding and scrambling to maintain signal integrity and prevent long runs of identical bits. The scrambler uses an 11-bit Linear Feedback Shift Register, precomputed into lookup tables that take up about 10 KB of RAM. With pre-inverted scrambling and a stream of idle symbols, data can be pushed to the PIO entirely through DMA, keeping CPU load minimal.

This isn’t entirely a plug-and-play Ethernet solution. Connecting a microcontroller directly to a network interface designed for specialized PHY chips is a risky move. Markgraf warns users not to connect to any Power over Ethernet equipment and to use either a proper pulse transformer or a resistor network for protection. In testing, he found that a pair of resistors and an old Ethernet cable were sometimes enough, but success varied depending on the connected hardware.

The GitHub repository includes some example applications like counter, which streams a simple 16-bit value over UDP, internal_adc for sending analog readings, and pcm1802_audio, which transmits 75 kHz audio from an external ADC.

Most people would be better off picking up an Ethernet HAT for their Pico, but if you are in a rush to get your project done and don’t want to wait for a new component to ship, then Pico-100BASE-TX might be just what you are looking for.

Nick Bild
R&D, creativity, and building the next big thing you never knew you wanted are my specialties.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles