1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-23 08:45:22 +03:00

Merge remote-tracking branch 'esp8266/master'

This commit is contained in:
Me No Dev
2015-12-16 01:23:06 +02:00
21 changed files with 576 additions and 69 deletions

View File

@ -48,6 +48,14 @@ python get.py
```
- Restart Arduino
### Using stable version with PlatformIO
[PlatformIO](http://platformio.org) is a cross-platform code-builder and library manager for embedded development with no external dependencies. Works on the popular host OS: Mac OS X, Windows, Linux 32/64, Linux ARM (like Raspberry Pi, BeagleBone, CubieBoard). More details in documentation [What is PlatformIO? How does it work?](http://docs.platformio.org/en/latest/faq.html#general).
See [detailed instructions on how to use Espressif platform with PlatformIO](doc/platformio.md).
### Documentation
Documentation for latest development version:
- [Reference](doc/reference.md)

View File

@ -5,6 +5,7 @@ menu.FlashMode=Flash Mode
menu.FlashFreq=Flash Frequency
menu.UploadTool=Upload Using
menu.ResetMethod=Reset Method
menu.ESPModule=Module
##############################################################
generic.name=Generic ESP8266 Module
@ -95,6 +96,30 @@ generic.menu.FlashSize.1M256.build.spiffs_end=0xFB000
generic.menu.FlashSize.1M256.build.spiffs_blocksize=4096
generic.menu.FlashSize.1M256.upload.maximum_size=761840
generic.menu.FlashSize.1M192=1M (192K SPIFFS)
generic.menu.FlashSize.1M192.build.flash_size=1M
generic.menu.FlashSize.1M192.build.flash_ld=eagle.flash.1m192.ld
generic.menu.FlashSize.1M192.build.spiffs_start=0xCB000
generic.menu.FlashSize.1M192.build.spiffs_end=0xFB000
generic.menu.FlashSize.1M192.build.spiffs_blocksize=4096
generic.menu.FlashSize.1M192.upload.maximum_size=827376
generic.menu.FlashSize.1M160=1M (160K SPIFFS)
generic.menu.FlashSize.1M160.build.flash_size=1M
generic.menu.FlashSize.1M160.build.flash_ld=eagle.flash.1m160.ld
generic.menu.FlashSize.1M160.build.spiffs_start=0xD3000
generic.menu.FlashSize.1M160.build.spiffs_end=0xFB000
generic.menu.FlashSize.1M160.build.spiffs_blocksize=4096
generic.menu.FlashSize.1M160.upload.maximum_size=860144
generic.menu.FlashSize.1M144=1M (144K SPIFFS)
generic.menu.FlashSize.1M144.build.flash_size=1M
generic.menu.FlashSize.1M144.build.flash_ld=eagle.flash.1m144.ld
generic.menu.FlashSize.1M144.build.spiffs_start=0xD7000
generic.menu.FlashSize.1M144.build.spiffs_end=0xFB000
generic.menu.FlashSize.1M144.build.spiffs_blocksize=4096
generic.menu.FlashSize.1M144.upload.maximum_size=876528
generic.menu.FlashSize.1M128=1M (128K SPIFFS)
generic.menu.FlashSize.1M128.build.flash_size=1M
generic.menu.FlashSize.1M128.build.flash_ld=eagle.flash.1m128.ld
@ -160,7 +185,7 @@ huzzah.name=Adafruit HUZZAH ESP8266
huzzah.upload.tool=esptool
huzzah.upload.speed=115200
huzzah.upload.resetmethod=ck
huzzah.upload.resetmethod=nodemcu
huzzah.upload.maximum_size=1044464
huzzah.upload.maximum_data_size=81920
huzzah.upload.wait_for_upload_port=true
@ -408,7 +433,7 @@ thing.name=SparkFun ESP8266 Thing
thing.upload.tool=esptool
thing.upload.speed=921600
thing.upload.resetmethod=ck
thing.upload.resetmethod=nodemcu
thing.upload.maximum_size=434160
thing.upload.maximum_data_size=81920
thing.upload.wait_for_upload_port=true
@ -771,3 +796,126 @@ espino.menu.ResetMethod.ck=ck
espino.menu.ResetMethod.ck.upload.resetmethod=ck
espino.menu.ResetMethod.nodemcu=nodemcu
espino.menu.ResetMethod.nodemcu.upload.resetmethod=nodemcu
##############################################################
wifinfo.name=WifInfo
wifinfo.upload.tool=esptool
wifinfo.upload.speed=115200
wifinfo.upload.resetmethod=nodemcu
wifinfo.upload.maximum_size=434160
wifinfo.upload.maximum_data_size=81920
wifinfo.upload.wait_for_upload_port=true
wifinfo.serial.disableDTR=true
wifinfo.serial.disableRTS=true
wifinfo.build.mcu=esp8266
wifinfo.build.f_cpu=80000000L
wifinfo.build.core=esp8266
wifinfo.build.variant=wifinfo
wifinfo.build.flash_mode=qio
wifinfo.build.spiffs_pagesize=256
#wifinfo.menu.ESPModule.ESP07512=ESP07 (1M/512K SPIFFS)
#wifinfo.menu.ESPModule.ESP07512.build.board=ESP8266_ESP07
#wifinfo.menu.ESPModule.ESP07512.build.flash_size=1M
#wifinfo.menu.ESPModule.ESP07512.build.flash_ld=eagle.flash.1m512.ld
#wifinfo.menu.ESPModule.ESP07512.build.spiffs_start=0x7B000
#wifinfo.menu.ESPModule.ESP07512.build.spiffs_end=0xFB000
#wifinfo.menu.ESPModule.ESP07512.build.spiffs_blocksize=8192
#wifinfo.menu.ESPModule.ESP07512.upload.maximum_size=499696
#wifinfo.menu.ESPModule.ESP07256=ESP07 (1M/256K SPIFFS)
#wifinfo.menu.ESPModule.ESP07256.build.board=ESP8266_ESP07
#wifinfo.menu.ESPModule.ESP07256.build.flash_size=1M
#wifinfo.menu.ESPModule.ESP07256.build.flash_ld=eagle.flash.1m256.ld
#wifinfo.menu.ESPModule.ESP07256.build.spiffs_start=0xBB000
#wifinfo.menu.ESPModule.ESP07256.build.spiffs_end=0xFB000
##wifinfo.menu.ESPModule.ESP07256.build.spiffs_blocksize=4096
#wifinfo.menu.ESPModule.ESP07256.upload.maximum_size=761840
wifinfo.menu.ESPModule.ESP07192=ESP07 (1M/192K SPIFFS)
wifinfo.menu.ESPModule.ESP07192.build.board=ESP8266_ESP07
wifinfo.menu.ESPModule.ESP07192.build.flash_size=1M
wifinfo.menu.ESPModule.ESP07192.build.flash_ld=eagle.flash.1m192.ld
wifinfo.menu.ESPModule.ESP07192.build.spiffs_start=0xCB000
wifinfo.menu.ESPModule.ESP07192.build.spiffs_end=0xFB000
wifinfo.menu.ESPModule.ESP07192.build.spiffs_blocksize=4096
wifinfo.menu.ESPModule.ESP07192.upload.maximum_size=827376
#wifinfo.menu.ESPModule.ESP07160=ESP07 (1M/160K SPIFFS)
#wifinfo.menu.ESPModule.ESP07160.build.board=ESP8266_ESP07
#wifinfo.menu.ESPModule.ESP07160.build.flash_size=1M
#wifinfo.menu.ESPModule.ESP07160.build.flash_ld=eagle.flash.1m160.ld
#wifinfo.menu.ESPModule.ESP07160.build.spiffs_start=0xD3000
#wifinfo.menu.ESPModule.ESP07160.build.spiffs_end=0xFB000
#wifinfo.menu.ESPModule.ESP07160.build.spiffs_blocksize=4096
#wifinfo.menu.ESPModule.ESP07160.upload.maximum_size=860144
#
#wifinfo.menu.ESPModule.ESP07144=ESP07 (1M/144K SPIFFS)
#wifinfo.menu.ESPModule.ESP07144.build.board=ESP8266_ESP07
#wifinfo.menu.ESPModule.ESP07144.build.flash_size=1M
#wifinfo.menu.ESPModule.ESP07144.build.flash_ld=eagle.flash.1m144.ld
#wifinfo.menu.ESPModule.ESP07144.build.spiffs_start=0xD7000
#wifinfo.menu.ESPModule.ESP07144.build.spiffs_end=0xFB000
#wifinfo.menu.ESPModule.ESP07144.build.spiffs_blocksize=4096
#wifinfo.menu.ESPModule.ESP07144.upload.maximum_size=876528
#
#wifinfo.menu.ESPModule.ESP07=ESP07 (1M/64K SPIFFS)
#wifinfo.menu.ESPModule.ESP07.build.board=ESP8266_ESP07
#wifinfo.menu.ESPModule.ESP07.build.flash_size=1M
#wifinfo.menu.ESPModule.ESP07.build.flash_ld=eagle.flash.1m64.ld
#wifinfo.menu.ESPModule.ESP07.build.spiffs_start=0xEB000
#wifinfo.menu.ESPModule.ESP07.build.spiffs_end=0xFB000
#wifinfo.menu.ESPModule.ESP07.build.spiffs_blocksize=4096
#wifinfo.menu.ESPModule.ESP07.upload.maximum_size=958448
wifinfo.menu.ESPModule.ESP12=ESP12 (4M/1M SPIFFS)
wifinfo.menu.ESPModule.ESP12.build.board=ESP8266_ESP12
wifinfo.menu.ESPModule.ESP12.build.flash_size=4M
wifinfo.menu.ESPModule.ESP12.build.flash_ld=eagle.flash.4m1m.ld
wifinfo.menu.ESPModule.ESP12.build.spiffs_start=0x300000
wifinfo.menu.ESPModule.ESP12.build.spiffs_end=0x3FB000
wifinfo.menu.ESPModule.ESP12.build.spiffs_blocksize=8192
wifinfo.menu.ESPModule.ESP12.build.spiffs_pagesize=256
wifinfo.menu.ESPModule.ESP12.upload.maximum_size=1044464
wifinfo.menu.UploadTool.esptool=Serial
wifinfo.menu.UploadTool.esptool.upload.tool=esptool
wifinfo.menu.UploadTool.esptool.upload.verbose=-vv
wifinfo.menu.UploadTool.espota=OTA
wifinfo.menu.UploadTool.espota.upload.tool=espota
wifinfo.menu.CpuFrequency.80=80 MHz
wifinfo.menu.CpuFrequency.80.build.f_cpu=80000000L
wifinfo.menu.CpuFrequency.160=160 MHz
wifinfo.menu.CpuFrequency.160.build.f_cpu=160000000L
wifinfo.menu.FlashFreq.40=40MHz
wifinfo.menu.FlashFreq.40.build.flash_freq=40
wifinfo.menu.FlashFreq.80=80MHz
wifinfo.menu.FlashFreq.80.build.flash_freq=80
wifinfo.menu.FlashMode.dio=DIO
wifinfo.menu.FlashMode.dio.build.flash_mode=dio
wifinfo.menu.FlashMode.qio=QIO
wifinfo.menu.FlashMode.qio.build.flash_mode=qio
wifinfo.menu.UploadSpeed.115200=115200
wifinfo.menu.UploadSpeed.115200.upload.speed=115200
wifinfo.menu.UploadSpeed.9600=9600
wifinfo.menu.UploadSpeed.9600.upload.speed=9600
wifinfo.menu.UploadSpeed.57600=57600
wifinfo.menu.UploadSpeed.57600.upload.speed=57600
wifinfo.menu.UploadSpeed.256000.windows=256000
wifinfo.menu.UploadSpeed.256000.upload.speed=256000
wifinfo.menu.UploadSpeed.230400.linux=230400
wifinfo.menu.UploadSpeed.230400.macosx=230400
wifinfo.menu.UploadSpeed.230400.upload.speed=230400
wifinfo.menu.UploadSpeed.460800.linux=460800
wifinfo.menu.UploadSpeed.460800.macosx=460800
wifinfo.menu.UploadSpeed.460800.upload.speed=460800
wifinfo.menu.UploadSpeed.512000.windows=512000
wifinfo.menu.UploadSpeed.512000.upload.speed=512000
wifinfo.menu.UploadSpeed.921600=921600
wifinfo.menu.UploadSpeed.921600.upload.speed=921600

View File

@ -29,6 +29,7 @@
#include <inttypes.h>
#include "Arduino.h"
#include "cbuf.h"
#include "interrupts.h"
extern "C" {
#include "osapi.h"
@ -556,6 +557,7 @@ int HardwareSerial::available(void) {
int result = 0;
if (_uart != NULL && _uart->rxEnabled) {
InterruptLock il;
result = static_cast<int>(_rx_buffer->getSize());
}
@ -570,6 +572,7 @@ int HardwareSerial::peek(void) {
if(_uart == 0)
return -1;
if(_uart->rxEnabled) {
InterruptLock il;
return _rx_buffer->peek();
} else {
return -1;
@ -580,6 +583,7 @@ int HardwareSerial::read(void) {
if(_uart == 0)
return -1;
if(_uart->rxEnabled) {
InterruptLock il;
return _rx_buffer->read();
} else {
return -1;
@ -590,6 +594,7 @@ int HardwareSerial::availableForWrite(void) {
if(_uart == 0)
return 0;
if(_uart->txEnabled) {
InterruptLock il;
return static_cast<int>(_tx_buffer->room());
} else {
return 0;
@ -604,9 +609,16 @@ void HardwareSerial::flush() {
if(!_written)
return;
while(_tx_buffer->getSize() || uart_get_tx_fifo_room(_uart) < UART_TX_FIFO_SIZE)
while(true) {
{
InterruptLock il;
if(_tx_buffer->getSize() == 0 &&
uart_get_tx_fifo_room(_uart) >= UART_TX_FIFO_SIZE) {
break;
}
}
yield();
}
_written = false;
}
@ -614,18 +626,24 @@ size_t HardwareSerial::write(uint8_t c) {
if(_uart == 0 || !_uart->txEnabled)
return 0;
_written = true;
size_t room = uart_get_tx_fifo_room(_uart);
if(room > 0 && _tx_buffer->empty()) {
while(true) {
{
InterruptLock il;
if(_tx_buffer->empty()) {
if(uart_get_tx_fifo_room(_uart) > 0) {
uart_transmit_char(_uart, c);
return 1;
}
while(_tx_buffer->room() == 0) {
yield();
}
} else {
_tx_buffer->write(c);
uart_arm_tx_interrupt(_uart);
}
break;
} else if(_tx_buffer->write(c)) {
break;
}
}
yield();
}
return 1;
}

View File

@ -38,14 +38,14 @@ void UpdaterClass::_reset() {
bool UpdaterClass::begin(size_t size, int command) {
if(_size > 0){
#ifdef DEBUG_UPDATER
DEBUG_UPDATER.println("already running");
DEBUG_UPDATER.println("[begin] already running");
#endif
return false;
}
#ifdef DEBUG_UPDATER
if (command == U_SPIFFS) {
DEBUG_UPDATER.println("Update SPIFFS.");
DEBUG_UPDATER.println("[begin] Update SPIFFS.");
}
#endif
@ -73,6 +73,12 @@ bool UpdaterClass::begin(size_t size, int command) {
//address where we will start writing the update
updateStartAddress = updateEndAddress - roundedSize;
#ifdef DEBUG_UPDATER
DEBUG_UPDATER.printf("[begin] roundedSize: 0x%08X (%d)\n", roundedSize, roundedSize);
DEBUG_UPDATER.printf("[begin] updateEndAddress: 0x%08X (%d)\n", updateEndAddress, updateEndAddress);
DEBUG_UPDATER.printf("[begin] currentSketchSize: 0x%08X (%d)\n", currentSketchSize, currentSketchSize);
#endif
//make sure that the size of both sketches is less than the total space (updateEndAddress)
if(updateStartAddress < currentSketchSize) {
_error = UPDATE_ERROR_SPACE;
@ -88,7 +94,7 @@ bool UpdaterClass::begin(size_t size, int command) {
else {
// unknown command
#ifdef DEBUG_UPDATER
DEBUG_UPDATER.println("Unknown update command.");
DEBUG_UPDATER.println("[begin] Unknown update command.");
#endif
return false;
}
@ -100,6 +106,12 @@ bool UpdaterClass::begin(size_t size, int command) {
_buffer = new uint8_t[FLASH_SECTOR_SIZE];
_command = command;
#ifdef DEBUG_UPDATER
DEBUG_UPDATER.printf("[begin] _startAddress: 0x%08X (%d)\n", _startAddress, _startAddress);
DEBUG_UPDATER.printf("[begin] _currentAddress: 0x%08X (%d)\n", _currentAddress, _currentAddress);
DEBUG_UPDATER.printf("[begin] _size: 0x%08X (%d)\n", _size, _size);
#endif
_md5.begin();
return true;
}
@ -168,9 +180,14 @@ bool UpdaterClass::end(bool evenIfRemaining){
}
bool UpdaterClass::_writeBuffer(){
yield();
bool result = ESP.flashEraseSector(_currentAddress/FLASH_SECTOR_SIZE);
yield();
if (result) {
result = ESP.flashWrite(_currentAddress, (uint32_t*) _buffer, _bufferLen);
}
yield();
bool result = ESP.flashEraseSector(_currentAddress/FLASH_SECTOR_SIZE) &&
ESP.flashWrite(_currentAddress, (uint32_t*) _buffer, _bufferLen);
if (!result) {
_error = UPDATE_ERROR_WRITE;
@ -223,14 +240,17 @@ size_t UpdaterClass::writeStream(Stream &data) {
return 0;
while(remaining()) {
toRead = FLASH_SECTOR_SIZE - _bufferLen;
toRead = data.readBytes(_buffer + _bufferLen, toRead);
if(toRead == 0){ //Timeout
toRead = data.readBytes(_buffer + _bufferLen, (FLASH_SECTOR_SIZE - _bufferLen));
if(toRead == 0) { //Timeout
delay(100);
toRead = data.readBytes(_buffer + _bufferLen, (FLASH_SECTOR_SIZE - _bufferLen));
if(toRead == 0) { //Timeout
_error = UPDATE_ERROR_STREAM;
_currentAddress = (_startAddress + _size);
#ifdef DEBUG_UPDATER
printError(DEBUG_UPDATER);
#endif
}
return written;
}
_bufferLen += toRead;

View File

@ -121,6 +121,7 @@ ICACHE_FLASH_ATTR String::~String() {
if(buffer) {
free(buffer);
}
init();
}
// /*********************************************/
@ -136,8 +137,7 @@ inline void String::init(void) {
void ICACHE_FLASH_ATTR String::invalidate(void) {
if(buffer)
free(buffer);
buffer = NULL;
capacity = len = 0;
init();
}
unsigned char ICACHE_FLASH_ATTR String::reserve(unsigned int size) {

View File

@ -76,7 +76,11 @@ class String {
// invalid string (i.e., "if (s)" will be true afterwards)
unsigned char reserve(unsigned int size);
inline unsigned int length(void) const {
if(buffer) {
return len;
} else {
return 0;
}
}
// creates a copy of the assigned value. if the value is null or

View File

@ -113,9 +113,9 @@ class cbuf {
return (ptr == _bufend) ? _buf : ptr;
}
size_t _size;
const size_t _size;
char* _buf;
char* _bufend;
const char* const _bufend;
char* _begin;
char* _end;
};

View File

@ -41,11 +41,13 @@ extern int32_t spiffs_hal_write(uint32_t addr, uint32_t size, uint8_t *src);
extern int32_t spiffs_hal_erase(uint32_t addr, uint32_t size);
extern int32_t spiffs_hal_read(uint32_t addr, uint32_t size, uint8_t *dst);
int getSpiffsMode(OpenMode openMode, AccessMode accessMode);
static int getSpiffsMode(OpenMode openMode, AccessMode accessMode);
static bool isSpiffsFilenameValid(const char* name);
class SPIFFSFileImpl;
class SPIFFSDirImpl;
class SPIFFSImpl : public FSImpl {
public:
SPIFFSImpl(uint32_t start, uint32_t size, uint32_t pageSize, uint32_t blockSize, uint32_t maxOpenFds)
@ -63,6 +65,14 @@ public:
DirImplPtr openDir(const char* path) override;
bool rename(const char* pathFrom, const char* pathTo) override {
if (!isSpiffsFilenameValid(pathFrom)) {
DEBUGV("SPIFFSImpl::rename: invalid pathFrom=`%s`\r\n", path);
return false;
}
if (!isSpiffsFilenameValid(pathTo)) {
DEBUGV("SPIFFSImpl::rename: invalid pathTo=`%s` \r\n", path);
return false;
}
auto rc = SPIFFS_rename(&_fs, pathFrom, pathTo);
if (rc != SPIFFS_OK) {
DEBUGV("SPIFFS_rename: rc=%d, from=`%s`, to=`%s`\r\n", rc,
@ -86,6 +96,10 @@ public:
}
bool remove(const char* path) override {
if (!isSpiffsFilenameValid(path)) {
DEBUGV("SPIFFSImpl::remove: invalid path=`%s`\r\n", path);
return false;
}
auto rc = SPIFFS_remove(&_fs, path);
if (rc != SPIFFS_OK) {
DEBUGV("SPIFFS_remove: rc=%d path=`%s`\r\n", rc, path);
@ -229,7 +243,7 @@ protected:
std::unique_ptr<uint8_t[]> _cacheBuf;
};
#define CHECKFD() while (_fd == 0) { DEBUGV("SPIFFSFileImpl(%d) _fd == 0\r\n", __LINE__); abort(); }
#define CHECKFD() while (_fd == 0) { panic(); }
class SPIFFSFileImpl : public FileImpl {
public:
@ -408,6 +422,10 @@ protected:
FileImplPtr SPIFFSImpl::open(const char* path, OpenMode openMode, AccessMode accessMode) {
if (!isSpiffsFilenameValid(path)) {
DEBUGV("SPIFFSImpl::open: invalid path=`%s` \r\n", path);
return FileImplPtr();
}
int mode = getSpiffsMode(openMode, accessMode);
int fd = SPIFFS_open(&_fs, path, mode, 0);
if (fd < 0 && _fs.err_code == SPIFFS_ERR_DELETED && (openMode & OM_CREATE)) {
@ -430,12 +448,20 @@ FileImplPtr SPIFFSImpl::open(const char* path, OpenMode openMode, AccessMode acc
}
bool SPIFFSImpl::exists(const char* path) {
if (!isSpiffsFilenameValid(path)) {
DEBUGV("SPIFFSImpl::exists: invalid path=`%s` \r\n", path);
return false;
}
spiffs_stat stat;
int rc = SPIFFS_stat(&_fs, path, &stat);
return rc == SPIFFS_OK;
}
DirImplPtr SPIFFSImpl::openDir(const char* path) {
if (!isSpiffsFilenameValid(path)) {
DEBUGV("SPIFFSImpl::openDir: invalid path=`%s` \r\n", path);
return DirImplPtr();
}
spiffs_DIR dir;
spiffs_DIR* result = SPIFFS_opendir(&_fs, path, &dir);
if (!result) {
@ -445,7 +471,7 @@ DirImplPtr SPIFFSImpl::openDir(const char* path) {
return std::make_shared<SPIFFSDirImpl>(path, this, dir);
}
int getSpiffsMode(OpenMode openMode, AccessMode accessMode) {
static int getSpiffsMode(OpenMode openMode, AccessMode accessMode) {
int mode = 0;
if (openMode & OM_CREATE) {
mode |= SPIFFS_CREAT;
@ -465,6 +491,13 @@ int getSpiffsMode(OpenMode openMode, AccessMode accessMode) {
return mode;
}
static bool isSpiffsFilenameValid(const char* name) {
if (name == nullptr)
return false;
auto len = strlen(name);
return len > 0 && len <= SPIFFS_OBJ_NAME_LEN;
}
// these symbols should be defined in the linker script for each flash layout
extern "C" uint32_t _SPIFFS_start;
extern "C" uint32_t _SPIFFS_end;

View File

@ -12,6 +12,7 @@ title: Supported Hardware
* [SparkFun ESP8266 Thing](#sparkfun-esp8266-thing)
* [SweetPea ESP\-210](#sweetpea-esp-210)
* [ESPino](#espino)
* [WifInfo](#WifInfo)
* [Generic ESP8266 modules](#generic-esp8266-modules)
* [Serial Adapter](#serial-adapter)
* [Minimal Hardware Setup for Bootloading and Usage](#minimal-hardware-setup-for-bootloading-and-usage)
@ -100,6 +101,12 @@ For more information about the hardware, pinout diagram and programming procedur
Product page: http://www.espino.io/en
## WifInfo
WifInfo integrates the ESP-12 or ESP-07+Ext antenna module with a 3.3v regulator and the hardware to be able to measure French telemetry issue from ERDF powering meter serial output. It has a USB connector for powering, an RGB WS2812 Led, 4 pins I2C connector to fit OLED or sensor, and two buttons + FTDI connector and auto reset feature.
For more information, please see WifInfo related [blog](http://hallard.me/category/wifinfo/) entries, [github](https://github.com/hallard/WifInfo) and [community](https://community.hallard.me/category/16/wifinfo) forum.
## Generic ESP8266 modules
These modules come in different form factors and pinouts. See the page at ESP8266 community wiki for more info:

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -11,6 +11,7 @@ title: OTA Update
* [Requirements](#requirements)
* [Application Example](#application-example)
* [Classic OTA](#classic-ota)
* [Troubleshooting](#troubleshooting)
* [ArduinoOTA](#arduinoota)
* [Web Browser](#web-browser)
* [Requirements](#requirements-1)
@ -79,13 +80,14 @@ void onError(OTA_CALLBACK_ERROR (fn));
### Basic Requirements
Flash chip size needs a size thats is able to hold the old sketch (currently running) and the new sketch (OTA) at the same time.
keep in mind that the File system and EEPROM for example needs space too (one time) see [flash layout](../filesystem.md#flash-layout).
Flash chip size needs a size that is able to hold the old sketch (currently running) and the new sketch (OTA) at the same time.
Keep in mind that the File system and EEPROM for example needs space too (one time) see [flash layout](../filesystem.md#flash-layout).
```cpp
ESP.getFreeSketchSpace();
```
can be used for checking the free space for the new sketch.
For overview of memory layout, where new sketch is stored and how it is copied during OTA process see [Update process - memory view]( https://github.com/esp8266/Arduino/blob/master/doc/ota_updates/ota_updates.md#update-process---memory-view).
The following chapters provide more details and specific methods of doing OTA.
@ -155,6 +157,57 @@ Instructions below demonstrate how to configure both [Classic OTA](#classic-ota-
**Note:** To be able to upload your sketch over and over again using OTA, you need to embed OTA routines inside. Please use DNS_SD_Arduino_OTA.ino as an example.
#### Troubleshooting
If OTA update fails, first step is to check for error messages that may be shown in upload window of Arduino IDE. If this is not providing any useful hints try to upload again while checking what is shown by ESP on serial port. Serial Monitor from IDE will not be useful in that case. When attempting to open it, you will likely see the following:
![Arduino IDE network terminal window](ota-ide-network-terminal.png)
This window is for Arduino Yún and not yet implemented for esp8266/Arduino. It shows up because IDE is attempting to open Serial Monitor using network port you have selected for OTA upload.
Instead you need an external serial monitor. If you are a Windows user check out [Termite](http://www.compuphase.com/software_termite.htm). This is handy, slick and simple RS232 terminal that does not impose RTS or DTR flow control. Such flow control may cause issues if you are using respective lines to toggle GPIO0 and RESET pins on ESP for upload.
Select COM port and baud rate on external terminal program as if you were using Arduino Serial Monitor. Please see typical settings for [Termite](http://www.compuphase.com/software_termite.htm) below:
![Termite settings](termite-configuration.png)
Then run OTA from IDE and look what is displayed on terminal. Successful OTA process looks like below (sketch and free memory sizes as well as IP addresses depend on your particular s/w and h/w configuration):
```
Arduino OTA Test
Sketch size: 346664
Free size: 700416
IP address: 192.168.1.100
Update Start: ip:192.168.1.10, port:48266, size:346672
Update Success: 6113
Rebooting...
ets Jan 8 2013,rst cause:1, boot mode:(3,7)
load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
@cp:0
ld
Arduino OTA Test
Sketch size: 346664
Free size: 700416
IP address: 192.168.1.100
```
If upload fails you will likely see errors caught by the uploader, exception and the stack dump, or both.
The most common causes of OTA failure are as follows:
* not enough physical memory on the chip (e.g. ESP01 with 512K flash memory is not enough for OTA),
* too much memory declared for SPIFFS so new sketch will not fit between existing sketch and SPIFFS see [Update process - memory view]( https://github.com/esp8266/Arduino/blob/master/doc/ota_updates/ota_updates.md#update-process---memory-view),
* too little memory declared in Arduino IDE for your selected board (i.e. less than physical size).
For more details regarding flash memory layout please check [File system]( https://github.com/esp8266/Arduino/blob/master/doc/filesystem.md).
For overview where new sketch is stored, how it is copied and how memory is organized for the purpose of OTA see [Update process - memory view]( https://github.com/esp8266/Arduino/blob/master/doc/ota_updates/ota_updates.md#update-process---memory-view).
#### ArduinoOTA
1. Upload and install the following software:
@ -183,7 +236,7 @@ Updates described in this chapter are done with a web browser that can be useful
### Implementation Overview
Updates with a web browswer are implemented using ```ESP8266HTTPUpdateServer``` class together with ```ESP8266WebServer``` and ```ESP8266mDNS``` classes. The following code is required to get it work:
Updates with a web browser are implemented using ```ESP8266HTTPUpdateServer``` class together with ```ESP8266WebServer``` and ```ESP8266mDNS``` classes. The following code is required to get it work:
setup()
@ -222,10 +275,10 @@ You can use another module if it meets “Flash chip size is 2x the size of the
2. Prepare the sketch and configuration for initial upload with a serial port.
- Start Arduino IDE and load sketch WebUpdater.ino available under File > Examples > ESP8266HTTPUpdateServer.
- Update ssid and pass in the sketch so the module can join your Wi-Fi network.
- Update SSID and password in the sketch so the module can join your Wi-Fi network.
- Open File > Preferences, look for “Show verbose output during:” and check out “compilation” option.
![Preferences - enablig verbose output during compilation](ota-web-show-verbose-compilation.png)
![Preferences - enabling verbose output during compilation](ota-web-show-verbose-compilation.png)
**Note:** This setting will be required in step 5 below. You can uncheck this setting afterwards.
@ -315,7 +368,7 @@ For the simple updater the server only needs to deliver the binary file for upda
##### Advanced updater
For advanced update management a script needs to run at the server side, for example a PHP script.
At every update request the the ESP sends some information in HTTP headers to the server.
At every update request the ESP sends some information in HTTP headers to the server.
Example header data:
```
@ -329,7 +382,7 @@ Example header data:
[HTTP_X_ESP8266_VERSION] => DOOR-7-g14f53a19
```
With this information the script now can check if a update is needed. It is also possible to deliver different binaries based on the MAC address for example.
With this information the script now can check if an update is needed. It is also possible to deliver different binaries based on the MAC address for example.
Script example:
@ -405,6 +458,15 @@ The Stream Interface is the base for all other update modes like OTA, http Serve
## Updater class
TODO describe Updater class
Updater is in the Core and deals with writing the firmware to the flash,
checking its integrity and telling the bootloader to load the new firmware on the next boot.
### Update process - memory view
- The new sketch will be stored in the space between the old sketch and the spiff.
- on the next reboot the "eboot" bootloader check for commands.
- the new sketch is now copied "over" the old one.
- the new sketch is started.
![Memory Copy](update_memory_copy.png)
Updater is in the Core and deals with writing the firmware to the flash, checking its integrity and telling the bootloader to load the new firmware on the next boot.

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

61
doc/platformio.md Normal file
View File

@ -0,0 +1,61 @@
## Using PlatformIO
- Install [PlatformIO](http://platformio.org)
- Initialise new project
```bash
#
# Create empty directory
#
mkdir myproject
cd myproject
#
# Find type of supported boards
#
platformio boards espressif
# Platform: espressif
# --------------------------------------------------------------------------------------------------------
# Type MCU Frequency Flash RAM Name
# --------------------------------------------------------------------------------------------------------
# esp01 esp8266 80Mhz 512Kb 32Kb Espressif ESP8266 ESP-01 board
# esp01_1m esp8266 80Mhz 1024Kb 32Kb Espressif ESP8266 ESP-01-1MB board
# esp12e esp8266 80Mhz 4096Kb 32Kb Espressif ESP8266 ESP-12E board (NodeMCU)
# ...
#
# Initialise base project
#
platformio init --board %TYPE%(see above)
# The next files/directories will be created in myproject
# platformio.ini - Project Configuration File. |-> PLEASE EDIT ME <-|
# src - Put your source files here
# lib - Put here project specific (private) libraries
# Do you want to continue? [y/N]: Y
```
- Place your source code to `src` directory
- Build/Upload project
```
# process/build project
platformio run
# build+upload firmware
platformio run --target upload
# build+upload firmware via OTA
platformio run --target upload --upload-port IP_ADDRESS_HERE
```
## IDE Integration
In addition, PlatformIO [can be integrated into the popular IDEs](http://docs.platformio.org/en/latest/ide.html). For example, initialise project for Espressif ESP8266 ESP-01 board and Eclipse IDE
```
platformio init --board esp01 --ide eclipse
```
Then [import project](http://docs.platformio.org/en/latest/ide/eclipse.html) using `Eclipse Menu: File > Import... > General > Existing Projects into Workspace`.
## Demo of OTA firmware uploading
[![PlatformIO and OTA firmware uploading to Espressif ESP8266 ESP-01](http://img.youtube.com/vi/W8wWjvQ8ZQs/0.jpg)](http://www.youtube.com/watch?v=W8wWjvQ8ZQs "PlatformIO and OTA firmware uploading to Espressif ESP8266 ESP-01")

View File

@ -42,10 +42,10 @@ ESP8266HTTPUpdate::~ESP8266HTTPUpdate(void) {
* @param httpsFingerprint const char *
* @return t_httpUpdate_return
*/
t_httpUpdate_return ESP8266HTTPUpdate::update(const char * url, const char * current_version, const char * httpsFingerprint) {
t_httpUpdate_return ESP8266HTTPUpdate::update(const char * url, const char * current_version, const char * httpsFingerprint, bool reboot) {
HTTPClient http;
http.begin(url, httpsFingerprint);
return handleUpdate(&http, current_version);
return handleUpdate(&http, current_version, reboot, false);
}
/**
@ -55,10 +55,10 @@ t_httpUpdate_return ESP8266HTTPUpdate::update(const char * url, const char * cur
* @param httpsFingerprint const char *
* @return t_httpUpdate_return
*/
t_httpUpdate_return ESP8266HTTPUpdate::updateSpiffs(const char * url, const char * current_version, const char * httpsFingerprint) {
t_httpUpdate_return ESP8266HTTPUpdate::updateSpiffs(const char * url, const char * current_version, const char * httpsFingerprint, bool reboot) {
HTTPClient http;
http.begin(url, httpsFingerprint);
return handleUpdate(&http, current_version, false, true);
return handleUpdate(&http, current_version, reboot, true);
}
/**
@ -70,16 +70,16 @@ t_httpUpdate_return ESP8266HTTPUpdate::updateSpiffs(const char * url, const char
* @param httpsFingerprint const char *
* @return
*/
t_httpUpdate_return ESP8266HTTPUpdate::update(const char * host, uint16_t port, const char * url, const char * current_version, bool https, const char * httpsFingerprint) {
t_httpUpdate_return ESP8266HTTPUpdate::update(const char * host, uint16_t port, const char * url, const char * current_version, bool https, const char * httpsFingerprint, bool reboot) {
HTTPClient http;
http.begin(host, port, url, https, httpsFingerprint);
return handleUpdate(&http, current_version);
return handleUpdate(&http, current_version, reboot, false);
}
t_httpUpdate_return ESP8266HTTPUpdate::update(String host, uint16_t port, String url, String current_version, bool https, String httpsFingerprint) {
t_httpUpdate_return ESP8266HTTPUpdate::update(String host, uint16_t port, String url, String current_version, bool https, String httpsFingerprint, bool reboot) {
HTTPClient http;
http.begin(host, port, url, https, httpsFingerprint);
return handleUpdate(&http, current_version.c_str());
return handleUpdate(&http, current_version.c_str(), reboot, false);
}
/**

View File

@ -49,11 +49,11 @@ class ESP8266HTTPUpdate {
ESP8266HTTPUpdate(void);
~ESP8266HTTPUpdate(void);
t_httpUpdate_return update(const char * url, const char * current_version = "", const char * httpsFingerprint = "");
t_httpUpdate_return update(const char * host, uint16_t port, const char * url = "/", const char * current_version = "", bool https = false, const char * httpsFingerprint = "");
t_httpUpdate_return update(String host, uint16_t port, String url = "/", String current_version = "", bool https = false, String httpsFingerprint = "");
t_httpUpdate_return update(const char * url, const char * current_version = "", const char * httpsFingerprint = "", bool reboot = true);
t_httpUpdate_return update(const char * host, uint16_t port, const char * url = "/", const char * current_version = "", bool https = false, const char * httpsFingerprint = "", bool reboot = true);
t_httpUpdate_return update(String host, uint16_t port, String url = "/", String current_version = "", bool https = false, String httpsFingerprint = "", bool reboot = true);
t_httpUpdate_return updateSpiffs(const char * url, const char * current_version = "", const char * httpsFingerprint = "");
t_httpUpdate_return updateSpiffs(const char * url, const char * current_version = "", const char * httpsFingerprint = "", bool reboot = false);
protected:
t_httpUpdate_return handleUpdate(HTTPClient * http, const char * current_version, bool reboot = true, bool spiffs = false);

View File

@ -51,6 +51,9 @@
},
{
"name": "ESPino"
},
{
"name": "WifInfo"
}
],
"toolsDependencies": [

View File

@ -0,0 +1,19 @@
/* Flash Split for 1M chips */
/* sketch 855KB */
/* spiffs 144KB */
/* eeprom 20KB */
MEMORY
{
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x14000
iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40201010, len = 0xd5ff0
}
PROVIDE ( _SPIFFS_start = 0x402D7000 );
PROVIDE ( _SPIFFS_end = 0x402FB000 );
PROVIDE ( _SPIFFS_page = 0x100 );
PROVIDE ( _SPIFFS_block = 0x1000 );
INCLUDE "../ld/eagle.app.v6.common.ld"

View File

@ -0,0 +1,19 @@
/* Flash Split for 1M chips */
/* sketch 839KB */
/* spiffs 160KB */
/* eeprom 20KB */
MEMORY
{
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x14000
iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40201010, len = 0xd1ff0
}
PROVIDE ( _SPIFFS_start = 0x402D3000 );
PROVIDE ( _SPIFFS_end = 0x402FB000 );
PROVIDE ( _SPIFFS_page = 0x100 );
PROVIDE ( _SPIFFS_block = 0x1000 );
INCLUDE "../ld/eagle.app.v6.common.ld"

View File

@ -0,0 +1,19 @@
/* Flash Split for 1M chips */
/* sketch 807KB */
/* spiffs 192KB */
/* eeprom 20KB */
MEMORY
{
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x14000
iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40201010, len = 0xc9ff0
}
PROVIDE ( _SPIFFS_start = 0x402CB000 );
PROVIDE ( _SPIFFS_end = 0x402FB000 );
PROVIDE ( _SPIFFS_page = 0x100 );
PROVIDE ( _SPIFFS_block = 0x1000 );
INCLUDE "../ld/eagle.app.v6.common.ld"

View File

@ -0,0 +1,86 @@
/*
pins_arduino.h - Pin definition functions for Arduino
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2007 David A. Mellis
Modified for ESP8266 platform by Ivan Grokhotkov, 2014-2015.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
Changed : 20 Nov 2015 Charles-Henri Hallard
Definition for WifInfo boards
see https://github.com/hallard/LibTeleinfo/tree/master/examples/ESP8266_WifInfo
see https://hallard.me/wifinfo/
$Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#define EXTERNAL_NUM_INTERRUPTS 16
#define NUM_DIGITAL_PINS 17
#define NUM_ANALOG_INPUTS 1
#define analogInputToDigitalPin(p) ((p > 0)?NOT_A_PIN:0)
#define digitalPinToInterrupt(p) (((p) < EXTERNAL_NUM_INTERRUPTS)?p:NOT_A_PIN)
#define digitalPinHasPWM(p) (((p) < NUM_DIGITAL_PINS)?p:NOT_A_PIN)
static const uint8_t SDA = 4;
static const uint8_t SCL = 5;
static const uint8_t SS = 15;
static const uint8_t MOSI = 13;
static const uint8_t MISO = 12;
static const uint8_t SCK = 14;
static const uint8_t BUILTIN_LED = 12;
static const uint8_t A0 = 17;
static const uint8_t D0 = 16;
static const uint8_t D1 = 5;
static const uint8_t D2 = 4;
static const uint8_t D3 = 0;
static const uint8_t D4 = 2;
static const uint8_t D5 = 14;
static const uint8_t D6 = 12;
static const uint8_t D7 = 13;
static const uint8_t D8 = 15;
static const uint8_t D9 = 3;
static const uint8_t D10 = 1;
// These serial port names are intended to allow libraries and architecture-neutral
// sketches to automatically default to the correct port name for a particular type
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
//
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
//
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
//
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
//
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
//
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
// pins are NOT connected to anything by default.
#define SERIAL_PORT_MONITOR Serial1
#define SERIAL_PORT_USBVIRTUAL Serial
#define SERIAL_PORT_HARDWARE Serial
#define SERIAL_PORT_HARDWARE_OPEN Serial
#endif /* Pins_Arduino_h */