On hardware state machines: How to write a simple MAC controller using the RP2040 PIOs
Hardware state machines are nice, and the RP2040 has two blocks with up to four machines each. Their instruction set is limited, but powerful, and they can execute an instruction per cycle, pushing and popping from their FIFOs and shifting bytes in and out. The Raspberry Pi Pico does not have an Ethernet connection, but there are many PHY boards available… take a LAN8720 board and connect it to the Pico; you’re done. The firmware ? Introducing Mongoose…
Summary
This blog shows how to implement a simple Ethernet MAC controller using the RP2040's PIO hardware state machines and a LAN8720 PHY. It explains the PIO instruction model, how to stream bytes in and out via FIFOs and DMA, and how to integrate the low-level MAC with higher-layer firmware (using the Mongoose stack as an example).
Key Takeaways
- Implement a byte-oriented Ethernet MAC in RP2040 PIOs to handle frame transmission and reception.
- Design compact PIO state machines that manage preamble/SFD, bit shifting, and CRC within the RP2040 instruction set.
- Integrate PIO FIFOs and RP2040 DMA/IRQ handling to sustain wire-speed throughput to/from a LAN8720 PHY.
- Integrate the custom MAC with higher-level networking code (example uses the Mongoose networking stack) and optimize for timing and resource use.
Who Should Read This
Embedded firmware engineers and developers experienced with microcontroller peripherals who want to build low-level Ethernet MAC logic on the RP2040 or learn advanced PIO usage.
Still RelevantAdvanced
Related Documents
- Consistent Overhead Byte Stuffing TimelessIntermediate
- PID Without a PhD TimelessIntermediate
- Introduction to Embedded Systems - A Cyber-Physical Systems Approach Still RelevantIntermediate
- Can an RTOS be really real-time? TimelessAdvanced
- Memory Mapped I/O in C TimelessIntermediate








