Thursday, November 14

I Sent an Ethernet Packet

For as long as I’ve been making videos on the low byte productions youtube channel, I’ve wished to make a series about “Networking from scratch”, by which I imply constructing a complete TCP/IP stack from the ground up on a microcontroller. It’s been almost 6 years now, and the previous couple of days seemed like as excellent a time as any to begin.

This blog site entry is relatively restricted in scope; On the surface area, it’s about how I effectively sent my very first ethernet package, however truly it’s a story about bugs and debugging, and some ideas about conquering obstacles in tasks.

Microcontroller

The microcontroller I’m utilizing is an STM32F401 on a nucleo devboard. This is the very same setup I utilized in the Blinky to bootloader series, the 3D renderer on an oscilloscope video, and a lot of others. It’s an ARM Cortex-M4 that can add to 84MHz, with 96KiB of RAM. That’s adequate to keep good handful of packages.

Ethernet

Ethernet is a word that covers an unexpected variety of things. You may associate it with the port you plug into for wired web, or learn about the concept of ethernet framesEthernet is really an entire household of innovations and requirements (a lot of which are now outdated) that includes the hardware included at the physical level, numerous signalling formats that encode and transfer bits, the techniques for handling bus crashes, and the design of frames, which consist of and safeguard the information being sent out from one location to another.

Due to the intricacy of the signalling included with ethernet, a devoted ASIC is typically utilized, which takes in information at the frame level, and looks after wiggling the electrical lines in the proper way over a cable television (though there are obviously exceptions). For this job, I’m utilizing the W5100 chip from Wiznet, in the type of the initial Arduino Ethernet guard. Well, it’s a low-cost knockoff that wound up requiring some revamp to in fact work correctly, however we’ll get to that.

The W5100 chip itself is quite cool. It’s basically an ethernet ASIC with a hardware TCP/IP stack built-in. It has 4 “sockets”, which can be established to operate at the TCP, UDP, IP, or “MAC Raw” levels. Given that the entire point of this job is develop a TCP/IP stack from scratch, I’m just utilizing one socket in the MAC Raw mode, where I hand it ethernet frames, and it sends them out. The caution is that an real ethernet frame includes more than simply the information; It likewise consists of: A preamble, start of frame marker, and a 32-bit CRC. The preamble and start of frame marker are truly just pertinent at the electrical level, which the chip completely makes sure, and the CRC is likewise helpfully calculated by the W5100.

Issue No. 1: Shouting into deep space

I coded up a motorist to interact with the W5100 chip.

» …
Learn more