Skip to content

Commit 934ab80

Browse files
committed
Merge remote-tracking branch 'origin/master' into secure-connected-means-read-and-write
2 parents 8e8cbd2 + 15e7d35 commit 934ab80

File tree

167 files changed

+3846
-2941
lines changed

Some content is hidden

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

167 files changed

+3846
-2941
lines changed

boards.txt

Lines changed: 339 additions & 549 deletions
Large diffs are not rendered by default.

cores/esp8266/Arduino.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ void attachInterrupt(uint8_t pin, void (*)(void), int mode);
186186
void detachInterrupt(uint8_t pin);
187187
void attachInterruptArg(uint8_t pin, void (*)(void*), void* arg, int mode);
188188

189+
#if FLASH_MAP_SUPPORT
190+
#include "flash_hal.h"
191+
#endif
189192
void preinit(void);
190193
void setup(void);
191194
void loop(void);
@@ -279,6 +282,8 @@ inline void configTzTime(const char* tz, const char* server1,
279282
configTime(tz, server1, server2, server3);
280283
}
281284

285+
bool getLocalTime(struct tm * info, uint32_t ms = 5000);
286+
282287
// Everything we expect to be implicitly loaded for the sketch
283288
#include <pgmspace.h>
284289

cores/esp8266/Esp-frag.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,18 @@
2323
#include "coredecls.h"
2424
#include "Esp.h"
2525

26-
void EspClass::getHeapStats(uint32_t* hfree, uint16_t* hmax, uint8_t* hfrag)
26+
void EspClass::getHeapStats(uint32_t* hfree, uint32_t* hmax, uint8_t* hfrag)
2727
{
2828
// L2 / Euclidean norm of free block sizes.
2929
// Having getFreeHeap()=sum(hole-size), fragmentation is given by
3030
// 100 * (1 - sqrt(sum(hole-size²)) / sum(hole-size))
31-
3231
umm_info(NULL, false);
3332

3433
uint32_t free_size = umm_free_heap_size_core(umm_get_current_heap());
3534
if (hfree)
3635
*hfree = free_size;
3736
if (hmax)
38-
*hmax = (uint16_t)umm_max_block_size_core(umm_get_current_heap());
37+
*hmax = umm_max_block_size_core(umm_get_current_heap());
3938
if (hfrag) {
4039
if (free_size) {
4140
*hfrag = umm_fragmentation_metric_core(umm_get_current_heap());
@@ -45,6 +44,18 @@ void EspClass::getHeapStats(uint32_t* hfree, uint16_t* hmax, uint8_t* hfrag)
4544
}
4645
}
4746

47+
void EspClass::getHeapStats(uint32_t* hfree, uint16_t* hmax, uint8_t* hfrag)
48+
{
49+
uint32_t hmax32;
50+
getHeapStats(hfree, &hmax32, hfrag);
51+
if (hmax) {
52+
// With the MMU_EXTERNAL_HEAP option, hmax could overflow for heaps larger
53+
// then 64KB. return UINT16_MAX (saturation) for those cases.
54+
// Added deprecated attribute and message.
55+
*hmax = (hmax32 > UINT16_MAX) ? UINT16_MAX : hmax32;
56+
}
57+
}
58+
4859
uint8_t EspClass::getHeapFragmentation()
4960
{
5061
return (uint8_t)umm_fragmentation_metric();

cores/esp8266/Esp.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "MD5Builder.h"
2727
#include "umm_malloc/umm_malloc.h"
2828
#include "cont.h"
29-
29+
#include "flash_hal.h"
3030
#include "coredecls.h"
3131
#include "umm_malloc/umm_malloc.h"
3232
#include <pgmspace.h>
@@ -115,20 +115,18 @@ void EspClass::wdtFeed(void)
115115
system_soft_wdt_feed();
116116
}
117117

118-
extern "C" void esp_yield();
119-
120118
void EspClass::deepSleep(uint64_t time_us, WakeMode mode)
121119
{
122120
system_deep_sleep_set_option(static_cast<int>(mode));
123121
system_deep_sleep(time_us);
124-
esp_yield();
122+
esp_suspend();
125123
}
126124

127125
void EspClass::deepSleepInstant(uint64_t time_us, WakeMode mode)
128126
{
129127
system_deep_sleep_set_option(static_cast<int>(mode));
130128
system_deep_sleep_instant(time_us);
131-
esp_yield();
129+
esp_suspend();
132130
}
133131

134132
//this calculation was taken verbatim from the SDK api reference for SDK 2.1.0.
@@ -200,7 +198,7 @@ void EspClass::reset(void)
200198
void EspClass::restart(void)
201199
{
202200
system_restart();
203-
esp_yield();
201+
esp_suspend();
204202
}
205203

206204
[[noreturn]] void EspClass::rebootIntoUartDownloadMode()
@@ -224,7 +222,7 @@ uint32_t EspClass::getFreeHeap(void)
224222
return system_get_free_heap_size();
225223
}
226224

227-
uint16_t EspClass::getMaxFreeBlockSize(void)
225+
uint32_t EspClass::getMaxFreeBlockSize(void)
228226
{
229227
return umm_max_block_size();
230228
}
@@ -293,13 +291,17 @@ uint32_t EspClass::getFlashChipRealSize(void)
293291

294292
uint32_t EspClass::getFlashChipSize(void)
295293
{
294+
#if FLASH_MAP_SUPPORT
295+
return getFlashChipRealSize();
296+
#else
296297
uint32_t data;
297298
uint8_t * bytes = (uint8_t *) &data;
298299
// read first 4 byte (magic byte + flash config)
299300
if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
300301
return magicFlashChipSize((bytes[3] & 0xf0) >> 4);
301302
}
302303
return 0;
304+
#endif
303305
}
304306

305307
uint32_t EspClass::getFlashChipSpeed(void)
@@ -325,6 +327,7 @@ FlashMode_t EspClass::getFlashChipMode(void)
325327
return mode;
326328
}
327329

330+
#if !FLASH_MAP_SUPPORT
328331
uint32_t EspClass::magicFlashChipSize(uint8_t byte) {
329332
switch(byte & 0x0F) {
330333
case 0x0: // 4 Mbit (512KB)
@@ -345,6 +348,7 @@ uint32_t EspClass::magicFlashChipSize(uint8_t byte) {
345348
return 0;
346349
}
347350
}
351+
#endif
348352

349353
uint32_t EspClass::magicFlashChipSpeed(uint8_t byte) {
350354
switch(byte & 0x0F) {
@@ -614,14 +618,12 @@ uint32_t EspClass::getSketchSize() {
614618
return result;
615619
}
616620

617-
extern "C" uint32_t _FS_start;
618-
619621
uint32_t EspClass::getFreeSketchSpace() {
620622

621623
uint32_t usedSize = getSketchSize();
622624
// round one sector up
623625
uint32_t freeSpaceStart = (usedSize + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
624-
uint32_t freeSpaceEnd = (uint32_t)&_FS_start - 0x40200000;
626+
uint32_t freeSpaceEnd = (uint32_t)FS_start - 0x40200000;
625627

626628
#ifdef DEBUG_SERIAL
627629
DEBUG_SERIAL.printf("usedSize=%u freeSpaceStart=%u freeSpaceEnd=%u\r\n", usedSize, freeSpaceStart, freeSpaceEnd);

cores/esp8266/Esp.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ class EspClass {
114114
static uint32_t getChipId();
115115

116116
static uint32_t getFreeHeap();
117-
static uint16_t getMaxFreeBlockSize();
117+
static uint32_t getMaxFreeBlockSize();
118118
static uint8_t getHeapFragmentation(); // in %
119-
static void getHeapStats(uint32_t* free = nullptr, uint16_t* max = nullptr, uint8_t* frag = nullptr);
119+
static void getHeapStats(uint32_t* free = nullptr, uint16_t* max = nullptr, uint8_t* frag = nullptr) __attribute__((deprecated("Use 'uint32_t*' on max, 2nd argument")));
120+
static void getHeapStats(uint32_t* free = nullptr, uint32_t* max = nullptr, uint8_t* frag = nullptr);
120121

121122
static uint32_t getFreeContStack();
122123
static void resetFreeContStack();

cores/esp8266/FS.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ class File : public Stream
118118
time_t getCreationTime();
119119
void setTimeCallback(time_t (*cb)(void));
120120

121+
// Stream::send configuration
122+
123+
bool inputCanTimeout () override {
124+
// unavailable data can't become later available
125+
return false;
126+
}
127+
128+
bool outputCanTimeout () override {
129+
// free space for write can't increase later
130+
return false;
131+
}
132+
121133
protected:
122134
FileImplPtr _p;
123135
time_t (*_timeCallback)(void) = nullptr;

cores/esp8266/FlashMap.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
// - do not edit - autogenerated by boards.txt.py
3+
4+
#ifndef __FLASH_MAP_H
5+
#define __FLASH_MAP_H
6+
7+
#include <stdint.h>
8+
#include <stddef.h>
9+
10+
typedef struct
11+
{
12+
uint32_t eeprom_start;
13+
uint32_t fs_start;
14+
uint32_t fs_end;
15+
uint32_t fs_block_size;
16+
uint32_t fs_page_size;
17+
uint32_t flash_size_kb;
18+
} flash_map_s;
19+
20+
/*
21+
Following definitions map the above structure, one per line.
22+
FLASH_MAP_* is a user choice in sketch:
23+
`FLASH_MAP_SETUP_CONFIG(FLASH_MAP_OTA_FS)`
24+
Configuration is made at boot with detected flash chip size (last argument 512..16384)
25+
Other values are defined from `tools/boards.txt.py`.
26+
*/
27+
28+
#define FLASH_MAP_OTA_FS \
29+
{ \
30+
{ .eeprom_start = 0x402fb000, .fs_start = 0x402eb000, .fs_end = 0x402fb000, .fs_block_size = 0x1000, .fs_page_size = 0x100, .flash_size_kb = 1024 }, \
31+
{ .eeprom_start = 0x403fb000, .fs_start = 0x403c0000, .fs_end = 0x403fb000, .fs_block_size = 0x1000, .fs_page_size = 0x100, .flash_size_kb = 2048 }, \
32+
{ .eeprom_start = 0x405fb000, .fs_start = 0x40400000, .fs_end = 0x405fa000, .fs_block_size = 0x2000, .fs_page_size = 0x100, .flash_size_kb = 4096 }, \
33+
{ .eeprom_start = 0x409fb000, .fs_start = 0x40400000, .fs_end = 0x409fa000, .fs_block_size = 0x2000, .fs_page_size = 0x100, .flash_size_kb = 8192 }, \
34+
{ .eeprom_start = 0x411fb000, .fs_start = 0x40400000, .fs_end = 0x411fa000, .fs_block_size = 0x2000, .fs_page_size = 0x100, .flash_size_kb = 16384 }, \
35+
{ .eeprom_start = 0x4027b000, .fs_start = 0x40273000, .fs_end = 0x4027b000, .fs_block_size = 0x1000, .fs_page_size = 0x100, .flash_size_kb = 512 }, \
36+
}
37+
38+
#define FLASH_MAP_MAX_FS \
39+
{ \
40+
{ .eeprom_start = 0x402fb000, .fs_start = 0x4027b000, .fs_end = 0x402fb000, .fs_block_size = 0x2000, .fs_page_size = 0x100, .flash_size_kb = 1024 }, \
41+
{ .eeprom_start = 0x403fb000, .fs_start = 0x40300000, .fs_end = 0x403fa000, .fs_block_size = 0x2000, .fs_page_size = 0x100, .flash_size_kb = 2048 }, \
42+
{ .eeprom_start = 0x405fb000, .fs_start = 0x40300000, .fs_end = 0x405fa000, .fs_block_size = 0x2000, .fs_page_size = 0x100, .flash_size_kb = 4096 }, \
43+
{ .eeprom_start = 0x409fb000, .fs_start = 0x40300000, .fs_end = 0x409fa000, .fs_block_size = 0x2000, .fs_page_size = 0x100, .flash_size_kb = 8192 }, \
44+
{ .eeprom_start = 0x411fb000, .fs_start = 0x40300000, .fs_end = 0x411fa000, .fs_block_size = 0x2000, .fs_page_size = 0x100, .flash_size_kb = 16384 }, \
45+
{ .eeprom_start = 0x4027b000, .fs_start = 0x4025b000, .fs_end = 0x4027b000, .fs_block_size = 0x1000, .fs_page_size = 0x100, .flash_size_kb = 512 }, \
46+
}
47+
48+
#define FLASH_MAP_NO_FS \
49+
{ \
50+
{ .eeprom_start = 0x402fb000, .fs_start = 0x402fb000, .fs_end = 0x402fb000, .fs_block_size = 0x0, .fs_page_size = 0x0, .flash_size_kb = 1024 }, \
51+
{ .eeprom_start = 0x403fb000, .fs_start = 0x403fb000, .fs_end = 0x403fb000, .fs_block_size = 0x0, .fs_page_size = 0x0, .flash_size_kb = 2048 }, \
52+
{ .eeprom_start = 0x405fb000, .fs_start = 0x405fb000, .fs_end = 0x405fb000, .fs_block_size = 0x0, .fs_page_size = 0x0, .flash_size_kb = 4096 }, \
53+
{ .eeprom_start = 0x409fb000, .fs_start = 0x409fb000, .fs_end = 0x409fb000, .fs_block_size = 0x0, .fs_page_size = 0x0, .flash_size_kb = 8192 }, \
54+
{ .eeprom_start = 0x411fb000, .fs_start = 0x411fb000, .fs_end = 0x411fb000, .fs_block_size = 0x0, .fs_page_size = 0x0, .flash_size_kb = 16384 }, \
55+
{ .eeprom_start = 0x4027b000, .fs_start = 0x4027b000, .fs_end = 0x4027b000, .fs_block_size = 0x0, .fs_page_size = 0x0, .flash_size_kb = 512 }, \
56+
}
57+
58+
#endif // __FLASH_MAP_H
59+

cores/esp8266/HardwareSerial.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ unsigned long HardwareSerial::detectBaudrate(time_t timeoutMillis)
143143
if ((detectedBaudrate = testBaudrate())) {
144144
break;
145145
}
146-
delay(100);
146+
esp_delay(100);
147147
}
148148
return detectedBaudrate;
149149
}

cores/esp8266/LwipIntfDev.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class LwipIntfDev: public LwipIntf, public RawDev
6666

6767
void setDefault();
6868

69+
// true if interface has a valid IPv4 address
6970
bool connected()
7071
{
7172
return !!ip4_addr_get_u32(ip_2_ip4(&_netif.ip_addr));
@@ -305,8 +306,10 @@ void LwipIntfDev<RawDev>::netif_status_callback()
305306
{
306307
if (connected())
307308
{
308-
if (_default)
309+
if (_default || (netif_default == nullptr && !ip_addr_isany(&_netif.gw)))
309310
{
311+
// on user request,
312+
// or if there is no current default interface, but a gateway is valid
310313
netif_set_default(&_netif);
311314
}
312315
sntp_stop();

cores/esp8266/PolledTimeout.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <limits> // std::numeric_limits
2828
#include <type_traits> // std::is_unsigned
2929
#include <core_esp8266_features.h>
30+
#include <coredecls.h>
3031

3132
namespace esp8266
3233
{
@@ -45,7 +46,7 @@ struct DoNothing
4546

4647
struct YieldOrSkip
4748
{
48-
static void execute() {delay(0);}
49+
static void execute() {esp_yield();}
4950
};
5051

5152
template <unsigned long delayMs>

cores/esp8266/Schedule.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ bool schedule_recurrent_function_us(const std::function<bool(void)>& fn,
135135

136136
void run_scheduled_functions()
137137
{
138-
esp8266::polledTimeout::periodicFastMs yieldNow(100); // yield every 100ms
139-
140138
// prevent scheduling of new functions during this run
141139
auto stop = sLast;
142140
bool done = false;
@@ -161,13 +159,10 @@ void run_scheduled_functions()
161159
recycle_fn_unsafe(to_recycle);
162160
}
163161

164-
if (yieldNow)
165-
{
166-
// because scheduled functions might last too long for watchdog etc,
167-
// this is yield() in cont stack:
168-
esp_schedule();
169-
cont_yield(g_pcont);
170-
}
162+
// scheduled functions might last too long for watchdog etc.
163+
// yield() is allowed in scheduled functions, therefore
164+
// recursion into run_scheduled_recurrent_functions() is permitted
165+
optimistic_yield(100000);
171166
}
172167
}
173168

@@ -241,9 +236,10 @@ void run_scheduled_recurrent_functions()
241236
if (yieldNow)
242237
{
243238
// because scheduled functions might last too long for watchdog etc,
244-
// this is yield() in cont stack:
239+
// this is yield() in cont stack, but need to call cont_suspend directly
240+
// to prevent recursion into run_scheduled_recurrent_functions()
245241
esp_schedule();
246-
cont_yield(g_pcont);
242+
cont_suspend(g_pcont);
247243
}
248244
} while (current && !done);
249245

cores/esp8266/Stream.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ int Stream::read (uint8_t* buffer, size_t maxLen)
274274
int c = read();
275275
if (c == -1)
276276
break;
277-
buffer[nbread++] = read();
277+
buffer[nbread++] = c;
278278
}
279279
return nbread;
280280
}

cores/esp8266/Stream.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class Stream: public Print {
6161
virtual int peek() = 0;
6262

6363
Stream() {}
64+
virtual ~Stream() {}
6465

6566
// parsing methods
6667

cores/esp8266/StreamDev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class StreamConstPtr: public StreamNull
160160
size_t _peekPointer = 0;
161161

162162
public:
163+
StreamConstPtr(const String&& string) = delete; // prevents passing String temporary, use ctor(buffer,size) if you know what you are doing
163164
StreamConstPtr(const String& string): _buffer(string.c_str()), _size(string.length()), _byteAddressable(true) { }
164165
StreamConstPtr(const char* buffer, size_t size): _buffer(buffer), _size(size), _byteAddressable(__byteAddressable(buffer)) { }
165166
StreamConstPtr(const uint8_t* buffer, size_t size): _buffer((const char*)buffer), _size(size), _byteAddressable(__byteAddressable(buffer)) { }

cores/esp8266/StreamSend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ Stream& operator << (Stream& out, Stream& stream)
341341

342342
Stream& operator << (Stream& out, const char* text)
343343
{
344-
StreamConstPtr(text).sendAll(out);
344+
StreamConstPtr(text, strlen_P(text)).sendAll(out);
345345
return out;
346346
}
347347

cores/esp8266/StreamString.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#define __STREAMSTRING_H
2525

2626
#include <limits>
27+
#include <algorithm>
28+
#include "Stream.h"
2729
#include "WString.h"
2830

2931
///////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)