ESP32 As Your Raspberry Pi’s Linux Wi-fi Co-processor

A laptop computer with no wi-fi connectivity looks like a rarity – however whenever you store for highly effective Linux single-board computer systems (SBCs), it’s fairly widespread to see one skimp on WiFi. At the identical time, present wi-fi playing cards can go away a lot to be desired. A multitude of proprietary firmware, ephemeral and even binary blob drivers, bizarre glitches by no means resolved, and generally solely source-less blobs with an expiration date. Maybe the SBC doesn’t have a free USB port for a plug-and-play WiFi chip, otherwise you don’t need to design for an obscure hard-to-source castellated module.
What if I informed you there’s a novel answer to the issue, so long as the SBC has an SDIO or SPI to spare? There’s a wi-fi card we will all attempt to get behind, and it’s definitely not flawless however offers us far more room to develop – it’s acquired considerably open-source firmware, it comes from a good firm, and it’s nigh-guaranteed to be simple to supply. I’m, in fact, speaking about esp-hosted – utilizing ESP32 modules as your WiFi/BT card, over SDIO or SPI.
I’ve not too long ago added an ESP32-C6 into my mission, and organising esp-hosted wasn’t extremely simple – so right here’s a information, and a dialogue on what makes esp-hosted so cool and so extremely promising. Spoilers: it really works with privateness switches that reduce out energy, it may very well be hacked right into a coprocessor for mesh protocols, and it might probably assist us construct a completely open-source SDIO WiFi card.
Two Halves, Most Chips Supported
A fast clarification is warranted, as there are two tasks under the esp-hosted roof. There’s the esp-hosted-mcu (beforehand referred to as esp-hosted-fg, “First Generation”), which runs the ESP32 as extra of an MCU related to WiFi and gives a comparatively restricted however self-sufficient interface on the Linux aspect; your connection features are largely managed by the ESP32 module, so it’s going to connect with your outlined WiFi networks irrespective of in case your host is rebooting and even totally off. As such, esp-hosted-mcu works greatest on microcontrollers, or in instances the place you need your ESP32 to be a completely aware separate entity, so to say. Want to make your ESP32 into an EC in your board, full with WiFi connectivity? Then go together with the -mcu model.
esp-hosted-linux (beforehand referred to as esp-hosted-ng, “New Generation”) leaves the wi-fi stack on the Linux aspect, with the ESP32 being a comparatively skinny proxy for the Linux wi-fi stack. I’ll speak about esp-hosted-linux right here as a result of it behaves in essentially the most “native” approach that common WiFi playing cards do below Linux, however a whole lot of this text will apply to esp-hosted-mcu too.
esp-hosted requires two to tango: a Linux pc with an SDIO or SPI port to spare, and an ESP32 chip/module out of supported ones, I opted for ESP32-C6. The generic ESP32-WROOM modules are greater than sufficient, however many of the shiny new chips are supported as nicely. Specifically, ESP32-S2, -S3, -C2, -C3, -C5, and -C6/C61 can all work with the esp-hosted-linux, and in the event you’re taking part in with one thing just like the -S31, verify the issue tracker of the parent project. I run the C6 as a result of I believed it was the chip with the most important quantity of supported options, and it’s marginally costlier than any of the opposite ones, so why wouldn’t I? However! That was a mistake, and if I had been to design a brand new board, I’d go together with the ESP32-C5. Turns out, regardless of the C quantity being decrease, ESP32-C5 is straight up higher than the ESP32-C6, sporting 5GHz help particularly.
From there, you’ll need to wire it up over SDIO or SPI – I like to recommend SDIO if out there, as a result of it’s approach speedier. One factor – ensure that your SBC’s SDIO interface is supported by the OS, and never within the limbo state of “the {hardware} is prepared, somebody simply must make the driving force work”, until you might be that anyone. If you have already got a devboard, you’ll be able to bodge in an SD card onto your supposedly-SDIO pins to confirm that your SDIO interface truly features!
SDIO is basically a full-duplex parallel bus with one management sign (CMD), one clock (CLK), and 4 knowledge strains (D0-D3) – or only one knowledge line, D0, in the event you feeling ascetic. These strains wiggle quick, and so they’re not diffpairs, so that you’ll need to lay them out with respect as single-ended wires. I’ll be writing up a bigger SDIO article, however till then, do consult with one of many quite a few SDIO structure tutorials on-line. Here’s a reference schematic:
A brief SDIO structure advice: be sure there’s a steady floor return path beneath, length-match between indicators to the very best of your capability (inside 1 mm?), and general maintain the SDIO hyperlink as brief as you probably can. When wiring up SDIO coming from the 40-pin header on a Pi Zero or a full-sized Pi, some indicators will want a whole lot of length-matching and a few will want none in any respect – that’s regular, such is the Raspberry Pi GPIO pinout, simply keep in mind to match them. Include each sequence resistors and pullup resistors, as requested by the ESP-Hosted documentation.
Apart from the SDIO indicators, you’ll need management over EN, so the driving force can reset the ESP32 right into a known-good state earlier than beginning communications. For that matter, you can too wire up EN to a basic RC circuit used for OLED shows, in the event you’re brief on GPIOs and don’t thoughts – the driving force desires EN provided, but it surely doesn’t require-require it, you’ll be able to simply present resetpin=-1 to the driving force init script in the event you care for EN switching by yourself.

You don’t want to fret in regards to the BOOT pin. You do want to verify there’s ample 3.3 V energy out there, although: 300 mA to 400mA. The 3.3 V energy rail on Raspberry Pi boards will usually be greater than sufficient for powering your ESP32, however on different SBCs, you would possibly find yourself including an additional 3.3 V regulator to satiate the ESP32’s 3.3 V urge for food. Last however not least, expose the ESP32 USB port by some means, since you’ll want it for flashing the firmware. Thankfully, the firmware flashing solely must be achieved as soon as. Personally, I put it on a 4-pin JST-SH with a QWIIC-like pinout, as you’ll be able to see on the schematic above.
Build Firmware, Or Don’t
There are three things you need to do. Make positive your SBC’s SDIO (or SPI) interface is freed up, compile and flash your ESP32 firmware, then compile and cargo the driving force. Not essentially on this order, in fact, however you want all three.
Freeing up the SDIO interface is comparatively simple on Raspberry Pi: it’s a quick config.txt job. You solely must remap the SDIO pins, and if there’s an present WiFi card, additionally disable its Bluetooth. The “Bluetooth disable” half is probably going required as a result of the onboard WiFi card’s firmware is uploaded over SDIO, so the Bluetooth a part of the cardboard wouldn’t perform, anyway. It additionally frees up the UART console port on the Pi, which might be extremely useful if you have to debug your WiFi interface bringup! By the best way, I’ve my doubts that the poll_once=off SDIO overlay parameter is required, and it does appear to spam up dmesg. If you ever must eliminate that spam, eradicating that ballot possibility could be a superb begin.
On different SBCs, you would possibly wrestle with SDIO, however so long as it isn’t too obscure, it shouldn’t be too huge of an issue. If you’re rolling your personal SBC, and in case you have a devboard, be happy to wire up a microSD socket to the SDIO pins, add pullups as required, and debug your SDIO interface bringup utilizing a spare microSD card. If a microSD card works, then in all probability, the ESP32 will work too.
ESP32 firmware compilation can also be comparatively simple. Maybe you don’t need to compile the ESP32 firmware in your SBC, since it’d run out of RAM and lock up whereas executing cmake. On a Pi Zero, the lockup is principally assured. Simply use your desktop pc to compile the firmware and keep away from the effort. Alternatively, you’ll be able to skip all of that and download a firmware from the Releases tab on Github. Those are presently saved within the legacy repo, however I’m assuming ultimately new releases can be put into the esp-hosted-linux repository, so look out.
Make positive that your driver is constructed from the identical esp-hosted git repository model as your ESP32 firmware, utilizing git log or the wish to verify the final commit. Otherwise, the driving force will throw a warning and refuse to load, you’ll be able to patch out that warning in the event you assume the distinction is just too minor, however that’s at your personal threat.
Drivers Done In Old-Fashioned Way
Now, the driving force, you’ll need to compile the driving force on the SBC itself, until you cross-compile. The rpi_init.sh script compiles and hundreds the driving force, and it additionally accommodates some notes you would possibly discover useful. If you might have an SBC with 512 MB of RAM or much less – open the rpi_init.sh within the editor, find the make -j8 command, and exchange it with make -j2 (and even -j1). Otherwise, your compilation course of will run out of RAM and lock up your SBC.
Do you might have the whole lot related by now? If you might have SDIO correctly configured and firmware has been flashed, the driving force will simply load efficiently and a wlan interface will seem. Problems with that? Check dmesg to see the debug output of the driving force module. I get pleasure from working dmesg -Hw in a spare terminal window, or simply within the background.
Now, the rpi_init.sh script is a good device for debugging, but it surely’s a device you’ll need to shed when working the module longer-term, largely as a result of it recompiles the module each time it’s run. In the identical listing, you’ll discover esp_sdio.ko – that’s the Linux module you simply compiled. Do this:
sudo cp esp_sdio.ko /lib/modules/uname -r/kernel/drivers>/code>sudo depmod -a
It could also be a hack, however at the very least now, you’ll be able to modprobe esp_sdio, as an alternative of insmod from the script listing. You can then additionally put the module title (esp_sdio) into /and so on/modules to have it auto-load on each boot, which is approach higher than re-running the script and the related recompile.
Workable And Very Promising

There are some issues to be desired, in fact. The module needs to be correctly built-in into system tree interfaces, for one, in order that it doesn’t must be added into /and so on/modules and might as an alternative be auto-loaded by an overlay. It additionally ought to get a dkms integration, in the identical approach the esp8089 driver was distributed. Currently, it’s a must to recompile it and re-add the module into the kernel modules listing after each kernel improve, and dkms would reduce that proper out. Throughput is alright, you will get 40 Mbps to 50 Mbps at default SDIO frequency. If you assume your {hardware} is sweet sufficient and might push SDIO limits additional, there’s some dials and knobs you’ll be able to tweak!
Cool Trick, But Why?
So why speak about this? There are 4 causes that I discover vital. First, that is the one WiFi card I do know that may move Bluetooth by way of over SDIO as an alternative of tying up a UART port, which is particularly useful for Pi Zero form-factor boards. That alone is fairly cool.
Second, whereas the code is imperfect and there’s a heap of pull requests one ought to check out, esp-hosted does deal with {hardware} energy switches in my mission! There aren’t any kernel module crashes or failures because the ESP32 loses energy, it disconnects and reconnects seamlessly, the {hardware} swap simply works, and I discover that endearing.
The subsequent two causes are each about this being an primarily open-firmware WiFi card. The ESP32 firmware isn’t totally open, because the RF bits are historically closed-source and get compiled in as blobs, however there have been some mighty projects attempting to liberate the proprietary bits of the ESP32 WiFi stack. As an increasing number of individuals get a stab at it, it’s solely attainable we might flip the omnipresent ESP32 modules into totally open-source firmware Linux WiFi playing cards, extremely low-cost and considerable anyplace, too. Truly hacker-friendly WiFi playing cards that final, what’s to not love?
The closing cause is essentially the most enjoyable of all, and doesn’t even want the de-proprietarization. After SDIO wireup, the ESP32 is left with many free pins, together with ones with high-speed SPI. Who’s to say that we will’t wire up a LoRa modem to it and run Meshtastic/Meshcore/and so on.? Since the firmware is usually open, in principle, any code may very well be added throughout the WiFi/BT gaps, any significant knowledge then forwarded to the Linux host. It additionally doesn’t escape my eye that new ESP32 chips help Zigbee and Thread natively, and exposing that to Linux is barely a matter of code, too. To me, that’s the very best half, pondering that sooner or later we might flip the ESP32 into a real Swiss military knife communications co-processor for any Linux-running CPU.

