* precache() - preload code into the flash cache. By preloading code into the flash cache we can take control over when SPI Flash reads will occur when code is executing. This can be useful where the timing of a section of code is extremely critical and we don't want random pauses to pull code in from the SPI flash chip. It can also be useful for code that accesses/uses SPI0 which is connected to the flash chip. Non interrupt handler code that is infrequently called but might otherwise require being in valuable IRAM - such as bit-banging I/O code or some code run at bootup can avoid being permanently in IRAM. Macros are provided to make precaching one or more blocks of code in any function easy. * Fix missing include * Make precache extern "C" * Attempt 2 at making precache extern "C" * Fix calculation of number of cache lines to preload With certain alignments/lengths of code it was possible to not read enough into the flash cache. This commit makes the length calculation clearer and adds an extra cache line to ensure we precache enough code. * SPI0Command - A utility function for generic SPI commands on SPI0 The rom code does not support some flash functions, or have a generic way of sending custom commands to the flash chip. In particular XMC flash chips have a third status register, and the ROM only supports two. There are also certain requirements for using SPI0 such as waiting for the flash to be idle and not allowing your code to trigger a flash cache miss while using SPI0. * Clean some trailing spaces * Upgrade _SPI0Command to _SPICommand We needed to assess the SPI registers as base+offset to avoid referring to the registers using constant addresses as these addresses were loaded from flash and had the potential to trigger a flash cache miss. For similar reasons functions need to be called via function pointers stored in RAM. Also avoid constants in FLASH, use a copy stored in RAM. As a side effect we can now select which controller to access as a parameter. * Tidy up a comment thats no longer applicable * Comments, formatting and variable renames Added a number of comments to better explain the code and improved the formatting. Also renamed some variables for consistency. * put SPI0Command in namespace experimental * Add a comment noting that the code has only been tested on bus 0 * Replace use of memcpy with for loops in _SPICommand() memcpy is not guaranteed to be safe (IRAM_ATTR or ROM) like I thought. As a bonus the for loop is guaranteed to do 32-bit wide transfers, unlike memcpy. * Typo fix what happens when you forget to edit after copy/paste * Move the SpiOpResult enum into experimental namespace
Arduino core for ESP8266 WiFi chip
Quick links
Arduino on ESP8266
This project brings support for the ESP8266 chip to the Arduino environment. It lets you write sketches, using familiar Arduino functions and libraries, and run them directly on ESP8266, with no external microcontroller required.
ESP8266 Arduino core comes with libraries to communicate over WiFi using TCP and UDP, set up HTTP, mDNS, SSDP, and DNS servers, do OTA updates, use a file system in flash memory, and work with SD cards, servos, SPI and I2C peripherals.
Contents
- Installing options:
- Documentation
- Issues and support
- Contributing
- License and credits
Installing with Boards Manager
Starting with 1.6.4, Arduino allows installation of third-party platform packages using Boards Manager. We have packages available for Windows, Mac OS, and Linux (32 and 64 bit).
- Install the current upstream Arduino IDE at the 1.8.7 level or later. The current version is on the Arduino website.
- Start Arduino and open the Preferences window.
- Enter
https://arduino.esp8266.com/stable/package_esp8266com_index.json
into the Additional Board Manager URLs field. You can add multiple URLs, separating them with commas. - Open Boards Manager from Tools > Board menu and install esp8266 platform (and don't forget to select your ESP8266 board from Tools > Board menu after installation).
Latest release 
Boards manager link: https://arduino.esp8266.com/stable/package_esp8266com_index.json
Documentation: https://arduino-esp8266.readthedocs.io/en/2.5.2/
Using git version
Also known as latest git or master branch.
- Install the current upstream Arduino IDE at the 1.8 level or later. The current version is on the Arduino website.
- Follow the instructions in the documentation.
Using PlatformIO
PlatformIO is an open source ecosystem for IoT development with a cross-platform build system, a library manager, and full support for Espressif (ESP8266) development. It works on the following popular host operating systems: macOS, Windows, Linux 32/64, and Linux ARM (like Raspberry Pi, BeagleBone, CubieBoard).
- What is PlatformIO?
- PlatformIO IDE
- PlatformIO Core (command line tool)
- Advanced usage - custom settings, uploading to SPIFFS, Over-the-Air (OTA), staging version
- Integration with Cloud and Standalone IDEs - Cloud9, Codeanywhere, Eclipse Che (Codenvy), Atom, CLion, Eclipse, Emacs, NetBeans, Qt Creator, Sublime Text, VIM, Visual Studio, and VSCode
- Project Examples
Building with make
makeEspArduino is a generic makefile for any ESP8266 Arduino project. Using make instead of the Arduino IDE makes it easier to do automated and production builds.
Documentation
Documentation for latest development version: https://arduino-esp8266.readthedocs.io/en/latest/
Issues and support
ESP8266 Community Forum is a well-established community for questions and answers about Arduino for ESP8266. If you need help, have a "How do I..." type question, have a problem with a 3rd party library not hosted in this repo, or just want to discuss how to approach a problem, please ask there.
If you find the forum useful, please consider supporting it with a donation.
If you encounter an issue which you think is a bug in the ESP8266 Arduino Core or the associated libraries, or if you want to propose an enhancement, you are welcome to submit it here on Github: https://github.com/esp8266/Arduino/issues.
Please provide as much context as possible, as well as the information requested in the issue template:
- ESP8266 Arduino core version which you are using (you can check it in Boards Manager)
- your sketch code; please wrap it into a code block, see Github markdown manual
- when encountering an issue that happens at run time, attach the serial output. Wrap it into a code block, just like the code.
- for issues that happen at compile time, enable verbose compiler output in the IDE preferences, and attach that output (also inside a code block)
- ESP8266 development board model
- IDE settings (board choice, flash size)
- etc
Contributing
For minor fixes of code and documentation, please go ahead and submit a pull request. A gentle introduction to the process can be found here.
Check out the list of issues that are easy to fix — easy issues pending. Working on them is a great way to move the project forward.
Larger changes (rewriting parts of existing code from scratch, adding new functions to the core, adding new libraries) should generally be discussed by opening an issue first.
Feature branches with lots of small commits (especially titled "oops", "fix typo", "forgot to add file", etc.) should be squashed before opening a pull request. At the same time, please refrain from putting multiple unrelated changes into a single pull request.
License and credits
Arduino IDE is developed and maintained by the Arduino team. The IDE is licensed under GPL.
ESP8266 core includes an xtensa gcc toolchain, which is also under GPL.
Esptool written by Christian Klippel is licensed under GPLv2, currently maintained by Ivan Grokhotkov: https://github.com/igrr/esptool-ck.
Espressif SDK included in this build is under Espressif MIT License.
ESP8266 core files are licensed under LGPL.
SPI Flash File System (SPIFFS) written by Peter Andersson is used in this project. It is distributed under the MIT license.
umm_malloc memory management library written by Ralph Hempel is used in this project. It is distributed under the MIT license.
SoftwareSerial library and examples written by Peter Lerup. Distributed under LGPL 2.1.
axTLS library written by Cameron Rich, built from https://github.com/igrr/axtls-8266, is used in this project. It is distributed under BSD license.
BearSSL library written by Thomas Pornin, built from https://github.com/earlephilhower/bearssl-esp8266, is used in this project. It is distributed under the MIT License.
LittleFS library written by ARM Limited and released under the BSD 3-clause license.