6 ms·
I sent an Ethernet packet
- vbezhenar 2y agoAs a hobbyist I wish that electronic gods would invent a way to bit-bang real world protocols. It is possible with simple protocols, but when we move to MHz range, it moves to impossible. Some kind of co-processor which would work at, say, 100 GHz speed with very limited instruction set. So I could implement some simple protocol parsing and buffering for more complex processing at lower speeds. Probably not possible, but who knows...
- danhor 2y agoYou're basically talking about FPGAs. Sure, for >500 MHz (depending on the FPGA) you'll need to use the integrated transceivers, but they're flexible and support the physical layer of many protocols.
- vardump 2y agoRaspberry RP2040/2350 microcontrollers are more than capable of bitbanging up to 100-300 MHz range by using PIO and HSTX. Higher end with some overclocking.
- MathMonkeyMan 2y agoThe rp2040 and its newer sibling can be clocked north of 100 MHz and have special hardware called PIO (programmable input/output) that runs at one instruction per cycle and can do multiple IO operations per instruction. That's a microcontroller. I wonder if more powerful chips can do more.
- crote 2y agoThe main issue with that is that the PIO does not have decent support for external clock inputs, let alone any kind of clock recovery. It can easily send a 100MHz signal, but it can't reliably receive one. The PIO allows for single-cycle or dual-cycle data output, which essentially just pulls bits from a FIFO and puts them on some pins. The "side-set pin" makes it really easy to generate a clock signal as well. If the target devices samples on rising edge, it becomes essentially "output data, clock low; nop, clock high; implicit repeat" or even "output data; implicit repeat" if the target can do its own clock recovery or uses DDR. This is great, because you can output a lot of data at quite high speeds. But the opposite is a lot harder. The PIO has no native clock support, so you're left simulating it yourself with a multi-instruction operation. If you need even as little as two instructions to receive a bit, that 133MHz MCU clock already limits you to a 66MHz signal! In theory you could use an external clock input - but those pins are limited to 50MHz. You could also feed the external clock into the main oscillator input - but that breaks a bunch of other functionality, especially if the external clock isn't reliable. Oversampling isn't an option either: you'd have to read the pins at 4x the signal frequency (limiting you to 33MHz) and dedicate a lot of computing resources to that. In other words, high-speed input is only really an option if you don't care about synchronization, such as a free-running logic analyzer. But bitbanging 100BASE-T Ethernet? Don't count on it. Even the 2-bit-wide 50MHz RMII interface has proven to be quite challenging.
- MathMonkeyMan 2y agoThanks for the insights. I've only written one PIO program, and it's for a DHT22 sensor. I divided the clock down to 1 MHz so I could count microseconds. Really, CPU bit-banging would have worked fine at those speeds. Now that I think about it more, you're right. Best case scenario for reading a bit would be to wait for the pin to go high/low, then push the corresponding bit into the input shift register, and have that automatically flush to DMA every 32 bits, say. Can't do better than some fraction of the clock speed because of the multiple instructions needed.
- Firerouge 2y agoWhat use cases are you imagining where you need arbitrary data output and processing at 100GHz speeds? It's my understanding that even 100GbE is running at a fraction of those frequencies.
- vbezhenar 2y agoTo be able to spend multiple cycles for processing a bit. Or process multiple bits arriving at the same time. Also it might be necessary to measure signal multiple times. May be 100 GHz is too much... For example I wanted to bit-bang FM radio by measuring antenna signal, that's around 100 MHz, so I need to probe around 200-300M times per second and perform at least minimal processing, I guess.
- anthomtb 2y agoI realize FM radio is strictly an example, but would you not rely on bandpass sampling? Where you sample at some multiple of your bandwidth and rely on the spectral replication effect to get your waveform. Ref: https://en.wikipedia.org/wiki/Undersampling https://en.wikipedia.org/wiki/Undersampling (funny enough, this article explicitly calls out the FM radio use case).
- immibis 2y agoYou need a very stable clock for that, which was also called out as a thing. With some PLLs you could lower the needed frequency. I think you're really looking for a small FPGA though.
- pjc50 2y agoThis is basically what FPGAs offer, although above 1GHz the transceiver design becomes difficult and expensive. 1GHz should be possible on hobbyist-priced parts. 100GHz is .. well, can anyone find any part with that capability? Seems to top out around 10GHz for ethernet transceivers.
- Brusco_RF 2y agoI think he meant 100MHz. In case he actually meant 100GHz, I would gently remind him that light only travels ~3mm in 10ps
- qiqitori 2y agoAs others have said, PIO has your back. https://hackaday.com/2022/12/03/bit-banging-bidirectional-ethernet-on-a-pi-pico/ https://hackaday.com/2022/12/03/bit-banging-bidirectional-et...
- lukeh 2y agoThere's also XMOS (effectively, software defined hardware). But ain't going to do those speeds.
- sgjohnson 2y agoEthernet deals with frames, not packets. Packets are an IP concept :)
- anilakar 2y agoPackets are a TCP concept. IP sends datagrams :)
- samarthr1 2y agoI thought UDP sent datagrams?
- deleted 2y ago[deleted]
- tsimionescu 2y agoBoth IP and UDP call their packets "datagrams".
- brewmarche 2y agoThe TCP unit is called segment
- cat-snatcher 2y agoNo it's called a slice.
- mhandley 2y agoRFC 791 which defines IP talks about both packets and datagrams. IP sends datagrams. Each IP datagram is fragmented into one or more packets depending on the underlying L2 network. But RFC 791 dates from when the underlying L2 network was most likely ARPAnet, which had 128 byte packets. Today the distinction is (or should be) moot - if you're relying on IP fragmentation to send your large IP datagram over multiple L2 packets, you're doing something wrong. IPv6 doesn't even support in-network fragmentation. In practice, the distinction has largely disappeared over time. Everyone I know talks about packets and very rarely bothers to distinguish between frames, datagrams and packets, because in practice one Ethernet frame generally carries one IP datagram, and everyone calls it a packet.
- michaelt 2y agoIf you've got a hankering for wired ethernet on a microcontroller, several of the larger STM32 Nucleo boards [1] have 100Mbps ethernet built in - and at ~$25 they're pretty affordable. Their 'STM32Cube' software gets mixed reviews, but it will spit out a working example of ethernet communication. [1] https://www.st.com/en/evaluation-tools/nucleo-f439zi.html https://www.st.com/en/evaluation-tools/nucleo-f439zi.html
- Sponge5 2y ago> Their 'STM32Cube' software gets mixed reviews Thankfully there's more than one CMake projects on github as an alternative.
- naitgacem 2y agoI think the middle ground of generating code using MX and taking it from there using cmake is a really good place to start.
- tecleandor 2y agoI'm intrigued by this RISC-V ESP32-P4 board with Ethernet that should be around $20 ... https://liliputing.com/waveshare-esp32-p4-nano-is-a-tiny-risc-v-dev-board-with-ethernet-wifi-and-bluetooth/ https://liliputing.com/waveshare-esp32-p4-nano-is-a-tiny-ris... Edit: I just saw there are way cheaper modules, although probably not as performant, like the WT32-ETH01
- deleted 2y ago[deleted]
- rcxdude 2y ago>Their 'STM32Cube' software gets mixed reviews, but it will spit out a working example of ethernet communication. Sometimes. On some hardware it's broken.
- pjc50 2y agoThere's a distinct "nineties" feel to STM32Cube.
- Alifatisk 2y agoI remember many many years ago, learning about networking, I got very fixated towards constructing and sending my own packet over the wire. Good times. I'll never forget Packetfu (https://rubygems.org/gems/packetfu https://rubygems.org/gems/packetfu)
- Aromasin 2y agoI took a strange career jump recently into FPGA engineering with a focus on Ethernet. It's been a fun journey, which culminated in me finally designing my own Hard MAC IP and sending a packet over some custom PHY IP. I'd highly recommend it for those looking to try a "Hard Mode" version of this challenge. I feel like networking is very abstracted from users, so understanding how Ethernet cards, modems and switches put together and pull apart sections of packets, and how the PHY/PCS recovers signals over a link was really valuable.
- pjc50 2y agoA while ago (about a decade, oh no) I was involved in a project which did direct TCP from an FPGA. As part of debugging and verification, I made it so you could hook up the simulated version from Verilator to the Linux TUN/TAP device, enabling you to connect directly into it from the developer machine without tying up the physical hardware (which we only had one of). Fun project.
- naitgacem 2y agoRenode offers a similar approach, one could even route all stimulated packets into Wireshark. It's really powerful when it works
- babarjaana 2y agoSounds fun! Were you already familiar with networking/Ethernet when you started? If not, which resources - if any - did you use to get a broad overview of everything involved? My knowledge of networking ends at a very basic understanding of the OSI model, and I am very interested in taking a deep dive into the networking world.
- eszed 2y agoWireshark, plus a book about using Wireshark. I have "Wireshark Network Analysis", which looks to be shockingly expensive right now - to be fair, it's worth whatever price, but maybe not while you're speculativey getting your toes wet - and there are others out there. I am nowhere near an expert (I've only worked through about 1/3 of that book - just enough to solve the problem I had at the time!), but that's what's taught me what I know, and I know can take me further.
- thomasikzelf 2y agoI used the W5100 before with Arduino but I am not sure about "gold standard" quality. I had a lot of issues with random disconnects several times a day with this board. Maybe it's the board, or maybe it's the arduino code or the connection. Or maybe it was my code. I don't know. Eventually I switched to a pi and never had any connection problems anymore. When it comes to tcp connections linux seems more robust.
- fellerts 2y agoFirst time seeing the retcons for MOSI/MISO: main out/subordinate in instead of master out/slave in. I'll use that so I can still refer to the pins as MOSI/MISO. The COPI/CIPO alternative (controller out/peripheral in) never worked themselves into my brain stem properly.
- brabel 2y agoGosh, thanks for translating that into terms I actually knew.
- crest 2y agoMaster/sub would be funnier for getting a reaction out of prude Americans.
- formerly_proven 2y agoCAN bus almost got this right but someone scribbled "recessive" over "submissive". Or maybe they were thinking about strong and weak genes all along.
- camtarn 2y agoSince the title is rather vague, this is the start of a series about building a TCP/IP and Ethernet framing stack from scratch for a microcontroller. The author uses a chip (W5100) which can handle TCP/IP itself, but also supports handing it pre-built Ethernet frames, although the chip handles the preamble and CRC calculation. Most of the article is about trying to communicate with the chip itself, and sending a test packet (which I'm guessing is hardcoded, although it's not called out in the article). (I was hoping it would be about bit-banging Ethernet on some improbable bit of hardware.)
- crest 2y agoThe RP2040 can be convinced to bit-bang Ethernet (yes even 100Mb/s) with only a transceiver. Part of the trick is to modify the common PHY + MagJack breakout boards to let the RP2040 generate the clock signal so that the signals are in sync and you don't have to oversample the RMII. Just 10Mb/s can be done even dirtier. I'm still waiting for someone to combine an RP2040 with DVI/HDMI video output and Ethernet into a "modern" glass terminal (just telnet, SSH is probably asking too much).
- telgareith 2y agoSsh is not asking too much! In the world of irony- HDMI/DP will be far harder than ssh.
- robinsonb5 2y agoBut of course it has been done: https://github.com/Wren6991/picodvi https://github.com/Wren6991/picodvi (OK, it's DVI rather than HDMI - at low resolutions HDMI isn't more difficult, just more legally contentious.)
- camtarn 2y agoThat's incredible - I missed this when it was first released!
- drougge 2y ago
- zokier 2y agonote that if you want to play with writing your own network stack on linux, you can use `socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))` and operate on not too dissimilar level of abstraction as this is. SOCK_RAW packets are passed to and from the device driver without any changes in the packet data. When receiving a packet, the address is still parsed and passed in a standard sockaddr_ll address structure. When transmitting a packet, the user-supplied buffer should contain the physical-layer header. That packet is then queued unmodified to the network driver of the interface defined by the destination address. https://man7.org/linux/man-pages/man7/packet.7.html https://man7.org/linux/man-pages/man7/packet.7.html
- immibis 2y agoAnd to do it from the other direction, you can open a tun (virtual IP) or tap (virtual Ethernet) interface just as easily. This adds a virtual interface to the network stack (e.g. a VPN interface), while a packet socket does the opposite and lets you communicate directly through with a real interface.
- simfoo 2y agoNicely done! I just spent my last 16h of work time on implementing the reverse: parsing ethernet2 (with vlans!), ipv4+6 & UDP up to an automotive IP protocol. Use case is to understand a proprietary bus capturing stream that forwards ethernet frames (among other things) nested in ethernet frames that I receive on a raw socket. Fun stuff! Wireshark & Chatgpt are invaluable for this kind of task
- heisenbit 2y ago> But if I had any kind of point, it would probably be that spending the time to do things like write tools and explore the debugging space is pretty much always worth it. > Strangely, I've found that there is a not-insignificant number of people are against this - especially in a professional environment. I think this has something to do with the JIRA-fication of development process, where all work is divided and sub-divided, and anything that does not directly check a box and produce a deliverable is wasted effort. It's disheartening that there is a whole group of people - developers and managers alike - who do not understand or see the value in exploration as part of the process. So true, being able to create your own small tools is a superpower which is often at the heart of 10x programmers. It is sadly an art often practiced in the shadow.
- Cthulhu_ 2y ago10x developers (sweeping generalization here) are often not the ones that are beholden to a manager / product owner telling them what has the highest priority though. Whether that's because they won't be told what to do, are the manager themselves, or have no manager at all is not known to me. That said, writing your own tools if applicable is useful, however I'd argue that a productive developer writes the least code and instead uses what's off the shelf. To use this article as an example, nobody should be writing their own TCP stack, there are perfectly fine existing implementations. That said that said, writing your own stuff is probably the best way to get a deep understanding, and a deep understanding of things is a constituent part of the mythical 10x developer. I just wouldn't expect any employer to pay you for it.
- _yb2s 2y agoThe reason a “10x developer” can work on whatever they want is because it only takes 10% of their work hours to complete their job requirements- they are then free to experiment and play with a lot of their time.
- throwaway2037 2y agoI second this notion. In my experience, the most efficient / effective developers get to work on all sorts of interesting problems because they can finish their "regular" work so quickly.
- hydroid7 2y agoIt should be also noted, that you can write your own network stack on Linux with the help of AF_XDP[1]. [1] https://www.kernel.org/doc/html/v6.9/networking/af_xdp.html https://www.kernel.org/doc/html/v6.9/networking/af_xdp.html
- globular-toast 2y agoHow does this compare to a packet socket?
- naitgacem 2y agoI've done a similar thing with the exact same microcontroller! However it was on the "Black pill" board. It was really fun and surprisingly helped me get ahead in the networking class I'm taking.
- varispeed 2y agoHow quickly can you get from tinkering with Ethernet on Arduino to e.g. creating 10Gbit router with FPGA? I don't want to sound bad, but it's a bit like writing BASIC programs on C64 today? Fun, entertaining, but is it actually useful for developing skills in this domain?
- dailykoder 2y ago>Fun, entertaining, but is it actually useful for developing skills in this domain? Yes. Yes, always. You always learn, no matter what you do. Why build an 8-Bit CPU if you we have very complex 64 bit ones nowadays? Because the fundamentals are mostly the same.
- mrguyorama 2y agoAt a minimum, 4 years in college. The things required to do the 10gbit router are things you will never run into, learn, or be challenged by bit banging SPI with an existing Ethernet peripheral. Pretty much by definition, the engineering required for "high performance" anything is completely divorced from the knowledge required to implement basic systems.
- kev009 2y agoIf there is ambition to work at high speeds and feeds I would jump straight to FPGA and bypass anything like this WIZnet ASIC which simultaneously does too much and too little to be relevant to that pursuit (but it is great if you have the exact use case of wanting to add Ethernet to an existing MCU). Doing Ethernet at the logic design level is a lot of hard work but it isn't exactly a mystery at this point unless you are working on next generation speeds and feeds. A book on digital design, a book on HDL of choice, and a willingness to read specifications (IEEE 802, SFP MSA) and datasheets (FPGA MAC, third party PHY chips) is what you need to be successful. NetFPGA collates a lot of teaching materials and example code for this but the major FPGA vendors also have relevant works. Ignore any suggestions that you need formal education in the space, it's simply not true.
- immibis 2y agoThe physical layer is different. The data transferred across it is exactly the same.
- technothrasher 2y agoBack in the late 90's, when there was very little hand holding, I build a little web server board using an 8051. It was fun to learn the internals of a TCP/IP stack and magical when it served its first web page. Dang was it slow though!
- chasd00 2y agoAchtually, I think you meant Ethernet frame. pushes glasses up
- adamc 2y agoAs an exercise in self-learning, I thought this was wonderful.
- globular-toast 2y agoI really like digging into the "magic" like this. If anyone interested I have a notebook that goes from here to being able to send pings across the internet (which actually are packets): https://github.com/georgek/notebooks/blob/master/internet.ipynb https://github.com/georgek/notebooks/blob/master/internet.ip... I was going to implement TCP, but got bored (it suddenly becomes way more difficult)... It's just so amazing to me to behold the entire network stack and the fact it actually works (even if IPv4 is clinging on at this stage).
- dare944 2y agoI'm baffled as to why the author is using STM32F401 with a W5100 Ethernet shield when they could just as easily use an STM32F407 board, which includes a built-in Ethernet MAC, coupled with a cheap (2 for ~$12) Ethernet PHY board. Lots of example Ethernet projects available and just as easy to develop for as the STM32F401. Also, > Due to the complexity of the signalling involved with ethernet, a dedicated ASIC is generally used In the context of microcontrollers, I think this is generally not true. In most cases Ethernet functionality is incorporated as a embedded peripheral within the microcontroller itself, as it is with the STM32F407 and the ESP32 (both of which happen to use the same Ethernet peripheral sourced from an external provider).
- znpy 2y agofor some people the fun is just in learning, not necessarily doing the state of the art things.
- dare944 2y agoTotally get and applaud that. Indeed, I built a high-performance Ethernet driver for the STM32F4 chips just because I wanted to say I've done it. But his stated goal is to build a TCP/IP stack, not futz around with SPI and the particulars of an idiosyncratic network chip. There will be plenty of work (and learning) to do once he starts climbing up the network stack.
- deleted 2y ago[deleted]
- alsetmusic 2y ago> for some people the fun is just in learning, not necessarily doing the state of the art things. Over a decade ago, when I was just learning Linux, I set out on a quest to turn a CentOS box into a router that could perform NAT between two different networks. I spent an entire weekend researching and following every suggestion I could find until it finally worked. I was so proud when my pings reached their respective destinations. I took it apart the next day and never did anything more with it, but the journey and the reward was the fun of it.
- mastax 2y agoI was recently bringing up a custom board with a W6100 chip and it’s funny how closely my experience paralleled this one. I also had (a different) issue with SPI communication (the W6100 uses a little different protocol). I still couldn’t get any Ethernet packets to send/receive with a real machine, so I did basically the same debugging step: bought an off the shelf W6100 dev board and planned to use their arduino library to compare against. That’s where I left that project.
- albert_e 2y agois there already a "networking from scratch" type of content somewhere -- not focussed on implementing it in hardware -- but maybe a tool for interactively playing with bits, bytes, packets, frames, etc to simulate each layer of the stack and see how 2 or more devices on a network including switches and routers might communicate with each other
- enjoytheview 2y agoThis guys youtube channel (low byte productions) is an absolute gem if you like low level stuff.
- dare944 2y agoIncidentally, once the author gets his Ethernet interface work he could use this to test it: https://github.com/jaylogue/tiny-echo-server https://github.com/jaylogue/tiny-echo-server
- deleted 2y ago[deleted]
- jakemoroni 2y agoNice. I like those Ethernet chips. These days, you can find MCUs with built-in Ethernet hardware, but I still enjoy working with simple AVRs, so the w5500 (basically an upgraded w5100) is my go-to. I wrote a little framework (bootloader, utilities, etc.) to allow for updating firmware and tunneling stdout on AVRs over pure Ethernet. https://github.com/jakemoroni/Micro-Protocol-SDK https://github.com/jakemoroni/Micro-Protocol-SDK
- Liftyee 2y agoInteresting to see the Law of Leaky Abstractions at work: https://www.joelonsoftware.com/2002/11/11/the-law-of-leaky-abstractions/ https://www.joelonsoftware.com/2002/11/11/the-law-of-leaky-a... I admire this kind of low-level, first principles exploration which I personally don't do enough of.
- votick 2y agoI'll plug my own attempt at doing this a few years ago, https://www.youtube.com/watch?v=H8w0eFXaXjI https://www.youtube.com/watch?v=H8w0eFXaXjI The moment I received my first packet on a cut-up wired headset I used as a transceiver makeshift tenceiver it felt like something clicked and I just began to understand more how the universe works. I recommend projects of this type and wish more folks did it.
- stonethrowaway 2y ago> Due to the complexity of the signalling involved with ethernet, a dedicated ASIC is generally used, which takes in data at the frame level, and takes care of wiggling the electrical lines in the right way over a cable (though there are of course exceptions). Like others in this thread I was hoping I’d see an RJ45 breakout board directly hooked into an STM32 and doing onerous bit banging and keeping it as low level and basic as possible.
- fstokesman 2y agoAuthor here. CNLohr already did it better than I could 10+ years ago: https://www.youtube.com/watch?v=mwcvElQS-hM https://www.youtube.com/watch?v=mwcvElQS-hM
- banku_brougham 2y agoA short story in the data analysis space, a place where clever and underpaid people are discouraged from materializing logic into tables. It took me a while to realize the data consumers (those who need to look at and understand data) didnt have any orchestration tools, except a creaky UI cron type of scheduler. For my work I refused to compromise and spend all my days clicking in a UI, so I searched around for a good tool, decided on Prefect. It served me well, but I didn't realize going in that Prefect/Airflow/Argo etc are really orchestration engines and you still need to write the client software around it to serve your own (or the team) productivity. For example, connections to sources, methods to extract from source with a sql file, where to put the data after, injecting into publication channels, etc. I all gradually ended up writing functions to support this for my own personal IC work. I sank a ton of time into learning, had to learn how to develop python packages (I chose poetry), on an on. And yet despite all that time spent grinding away on indirectly productive learning I have still been more productive than my peers. It was a mystery so I spent time learning about my peer workflows, which people are so cagey about at my company. Anyway, everybody just crams 100s of lines of business logic into Tableau custom sql sources to avoid scrutiny of data artifacts like tables they might create on the data lake. I guess these are tableau flavored views, but its so hard to read and understand all this logic in the UI -- oh and the calculated fields also. I guess to sum up, if I am keeping up with peers using the latest expensive enterprise 'data storytelling' service while I self educate on basically data engineering to stats presentation plots, spark, julia, python, etc. I think I have concluded that Tableau should be considered harmful.
- mofosyne 2y agoYou may want to also consider ENC28J60 'Stand-Alone Ethernet Controller with SPI Interface' which lacks a hardware TCP/IP stack and is purely an Ethernet MAC and PHY accessible over SPI. This simplicity means it should be easier for you to get started with sending an ethernet packet. But of course if you want TCP/IP you will need to supply your own software implementation instead.
- brokenmachine 2y agoThis is great, I love reading these low-level debugging war stories.
- arnau_cruz 2y ago.
- arnau_cruz 2y ago..
- Bizex_LLC 2y ago[dead]