Firmware is the term given to software that runs from non-volatile memory (NVM) on a piece of hardware. It is the “permanent” program stored in the ROM of any device that contains a processor, like your TV’s remote control, your digital camera, your Wi-Fi router, and even modern light bulbs (the programmable LED ones). It is considered non-volatile because the program survives power-down states without requiring any sort of supplemental battery power.
Historically, a device’s firmware is set during manufacturing and never changed. Though, since re-writable flash memory has become inexpensive and widely deployed in the place of ROM memory, updating a device’s firmware is something that consumers are now able to perform on their own, and has even become a regular activity for certain types of hardware. The ability to update firmware has arguably extended the life of many devices that would have otherwise been deemed useless due to bugs or security issues with the original firmware installed at the factory.
The ESP8266-12 module contains 4 MB of SPI NOR Flash Memory (other modules also contain SPI flash, just maybe not 4 MB worth). This means that under that metal can on the module, AI-Thinker has permanently connected a flash memory chip to the ESP8266EX chip using six of its data lines, and program instructions are executed right from the NVM. It also means that we can overwrite whatever is on that Flash Memory with our own programs!
A Brief History of ESP8266 Firmware
The ESP8266EX is a fairly new chip. It was introduced in the summer of 2014, and almost all of the sparse documentation that did exist was in Chinese, so the platform was initially not well understood.
The first ESP8266 modules were sold as Serial-to-Wi-Fi adapters, intended as an inexpensive way to provide Wi-Fi connectivity to otherwise unconnected platforms, like the Arduino. The default factory firmware on these modules is known as the “AT Command Set Firmware”. This enables a separate microcontroller to access Wi-Fi functionality over a serial data connection, transforming the ESP8266 module into a Wi-Fi modem of sorts. Instructions are sent to the firmware using “AT Commands”, which derive from the Hayes modem commands from the days of BBS and dial-up internet.
For example, an Arduino device could tell the ESP8266 module to connect to an access point with SSID “YOURSSID” and password “helloworld” using the command:
TCP/IP connections are opened, and data is sent/received in a similar fashion using other AT commands. The ESP8266 does all of the hard work and buffering, freeing up the separate processor from any of the networking concerns.
At the end of the summer in 2014, Expressif released an actual SDK, shortly followed by a pre-configured virtual machine image that could be used to compile source code without the need to install a full toolchain. The SDK contained pre-compiled libraries of code (without source) and C header files, allowing people to build their own firmware for the ESP8266. Having the ability to create custom firmware meant that the ESP8266 could act as its own stand-alone processor to power devices!
There have been many version releases of the SDK since the fall of 2014, and Expressif now maintains two different SDKs: one known as the “Non-OS SDK” that is based on a callback architecture, and one known as the “RTOS SDK” based on FreeRTOS.
For the longest time (relatively speaking, since the first SDK was released a little over a year ago at the time of this writing), the stable version of the SDK that was widely used was the Non-OS SDK 0.96. However, just recently people have started switching over to the Non-OS 1.4 SDK in earnest due to its bug fixes, stability, and memory optimizations. UPDATE: SDK 1.5 was just announced.
The most current SDK versions as of the time of this writing are:
- Non-OS SDK 1.5 released on November 27, 2015
- RTOS SDK 1.3.0 released on November 2, 2015
Using a toolchain in conjunction with the SDK allows for a firmware image to be written using C. When flashed to the NVM of the ESP8266 module, the program will start executing once the device is powered on, and can do just about anything that you need your Thing to do, such as:
- Sample data from weather sensors and POST to a web service running in the cloud
- Connect to a MQTT broker and await instructions to do something using GPIO
- Serve as an access point with a captive portal to collect information from people using their mobile phone and a web browser
- and more!
The combination of an inexpensive and useful hardware platform, the ability to create custom firmware, and an improvement in the documentation published by Espressif (including English tech docs) permitted many grassroots efforts to create general-purpose firmware images. These firmware images would expose SDK functionality to a language service, and then allow scripts to be provided by a developer in order to automate the Thing using their favorite language. What is important to note about this concept is that the script developer does not need to compile a custom firmware or even know C in order to write programs for the ESP8266.
A sample of ESP8266 firmware projects includes:
- NodeMCU, which uses the Lua language
- MicroPython, which uses the Python language
- ESP8266Basic, which uses the BASIC language
- Arduino support for the ESP8266
With so many options to choose from, which one should you use to get started with? My recommendation would be to take a day to explore any and all of them, because you will find that some projects are further along in features and memory optimization (an important factor for microcontroller-based platforms) than others.
In the next post, I’ll introduce my personal preference: the NodeMCU firmware. This shares its name with the open source hardware project for the NodeMCU Development Kit, but the firmware works on any ESP8266 device (i.e., it is the default firmware that ships with the Adafruit Huzzah).
Later, I will outline steps for setting up the build environment needed to create a custom version of the NodeMCU firmware.
Latest posts by Falafel Posts (see all)
- Matching Complex Query String Rewrite Rule in IIS - March 22, 2017
- Disable Content Filters in Sitefinity - March 8, 2017
- On Sitefinity Custom Widget Caching - February 22, 2017
- Dynamic Content Detail Widget Templates in Sitefinity - February 8, 2017
- Using Google Services in UWP C# Apps – Part 2 - February 7, 2017