1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/cpu/esp8266/doc.txt

985 lines
46 KiB
Plaintext
Raw Normal View History

2018-09-05 02:39:50 +02:00
/**
2018-10-06 12:02:13 +02:00
@defgroup cpu_esp8266 ESP8266 / ESP8285
2018-09-05 02:39:50 +02:00
@ingroup cpu
@brief RIOT-OS port for Espressif's ESP8266 / ESP8285 MCUs
\section esp8266_riot RIOT-OS on ESP8266 and ESP8285 boards
## <a name="esp8266_toc"> Table of Contents </a>
1. [Overview](#esp8266_overview)
2. [Short Configuration Reference](#esp8266_short_configuration_reference)
3. [MCU ESP8266](#esp8266_mcu_esp8266)
1. [Features of ESP8266](#esp8266_features)
2. [Features Supported by RIOT-OS](#esp8266_supported_features)
4. [Toolchain](#esp8266_toolchain)
2018-09-05 02:39:50 +02:00
1. [RIOT Docker Toolchain (riotdocker)](#esp8266_riot_docker_toolchain)
2. [Precompiled Toolchain](#esp8266_precompiled_toolchain)
3. [Manual Toolchain Installation](#esp8266_manual_toolchain_installation)
5. [Flashing the Device](#esp8266_flashing_the_device)
2018-09-05 02:39:50 +02:00
1. [Toolchain Usage](#esp8266_toolchain_usage)
2. [Compile Options](#esp8266_compile_options)
3. [Flash Modes](#esp8266_flash_modes)
2018-10-06 12:02:13 +02:00
4. [Erasing the Device](#esp8266_erasing)
6. [Peripherals](#esp8266_peripherals)
2018-09-05 02:39:50 +02:00
1. [GPIO pins](#esp8266_gpio_pins)
2. [ADC Channels](#esp8266_adc_channels)
3. [PWM Channels](#esp8266_pwm_channels)
2018-09-05 02:39:50 +02:00
4. [I2C Interfaces](#esp8266_i2c_interfaces)
5. [SPI Interfaces](#esp8266_spi_interfaces)
2018-09-05 02:39:50 +02:00
6. [Timers](#esp8266_timers)
7. [SPIFFS Device](#esp8266_spiffs_device)
8. [Other Peripherals](#esp8266_other_peripherals)
7. [Network Interfaces](#esp8266_network_interfaces)
2019-01-16 20:54:53 +01:00
1. [WiFi Network Interface](#esp8266_wifi_network_interface)
2. [ESP-NOW Network Interface](#esp8266_esp_now_network_interface)
8. [Preconfigured Devices](#esp8266_preconfigured_devices)
2018-09-05 02:39:50 +02:00
1. [Network Devices](#esp8266_network_devices)
2. [SD-Card Device](#esp8266_sd_card_device)
9. [Application-Specific Configurations](#esp8266_application_specific_configurations)
2018-09-05 02:39:50 +02:00
1. [Application-Specific Board Configuration](#esp8266_application_specific_board_configuration)
2. [Application-Specific Driver Configuration](#esp8266_application_specific_driver_configuration)
10. [SDK Task Handling](#esp8266_sdk_task_handling)
11. [QEMU Mode and GDB](#esp8266_qemu_mode_and_gdb)
2018-09-05 02:39:50 +02:00
2018-09-05 02:39:50 +02:00
# <a name="esp8266_overview"> Overview </a> &nbsp;&nbsp; [[TOC](#esp8266_toc)]
There are two implementations that can be used:
- the **SDK version** which is realized on top of an SDK (*esp-open-sdk* or
*ESP8266_NONOS_SDK*) and
2018-09-05 02:39:50 +02:00
- the **non-SDK version** which is realized without the SDK.
The non-SDK version produces a much smaller code size than the SDK version and
is more efficient in execution because it does not need to run additional SDK
functions to keep the SDK system alive.
2018-09-05 02:39:50 +02:00
The **non-SDK version** is probably the **best choice if you do not need the
built-in WiFi module**, for example, when you plan to connect an IEEE 802.15.4
radio module to the MCU for communication.
2018-09-05 02:39:50 +02:00
By **default**, the **non-SDK version** is compiled. To compile the SDK
version, enable module `esp_wifi`, for example, at the make command line:
2018-09-05 02:39:50 +02:00
```
USEMODULE=esp_sdk make flash BOARD=esp8266-esp-12x -C tests/shell ...
2018-09-05 02:39:50 +02:00
```
The SDK version is compiled automatically if one of the modules `esp_wifi`,
`esp_now` or `esp_sw_timers` is enabled.
For more information about the make command variables, see section
[Compile Options](#esp8266_compile_options).
2018-09-05 02:39:50 +02:00
# <a name="esp8266_short_configuration_reference"> Short Configuration Reference </a> &nbsp;[[TOC](#esp8266_toc)]
The following table gives a short reference of all board configuration parameters used by the ESP8266 port in alphabetical order.
<center>
Parameter | Short Description | Type*
----------|----------------------------------------|------
[I2C0_SPEED](#esp8266_i2c_interfaces)| Bus speed of I2C_DEV(0) | o
[I2C0_SCL](#esp8266_i2c_interfaces) | GPIO used as SCL for I2C_DEV(0) | o
[I2C0_SDA](#esp8266_i2c_interfaces) | GPIO used as SCL for I2C_DEV(0 | o
[PWM0_GPIOS](#esp8266_pwm_channels) | GPIOs that can be used at channels of PWM_DEV(0) | o
[SPI0_CS0](#esp8266_spi_interfaces) | GPIO used as default CS for SPI_DEV(0) | o
</center>
<b>Type:</b> m - mandatory, o - optional# <a name=esp8266_mcu_esp8266> MCU ESP8266 </a> &nbsp;[[TOC](#esp8266_toc)]
The following table gives a short reference in alphabetical order of modules that can be enabled/disabled by board configurations and/or application's makefile using `USEMODULE` and `DISABLE_MODULE`.
<center>
Module | Default | Short description
----------|----------|-------------------
[esp_gdb](#esp8266_qemu_mode_and_gdb) | not used | Enable the compilation with debug information for debugging.
[esp_now](#esp8266_esp_now_network_interface) | not used | Enable the ESP-NOW network device, implies the module `esp_sdk`.
[esp_sdk](#esp8266_sdk_task_handling) | not used | Enable the SDK version.
[esp_spiffs](#esp8266_spiffs_device) | not used | Enable the SPIFFS drive in on-board flash memory.
[esp_sw_timer](#esp8266_timers) | not used | Enable software timer implementation, implies the module `esp_sdk`.
[esp_wifi](#esp8266_wifi_network_interface) | not used | Enable the built-in WiFi module as `netdev` network device, implies the module `esp_sdk`.
</center>
2018-09-05 02:39:50 +02:00
ESP8266 is a low-cost, ultra-low-power, single-core SoCs with an integrated WiFi module from Espressif Systems. The processor core is based on the Tensilica Xtensa Diamond Standard 106Micro 32-bit Controller Processor Core, which Espressif calls L106. The key features of ESP8266 are:
## <a name=esp8266_features> Features of ESP8266 </a> &nbsp;[[TOC](#esp8266_toc)]
The key features of ESP8266 are:
2018-09-05 02:39:50 +02:00
<center>
MCU | ESP8266EX
------------|----------------------------
Vendor | Espressif
Cores | 1 x Tensilica Xtensa LX106
FPU | no
RAM | 80 kByte user-data RAM <br> 32 kByte instruction RAM <br> 32 kByte instruction cache <br/> 16 kByte EST system-data RAM
Flash | 512 kByte ... 16 MByte
Frequency | 80 MHz or 160 MHz
Power Consumption | 70 mA in normal operating mode <br> 20 uA in deep sleep mode
Timers | 1 x 32 bit
ADCs | 1 x 10 bit (1 channel)
GPIOs | 16
I2Cs | 2 (software implementation)
SPIs | 2
UARTs | 1 (console) + 1 transmit-only
WiFi | IEEE 802.11 b/g/n built in
Vcc | 2.5 - 3.6 V
Datasheet | [Datasheet](https://www.espressif.com/sites/default/files/documentation/0a-esp8266ex_datasheet_en.pdf)
Technical Reference | [Technical Reference](https://www.espressif.com/sites/default/files/documentation/esp8266-technical_reference_en.pdf)
</center><br>
@note ESP8285 is simply an ESP8266 SoC with 1 MB built-in flash. Therefore, the documentation also applies to the SoC ESP8285, even if only the ESP8266 SoC is described below.
## <a name="esp8266_supported_features"> Features Supported by RIOT-OS </a> &nbsp;[[TOC](#esp8266_toc)]
The RIOT-OS for ESP8266 SoCs supports the following features at the moment:
- I2C interfaces
- SPI interfaces
- UART interfaces
- CPU ID access
- ADC channel
- PWM channels
- SPI Flash Drive (MTD with SPIFFS and VFS)
- Hardware number generator
- Hardware timer devices
- ESP-NOW netdev interface
2018-09-05 02:39:50 +02:00
# <a name="esp8266_toolchain"> Toolchain</a> &nbsp;[[TOC](#esp8266_toc)]
To compile RIOT for The ESP8266 SoC, the following software components are required:
- **esp-open-sdk** which includes the **Xtensa GCC** compiler toolchain, the hardware abstraction library **libhal** for Xtensa LX106, and the flash programmer tool <b>`esptool.py`</b>
2018-09-05 02:39:50 +02:00
- **newlib-c** library for Xtensa (esp-open-rtos version)
- **SDK (optional)**, either as part of <b>`esp-open-sdk`</b> or the <b>`ESP8266_NONOS_SDK`</b>
2018-09-05 02:39:50 +02:00
You have the following options to install the Toolchain:
- <b>`riotdocker`</b> image and <b>`esptool.py`</b>, see section [RIOT Docker Toolchain (riotdocker)](#esp8266_riot_docker_toolchain)
2018-09-05 02:39:50 +02:00
- **precompiled toolchain** installation from GIT, see section [Precompiled Toolchain](#esp8266_toolchain_installation)
- **manual installation**, see section [Manual Toolchain Installation](#esp8266_manual_toolchain_installation)
## <a name="esp8266_riot_docker_toolchain"> RIOT Docker Toolchain (riotdocker) </a> &nbsp;[[TOC](#esp8266_toc)]
2018-12-23 18:28:08 +01:00
The easiest way to use the toolchain is Docker.
2018-09-05 02:39:50 +02:00
### <a name="esp8266_preparing_the_environment"> Preparing the Environment </a> &nbsp;[[TOC](#esp8266_toc)]
Using RIOT Docker requires at least the following software:
- <b>`Docker`</b> container virtualization software
- RIOT Docker (<b>`riotdocker`</b>) image
- flasher tool <b>`esptool.py`</b>
2018-09-05 02:39:50 +02:00
For information about installing Docker on your host, refer to the appropriate manuals for your operating system. For example, the easiest way to install Docker on the Ubuntu/Debian system is:
```
sudo apt-get install docker.io
```
The ESP Flasher tool <b>`esptool.py`</b> is available at [GitHub](https://github.com/espressif/esptool). To install the tool, either Python 2.7 or Python 3.4 or later must be installed. The latest stable version of `esptool.py` can be installed with `pip`:
2018-09-05 02:39:50 +02:00
```
pip install esptool
```
<b>`esptool.py`</b> depends on `pySerial` which can be installed either using `pip`
2018-09-05 02:39:50 +02:00
```
pip install pyserial
```
or the package manager of your OS, for example on Debian/Ubuntu systems:
```
apt-get install pyserial
```
For more information on `esptool.py`, please refer the [git repository](https://github.com/espressif/esptool)
2018-09-05 02:39:50 +02:00
Please make sure that `esptool.py` is in your `PATH` variable.
2018-09-05 02:39:50 +02:00
### <a name="esp8266_generating_docker_image"> Generating a riotdocker Image </a> &nbsp;[[TOC](#esp8266_toc)]
A `riotdocker` fork that only installs the `RIOT-Xtensa-ESP8266-toolchain` is available at [GitHub](https://github.com/gschorcht/riotdocker-Xtensa-ESP.git). After cloning this git repository, you can use branch `esp8266_only` to generate a Docker image with a size of "only" 990 MByte:
2018-09-05 02:39:50 +02:00
```
git clone https://github.com/gschorcht/riotdocker-Xtensa-ESP.git
cd riotdocker-Xtensa-ESP
git checkout esp8266_only
docker build -t riotbuild .
```
A `riotdocker` version that contains the toolchains for all different RIOT platforms can be found at [GitHub](https://github.com/RIOT-OS/riotdocker). However, the Docker image generated from the this Docker file has a size of about 1.5 GByte.
2018-09-05 02:39:50 +02:00
Once a Docker image has been created, it can be started with the following commands while in the RIOT root directory:
```
cd /path/to/RIOT
docker run -i -t --privileged -v /dev:/dev -u $UID -v $(pwd):/data/riotbuild riotbuild
```
@note RIOT's root directory `/path/to/RIOT` becomes visible as the home directory of the `riotbuild` user in the Docker image. That is, the output of compilations performed in RIOT Docker is also accessible on the host system.
2018-09-05 02:39:50 +02:00
Please refer the [RIOT wiki](https://github.com/RIOT-OS/RIOT/wiki/Use-Docker-to-build-RIOT) on how to use the Docker image to compile RIOT OS.
### <a name="esp8266_using_existing_docker_image"> Using an Existing riotdocker Image </a> &nbsp;[[TOC](#esp8266_toc)]
Alternatively, an existing Docker image from Docker Hub can be used. You can either pull and start the [schorcht/riotbuild_esp8266](https://hub.docker.com/r/schorcht/riotbuild_esp8266) Docker image which only contains the `RIOT-Xtensa-ESP8266-toolchain` using
2018-09-05 02:39:50 +02:00
```
cd /path/to/RIOT
docker run -i -t --privileged -v /dev:/dev -u $UID -v $(pwd):/data/riotbuild schorcht/riotbuild_esp8266
```
or the [riot/riotbuild](https://hub.docker.com/r/riot/riotbuild/) Docker image (size is about 1.5 GB) which contains the toolchains for all platforms using
```
cd /path/to/RIOT
docker run -i -t --privileged -v /dev:/dev -u $UID -v $(pwd):/data/riotbuild riot/riotbuild
```
### <a name="esp8266_flashing_using_docker"> Make Process with Docker Image </a> &nbsp;[[TOC](#esp8266_toc)]
Using Docker, the make process consists of the following two steps:
1. **making** the RIOT binary **within a RIOT Docker image**
2. **flashing** the RIOT binary using a flasher program **on the host system**
Once the RIOT Docker image has been started from RIOT's root directory, a RIOT application can be compiled inside the Docker using the make command as usual, for example:
```
make BOARD=esp8266-esp-12x -C tests/shell ...
```
This will generate a RIOT binary in ELF format.
@note You can't use the `flash` target inside the Docker image.
2018-09-05 02:39:50 +02:00
The RIOT binary has to be flash outside docker on the host system. Since the Docker image was stared while in RIOT's root directory, the output of the compilations is also accessible on the host system. On the host system, the `flash-only` target can then be used to flash the binary.
2018-09-05 02:39:50 +02:00
```
make flash-only BOARD=esp8266-esp-12x -C tests/shell
```
## <a name="esp8266_precompiled_toolchain"> Precompiled Toolchain </a> &nbsp;[[TOC](#esp8266_toc)]
You can get a precompiled version of the whole toolchain from the GIT repository [RIOT-Xtensa-ESP8266-toolchain](https://github.com/gschorcht/RIOT-Xtensa-ESP8266-toolchain). This repository contains the precompiled toolchain including all libraries that are necessary to compile RIOT-OS for ESP8266.
@note To use the precompiled toolchain the following packages (Debian/Ubuntu) have to be installed:<br> `cppcheck` `coccinelle` `curl` `doxygen` `git` `graphviz` `make` `pcregrep` `python` `python-serial` `python3` `python3-flake8` `unzip` `wget`
2018-09-05 02:39:50 +02:00
To install the toolchain use the following commands:
```
cd /opt
sudo git clone https://github.com/gschorcht/RIOT-Xtensa-ESP8266-toolchain.git esp
```
After the installation, all components of the toolchain are installed in directory `/opt/esp`. Of course, you can use any other location for the installation.
2018-09-05 02:39:50 +02:00
To use the toolchain, you have to add the path of the binaries to your `PATH` variable according to your toolchain location
2018-09-05 02:39:50 +02:00
```
export PATH=$PATH:/path/to/toolchain/esp-open-sdk/xtensa-lx106-elf/bin
```
where `/path/to/toolchain/` is the directory you selected for the installation of the toolchain. For the default installation in `/opt/esp` this would be:
2018-09-05 02:39:50 +02:00
```
export PATH=$PATH:/opt/esp/esp-open-sdk/xtensa-lx106-elf/bin
```
Furthermore, you have to set variables `ESP8266_SDK_DIR` and `ESP8266_NEWLIB_DIR` according to the location of the toolchain.
2018-09-05 02:39:50 +02:00
```
export ESP8266_SDK_DIR=/path/to/toolchain/esp-open-sdk/sdk
export ESP8266_NEWLIB_DIR=/path/to/toolchain/newlib-xtensa
```
If you have used `/opt/esp` as installation directory, it is not necessary to set these variables since makefiles use them as default directories.
2018-09-05 02:39:50 +02:00
## <a name="esp8266_manual_toolchain_installation"> Manual Toolchain Installation </a> &nbsp;[[TOC](#esp8266_toc)]
The most difficult way to install the toolchain is the manual installation of required components as described below.
@note Manual toolchain installation requires that the following packages (Debian/Ubuntu) are installed: `autoconf` `automake` `bash` `bison` `build-essential` `bzip2` `coccinelle` `cppcheck` `curl` `doxygen` `g++` `gperf` `gawk` `gcc` `git` `graphviz` `help2man` `flex` `libexpat-dev` `libtool` `libtool-bin` `make` `ncurses-dev` `pcregrep` `python` `python-dev` `python-serial` `python3` `python3-flake8` `sed` `texinfo` `unrar-free` `unzip wget`
2018-09-05 02:39:50 +02:00
### <a name="esp8266_installation_of_esp_open_sdk"> Installation of esp-open-sdk </a> &nbsp;[[TOC](#esp8266_toc)]
esp-open-sdk is directly installed inside its source directory. Therefore, change directly to the target directory of the toolchain to build it.
```
cd /path/to/esp
git clone --recursive https://github.com/pfalcon/esp-open-sdk.git
cd esp-open-sdk
export ESP_OPEN_SDK_DIR=$PWD
```
If you plan to use the SDK version of the RIOT port and to use the SDK as part of esp-open-sdk, simply build its standalone version.
```
make STANDALONE=y
```
If you only plan to use the non-SDK version of the RIOT port or if you want to use one of Espressif's original SDKs, it is enough to build the toolchain.
```
make toolchain esptool libhal STANDALONE=n
```
Once compilation has been finished, the toolchain is available in `$PWD/xtensa-lx106-elf/bin`. To use it, set the `PATH` variable accordingly.
2018-09-05 02:39:50 +02:00
```
export PATH=$ESP_OPEN_SDK_DIR/xtensa-lx106-elf/bin:$PATH
```
If you have compiled the standalone version of esp-open-sdk and you plan to use this SDK version, set additionally the `ESP8266_SDK_DIR` variable.
2018-09-05 02:39:50 +02:00
```
export ESP8266_SDK_DIR=$ESP_OPEN_SDK_DIR/sdk
```
### <a name="esp8266_installation_of_newlib-c"> Installation of newlib-c </a> &nbsp;[[TOC](#esp8266_toc)]
First, set the target directory for the installation.
```
export ESP8266_NEWLIB_DIR=/path/to/esp/newlib-xtensa
```
Please take care, to use the newlib-c version that was modified for esp-open-rtos since it includes `stdatomic.h`.
2018-09-05 02:39:50 +02:00
```
cd /my/source/dir
git clone https://github.com/ourairquality/newlib.git
```
Once you have cloned the GIT repository, build and install it with following commands.
```
cd newlib
./configure --prefix=$ESP8266_NEWLIB_DIR --with-newlib --enable-multilib --disable-newlib-io-c99-formats --enable-newlib-supplied-syscalls --enable-target-optspace --program-transform-name="s&^&xtensa-lx106-elf-&" --disable-option-checking --with-target-subdir=xtensa-lx106-elf --target=xtensa-lx106-elf --enable-newlib-nano-formatted-io --enable-newlib-reent-small
make
make install
```
### <a name="esp8266_installation_of_espressif_original_sdk"> Installation of Espressif original SDK (optional) </a> &nbsp;[[TOC](#esp8266_toc)]
If you plan to use the SDK version of the RIOT port and if you want to use one of Espressif's original SDKs, you have to install it.
First, download the _ESP8266_NONOS_SDK_ version 2.1.0 from the [Espressif web site](https://github.com/espressif/ESP8266_NONOS_SDK/releases/tag/v2.1.0). Probably other version might also work. However, RIOT port is tested with version 2.1.0.
Once you have downloaded it, you can install it with following commands.
```
cd /path/to/esp
tar xvfz /downloads/ESP8266_NONOS_SDK-2.1.0.tar.gz
```
To use the installed SDK, set variable `ESP8266_SDK_DIR` accordingly.
2018-09-05 02:39:50 +02:00
```
export ESP8266_SDK_DIR=/path/to/esp/ESP8266_NONOS_SDK-2.1.0
```
# <a name="esp8266_flashing_the_device"> Flashing the Device </a> &nbsp;[[TOC](#esp8266_toc)]
## <a name="esp8266_toolchain_usage"> Toolchain Usage </a> &nbsp;[[TOC](#esp8266_toc)]
Once you have installed all required components, you should have the following directories.
```
/path/to/esp/esp-open-sdk
/path/to/esp/newlib-xtensa
/path/to/esp/ESP8266_NONOS_SDK-2.1.0 (optional)
```
To use the toolchain and optionally the SDK, please check that your environment variables are set correctly to
```
export PATH=/path/to/esp/esp-open-sdk/xtensa-lx106-elf/bin:$PATH
export ESP8266_NEWLIB_DIR=/path/to/esp/newlib-xtensa
```
and
```
export ESP8266_SDK_DIR=/path/to/esp/esp-open-sdk/sdk
```
or
```
export ESP8266_SDK_DIR=/path/to/esp/ESP8266_NONOS_SDK-2.1.0
```
## <a name="esp8266_compile_options"> Compile Options </a> &nbsp;[[TOC](#esp8266_toc)]
The compilation process can be controlled by a number of variables for the make command:
<center>
Option | Values | Default | Description
-------|--------|---------|------------
ENABLE_GDB | 0, 1 | 0 | Enable compilation with debug information for debugging with QEMU (`QEMU=1`), see section [QEMU Mode and GDB](#esp8266_qemu_mode_and_gdb)
2018-09-05 02:39:50 +02:00
FLASH_MODE | dout, dio, qout, qio | dout | Set the flash mode, please take care with your module, see section [Flash Modes](#esp8266_flash_modes)
2018-12-23 18:28:08 +01:00
PORT | /dev/ttyUSBx | /dev/* | Set the USB port for flashing the firmware
2018-09-05 02:39:50 +02:00
QEMU | 0, 1 | 0 | Generate an image for QEMU, see section [QEMU Mode and GDB](#esp8266_qemu_mode_and_gdb).
USE_SDK | 0, 1 | 0 | Compile the SDK version (`USE_SDK=1`), see section [SDK Task Handling](#esp8266_sdk_task_handling)
2018-09-05 02:39:50 +02:00
</center><br>
Optional features of ESP8266 can be enabled by `USEMODULE` definitions in the makefile of the application. These are:
2018-09-05 02:39:50 +02:00
<center>
Module | Description
-------|------------
[esp_gdb](#esp8266_qemu_mode_and_gdb) | Enable the compilation with debug information, which is equivalent to using `ENABLE_GDB=1`.
[esp_now](#esp8266_esp_now_network_interface) | Enable the built-in WiFi module with the ESP-NOW protocol as `netdev` network device, implies the setting module `esp_sdk`.
[esp_sdk](#esp8266_sdk_task_handling) | Enable the SDK version, which is equivalent to using `USE_SDK=1`.
2018-12-23 18:28:08 +01:00
[esp_spiffs](#esp8266_spiffs_device) | Enable the SPIFFS drive in on-board flash memory
[esp_sw_timer](#esp8266_timers) | Enable software timer implementation, implies the setting module `esp_sdk`.
[esp_wifi](#esp8266_wifi_network_interface) | Use the built-in WiFi module as `netdev` network device, implies the setting module `esp_sdk`.
2018-09-05 02:39:50 +02:00
</center><br>
For example, to activate the SPIFFS drive in on-board flash memory, the makefile of application has simply to add the `esp_spiffs` module to `USEMODULE` make variable:
2018-12-23 18:28:08 +01:00
```
USEMODULE += esp_spiffs
```
Modules can also be activated temporarily at the command line when calling the make command:
```
USEMODULE="esp_spiffs" make BOARD=...
```
2018-09-05 02:39:50 +02:00
## <a name="esp8266_flash_modes"> Flash Modes </a> &nbsp;[[TOC](#esp8266_toc)]
The `FLASH_MODE` make command variable determines the mode that is used for flash access in normal operation.
2018-09-05 02:39:50 +02:00
The flash mode determines whether 2 data lines (`dio` and `dout`) or 4 data lines (`qio` and `qout`) for addressing and data access. For each data line, one GPIO is required. Therefore, using `qio` or `qout` increases the performance of SPI Flash data transfers, but uses two additional GPIOs (GPIO9 and GPIO10). That is, in this flash modes these GPIOs are not available for other purposes. If you can live with lower flash data transfer rates, you should always use `dio` or `dout` to keep GPIO9 and GPIO10 free for other purposes.
2018-09-05 02:39:50 +02:00
For more information about these flash modes, refer the documentation of [esptool.py](https://github.com/espressif/esptool/wiki/SPI-Flash-Modes).
@note While ESP8266 modules can be flashed with `qio`, `qout`, `dio` and `dout`, ESP8285 modules have to be always flashed in `dout` mode. The default flash mode is `dout`.
2018-09-05 02:39:50 +02:00
2018-10-06 12:02:13 +02:00
## <a name="esp8266_erasing"> Erasing the Device </a> &nbsp;[[TOC](#esp8266_toc)]
The flash memory of ESP8266 can be erased completely with following command:
```
esptool.py erase_flash
```
@note After deleting the flash, the default init data must be rewritten. In a non-SDK version, this will happen automatically when RIOT is started for the first time after flashing the image. In the SDK version, this must be done explicitly. There are two possible approaches to rewriting standard initialization data:
- Flash and start a non-SDK image before the SDK version is flashed.
- Use the esptool.py file to update the default init data as following.
```
esptool.py write_flash <address> $RIOTBASE/cpu/esp8266/bin/esp_init_data_default.bin
```
where `address` depends on ESP8266 chip version.
2018-10-06 12:02:13 +02:00
Chip version | `address` | Module examples
2018-10-06 12:02:13 +02:00
------------ | ------------- | ----------------
512 kByte | 0x07c000 | ESP-01, ESP-03, ESP-07, etc.
1 MByte | 0x0fc000 | ESP8285-based modules like Wemos D1 mini lite, PSF-A85, some ESP-01, ESP-03 etc.
2 MByte | 0x1fc000 | |
4 MByte | 0x3fc000 | ESP-12E, NodeMCU devkit 1.0, WeMos D1 mini
8 MByte | 0x7fc000 | |
16 MByte | 0xffc000 | WeMos D1 mini pro (USE 0x07c000!)
2018-09-05 02:39:50 +02:00
# <a name="esp8266_peripherals"> Peripherals </a> &nbsp;[[TOC](#esp8266_toc)]
## <a name="esp8266_gpio_pins"> GPIO pins </a> &nbsp;[[TOC](#esp8266_toc)]
ESP8266 has 17 GPIO pins, which are all digital pins. Some of them can not be used at all or have bootstrapping capabilities and are therefore not available on all boards.
<center>
Pin | Remarks
-------|--------
GPIO0 | usually pulled up
GPIO1 | UART TxD
GPIO2 | usually pulled up
GPIO3 | UART RxD
GPIO4 | |
GPIO5 | |
GPIO6 | Flash SPI
GPIO7 | Flash SPI
GPIO8 | Flash SPI
GPIO9 | Flash SPI in `qout` and `qio` mode, see section [Flash Modes](#esp8266_flash_modes)
GPIO10 | Flash SPI in `qout` and `qio` mode, see section [Flash Modes](#esp8266_flash_modes)
2018-09-05 02:39:50 +02:00
GPIO11 | Flash SPI
GPIO12 | |
GPIO13 | |
GPIO14 | |
GPIO15 | usually pulled down
GPIO16 | RTC pin and wake up signal in deep sleep mode
</center>
GPIO0, GPIO2, and GPIO15 are bootstrapping pins which are used to boot ESP8266 in different modes:
<center>
GPIO0 | GPIO2 | GPIO15 (MTDO) | Mode
:----:|:-----:|:-------------:|:------------------
1 | X | X | boot in SDIO mode to start OCD
0 | 0 | 1 | boot in UART mode for flashing the firmware
0 | 1 | 1 | boot in FLASH mode to boot the firmware from flash (default mode)
</center>
## <a name="esp8266_adc_channels"> ADC Channels </a> &nbsp;[[TOC](#esp8266_toc)]
ESP8266 has **one dedicated ADC** pin with a resolution of 10 bits. This ADC pin can measure voltages in the range of **0 V ... 1.1 V**.
@note Some boards have voltage dividers to scale this range to a maximum of 3.3 V. For more information, see the hardware manual for the board.
## <a name="esp8266_pwm_channels"> PWM Channels </a> &nbsp;[[TOC](#esp8266_toc)]
2018-09-05 02:39:50 +02:00
The hardware implementation of ESP8266 PWM supports only frequencies as power of two. Therefore, a **software implementation** of **one PWM device** (`PWM_DEV(0)`) with up to **8 PWM channels** (`PWM_CHANNEL_NUM_MAX`) is used.
2018-09-05 02:39:50 +02:00
@note The minimum PWM period that can be realized with this software implementation is 10 us or 100.000 PWM clock cycles per second. Therefore, the product of frequency and resolution should not be greater than 100.000. Otherwise the frequency is scaled down automatically.
2018-09-05 02:39:50 +02:00
GPIOs that can be used as channels of the PWM device `PWM_DEV(0)` are defined by `PWM0_CHANNEL_GPIOS`. By default, GPIOs 2, 4 and 5 are defined as PWM channels. As long as these channels are not started with function `pwm_set`, they can be used as normal GPIOs for other purposes.
2018-09-05 02:39:50 +02:00
GPIOs in `PWM0_CHANNEL_GPIOS` with a duty cycle value of 0 can be used as normal GPIOs for other purposes. GPIOs in `PWM0_CHANNEL_GPIOS` that are used for other purposes, e.g., I2C or SPI, are no longer available as PWM channels.
2018-09-05 02:39:50 +02:00
To define other GPIOs as PWM channels, just overwrite the definition of `PWM_CHANNEL_GPIOS` in an [application-specific board configuration](#esp8266_application_specific_board_configuration)
2018-09-05 02:39:50 +02:00
```
#define PWM0_CHANNEL_GPIOS { GPIO12, GPIO13, GPIO14, GPIO15 }
```
2018-09-05 02:39:50 +02:00
## <a name="esp8266_i2c_interfaces"> I2C Interfaces </a> &nbsp;[[TOC](#esp8266_toc)]
2018-09-05 02:39:50 +02:00
Since the ESP8266 does not or only partially support the I2C in hardware, I2C interfaces are realized as **bit-banging protocol in software**. The maximum usable bus speed is `I2C_SPEED_FAST_PLUS`. The maximum number of buses that can be defined is 2, `I2C_DEV(0)` ... `I2C_DEV(1)`.
2018-09-05 02:39:50 +02:00
The board-specific configuration of the I2C interface <b>`I2C_DEV(n)`</b> requires the definition of
2018-09-05 02:39:50 +02:00
- <b>`I2Cn_SPEED`</b>, the bus speed,
- <b>`I2Cn_SCL`</b>, the GPIO used as SCL signal, and
- <b>`I2Cn_SDA`</b>, the GPIO used as SDA signal,
2018-09-05 02:39:50 +02:00
where `n` can be 0 or 1. If they are not defined, the I2C interface `I2C_DEV(n)` is not used.
2018-09-05 02:39:50 +02:00
In the following example, only one I2C bus is defined:
```
#define I2C_NUMOF (1)
#define I2C0_SPEED I2C_SPEED_FAST
#define I2C0_SDA GPIO4
#define I2C0_SCL GPIO5
```
A configuration with two I2C buses would look like the following:
```
#define I2C_NUMOF (2)
#define I2C0_SPEED I2C_SPEED_FAST
#define I2C0_SDA GPIO4
#define I2C0_SCL GPIO5
#define I2C1_SPEED I2C_SPEED_NORMAL
#define I2C1_SDA GPIO2
#define I2C1_SCL GPIO14
```
All these configurations can be overridden by an [application-specific board configuration](#esp8266_application_specific_board_configuration).
## <a name="esp8266_spi_interfaces"> SPI Interfaces </a> &nbsp;[[TOC](#esp8266_toc)]
2018-09-05 02:39:50 +02:00
ESP8266 provides two hardware SPI interfaces:
2018-09-05 02:39:50 +02:00
- _FSPI_ for flash memory access that is usually simply referred to as _SPI_
- _HSPI_ for peripherals
2018-09-05 02:39:50 +02:00
Even though _FSPI_ (or simply _SPI_) is a normal SPI interface, it is not possible to use it for peripherals. **HSPI is therefore the only usable SPI interface** available for peripherals as RIOT's `SPI_DEV(0)`.
2018-09-05 02:39:50 +02:00
The pin configuration of the _HSPI_ interface is defined as shown in the following table. Only the CS signal can be configured and overridden by [application-specific card configuration] (# esp8266_application_specific_board_configuration).
2018-09-05 02:39:50 +02:00
<center>
Signal of _HSPI_ | Pin
-----------------|-------
MISO | GPIO12
MOSI | GPIO13
SCK | GPIO14
CS | GPIO15
</center>
2018-09-05 02:39:50 +02:00
When SPI is enabled using module `periph_spi`, these GPIOs cannot be used for any other purpose. The given CS pin is used when `spi_acquire` is called with `cs=GPIO_UNDEF` parameter.
To the default CS can be overridden as following:
2018-09-05 02:39:50 +02:00
```
#define SPI0_CS0_GPIO GPIO15 /* HSPI/SPI_DEV(0) CS default pin */
2018-09-05 02:39:50 +02:00
```
GPIOs 0, 2, 4, 5, 15, and 16 can be used as CS signal. In `dio` and `dout` flash modes (see section [Flash Modes](#esp8266_flash_modes)), GPIOs 9 and 10 can also be used as CS signal.
2018-09-05 02:39:50 +02:00
## <a name="esp8266_timers"> Timers </a> &nbsp;[[TOC](#esp8266_toc)]
There are two timer implementations:
- **hardware timer** implementation with **1 timer device** and only **1 channel**, the default
- **software timer** implementation with **1 timer device** and only **10 channels**
By default, the **hardware timer implementation** is used.
When the SDK version of the RIOT port (`USE_SDK=1`) is used, the **software timer** implementation is activated by using module `esp_sw_timer`.
2018-09-05 02:39:50 +02:00
The software timer uses SDK's software timers to implement the timer channels. Although these SDK timers usually have a precision of a few microseconds, they can deviate up to 500 microseconds. So if you need a timer with high accuracy, you'll need to use the hardware timer with only one timer channel.
@note When module `esp_sw_timer` is used, the SDK version is automatically compiled (`USE_SDK=1`).
2018-09-05 02:39:50 +02:00
## <a name="esp8266_spiffs_device"> SPIFFS Device </a> &nbsp;[[TOC](#esp8266_toc)]
If SPIFFS module is enabled (`USEMODULE += esp_spiffs`), the implemented MTD system drive `mtd0` for the on-board SPI flash memory is used together with modules `spiffs` and `vfs` to realize a persistent file system.
2018-09-05 02:39:50 +02:00
For this purpose, the flash memory is formatted as SPIFFS starting at the address `0x80000` (512 kByte) on first boot. All sectors up to the last 5 sectors of the flash memory are then used for the file system. With a fixed sector size of 4096 bytes, the top address of the SPIFF is `flash_size - 5 * 4096`, e.g., `0xfb000` for a flash memory of 1 MByte. The size of the SPIFF then results from:
2018-09-05 02:39:50 +02:00
```
flash_size - 5 * 4096 - 512 kByte
```
Please refer file `$RIOTBASE/tests/unittests/test-spiffs/tests-spiffs.c` for more information on how to use SPIFFS and VFS together with a MTD device `mtd0` alias `MTD_0`.
2018-09-05 02:39:50 +02:00
## <a name="esp8266_other_peripherals"> Other Peripherals </a> &nbsp;[[TOC](#esp8266_toc)]
The ESP8266 port of RIOT also supports
- one hardware number generator with 32 bit,
- one UART interface (GPIO1 and GPIO3),
- a CPU-ID function, and
- power management functions.
RTC is not yet implemented.
2019-01-16 20:54:53 +01:00
# <a name="esp8266_network_interfaces"> Network Interfaces </a> &nbsp;[[TOC](#esp8266_toc)]
ESP8266 provides different built-in possibilities to realize network devices:
- <b>ESP WiFi</b>, usual AP-based infrastructure mode wireless LAN
2019-01-16 20:54:53 +01:00
- <b>ESP-NOW</b>, a WiFi based AP-less and connectionless peer to peer communication protocol
\anchor esp8266_wifi_network_interface
## <a name="esp8266_wifi_network_interface"> WiFi Network Interface </a> &nbsp;[[TOC](#esp8266_toc)]
The RIOT port for ESP8266 implements in module `esp_wifi` a `netdev` driver for
the built-in WiFi interface.
@note Due to symbol conflicts with the `crypto` and `hash` modules of RIOT
in vendor library `libwpa.so`, which is required by module
`esp_wifi`, `esp_wifi` cannot be used for applications that use these modules.
Therefore, module **`esp_wifi` is not automatically enabled** when module
2019-01-16 20:54:53 +01:00
`netdev_default` is used. Instead, if necessary, the application has to add
the module `esp_wifi` in the Makefile.
```
USEMODULE += esp_wifi
```
Furthermore, the following configuration parameters have to be defined:
<center>
Parameter | Default | Description
:------------------|:--------------------------|:------------
ESP_WIFI_SSID | "RIOT_AP" | SSID of the AP to be used.
ESP_WIFI_PASS | "ThisistheRIOTporttoESP" | Passphrase used for the AP as clear text (max. 64 chars).
ESP_WIFI_STACKSIZE | 1536 | Stack size used for the WiFi netdev driver thread.
2019-01-16 20:54:53 +01:00
</center>
These configuration parameter definitions, as well as enabling the `esp_wifi`
module, can be done either in the makefile of the project or at make command
line, e.g.:
```
USEMODULE=esp_wifi \
CFLAGS='-DESP_WIFI_SSID=\"MySSID\" -DESP_WIFI_PASS=\"MyPassphrase\"' \
make -C examples/gnrc_networking BOARD=...
```
@note The Wifi network interface (module `esp_wifi`) and the
[ESP-NOW network interface](#esp8266_esp_now_network_interface)
(module `esp_now`) can be used simultaneously, for example, to realize a
border router for a mesh network which uses ESP-NOW.
\anchor esp8266_esp_now_network_interface
## <a name="esp8266_esp_now_network_interface"> ESP-NOW Network Interface </a> &nbsp;[[TOC](#esp8266_toc)]
With ESP-NOW, the ESP8266 provides a connectionless communication technology,
featuring short packet transmission. It applies the IEEE802.11 Action Vendor
frame technology, along with the IE function developed by Espressif, and CCMP
encryption technology, realizing a secure, connectionless communication solution.
The RIOT port for ESP8266 implements in module `esp_now` a `netdev` driver
which uses ESP-NOW to provide a link layer interface to a meshed network of
ESP8266 nodes. In this network, each node can send short packets with up to
250 data bytes to all other nodes that are visible in its range.
@note Due to symbol conflicts in vendor library `libwpa.so` used by the
`esp_now` with RIOT's `crypto` and `hashes` modules, ESP-NOW cannot be used
for application that use these modules. Therefore, the module **`esp_now` is
not enabled automatically** if the `netdev_default` module is used. Instead,
2019-01-16 20:54:53 +01:00
the application has to add the `esp_now` module in its makefile when needed.<br>
```
USEMODULE += esp_now
```
For ESP-NOW, ESP8266 nodes are used in WiFi SoftAP + Station mode to advertise
their SSID and become visible to other ESP8266 nodes. The SSID of an ESP8266
node is the concatenation of the prefix `RIOT_ESP_` with the MAC address of
its SoftAP WiFi interface. The driver periodically scans all visible ESP8266
nodes.
The following parameters are defined for ESP-NOW nodes. These parameters can
be overriden by [application-specific board configurations](#esp8266_application_specific_board_configuration).
<center>
Parameter | Default | Description
:---------|:--------|:-----------
ESP_NOW_SCAN_PERIOD | 10000000UL | Defines the period in us at which an node scans for other nodes in its range. The default period is 10 s.
ESP_NOW_SOFT_AP_PASS | "ThisistheRIOTporttoESP" | Defines the passphrase as clear text (max. 64 chars) that is used for the SoftAP interface of ESP-NOW nodes. It has to be same for all nodes in one network.
ESP_NOW_CHANNEL | 6 | Defines the channel that is used as the broadcast medium by all nodes together.
ESP_NOW_KEY | NULL | Defines a key that is used for encrypted communication between nodes. If it is NULL, encryption is disabled. The key has to be of type `uint8_t[16]` and has to be exactly 16 bytes long.
ESP_WIFI_STACKSIZE | @ref THREAD_STACKSIZE_DEFAULT | Stack size used for the WiFi netdev driver thread.
2019-01-16 20:54:53 +01:00
</center>
These configuration parameter definitions, as well as enabling the `esp_wifi`
module, can be done either in the makefile of the project or at make command
line, e.g.:
```
USEMODULE=esp_now \
CFLAGS='-DESP_NOW_CHANNEL=8 -DESP_NOW_SOFT_AP_PASS=\"MyPassphrase\"' \
make -C examples/gnrc_networking BOARD=...
```
2019-01-16 20:54:53 +01:00
@note The ESP-NOW network interface (module `esp_now`) and the
[Wifi network interface](#esp8266_wifi_network_interface) (module `esp_wifi`)
can be used simultaneously, for example, to realize a border router for
a mesh network which uses ESP-NOW.
2018-09-05 02:39:50 +02:00
# <a name="esp8266_preconfigured_devices"> Preconfigured Devices </a> &nbsp;[[TOC](#esp8266_toc)]
The ESP8266 port of RIOT has been tested with several common external devices that can be connected to ESP8266 boards and are preconfigured accordingly.
## <a name="esp8266_network_devices"> Network Devices </a> &nbsp;[[TOC](#esp8266_toc)]
2018-12-23 18:28:08 +01:00
RIOT provides a number of driver modules for different types of network devices, e.g., IEEE 802.15.4 radio modules and Ethernet modules. The RIOT port for ESP8266 has been tested with the following network devices:
2018-09-05 02:39:50 +02:00
2018-12-23 18:28:08 +01:00
- [mrf24j40](https://riot-os.org/api/group__drivers__mrf24j40.html) (driver for Microchip MRF24j40 based IEEE 802.15.4
- [enc28j60](https://riot-os.org/api/group__drivers__enc28j60.html) (driver for Microchip ENC28J60 based Ethernet modules)
2018-09-05 02:39:50 +02:00
### <a name="esp8266_using_mrf24j40"> Using MRF24J40 (module `mrf24j40`) </a> &nbsp;[[TOC](#esp8266_toc)]
2018-09-05 02:39:50 +02:00
To use MRF24J40 based IEEE 802.15.4 modules as network device, the `mrf24j40` driver module has to be added to the makefile of the application:
2018-09-05 02:39:50 +02:00
```
USEMODULE += mrf24j40
```
The `mrf24j40` driver module uses the following preconfigured interface parameters for ESP8266 boards:
2018-09-05 02:39:50 +02:00
<center>
Parameter | Default | Remarks
-----------------------|--------------|----------------------------
2018-12-23 18:28:08 +01:00
MRF24J40_PARAM_SPI | SPI_DEV(0) | fixed, see section [SPI Interfaces](#esp8266_spi_interfaces)
MRF24J40_PARAM_SPI_CLK | SPI_CLK_1MHZ | fixed
2018-09-05 02:39:50 +02:00
MRF24J40_PARAM_CS | GPIO16 | can be overridden
MRF24J40_PARAM_INT | GPIO0 | can be overridden
MRF24J40_PARAM_RESET | GPIO2 | can be overridden
</center><br>
2018-12-23 18:28:08 +01:00
The GPIOs in this configuration can be overridden by [application-specific board configurations](#esp8266_application_specific_board_configuration).
2018-09-05 02:39:50 +02:00
### <a name="esp8266_using_enc28j60"> Using ENC28J60 (module `enc28j60`) </a> &nbsp;[[TOC](#esp8266_toc)]
2018-09-05 02:39:50 +02:00
To use ENC28J60 Ethernet modules as network device, the `enc28j60` driver module has to be added to the makefile of the application:
2018-09-05 02:39:50 +02:00
```
USEMODULE += enc28j60
```
The `enc28j60` driver module uses the following preconfigured interface parameters for ESP8266 boards:
2018-09-05 02:39:50 +02:00
<center>
Parameter | Default | Remarks
---------------------|--------------|----------------------------
2018-12-23 18:28:08 +01:00
ENC28J60_PARAM_SPI | SPI_DEV(0) | fixed, see section [SPI Interfaces](#esp8266_spi_interfaces)
2018-09-05 02:39:50 +02:00
ENC28J60_PARAM_CS | GPIO4 | can be overridden
ENC28J60_PARAM_INT | GPIO9 | can be overridden
ENC28J60_PARAM_RESET | GPIO10 | can be overridden
</center>
2018-12-23 18:28:08 +01:00
The GPIOs in this configuration can be overridden by [application-specific board configurations](#esp8266_application_specific_board_configuration).
2018-09-05 02:39:50 +02:00
## <a name="esp8266_sd_card_device"> SD-Card Device </a> &nbsp;[[TOC](#esp8266_toc)]
ESP8266 port of RIOT is preconfigured for RIOT applications that use the [SPI SD-Card driver](https://riot-os.org/api/group__drivers__sdcard__spi.html). To use SPI SD-Card driver, the `sdcard_spi` module has to be added to a makefile:
2018-09-05 02:39:50 +02:00
```
USEMODULE += sdcard_spi
```
The `sdcard_spi` driver module uses the following preconfigured interface parameters for ESP8266 boards:
2018-09-05 02:39:50 +02:00
<center>
Parameter | Default | Remarks
-----------------------|---------------|----------------------------
SDCARD_SPI_PARAM_SPI | SPI0_DEV | fix, see section [SPI Interfaces](#esp8266_spi_interfaces)
SDCARD_SPI_PARAM_CS | SPI0_CS0_GPIO | can be overridden
</center>
2018-12-23 18:28:08 +01:00
The GPIO used as CS signal can be overridden by [application-specific board configurations](#esp8266_application_specific_board_configuration).
2018-09-05 02:39:50 +02:00
2018-12-23 18:28:08 +01:00
\anchor esp8266_app_spec_conf
2018-09-05 02:39:50 +02:00
# <a name="esp8266_application_specific_configurations"> Application-Specific Configurations </a> &nbsp;[[TOC](#esp8266_toc)]
The board-specific configuration files `board.h` and `periph_conf.h` as well as the driver parameter configuration files `<driver>_params.h` define the default configurations for peripherals and device driver modules. These are, for example, the GPIOs used, bus interfaces used or available bus speeds. Because there are many possible configurations and many different application requirements, these default configurations are usually only a compromise between different requirements.
2018-12-23 18:28:08 +01:00
Therefore, it is often necessary to change some of these default configurations for individual applications. For example, while many PWM channels are needed in one application, another application does not need PWM channels, but many ADC channels.
2018-09-05 02:39:50 +02:00
## <a name="esp8266_application_specific_board_configuration"> Application-Specific Board Configuration </a> &nbsp;[[TOC](#esp8266_toc)]
To override default board configurations, simply create an application-specific board configuration file `$APPDIR/board.h` in the source directory `$APPDIR` of the application and add the definitions to be overridden. To force the preprocessor to include board's original `board.h` after that, add the `include_next` preprocessor directive as the <b>last</b> line.
2018-09-05 02:39:50 +02:00
For example to override the default definition of the GPIOs that are used as PWM channels, the application-specific board configuration file `$APPDIR/board.h` could look like the following:
2018-09-05 02:39:50 +02:00
```
#ifdef CPU_ESP8266
#define PWM0_CHANNEL_GPIOS { GPIO12, GPIO13, GPIO14, GPIO15 }
#endif
#include_next "board.h"
```
It is important to ensure that the application-specific board configuration `$APPDIR/board.h` is included first. Insert the following line as the <b>first</b> line to the application makefile `$APPDIR/Makefile`.
2018-12-23 18:28:08 +01:00
```
INCLUDES += -I$(APPDIR)
```
@note To make such application-specific board configurations dependent on the ESP8266 MCU or a particular ESP8266 board, you should always enclose these definitions in the following constructs
2018-09-05 02:39:50 +02:00
```
#ifdef CPU_ESP8266
...
#endif
2018-12-23 18:28:08 +01:00
#ifdef BOARD_ESP8266_ESP-12X
2018-09-05 02:39:50 +02:00
...
#endif
```
## <a name="esp8266_application_specific_driver_configuration"> Application-Specific Driver Configuration </a> &nbsp;[[TOC](#esp8266_toc)]
Using the approach for overriding board configurations, the parameters of drivers that are typically defined in `drivers/<device>/include/<device>_params.h` can be overridden. For that purpose just create an application-specific driver parameter file `$APPDIR/<device>_params.h` in the source directory `$APPDIR` of the application and add the definitions to be overridden. To force the preprocessor to include driver's original `<device>_params.h` after that, add the `include_next` preprocessor directive as the <b>last</b> line.
2018-09-05 02:39:50 +02:00
For example, to override a GPIO used for LIS3DH sensor, the application-specific driver parameter file `$APPDIR/<device>_params.h` could look like the following:
2018-09-05 02:39:50 +02:00
```
#ifdef CPU_ESP8266
#define LIS3DH_PARAM_INT2 (GPIO_PIN(0, 4))
#endif
#include_next "lis3dh_params.h"
```
2018-12-23 18:28:08 +01:00
It is important to ensure that the application-specific driver parameter file `$APPDIR/<device>_params.h` is included first. Insert the following line as the <b>first</b> line to the application makefile `$APPDIR/Makefile`.
2018-12-23 18:28:08 +01:00
```
INCLUDES += -I$(APPDIR)
```
**Pleae note:** To make such application-specific board configurations dependent on the ESP8266 MCU or a particular ESP8266 board, you should always enclose these definitions in the following constructs:
2018-09-05 02:39:50 +02:00
```
#ifdef CPU_ESP8266
...
#endif
2018-12-23 18:28:08 +01:00
#ifdef BOARD_ESP8266_ESP-12X
2018-09-05 02:39:50 +02:00
...
#endif
```
# <a name="esp8266_sdk_task_handling"> SDK Task Handling </a> &nbsp;[[TOC](#esp8266_toc)]
With make command variable `USE_SDK=1`, the Espressif SDK is used. This is
necessary, for example, if you want to use the built-in WLAN module. The
SDK is also used automatically when software timers are used by activating
the `esp_sw_timer` module.
Internally, the SDK uses its own priority-based multitasking sytsem,
the **ETS**, to handle hardware components such as the WiFi interface, or to
implement event-driven functions such as software timers. ETS periodically
executes all ETS tasks with pending events in an infinite loop with the ROM
function `ets_run`.
ETS doesn't process interrupts directly in interrupt service routines.
Instead, they use the `ets_post` ROM function to send an event to one of the
ETS tasks, which then processes the interrupts asynchronously. Context
switches are not possible in interrupt service routines.
To use SDK functions and keep the system alive, ETS tasks with pending events
have to be handled. For that purpose
- the `ets_task_func` RIOT thread with highest possible priority is used
- the ROM functions `ets_run` and `ets_post` are overwritten.
The `ets_task_func` RIOT thread is waiting for a thread flag, which is set
by the `ets_post` function at the end of an ETS interrupt service routine.
The flag indicates that there are ETS tasks with pending events that need
to be executed. The `ets_task_func` RIOT thread then calls the `ets_run`
function, which performs all ETS tasks with pending events exactly once.
Thus, when a hardware component used by the SDK triggers an interrupt, e.g.
the WiFi interface, the interrupt sevice routine posts an event to the ETS
task by calling the `ets_post` function. The overwritten version of this
function sets the thread flag of the `ets_task_func` thread. The thread
then calls function `ets_run` to process pending events.
@note Since the non-SDK version of RIOT is much smaller and faster than the
SDK version, you should always compile your application without the SDK
(`USE_SDK=0`, the default) if you don't need the built-in WiFi module.
2018-09-05 02:39:50 +02:00
# <a name="esp8266_qemu_mode_and_gdb"> QEMU Mode and GDB </a> &nbsp;[[TOC](#esp8266_toc)]
When QEMU mode is enabled (`QEMU=1`), instead of loading the image to the target hardware, a binary image `$ELFFILE.bin` is created in the target directory. This binary image file can be used together with QEMU to debug the code in GDB.
2018-09-05 02:39:50 +02:00
The binary image can be compiled with debugging information (`ENABLE_GDB=1` or module `esp_gdb`) or optimized without debugging information (`ENABLE_GDB=0`). The latter one is the default. The version with debugging information can be debugged in source code while the optimized version can only be debugged in assembler mode.
2018-09-05 02:39:50 +02:00
To use QEMU, you have to install QEMU for Xtensa with ESP8266 machine implementation as following.
```
cd /my/source/dir
git clone https://github.com/gschorcht/qemu-xtensa
cd qemu-xtensa/
git checkout xtensa-esp8266
export QEMU=/path/to/esp/qemu
./configure --prefix=$QEMU --target-list=xtensa-softmmu --disable-werror
make
make install
```
Once the compilation has been finished, QEMU for Xtensa with ESP8266 machine implementation should be available in `/path/to/esp/qemu/bin` and you can start it with
2018-09-05 02:39:50 +02:00
```
$QEMU/bin/qemu-system-xtensa -M esp8266 -nographic -serial stdio -monitor none -s -S -kernel /path/to/the/target/image.elf.bin
```
where `/path/to/the/target/image.elf.bin` is the path to the binary image as generated by the `make` command as `$ELFFILE.bin`. After that you can start GDB in another terminal window using command:
2018-09-05 02:39:50 +02:00
```
xtensa-lx106-elf-gdb
```
If you have compiled your binary image with debugging information, you can load the ELF file in gdb with:
```
(gdb) file /path/to/the/target/image.elf
```
To start debugging, you have to connect to QEMU with command:
```
(gdb) target remote :1234
```
2018-12-23 18:28:08 +01:00
2018-09-05 02:39:50 +02:00
*/