Compiling Cicero’s esp-enc28J60 Package on Linux

Just a couple of hints on compiling Cicero’s ethernet package under BSD/Linux.

ENC28J60 + ESP8266-12
Wirewrapped ENC to ESP Connections

Updated:- Scroll down to the bottom for more details on the hardware connections.

First, the default settings in the GitHub repository source are for a Windows configuration, so if you’re a Windows user, just go ahead and type (or whatever it is you folks do) “make” and you should be all set.  For those of us using BSD’s or Linux, there are a couple of extra steps before we get there.

 

The top-level Makefile

In the main Makefile in the esp_end28j60 directory, we need to update the paths to the Xtensa toolchain to match your machine.

At around line 15, at the top of the Makefile, locate the line starting “XTENSA_TOOLS_ROOT ?= ” and change the path to suit your specific installation.  As an example, my modified line looks like this:-

XTENSA_TOOLS_ROOT ?= /opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin

Next, just a couple of lines down, locate the line starting “SDK_BASE ?= ” and change that one to match the location of your SDK (which must be at least 1.5.0, by the way).  As an example, my modified line looks like this:-

SDK_BASE ?= /opt/Espressif/esp_iot_sdk_v1.5.1

Next, again just a couple of lines down, look for these two lines and update them, too:-

ESPTOOL ?= $(SDK_TOOLS)/esptool.exe
ESPPORT ?= COM3

Again, the new lines will reflect your specific filesystem layout.  As an example, my ESPTOOL and ESPPORT settings look like this:-

ESPTOOL ?= /opt/Espressif/esptool-py/esptool.py
ESPPORT ?= /dev/ttyUSB0

The first part is now complete, so save your updated Makefile, but don’t type “make” just yet.

 

The libesphttpd Makefile

There’s another Makefile hidden in the libesphttpd sub-directory, so cd ./libesphttpd and update the XTENSA_TOOLS_ROOT and SDK_BASE lines to match the ones you did in the top-level directory two minutes ago (there are no ESPTOOL or ESPPORT settings in this one, though).

Okay, save that updated Makefile too.  Just one more file change to make…

 

The mkespfsimage Makefile

Change directory into a sub-directory of the current, libesphttpd, directory:-

cd ./espfs/mkespfsimage

We don’t have to edit any files here, as there’s already a Linux variant of the makefile available (it’ just that the Window’s variant is the default), so…

mv Makefile Makefile_ORIG

cp Makefile.linux Makefile

 

The PATH setting

There’s just one more thing we need to do. One of the things which esptool does is to try and run the command xtensa-lx106-elf-readelf in order to figure out the structure of the elf binary before loading it to the ESP8266. Because there’s no universal standard for the xtensa toolchain installation, we need to tell esptool where to find the binary on your specific machine. Luckily, this is very easy (no editing involved). Just add exactly the same path which you used to update the Makefile XTENSA_TOOLS_ROOT entry to your own PATH environment before running make. Again, in my particular case the command to do this would look like this:-

PATH=${PATH}:/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin

(everything after the colon should be specific to your own installation).

Now we’re ready to build. Type make and you should see some fairly normal looking compiler messages and then after a couple of minutes you’ll end up with brand, shiny, new binaries in the firmware directory.

 

The second make

Okay, I admit it, I forgot this (and then sat there wondering why the ENC was obviously working, but only returned 404, “Not Found” errors).

Once you’ve done that initial make, you also need to load the firmware into the ESP.  That’s just a simple make flash, which I would guess most people are familiar with.  However, this application uses libesphttpd, which provides a nice little web server application (+ kittens).  You must load the (compressed) html files into the ESP flash at a different location from the application code, so once your initial make flash is finished, go ahead and do this extra step using:-

make htmlflash

…it only takes a few seconds and your user experience will be all the better for it.  🙂

 

Troubleshooting

If you see messages along the lines of:-

c:/Espressif/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc not found

…you’ve missed one of the Makefile updates (note the Windows “c:” drive selector at the beginning of the message).  Go back and verify your edits again.

If you see the following error:-
make[2]: Entering directory `/home/gaijin/ESP8266/esp_enc28j60/libesphttpd/espfs/mkespfsimage'
make -C mman-win32
make[3]: Entering directory `/home/gaijin/ESP8266/esp_enc28j60/libesphttpd/espfs/mkespfsimage/mman-win32'
gcc -o mman.o -c mman.c -Wall -O3 -fomit-frame-pointer
mman.c:2:21: fatal error: windows.h: No such file or directory
compilation terminated.

…you haven’t managed to change the mkespfsimage directory Makefile from the default Windows version to the Linux version.  Go back to that directory and try that part again.

If you see the message:-

Error calling xtensa-lx106-elf-readelf, do you have Xtensa toolchain in PATH?
make: *** [build/httpd.out] Error 1

…you failed to add the Xtensa toolchain bin directory to your PATH.  Check it with:-

echo ${PATH}

and verify that the path to the bin directory exists and is correct.

 

Note on the hardware shown above

As you can probably see from the photograph in the intro, this project was slapped together fairly quickly using one of the AI Thinker “Yellow” development boards.  There are absolutely no hardware changes to the board at all.  All of the LEDs are still in place (including the big, RGB one) and the board is still being run from the 3-cell battery pack.

The connections to the ENC module were made using a manual wire-wrap tool with 8, equal-length pieces of single-core wire-wrap wire (and kept short, not just for signal integrity, but because wire-wrap wire is getting expensive nowadays!).  It took all of about twenty minutes to put everything together (and most of that time was taken up with me trying to thread the dang wire-wrap tool).  Anyway, the beastie worked first time and now flashes LEDs all over the shop when initializing and handling a connection.  The pins on those board connectors aren’t nearly as sturdy as proper wire-wrap pins, but the technique still works well (even better for someone with steadier hands and younger eyes — see the trivia note, below) and is definitely sturdier than a plastic prototyping board with push-in cables.

And for those of you who are as colour-blind as I am, here are the pin names for the interconnects:-


ESP8266-ESP12                            ENC28J60

    3v3      <---->    VCC
    GND      <---->    GND
    GPIO15   <---->    CS
    GPIO5    <---->    RST (Reset)
    GPIO13   <---->    SI
    GPIO14   <---->    SCK
    GPIO12   <---->    SO
    GPIO4    <---->    INT


 

Note that the ENC module I got doesn’t have any mounting holes, BTW.  You have to pay extra for the holes (so check the photos carefully before you order).

Trivia note – My first wire-wrap tool was part of the tool-kit given to all techies working for a very large, U.S. computer corporation …specifically for maintenance of disk drives (the backplanes were manually wire-wrapped at the factory).