Skip to content

Commit 9e5b343

Browse files
Merge branch 'master' into pgmspace_to_libc
2 parents 03050e9 + e549355 commit 9e5b343

File tree

281 files changed

+9783
-10483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

281 files changed

+9783
-10483
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ matrix:
1313
- BUILD_TYPE=build_even
1414
- env:
1515
- BUILD_TYPE=build_odd
16+
- env:
17+
- BUILD_TYPE=debug_even
18+
- env:
19+
- BUILD_TYPE=debug_odd
1620
- env:
1721
- BUILD_TYPE=platformio
1822
- env:

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ESP8266 Arduino core comes with libraries to communicate over WiFi using TCP and
88
# Contents
99
- Installing options:
1010
- [Using Boards Manager](#installing-with-boards-manager)
11-
- [Using git version](#using-git-version)
11+
- [Using git version](#using-git-version-basic-instructions)
1212
- [Using PlatformIO](#using-platformio)
1313
- [Building with make](#building-with-make)
1414
- [Documentation](#documentation)
@@ -30,16 +30,20 @@ Boards manager link: `http://arduino.esp8266.com/stable/package_esp8266com_index
3030

3131
Documentation: [https://arduino-esp8266.readthedocs.io/en/2.4.2/](https://arduino-esp8266.readthedocs.io/en/2.4.2/)
3232

33-
### Using git version
33+
### Using git version (basic instructions)
3434
[![Linux build status](https://travis-ci.org/esp8266/Arduino.svg)](https://travis-ci.org/esp8266/Arduino)
3535

3636
- Install the current upstream Arduino IDE at the 1.8 level or later. The current version is at the [Arduino website](http://www.arduino.cc/en/main/software).
37-
- Go to Arduino application directory
37+
- Go to Arduino directory
3838
- For Mac OS X, it is `Arduino.app` showing as the Arduino icon.
3939
This location may be your `~/Downloads`, `~/Desktop` or even `/Applications`.
4040
```bash
4141
cd <application-directory>/Arduino.app/Contents/Java
4242
```
43+
- For Linux, it is ~/arduino by default.
44+
```bash
45+
cd ~arduino
46+
```
4347
- Clone this repository into hardware/esp8266com/esp8266 directory (or clone it elsewhere and create a symlink)
4448
```bash
4549
cd hardware
@@ -124,3 +128,5 @@ ESP8266 core files are licensed under LGPL.
124128
[umm_malloc](https://github.com/rhempel/umm_malloc) memory management library written by Ralph Hempel is used in this project. It is distributed under MIT license.
125129

126130
[axTLS](http://axtls.sourceforge.net/) library written by Cameron Rich, built from https://github.com/igrr/axtls-8266, is used in this project. It is distributed under [BSD license](https://github.com/igrr/axtls-8266/blob/master/LICENSE).
131+
132+
[BearSSL](https://bearssl.org) 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](https://bearssl.org/#legal-details).

boards.txt

Lines changed: 449 additions & 225 deletions
Large diffs are not rendered by default.

cores/esp8266/Client.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class Client: public Stream {
3434
virtual int read() = 0;
3535
virtual int read(uint8_t *buf, size_t size) = 0;
3636
virtual int peek() = 0;
37-
virtual void flush() = 0;
38-
virtual void stop() = 0;
37+
virtual bool flush(unsigned int maxWaitMs = 0) = 0;
38+
virtual bool stop(unsigned int maxWaitMs = 0) = 0;
3939
virtual uint8_t connected() = 0;
4040
virtual operator bool() = 0;
4141
protected:

cores/esp8266/Esp.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "interrupts.h"
2626
#include "MD5Builder.h"
2727
#include "umm_malloc/umm_malloc.h"
28+
#include "cont.h"
2829

2930
extern "C" {
3031
#include "user_interface.h"
@@ -177,6 +178,16 @@ uint16_t EspClass::getMaxFreeBlockSize(void)
177178
return umm_max_block_size();
178179
}
179180

181+
uint32_t EspClass::getFreeContStack()
182+
{
183+
return cont_get_free_stack(g_pcont);
184+
}
185+
186+
void EspClass::resetFreeContStack()
187+
{
188+
cont_repaint_stack(g_pcont);
189+
}
190+
180191
uint32_t EspClass::getChipId(void)
181192
{
182193
return system_get_chip_id();

cores/esp8266/Esp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ class EspClass {
110110
uint8_t getHeapFragmentation(); // in %
111111
void getHeapStats(uint32_t* free = nullptr, uint16_t* max = nullptr, uint8_t* frag = nullptr);
112112

113+
uint32_t getFreeContStack();
114+
void resetFreeContStack();
115+
113116
const char * getSdkVersion();
114117
String getCoreVersion();
115118
String getFullVersion();

cores/esp8266/Updater.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,23 @@ void UpdaterClass::_reset() {
3535
_currentAddress = 0;
3636
_size = 0;
3737
_command = U_FLASH;
38+
39+
if(_ledPin != -1) {
40+
digitalWrite(_ledPin, !_ledOn); // off
41+
}
3842
}
3943

40-
bool UpdaterClass::begin(size_t size, int command) {
44+
bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {
4145
if(_size > 0){
4246
#ifdef DEBUG_UPDATER
4347
DEBUG_UPDATER.println(F("[begin] already running"));
4448
#endif
4549
return false;
4650
}
4751

52+
_ledPin = ledPin;
53+
_ledOn = !!ledOn; // 0(LOW) or 1(HIGH)
54+
4855
/* Check boot mode; if boot mode is 1 (UART download mode),
4956
we will not be able to reset into normal mode once update is done.
5057
Fail early to avoid frustration.
@@ -360,18 +367,32 @@ size_t UpdaterClass::writeStream(Stream &data) {
360367
return 0;
361368
}
362369

370+
if(_ledPin != -1) {
371+
pinMode(_ledPin, OUTPUT);
372+
}
373+
363374
while(remaining()) {
364-
toRead = data.readBytes(_buffer + _bufferLen, (_bufferSize - _bufferLen));
375+
if(_ledPin != -1) {
376+
digitalWrite(_ledPin, _ledOn); // Switch LED on
377+
}
378+
size_t bytesToRead = _bufferSize - _bufferLen;
379+
if(bytesToRead > remaining()) {
380+
bytesToRead = remaining();
381+
}
382+
toRead = data.readBytes(_buffer + _bufferLen, bytesToRead);
365383
if(toRead == 0) { //Timeout
366384
delay(100);
367-
toRead = data.readBytes(_buffer + _bufferLen, (_bufferSize - _bufferLen));
385+
toRead = data.readBytes(_buffer + _bufferLen, bytesToRead);
368386
if(toRead == 0) { //Timeout
369387
_currentAddress = (_startAddress + _size);
370388
_setError(UPDATE_ERROR_STREAM);
371389
_reset();
372390
return written;
373391
}
374392
}
393+
if(_ledPin != -1) {
394+
digitalWrite(_ledPin, !_ledOn); // Switch LED off
395+
}
375396
_bufferLen += toRead;
376397
if((_bufferLen == remaining() || _bufferLen == _bufferSize) && !_writeBuffer())
377398
return written;

cores/esp8266/Updater.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class UpdaterClass {
3535
Call this to check the space needed for the update
3636
Will return false if there is not enough space
3737
*/
38-
bool begin(size_t size, int command = U_FLASH);
38+
bool begin(size_t size, int command = U_FLASH, int ledPin = -1, uint8_t ledOn = LOW);
3939

4040
/*
4141
Run Updater from asynchronous callbacs
@@ -162,6 +162,9 @@ class UpdaterClass {
162162

163163
String _target_md5;
164164
MD5Builder _md5;
165+
166+
int _ledPin;
167+
uint8_t _ledOn;
165168
};
166169

167170
extern UpdaterClass Update;

cores/esp8266/cont.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ int cont_get_free_stack(cont_t* cont);
7474
// continuation stack
7575
bool cont_can_yield(cont_t* cont);
7676

77+
// Repaint the stack from the current SP to the end, to allow individual
78+
// routines' stack usages to be calculated by re-painting, checking current
79+
// free, running the routine, then checking the max free
80+
void cont_repaint_stack(cont_t *cont);
81+
82+
7783
#ifdef __cplusplus
7884
}
7985
#endif

cores/esp8266/cont_util.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,18 @@ bool ICACHE_RAM_ATTR cont_can_yield(cont_t* cont) {
6464
return !ETS_INTR_WITHINISR() &&
6565
cont->pc_ret != 0 && cont->pc_yield == 0;
6666
}
67+
68+
// No need for this to be in IRAM, not expected to be IRQ called
69+
void cont_repaint_stack(cont_t *cont)
70+
{
71+
register uint32_t *sp asm("a1");
72+
// Ensure 64 bytes adjacent to the current SP don't get touched to endure
73+
// we don't accidentally trounce over locals or IRQ temps.
74+
uint32_t sp_safe = CONT_STACKSIZE/4 - ((sp - &cont->stack[0] - 64)/4);
75+
76+
// Fill stack with magic values
77+
for(uint32_t pos = 0; pos < sp_safe; pos++)
78+
{
79+
cont->stack[pos] = CONT_STACKGUARD;
80+
}
81+
}

cores/esp8266/core_esp8266_waveform.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#include "core_esp8266_waveform.h"
4242

4343
// Need speed, not size, here
44-
#pragma GCC optimize ("O3")
44+
#pragma GCC optimize ("O2")
4545

4646
// Maximum delay between IRQs
4747
#define MAXIRQUS (10000)
@@ -79,7 +79,13 @@ static Waveform waveform[] = {
7979
{0, 0, 1<<3, 0, 0, 0, 0, 0},
8080
{0, 0, 1<<4, 0, 0, 0, 0, 0},
8181
{0, 0, 1<<5, 0, 0, 0, 0, 0},
82-
// GPIOS 6-11 not allowed, used for flash
82+
// GPIOS 6-8 not allowed, used for flash
83+
// GPIO 9 and 10 only allowed in 2-bit flash mode
84+
#if !isFlashInterfacePin(9)
85+
{0, 0, 1<<9, 0, 0, 0, 0, 0},
86+
{0, 0, 1<<10, 0, 0, 0, 0, 0},
87+
#endif
88+
// GPIO 11 not allowed, used for flash
8389
{0, 0, 1<<12, 0, 0, 0, 0, 0},
8490
{0, 0, 1<<13, 0, 0, 0, 0, 0},
8591
{0, 0, 1<<14, 0, 0, 0, 0, 0},
@@ -131,7 +137,7 @@ static void initTimer() {
131137
timerRunning = true;
132138
}
133139

134-
static void deinitTimer() {
140+
static void ICACHE_RAM_ATTR deinitTimer() {
135141
timer1_attachInterrupt(NULL);
136142
timer1_disable();
137143
timer1_isr_init();
@@ -196,7 +202,7 @@ int startWaveform(uint8_t pin, uint32_t timeHighUS, uint32_t timeLowUS, uint32_t
196202
}
197203

198204
// Stops a waveform on a pin
199-
int stopWaveform(uint8_t pin) {
205+
int ICACHE_RAM_ATTR stopWaveform(uint8_t pin) {
200206
// Can't possibly need to stop anything if there is no timer active
201207
if (!timerRunning) {
202208
return false;

doc/Troubleshooting/debugging.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Debug Level
7474
All defines for the different levels starts with ``DEBUG_ESP_``
7575

7676
a full list can be found here in the
77-
`boards.txt <https://github.com/esp8266/Arduino/blob/master/boards.txt#L180>`__
77+
`boards.txt <https://github.com/esp8266/Arduino/blob/master/tools/boards.txt.py#L1045-L1047>`__
7878

7979
Example for own debug messages
8080
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

doc/esp8266wifi/client-class.rst

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ Methods documented for `Client <https://www.arduino.cc/en/Reference/WiFiClientCo
1818

1919
Methods and properties described further down are specific to ESP8266. They are not covered in `Arduino WiFi library <https://www.arduino.cc/en/Reference/WiFi>`__ documentation. Before they are fully documented please refer to information below.
2020

21+
flush and stop
22+
~~~~~~~~~~~~~~
23+
24+
``flush(timeoutMs)`` and ``stop(timeoutMs)`` both have now an optional argument: ``timeout`` in millisecond, and both return a boolean.
25+
26+
Default input value 0 means that effective value is left at the discretion of the implementer.
27+
28+
``flush()`` returning ``true`` indicates that output data have effectively been sent, and ``false`` that a timeout has occurred.
29+
30+
``stop()`` returns ``false`` in case of an issue when closing the client (for instance a timed-out ``flush``). Depending on implementation, its parameter can be passed to ``flush()``.
31+
2132
setNoDelay
2233
~~~~~~~~~~
2334

@@ -35,6 +46,47 @@ This algorithm is intended to reduce TCP/IP traffic of small packets sent over t
3546
3647
client.setNoDelay(true);
3748
49+
getNoDelay
50+
~~~~~~~~~~
51+
52+
Returns whether NoDelay is enabled or not for the current connection.
53+
54+
setSync
55+
~~~~~~~
56+
57+
This is an experimental API that will set the client in synchronized mode.
58+
In this mode, every ``write()`` is flushed. It means that after a call to
59+
``write()``, data are ensured to be received where they went sent to (that is
60+
``flush`` semantic).
61+
62+
When set to ``true`` in ``WiFiClient`` implementation,
63+
64+
- It slows down transfers, and implicitely disable the Nagle algorithm.
65+
66+
- It also allows to avoid a temporary copy of data that otherwise consumes
67+
at most ``TCP_SND_BUF`` = (2 * ``MSS``) bytes per connection,
68+
69+
getSync
70+
~~~~~~~
71+
72+
Returns whether Sync is enabled or not for the current connection.
73+
74+
setDefaultNoDelay and setDefaultSync
75+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76+
77+
These set the default value for both ``setSync`` and ``setNoDelay`` for
78+
every future instance of ``WiFiClient`` (including those coming from
79+
``WiFiServer.available()`` by default).
80+
81+
Default values are false for both ``NoDelay`` and ``Sync``.
82+
83+
This means that Nagle is enabled by default *for all new connections*.
84+
85+
getDefaultNoDelay and getDefaultSync
86+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87+
88+
Return the values to be used as default for NoDelay and Sync for all future connections.
89+
3890
Other Function Calls
3991
~~~~~~~~~~~~~~~~~~~~
4092

@@ -54,7 +106,6 @@ Other Function Calls
54106
uint16_t remotePort ()
55107
IPAddress localIP ()
56108
uint16_t localPort ()
57-
bool getNoDelay ()
58109
59110
Documentation for the above functions is not yet prepared.
60111

doc/esp8266wifi/generic-class.rst

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,46 @@ mode
5555
- ``WiFi.getMode()``: return current Wi-Fi mode (one out of four modes
5656
above)
5757

58+
WiFi power management, DTIM
59+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
60+
61+
.. code:: cpp
62+
63+
bool setSleepMode (WiFiSleepType_t type, int listenInterval=0)
64+
65+
Sleep mode type is ``WIFI_NONE_SLEEP``, ``WIFI_LIGHT_SLEEP`` or ``WIFI_MODEM_SLEEP``.
66+
67+
(``listenInterval`` appeared in esp8266-arduino core v2.5.0 using the last
68+
V2 revision of nonos-sdk before V3)
69+
70+
Quoting nonos-sdk datasheet:
71+
72+
* ``NONE``: disable power saving
73+
74+
* ``LIGHT`` or ``MODEM``: TCP timer rate raised from 250ms to 3s
75+
76+
When ``listenInterval`` is set to 1..10, in ``LIGHT`` or ``MODEM`` mode,
77+
station wakes up every (DTIM-interval * ``listenInterval``). This saves
78+
power but station interface may miss broadcast data.
79+
80+
Otherwise (default value 0), station wakes up at every DTIM-interval
81+
(configured in the access-point).
82+
83+
Quoting wikipedia:
84+
85+
A Delivery Traffic Indication Map (DTIM) is a kind of Traffic Indication Map
86+
(TIM) which informs the clients about the presence of buffered
87+
multicast/broadcast data on the access point. It is generated within the
88+
periodic beacon at a frequency specified by the DTIM Interval. Beacons are
89+
packets sent by an access point to synchronize a wireless network.
90+
91+
5892
Other Function Calls
5993
~~~~~~~~~~~~~~~~~~~~
6094

6195
.. code:: cpp
6296
6397
int32_t channel (void)
64-
bool setSleepMode (WiFiSleepType_t type)
6598
WiFiSleepType_t getSleepMode ()
6699
bool setPhyMode (WiFiPhyMode_t mode)
67100
WiFiPhyMode_t getPhyMode ()
@@ -73,6 +106,11 @@ Other Function Calls
73106
bool forceSleepWake ()
74107
int hostByName (const char *aHostname, IPAddress &aResult)
75108
109+
appeared with SDK pre-V3:
110+
uint8_t getListenInterval ();
111+
bool isSleepLevelMax ();
112+
113+
76114
Documentation for the above functions is not yet prepared.
77115

78116
For code samples please refer to separate section with `examples <generic-examples.rst>`__ dedicated specifically to the Generic Class.

0 commit comments

Comments
 (0)