Skip to content

Commit 336a2dc

Browse files
Merge branch 'master' into pgmspace_to_libc
2 parents f3f233d + ce28a76 commit 336a2dc

Some content is hidden

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

47 files changed

+5021
-4358
lines changed

boards.txt

Lines changed: 4325 additions & 4111 deletions
Large diffs are not rendered by default.

cores/esp8266/Esp-frag.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Esp.cpp - ESP8266-specific APIs
3+
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
4+
This file is part of the esp8266 core for Arduino environment.
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
#include "umm_malloc/umm_malloc.h"
22+
#include "umm_malloc/umm_malloc_cfg.h"
23+
#include "coredecls.h"
24+
#include "Esp.h"
25+
26+
void EspClass::getHeapStats(uint32_t* hfree, uint16_t* hmax, uint8_t* hfrag)
27+
{
28+
// L2 / Euclidian norm of free block sizes.
29+
// Having getFreeHeap()=sum(hole-size), fragmentation is given by
30+
// 100 * (1 - sqrt(sum(hole-size²)) / sum(hole-size))
31+
32+
umm_info(NULL, 0);
33+
uint8_t block_size = umm_block_size();
34+
uint32_t fh = ummHeapInfo.freeBlocks * block_size;
35+
if (hfree)
36+
*hfree = fh;
37+
if (hmax)
38+
*hmax = ummHeapInfo.maxFreeContiguousBlocks * block_size;
39+
if (hfrag)
40+
*hfrag = 100 - (sqrt32(ummHeapInfo.freeSize2) * 100) / fh;
41+
}
42+
43+
uint8_t EspClass::getHeapFragmentation()
44+
{
45+
uint8_t hfrag;
46+
getHeapStats(nullptr, nullptr, &hfrag);
47+
return hfrag;
48+
}

cores/esp8266/Esp.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <memory>
2525
#include "interrupts.h"
2626
#include "MD5Builder.h"
27+
#include "umm_malloc/umm_malloc.h"
2728

2829
extern "C" {
2930
#include "user_interface.h"
@@ -171,6 +172,11 @@ uint32_t EspClass::getFreeHeap(void)
171172
return system_get_free_heap_size();
172173
}
173174

175+
uint16_t EspClass::getMaxFreeBlockSize(void)
176+
{
177+
return umm_max_block_size();
178+
}
179+
174180
uint32_t EspClass::getChipId(void)
175181
{
176182
return system_get_chip_id();

cores/esp8266/Esp.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,13 @@ class EspClass {
103103
void restart();
104104

105105
uint16_t getVcc();
106-
uint32_t getFreeHeap();
107-
108106
uint32_t getChipId();
109107

108+
uint32_t getFreeHeap();
109+
uint16_t getMaxFreeBlockSize();
110+
uint8_t getHeapFragmentation(); // in %
111+
void getHeapStats(uint32_t* free = nullptr, uint16_t* max = nullptr, uint8_t* frag = nullptr);
112+
110113
const char * getSdkVersion();
111114
String getCoreVersion();
112115
String getFullVersion();

cores/esp8266/coredecls.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extern "C" {
88

99
// TODO: put declarations here, get rid of -Wno-implicit-function-declaration
1010

11+
#include <stdint.h>
1112
#include <cont.h> // g_pcont declaration
1213

1314
extern bool timeshift64_is_set;
@@ -18,6 +19,8 @@ void tune_timeshift64 (uint64_t now_us);
1819
void settimeofday_cb (void (*cb)(void));
1920
void disable_extra4k_at_link_time (void) __attribute__((noinline));
2021

22+
uint32_t sqrt32 (uint32_t n);
23+
2124
#ifdef __cplusplus
2225
}
2326
#endif

cores/esp8266/sqrt32.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
#include <coredecls.h>
3+
#include <stdint.h>
4+
5+
uint32_t sqrt32 (uint32_t n)
6+
{
7+
// http://www.codecodex.com/wiki/Calculate_an_integer_square_root#C
8+
// Another very fast algorithm donated by Tristan.Muntsinger@gmail.com
9+
// (note: tested across the full 32 bits range, see comment below)
10+
11+
// 15 iterations (c=1<<15)
12+
13+
unsigned int c = 0x8000;
14+
unsigned int g = 0x8000;
15+
16+
for(;;)
17+
{
18+
if (g*g > n)
19+
g ^= c;
20+
c >>= 1;
21+
if (!c)
22+
return g;
23+
g |= c;
24+
}
25+
}
26+
27+
/*
28+
* tested with:
29+
*
30+
31+
#include <stdio.h>
32+
#include <stdint.h>
33+
#include <math.h>
34+
35+
int main (void)
36+
{
37+
for (uint32_t i = 0; ++i; )
38+
{
39+
uint32_t sr = sqrt32(i);
40+
uint32_t ifsr = sqrt(i);
41+
42+
if (ifsr != sr)
43+
printf("%d: i%d f%d\n", i, sr, ifsr);
44+
45+
if (!(i & 0xffffff))
46+
{
47+
printf("%i%% (0x%08x)\r", ((i >> 16) * 100) >> 16, i);
48+
fflush(stdout);
49+
}
50+
}
51+
52+
printf("\n");
53+
}
54+
55+
*
56+
*/

cores/esp8266/umm_malloc/umm_malloc.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,10 @@ void ICACHE_FLASH_ATTR *umm_info( void *ptr, int force ) {
10241024
if( UMM_NBLOCK(blockNo) & UMM_FREELIST_MASK ) {
10251025
++ummHeapInfo.freeEntries;
10261026
ummHeapInfo.freeBlocks += curBlocks;
1027+
ummHeapInfo.freeSize2 += (unsigned int)curBlocks
1028+
* (unsigned int)sizeof(umm_block)
1029+
* (unsigned int)curBlocks
1030+
* (unsigned int)sizeof(umm_block);
10271031

10281032
if (ummHeapInfo.maxFreeContiguousBlocks < curBlocks) {
10291033
ummHeapInfo.maxFreeContiguousBlocks = curBlocks;
@@ -1761,4 +1765,13 @@ size_t ICACHE_FLASH_ATTR umm_free_heap_size( void ) {
17611765
return (size_t)ummHeapInfo.freeBlocks * sizeof(umm_block);
17621766
}
17631767

1768+
size_t ICACHE_FLASH_ATTR umm_max_block_size( void ) {
1769+
umm_info(NULL, 0);
1770+
return ummHeapInfo.maxFreeContiguousBlocks * sizeof(umm_block);
1771+
}
1772+
1773+
size_t ICACHE_FLASH_ATTR umm_block_size( void ) {
1774+
return sizeof(umm_block);
1775+
}
1776+
17641777
/* ------------------------------------------------------------------------ */

cores/esp8266/umm_malloc/umm_malloc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ typedef struct UMM_HEAP_INFO_t {
2626
unsigned short int freeBlocks;
2727

2828
unsigned short int maxFreeContiguousBlocks;
29+
30+
unsigned int freeSize2;
2931
}
3032
UMM_HEAP_INFO;
3133

@@ -41,6 +43,8 @@ void *umm_realloc( void *ptr, size_t size );
4143
void umm_free( void *ptr );
4244

4345
size_t umm_free_heap_size( void );
46+
size_t umm_max_block_size( void );
47+
size_t umm_block_size( void );
4448

4549
#ifdef __cplusplus
4650
}

doc/esp8266wifi/generic-class.rst

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ onEvent
1010

1111
.. code:: cpp
1212
13-
void onEvent (WiFiEventCb cb, WiFiEvent_t event=WIFI_EVENT_ANY) __attribute__((deprecated))
13+
void onEvent (WiFiEventCb cb, WiFiEvent_t event=WIFI_EVENT_ANY) __attribute__((deprecated))
1414
1515
To see how to use ``onEvent`` please check example sketch `WiFiClientEvents.ino <https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/WiFiClientEvents/WiFiClientEvents.ino>`__ available inside examples folder of the ESP8266WiFi library.
1616

@@ -19,13 +19,13 @@ WiFiEventHandler
1919

2020
.. code:: cpp
2121
22-
WiFiEventHandler onStationModeConnected (std::function< void(const WiFiEventStationModeConnected &)>)
23-
WiFiEventHandler onStationModeDisconnected (std::function< void(const WiFiEventStationModeDisconnected &)>)
24-
WiFiEventHandler onStationModeAuthModeChanged (std::function< void(const WiFiEventStationModeAuthModeChanged &)>)
25-
WiFiEventHandler onStationModeGotIP (std::function< void(const WiFiEventStationModeGotIP &)>)
26-
WiFiEventHandler onStationModeDHCPTimeout (std::function< void(void)>)
27-
WiFiEventHandler onSoftAPModeStationConnected (std::function< void(const WiFiEventSoftAPModeStationConnected &)>)
28-
WiFiEventHandler onSoftAPModeStationDisconnected (std::function< void(const WiFiEventSoftAPModeStationDisconnected &)>)
22+
WiFiEventHandler onStationModeConnected (std::function< void(const WiFiEventStationModeConnected &)>)
23+
WiFiEventHandler onStationModeDisconnected (std::function< void(const WiFiEventStationModeDisconnected &)>)
24+
WiFiEventHandler onStationModeAuthModeChanged (std::function< void(const WiFiEventStationModeAuthModeChanged &)>)
25+
WiFiEventHandler onStationModeGotIP (std::function< void(const WiFiEventStationModeGotIP &)>)
26+
WiFiEventHandler onStationModeDHCPTimeout (std::function< void(void)>)
27+
WiFiEventHandler onSoftAPModeStationConnected (std::function< void(const WiFiEventSoftAPModeStationConnected &)>)
28+
WiFiEventHandler onSoftAPModeStationDisconnected (std::function< void(const WiFiEventSoftAPModeStationDisconnected &)>)
2929
3030
To see a sample application with ``WiFiEventHandler``, please check separate section with `examples :arrow\_right: <generic-examples.rst>`__ dedicated specifically to the Generic Class..
3131

@@ -34,25 +34,21 @@ persistent
3434

3535
.. code:: cpp
3636
37-
WiFi.persistent (persistent)
37+
WiFi.persistent(persistent)
3838
39-
Module is able to reconnect to last used Wi-Fi network on power up or reset basing on settings stored in specific sectors of flash memory. By default these settings are written to flash each time they are used in functions like ``WiFi.begin(ssid, password)``. This happens no matter if SSID or password has been actually changed.
39+
ESP8266 is able to reconnect to the last used Wi-Fi network or establishes the same Access Point upon power up or reset.
40+
By default, these settings are written to specific sectors of flash memory every time they are changed in ``WiFi.begin(ssid, passphrase)`` or ``WiFi.softAP(ssid, passphrase, channel)``, and when ``WiFi.disconnect`` or ``WiFi.softAPdisconnect`` is invoked.
41+
Frequently calling these functions could cause wear on the flash memory (see issue `#1054 <https://github.com/esp8266/Arduino/issues/1054>`__).
4042

41-
This might result in some wear of flash memory depending on how often such functions are called.
42-
43-
Setting ``persistent`` to ``false`` will get SSID / password written to flash only if currently used values do not match what is already stored in flash.
44-
45-
Please note that functions ``WiFi.disconnect`` or ``WiFi.softAPdisconnect`` reset currently used SSID / password. If ``persistent`` is set to ``false``, then using these functions will not affect SSID / password stored in flash.
46-
47-
To learn more about this functionality, and why it has been introduced, check issue report `#1054 <https://github.com/esp8266/Arduino/issues/1054>`__.
43+
Once ``WiFi.persistent(false)`` is called, ``WiFi.begin``, ``WiFi.disconnect``, ``WiFi.softAP``, or ``WiFi.softAPdisconnect`` only changes the current in-memory Wi-Fi settings, and does not affect the Wi-Fi settings stored in flash memory.
4844

4945
mode
5046
~~~~
5147

5248
.. code:: cpp
5349
54-
WiFi.mode(m)
55-
WiFi.getMode()
50+
WiFi.mode(m)
51+
WiFi.getMode()
5652
5753
- ``WiFi.mode(m)``: set mode to ``WIFI_AP``, ``WIFI_STA``,
5854
``WIFI_AP_STA`` or ``WIFI_OFF``
@@ -64,17 +60,17 @@ Other Function Calls
6460

6561
.. code:: cpp
6662
67-
int32_t channel (void)
68-
bool setSleepMode (WiFiSleepType_t type)
69-
WiFiSleepType_t getSleepMode ()
70-
bool setPhyMode (WiFiPhyMode_t mode)
71-
WiFiPhyMode_t getPhyMode ()
72-
void setOutputPower (float dBm)
73-
WiFiMode_t getMode ()
74-
bool enableSTA (bool enable)
75-
bool enableAP (bool enable)
76-
bool forceSleepBegin (uint32 sleepUs=0)
77-
bool forceSleepWake ()
63+
int32_t channel (void)
64+
bool setSleepMode (WiFiSleepType_t type)
65+
WiFiSleepType_t getSleepMode ()
66+
bool setPhyMode (WiFiPhyMode_t mode)
67+
WiFiPhyMode_t getPhyMode ()
68+
void setOutputPower (float dBm)
69+
WiFiMode_t getMode ()
70+
bool enableSTA (bool enable)
71+
bool enableAP (bool enable)
72+
bool forceSleepBegin (uint32 sleepUs=0)
73+
bool forceSleepWake ()
7874
int hostByName (const char *aHostname, IPAddress &aResult)
7975
8076
Documentation for the above functions is not yet prepared.

doc/esp8266wifi/readme.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Soft Access Point
125125
~~~~~~~~~~~~~~~~~
126126

127127
An `access point (AP) <https://en.wikipedia.org/wiki/Wireless_access_point>`__ is a device that provides access to Wi-Fi network to other devices (stations)
128-
and connects them further to a wired network. ESP8266 can provide similar functionality except it does not have interface to a wired network. Such mode of operation is called soft access point (soft-AP). The maximum number of stations connected to the soft-AP is five.
128+
and connects them further to a wired network. ESP8266 can provide similar functionality except it does not have interface to a wired network. Such mode of operation is called soft access point (soft-AP). The maximum number of stations that can simultaneously be connected to the soft-AP can be set `from 1 to 8 <https://bbs.espressif.com/viewtopic.php?f=46&t=481&p=1832&hilit=max_connection#p1832>`__, but defaults to 4.
129129

130130
.. figure:: pictures/esp8266-soft-access-point.png
131131
:alt: ESP8266 operating in the Soft Access Point mode

doc/esp8266wifi/soft-access-point-class.rst

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,24 @@ To set up password protected network, or to configure additional network paramet
4444

4545
.. code:: cpp
4646
47-
WiFi.softAP(ssid, password, channel, hidden)
47+
WiFi.softAP(ssid, password, channel, hidden, max_connection)
4848
49-
The first parameter of this function is required, remaining three are optional.
49+
The first parameter of this function is required, remaining four are optional.
5050

51-
Meaning of all parameters is as follows: - ``ssid`` - character string containing network SSID (max. 63 characters) \* ``password`` - optional character string with a password. For WPA2-PSK network it should be at least 8 character long. If not specified, the access point will be open for anybody to connect. \* ``channel`` - optional parameter to set Wi-Fi channel, from 1 to 13. Default channel = 1. \* ``hidden`` - optional parameter, if set to ``true`` will hide SSID
51+
Meaning of all parameters is as follows:
52+
53+
- ``ssid`` - character string containing network SSID (max. 63 characters)
54+
- ``password`` - optional character string with a password. For WPA2-PSK network it should be at least 8 character long. If not specified, the access point will be open for anybody to connect.
55+
- ``channel`` - optional parameter to set Wi-Fi channel, from 1 to 13. Default channel = 1.
56+
- ``hidden`` - optional parameter, if set to ``true`` will hide SSID.
57+
- ``max_connection`` - optional parameter to set max simultaneous connected stations, `from 1 to 8 <https://bbs.espressif.com/viewtopic.php?f=46&t=481&p=1832&hilit=max_connection#p1832>`__. Defaults to 4. Once the max number has been reached, any other station that wants to connect will be forced to wait until an already connected station disconnects.
5258

5359
Function will return ``true`` or ``false`` depending on result of setting the soft-AP.
5460

55-
Notes: \* The network established by softAP will have default IP address of 192.168.4.1. This address may be changed using ``softAPConfig`` (see below). \* Even though ESP8266 can operate in soft-AP + station mode, it actually has only one hardware channel. Therefore in soft-AP + station mode, the soft-AP channel will default to the number used by station. For more information how this may affect operation of stations connected to ESP8266's soft-AP, please check `this FAQ entry <http://bbs.espressif.com/viewtopic.php?f=10&t=324>`__ on Espressif forum.
61+
Notes:
62+
63+
- The network established by softAP will have default IP address of 192.168.4.1. This address may be changed using ``softAPConfig`` (see below).
64+
- Even though ESP8266 can operate in soft-AP + station mode, it actually has only one hardware channel. Therefore in soft-AP + station mode, the soft-AP channel will default to the number used by station. For more information how this may affect operation of stations connected to ESP8266's soft-AP, please check `this FAQ entry <http://bbs.espressif.com/viewtopic.php?f=10&t=324>`__ on Espressif forum.
5665

5766
softAPConfig
5867
^^^^^^^^^^^^
@@ -63,10 +72,11 @@ Configure the soft access point's network interface.
6372
6473
softAPConfig (local_ip, gateway, subnet)
6574
66-
| All parameters are the type of ``IPAddress`` and defined as follows:
67-
\* ``local_ip`` - IP address of the soft access point \* ``gateway`` -
68-
gateway IP address
69-
| \* ``subnet`` - subnet mask
75+
All parameters are the type of ``IPAddress`` and defined as follows:
76+
77+
- ``local_ip`` - IP address of the soft access point
78+
- ``gateway`` - gateway IP address
79+
- ``subnet`` - subnet mask
7080

7181
Function will return ``true`` or ``false`` depending on result of changing the configuration.
7282

@@ -131,7 +141,7 @@ Get the count of the stations that are connected to the soft-AP interface.
131141

132142
Stations connected to soft-AP = 2
133143

134-
Note: the maximum number of stations that may be connected to ESP8266 soft-AP is five.
144+
Note: the maximum number of stations that may be connected to ESP8266 soft-AP is 4 by default. This can be changed from 1 to 8 via the ``max_connection`` argument of the softAP method.
135145

136146
softAPdisconnect
137147
^^^^^^^^^^^^^^^^

doc/faq/a02-my-esp-crashes.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,12 @@ Memory, memory, memory
291291
rely on exceptions for error handling, which is not available for the ESP, and in any
292292
case there is no access to the underlying code.
293293

294-
Instrumenting the code with the OOM debug option and calls to ``ESP.getFreeHeap()`` will
295-
help the process of finding leaks. Now is time to re-read about the
296-
`exception decoder <#exception-decoder>`__.
294+
Instrumenting the code with the OOM debug option and calls to
295+
``ESP.getFreeHeap()`` / ``ESP.getHeapFragmentation()`` /
296+
``ESP.getMaxFreeBlockSize()`` will help the process of finding memory issues.
297+
298+
Now is time to re-read about the `exception decoder
299+
<#exception-decoder>`__.
297300

298301

299302
*Some techniques for reducing memory usage*

doc/faq/a05-board-generator.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ It needs to be run from the root directory,
3434
C:\...> python tools\boards.txt.py
3535

3636
Running without parameters will show the command line help. They are
37-
generally self-explanatory.
37+
generally self-explanatory. Running with the parameters will show no output but will generate a new boards.txt file (and a backup boards.txt.orig).
38+
39+
The core root directory varies depending on your development environment. In Windows, core root is found under your home directory; for Arduino it is in AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\ for PlatformIO it is in .platformio\packages\framework-arduinoespressif8266.
3840

3941

4042
What can I do with it ?

doc/faq/readme.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ required to enable it:
6565

6666
`Read more <a05-board-generator.rst>`__.
6767

68+
For platformIO (and maybe other build environments), you will also need to add the build flag: -D NO_EXTRA_4K_HEAP
69+
6870
This manual selection is not needed starting from 2.5.0 (and in git
6971
version). WPS is always available, and not using it will give an extra
7072
~4.5KB compared to releases until 2.4.1 included.

0 commit comments

Comments
 (0)