Skip to content

Commit e67e830

Browse files
committed
Merge branch 'master' into ethernet
2 parents 823a245 + 35d22ed commit e67e830

Some content is hidden

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

50 files changed

+348
-12169
lines changed

bootloaders/eboot/eboot.elf

84 Bytes
Binary file not shown.

cores/esp8266/Esp.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -984,15 +984,20 @@ void EspClass::enableVM()
984984
void EspClass::setExternalHeap()
985985
{
986986
#ifdef UMM_HEAP_EXTERNAL
987-
if (vmEnabled)
988-
umm_push_heap(UMM_HEAP_EXTERNAL);
987+
if (vmEnabled) {
988+
if (!umm_push_heap(UMM_HEAP_EXTERNAL)) {
989+
panic();
990+
}
991+
}
989992
#endif
990993
}
991994

992995
void EspClass::setIramHeap()
993996
{
994997
#ifdef UMM_HEAP_IRAM
995-
umm_push_heap(UMM_HEAP_IRAM);
998+
if (!umm_push_heap(UMM_HEAP_IRAM)) {
999+
panic();
1000+
}
9961001
#endif
9971002
}
9981003

cores/esp8266/Esp.h

+31
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,41 @@ class EspClass {
215215
#else
216216
uint32_t getCycleCount();
217217
#endif // !defined(CORE_MOCK)
218+
/**
219+
* @brief Installs VM exception handler to support External memory (Experimental)
220+
*
221+
* @param none
222+
* @return none
223+
*/
218224
void enableVM();
225+
/**
226+
* @brief Push current Heap selection and set Heap selection to DRAM.
227+
*
228+
* @param none
229+
* @return none
230+
*/
219231
void setDramHeap();
232+
/**
233+
* @brief Push current Heap selection and set Heap selection to IRAM.
234+
*
235+
* @param none
236+
* @return none
237+
*/
220238
void setIramHeap();
239+
/**
240+
* @brief Push current Heap selection and set Heap selection to External. (Experimental)
241+
*
242+
* @param none
243+
* @return none
244+
*/
221245
void setExternalHeap();
246+
/**
247+
* @brief Restores Heap selection back to value present when
248+
* setDramHeap, setIramHeap, or setExternalHeap was called.
249+
*
250+
* @param none
251+
* @return none
252+
*/
222253
void resetHeap();
223254
private:
224255
#ifdef UMM_HEAP_EXTERNAL

cores/esp8266/FS.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ void File::setTimeCallback(time_t (*cb)(void)) {
206206
if (!_p)
207207
return;
208208
_p->setTimeCallback(cb);
209+
_timeCallback = cb;
209210
}
210211

211212
File Dir::openFile(const char* mode) {
@@ -221,7 +222,7 @@ File Dir::openFile(const char* mode) {
221222
}
222223

223224
File f(_impl->openFile(om, am), _baseFS);
224-
f.setTimeCallback(timeCallback);
225+
f.setTimeCallback(_timeCallback);
225226
return f;
226227
}
227228

@@ -287,7 +288,7 @@ void Dir::setTimeCallback(time_t (*cb)(void)) {
287288
if (!_impl)
288289
return;
289290
_impl->setTimeCallback(cb);
290-
timeCallback = cb;
291+
_timeCallback = cb;
291292
}
292293

293294

@@ -304,7 +305,7 @@ bool FS::begin() {
304305
DEBUGV("#error: FS: no implementation");
305306
return false;
306307
}
307-
_impl->setTimeCallback(timeCallback);
308+
_impl->setTimeCallback(_timeCallback);
308309
bool ret = _impl->begin();
309310
DEBUGV("%s\n", ret? "": "#error: FS could not start");
310311
return ret;
@@ -367,7 +368,7 @@ File FS::open(const char* path, const char* mode) {
367368
return File();
368369
}
369370
File f(_impl->open(path, om, am), this);
370-
f.setTimeCallback(timeCallback);
371+
f.setTimeCallback(_timeCallback);
371372
return f;
372373
}
373374

@@ -388,7 +389,7 @@ Dir FS::openDir(const char* path) {
388389
}
389390
DirImplPtr p = _impl->openDir(path);
390391
Dir d(p, this);
391-
d.setTimeCallback(timeCallback);
392+
d.setTimeCallback(_timeCallback);
392393
return d;
393394
}
394395

@@ -444,6 +445,7 @@ void FS::setTimeCallback(time_t (*cb)(void)) {
444445
if (!_impl)
445446
return;
446447
_impl->setTimeCallback(cb);
448+
_timeCallback = cb;
447449
}
448450

449451

cores/esp8266/FS.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class File : public Stream
118118

119119
protected:
120120
FileImplPtr _p;
121+
time_t (*_timeCallback)(void) = nullptr;
121122

122123
// Arduino SD class emulation
123124
std::shared_ptr<Dir> _fakeDir;
@@ -145,7 +146,7 @@ class Dir {
145146
protected:
146147
DirImplPtr _impl;
147148
FS *_baseFS;
148-
time_t (*timeCallback)(void) = nullptr;
149+
time_t (*_timeCallback)(void) = nullptr;
149150
};
150151

151152
// Backwards compatible, <4GB filesystem usage
@@ -198,7 +199,7 @@ class SPIFFSConfig : public FSConfig
198199
class FS
199200
{
200201
public:
201-
FS(FSImplPtr impl) : _impl(impl) { timeCallback = _defaultTimeCB; }
202+
FS(FSImplPtr impl) : _impl(impl) { _timeCallback = _defaultTimeCB; }
202203

203204
bool setConfig(const FSConfig &cfg);
204205

@@ -240,7 +241,7 @@ class FS
240241
protected:
241242
FSImplPtr _impl;
242243
FSImplPtr getImpl() { return _impl; }
243-
time_t (*timeCallback)(void);
244+
time_t (*_timeCallback)(void) = nullptr;
244245
static time_t _defaultTimeCB(void) { return time(NULL); }
245246
};
246247

cores/esp8266/FSImpl.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class FileImpl {
4545

4646
// Filesystems *may* support a timestamp per-file, so allow the user to override with
4747
// their own callback for *this specific* file (as opposed to the FSImpl call of the
48-
// same name. The default implementation simply returns time(&null)
49-
virtual void setTimeCallback(time_t (*cb)(void)) { timeCallback = cb; }
48+
// same name. The default implementation simply returns time(null)
49+
virtual void setTimeCallback(time_t (*cb)(void)) { _timeCallback = cb; }
5050

5151
// Return the last written time for a file. Undefined when called on a writable file
5252
// as the FS is allowed to return either the time of the last write() operation or the
@@ -56,7 +56,7 @@ class FileImpl {
5656
virtual time_t getCreationTime() { return 0; } // Default is to not support timestamps
5757

5858
protected:
59-
time_t (*timeCallback)(void) = nullptr;
59+
time_t (*_timeCallback)(void) = nullptr;
6060
};
6161

6262
enum OpenMode {
@@ -90,11 +90,11 @@ class DirImpl {
9090

9191
// Filesystems *may* support a timestamp per-file, so allow the user to override with
9292
// their own callback for *this specific* file (as opposed to the FSImpl call of the
93-
// same name. The default implementation simply returns time(&null)
94-
virtual void setTimeCallback(time_t (*cb)(void)) { timeCallback = cb; }
93+
// same name. The default implementation simply returns time(null)
94+
virtual void setTimeCallback(time_t (*cb)(void)) { _timeCallback = cb; }
9595

9696
protected:
97-
time_t (*timeCallback)(void) = nullptr;
97+
time_t (*_timeCallback)(void) = nullptr;
9898
};
9999

100100
class FSImpl {
@@ -118,11 +118,11 @@ class FSImpl {
118118

119119
// Filesystems *may* support a timestamp per-file, so allow the user to override with
120120
// their own callback for all files on this FS. The default implementation simply
121-
// returns the present time as reported by time(&null)
122-
virtual void setTimeCallback(time_t (*cb)(void)) { timeCallback = cb; }
121+
// returns the present time as reported by time(null)
122+
virtual void setTimeCallback(time_t (*cb)(void)) { _timeCallback = cb; }
123123

124124
protected:
125-
time_t (*timeCallback)(void) = nullptr;
125+
time_t (*_timeCallback)(void) = nullptr;
126126
};
127127

128128
} // namespace fs

cores/esp8266/core_esp8266_i2s.cpp

+25-10
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ typedef struct i2s_state {
6464
// Callback function should be defined as 'void ICACHE_RAM_ATTR function_name()',
6565
// and be placed in IRAM for faster execution. Avoid long computational tasks in this
6666
// function, use it to set flags and process later.
67+
bool driveClocks;
6768
} i2s_state_t;
6869

6970
// RX = I2S receive (i.e. microphone), TX = I2S transmit (i.e. DAC)
@@ -493,6 +494,10 @@ float i2s_get_real_rate(){
493494
}
494495

495496
bool i2s_rxtx_begin(bool enableRx, bool enableTx) {
497+
return i2s_rxtxdrive_begin(enableRx, enableTx, true, true);
498+
}
499+
500+
bool i2s_rxtxdrive_begin(bool enableRx, bool enableTx, bool driveRxClocks, bool driveTxClocks) {
496501
if (tx || rx) {
497502
i2s_end(); // Stop and free any ongoing stuff
498503
}
@@ -503,22 +508,28 @@ bool i2s_rxtx_begin(bool enableRx, bool enableTx) {
503508
// Nothing to clean up yet
504509
return false; // OOM Error!
505510
}
506-
pinMode(I2SO_WS, FUNCTION_1);
511+
tx->driveClocks = driveTxClocks;
507512
pinMode(I2SO_DATA, FUNCTION_1);
508-
pinMode(I2SO_BCK, FUNCTION_1);
513+
if (driveTxClocks) {
514+
pinMode(I2SO_WS, FUNCTION_1);
515+
pinMode(I2SO_BCK, FUNCTION_1);
516+
}
509517
}
510518
if (enableRx) {
511519
rx = (i2s_state_t*)calloc(1, sizeof(*rx));
512520
if (!rx) {
513521
i2s_end(); // Clean up any TX or pin changes
514522
return false; // OOM error!
515523
}
516-
pinMode(I2SI_WS, OUTPUT);
517-
pinMode(I2SI_BCK, OUTPUT);
524+
rx->driveClocks = driveRxClocks;
518525
pinMode(I2SI_DATA, INPUT);
526+
if (driveRxClocks) {
527+
pinMode(I2SI_WS, OUTPUT);
528+
pinMode(I2SI_BCK, OUTPUT);
529+
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_I2SI_BCK);
530+
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, FUNC_I2SI_WS);
531+
}
519532
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_I2SI_DATA);
520-
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, FUNC_I2SI_BCK);
521-
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, FUNC_I2SI_WS);
522533
}
523534

524535
if (!i2s_slc_begin()) {
@@ -579,15 +590,19 @@ void i2s_end() {
579590

580591
if (tx) {
581592
pinMode(I2SO_DATA, INPUT);
582-
pinMode(I2SO_BCK, INPUT);
583-
pinMode(I2SO_WS, INPUT);
593+
if (tx->driveClocks) {
594+
pinMode(I2SO_BCK, INPUT);
595+
pinMode(I2SO_WS, INPUT);
596+
}
584597
free(tx);
585598
tx = NULL;
586599
}
587600
if (rx) {
588601
pinMode(I2SI_DATA, INPUT);
589-
pinMode(I2SI_BCK, INPUT);
590-
pinMode(I2SI_WS, INPUT);
602+
if (rx->driveClocks) {
603+
pinMode(I2SI_BCK, INPUT);
604+
pinMode(I2SI_WS, INPUT);
605+
}
591606
free(rx);
592607
rx = NULL;
593608
}

cores/esp8266/core_esp8266_main.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,6 @@ extern "C" void app_entry_redefinable(void)
317317
cont_t s_cont __attribute__((aligned(16)));
318318
g_pcont = &s_cont;
319319

320-
#ifdef DEV_DEBUG_MMU_IRAM
321-
DBG_MMU_PRINT_STATUS();
322-
323-
DBG_MMU_PRINT_IRAM_BANK_REG(0, "");
324-
325-
DBG_MMU_PRINTF("\nCall call_user_start()\n");
326-
#endif
327-
328320
/* Call the entry point of the SDK code. */
329321
call_user_start();
330322
}

cores/esp8266/i2s.h

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#ifndef I2S_h
2222
#define I2S_h
2323

24+
#define I2S_HAS_BEGIN_RXTX_DRIVE_CLOCKS 1
25+
2426
/*
2527
How does this work? Basically, to get sound, you need to:
2628
- Connect an I2S codec to the I2S pins on the ESP.
@@ -42,6 +44,7 @@ extern "C" {
4244

4345
void i2s_begin(); // Enable TX only, for compatibility
4446
bool i2s_rxtx_begin(bool enableRx, bool enableTx); // Allow TX and/or RX, returns false on OOM error
47+
bool i2s_rxtxdrive_begin(bool enableRx, bool enableTx, bool driveRxClocks, bool driveTxClocks);
4548
void i2s_end();
4649
void i2s_set_rate(uint32_t rate);//Sample Rate in Hz (ex 44100, 48000)
4750
void i2s_set_dividers(uint8_t div1, uint8_t div2);//Direct control over output rate

cores/esp8266/umm_malloc/umm_malloc.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ void *umm_realloc( void *ptr, size_t size ) {
10381038
} else {
10391039
DBGLOG_DEBUG( "realloc %i to a bigger block %i failed - return NULL and leave the old block!\n", blockSize, blocks );
10401040
/* This space intentionally left blnk */
1041-
STATS__OOM_UPDATE();
1041+
/* STATS__OOM_UPDATE() has already been called by umm_malloc_core - don't duplicate count */
10421042
}
10431043
/* This is not accurate for OOM case; however, it will work for
10441044
* stopping a call to free before return.
@@ -1117,7 +1117,7 @@ void *umm_realloc( void *ptr, size_t size ) {
11171117
} else {
11181118
DBGLOG_DEBUG( "realloc %d to a bigger block %d failed - return NULL and leave the old block!\n", blockSize, blocks );
11191119
/* This space intentionally left blnk */
1120-
STATS__OOM_UPDATE();
1120+
/* STATS__OOM_UPDATE() has already been called by umm_malloc_core - don't duplicate count */
11211121
}
11221122
/* This is not accurate for OOM case; however, it will work for
11231123
* stopping a call to free before return.
@@ -1142,7 +1142,7 @@ void *umm_realloc( void *ptr, size_t size ) {
11421142
} else {
11431143
DBGLOG_DEBUG( "realloc %d to a bigger block %d failed - return NULL and leave the old block!\n", blockSize, blocks );
11441144
/* This space intentionally left blnk */
1145-
STATS__OOM_UPDATE();
1145+
/* STATS__OOM_UPDATE() has already been called by umm_malloc_core - don't duplicate count */
11461146
}
11471147
/* This is not accurate for OOM case; however, it will work for
11481148
* stopping a call to free before return.

doc/esp8266wifi/bearssl-server-secure-class.rst

+21-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Implements a TLS encrypted server with optional client certificate validation.
88
setBufferSizes(int recv, int xmit)
99
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1010

11-
Similar to the `BearSSL::WiFiClientSecure` method, sets the receive and transmit buffer sizes. Note that servers cannot request a buffer size from the client, so if these are shrunk and the client tries to send a chunk larger than the receive buffer, it will always fail. This must be called before the server is
11+
Similar to the `BearSSL::WiFiClientSecure` method, sets the receive and transmit buffer sizes. Note that servers cannot request a buffer size from the client, so if these are shrunk and the client tries to send a chunk larger than the receive buffer, it will always fail. Needs to be called before `begin()`
1212

1313
Setting Server Certificates
1414
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -33,6 +33,26 @@ setECCert(const BearSSL::X509List \*chain, unsigned cert_issuer_key_type, const
3333

3434
Sets an elliptic curve certificate and key for the server. Needs to be called before `begin()`.
3535

36+
Client sessions (Resuming connections fast)
37+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38+
39+
The TLS handshake process takes a long time because of all the back and forth between the client and the server. You can shorten it by caching the clients' sessions which will skip a few steps in the TLS handshake. In order for this to work, your client also needs to cache the session. `BearSSL::WiFiClientSecure <bearssl-client-secure-class.rst#sessions-resuming-connections-fast>`__ can do that as well as modern web browers.
40+
41+
Here are the kind of performance improvements that you'll be able to see for TLS handshakes with an ESP8266 with it's clock set at 160MHz on a network with fairly low latency:
42+
43+
* With an EC key of 256 bits, a request taking ~360ms without caching takes ~60ms with caching.
44+
* With an RSA key of 2048 bits, a request taking ~1850ms without caching takes ~70ms with caching.
45+
46+
setCache(BearSSL::ServerSessions \*cache)
47+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
48+
49+
Sets the cache for the server's sessions. When choosing the size of the cache, remember that each client session takes 100 bytes. If you setup a cache for 10 sessions, it will take 1000 bytes. Needs to be called before `begin()`
50+
51+
When creating the cache, you can use any of the 2 available constructors:
52+
53+
* `BearSSL::ServerSessions(ServerSession *sessions, uint32_t size)`: Creates a cache with the given buffer and number of sessions.
54+
* `BearSSL::ServerSessions(uint32_t size)`: Dynamically allocates a cache for the given number of sessions.
55+
3656
Requiring Client Certificates
3757
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3858

0 commit comments

Comments
 (0)