ESP8266 cmake Arduino IDE and Arduino-CMake-Toolchain

Why build using CMAKE

One major advantage of using cmake to build ESP8266 projects comes in the test cycle. The out-of-source tree builds, allow things like google-test to be used on small parts of logic within your own host and not on the target. This facilitates debugging and makes regression testing readily achievable.

CMAKE toolchain

Building firmware for the Arduino using the Arduino IDE/CLI with cmake is straightforward using the Arduino-CMake-Toolchain. The recent fork of the Arduino-CMake-Toolchain which allows ESP8266 to work is here Arduino-CMake-Toolchain .

Motivation

I am writing this to help provide the simple workarounds required to build projects on the ESP8266 using the libraries downloadable from the Arduino Boards Manager.

The Project

This project is aimed at demonstrating the WifiManager on an ESP8266 target.
This project was tested on a cheap $2 ESP-01S board which had an ESP9266EX chip and 1 MB of flash.

  • It is built using cmake under the Arduino-CMake-Toolchain.
  • The WifiManager is a wrapper class, which connects the existing WiFi object to a hub or configures it to act as a server.
    The Wifi object can then be used normally.
    Once configured, the WiFi object will be autoconnected on next reboot.

Things that needed to be in the CMakeLists.txt

Needed build.opt workaround in CMakeLists.txt

file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/core)
file(TOUCH ${CMAKE_BINARY_DIR}/core/build.opt)

Notes on Testing

After flashing with the ESP Link board - disconnect USB and reconnect.
On Linux to read the serial port (assuming the Serial channel is ttyUSB0):

stty -F /dev/ttyUSB0 115200 && cat /dev/ttyUSB0

Installation Notes:

The toolchain was installed in ~/lib.
The generated and modified BoardOptions was copied to ../.. from the esp8266 build dir.

BoardOptions:

The file generated on the first cmake pass (which throws an error) was then modified by:
just the following 'set' being uncommented.

#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# Arduino boards.
# Platform: esp8266
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
set(ARDUINO_BOARD "Generic ESP8266 Module [esp8266.generic]") # Generic ESP8266 Module

It was then copied, so the following could be used: -D ARDUINO_BOARD_OPTIONS_FILE=../../esp8266BoardOptions.cmake.

The full CMakeLists.txt is

CMakeLists.txt (936 Bytes)

The example sketch is

wifiMgr.cpp (1.6 KB)

Versions

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.