Skip to content

Commit a24b8d2

Browse files
authored
Merge branch 'master' into wifi_mesh_update_2.2
2 parents 548d702 + 9632e86 commit a24b8d2

Some content is hidden

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

51 files changed

+704
-161
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ Also known as latest git or master branch.
4848

4949
### Using PlatformIO
5050

51-
[PlatformIO](https://platformio.org?utm_source=github&utm_medium=arduino-esp8266) is an open source ecosystem for IoT
51+
[PlatformIO](https://platformio.org?utm_source=arduino-esp8266) is an open source ecosystem for IoT
5252
development with a cross-platform build system, a library manager, and full support
5353
for Espressif (ESP8266) development. It works on the following popular host operating systems: macOS, Windows,
5454
Linux 32/64, and Linux ARM (like Raspberry Pi, BeagleBone, CubieBoard).
5555

56-
- [What is PlatformIO?](https://docs.platformio.org/en/latest/what-is-platformio.html?utm_source=github&utm_medium=arduino-esp8266)
57-
- [PlatformIO IDE](https://platformio.org/platformio-ide?utm_source=github&utm_medium=arduino-esp8266)
58-
- [PlatformIO Core](https://docs.platformio.org/en/latest/core.html?utm_source=github&utm_medium=arduino-esp8266) (command line tool)
59-
- [Advanced usage](https://docs.platformio.org/en/latest/platforms/espressif8266.html?utm_source=github&utm_medium=arduino-esp8266) -
56+
- [What is PlatformIO?](https://docs.platformio.org/en/latest/what-is-platformio.html?utm_source=arduino-esp8266)
57+
- [PlatformIO IDE](https://platformio.org/platformio-ide?utm_source=arduino-esp8266)
58+
- [PlatformIO Core](https://docs.platformio.org/en/latest/core.html?utm_source=arduino-esp8266) (command line tool)
59+
- [Advanced usage](https://docs.platformio.org/en/latest/platforms/espressif8266.html?utm_source=arduino-esp8266) -
6060
custom settings, uploading to SPIFFS, Over-the-Air (OTA), staging version
61-
- [Integration with Cloud and Standalone IDEs](https://docs.platformio.org/en/latest/ide.html?utm_source=github&utm_medium=arduino-esp8266) -
61+
- [Integration with Cloud and Standalone IDEs](https://docs.platformio.org/en/latest/ide.html?utm_source=arduino-esp8266) -
6262
Cloud9, Codeanywhere, Eclipse Che (Codenvy), Atom, CLion, Eclipse, Emacs, NetBeans, Qt Creator, Sublime Text, VIM, Visual Studio, and VSCode
63-
- [Project Examples](https://docs.platformio.org/en/latest/platforms/espressif8266.html?utm_source=github&utm_medium=arduino-esp8266#examples)
63+
- [Project Examples](https://docs.platformio.org/en/latest/platforms/espressif8266.html?utm_source=arduino-esp8266#examples)
6464

6565
### Building with make
6666

boards.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,63 @@ esp8285.menu.eesz.1M.build.flash_ld=eagle.flash.1m.ld
625625
esp8285.menu.eesz.1M.build.spiffs_pagesize=256
626626
esp8285.menu.eesz.1M.upload.maximum_size=1023984
627627
esp8285.menu.eesz.1M.build.rfcal_addr=0xFC000
628+
esp8285.menu.eesz.2M64=2MB (FS:64KB OTA:~992KB)
629+
esp8285.menu.eesz.2M64.build.flash_size=2M
630+
esp8285.menu.eesz.2M64.build.flash_size_bytes=0x200000
631+
esp8285.menu.eesz.2M64.build.flash_ld=eagle.flash.2m64.ld
632+
esp8285.menu.eesz.2M64.build.spiffs_pagesize=256
633+
esp8285.menu.eesz.2M64.upload.maximum_size=1044464
634+
esp8285.menu.eesz.2M64.build.rfcal_addr=0x1FC000
635+
esp8285.menu.eesz.2M64.build.spiffs_start=0x1F0000
636+
esp8285.menu.eesz.2M64.build.spiffs_end=0x1FB000
637+
esp8285.menu.eesz.2M64.build.spiffs_blocksize=4096
638+
esp8285.menu.eesz.2M128=2MB (FS:128KB OTA:~960KB)
639+
esp8285.menu.eesz.2M128.build.flash_size=2M
640+
esp8285.menu.eesz.2M128.build.flash_size_bytes=0x200000
641+
esp8285.menu.eesz.2M128.build.flash_ld=eagle.flash.2m128.ld
642+
esp8285.menu.eesz.2M128.build.spiffs_pagesize=256
643+
esp8285.menu.eesz.2M128.upload.maximum_size=1044464
644+
esp8285.menu.eesz.2M128.build.rfcal_addr=0x1FC000
645+
esp8285.menu.eesz.2M128.build.spiffs_start=0x1E0000
646+
esp8285.menu.eesz.2M128.build.spiffs_end=0x1FB000
647+
esp8285.menu.eesz.2M128.build.spiffs_blocksize=4096
648+
esp8285.menu.eesz.2M256=2MB (FS:256KB OTA:~896KB)
649+
esp8285.menu.eesz.2M256.build.flash_size=2M
650+
esp8285.menu.eesz.2M256.build.flash_size_bytes=0x200000
651+
esp8285.menu.eesz.2M256.build.flash_ld=eagle.flash.2m256.ld
652+
esp8285.menu.eesz.2M256.build.spiffs_pagesize=256
653+
esp8285.menu.eesz.2M256.upload.maximum_size=1044464
654+
esp8285.menu.eesz.2M256.build.rfcal_addr=0x1FC000
655+
esp8285.menu.eesz.2M256.build.spiffs_start=0x1C0000
656+
esp8285.menu.eesz.2M256.build.spiffs_end=0x1FB000
657+
esp8285.menu.eesz.2M256.build.spiffs_blocksize=4096
658+
esp8285.menu.eesz.2M512=2MB (FS:512KB OTA:~768KB)
659+
esp8285.menu.eesz.2M512.build.flash_size=2M
660+
esp8285.menu.eesz.2M512.build.flash_size_bytes=0x200000
661+
esp8285.menu.eesz.2M512.build.flash_ld=eagle.flash.2m512.ld
662+
esp8285.menu.eesz.2M512.build.spiffs_pagesize=256
663+
esp8285.menu.eesz.2M512.upload.maximum_size=1044464
664+
esp8285.menu.eesz.2M512.build.rfcal_addr=0x1FC000
665+
esp8285.menu.eesz.2M512.build.spiffs_start=0x180000
666+
esp8285.menu.eesz.2M512.build.spiffs_end=0x1FA000
667+
esp8285.menu.eesz.2M512.build.spiffs_blocksize=8192
668+
esp8285.menu.eesz.2M1M=2MB (FS:1MB OTA:~512KB)
669+
esp8285.menu.eesz.2M1M.build.flash_size=2M
670+
esp8285.menu.eesz.2M1M.build.flash_size_bytes=0x200000
671+
esp8285.menu.eesz.2M1M.build.flash_ld=eagle.flash.2m1m.ld
672+
esp8285.menu.eesz.2M1M.build.spiffs_pagesize=256
673+
esp8285.menu.eesz.2M1M.upload.maximum_size=1044464
674+
esp8285.menu.eesz.2M1M.build.rfcal_addr=0x1FC000
675+
esp8285.menu.eesz.2M1M.build.spiffs_start=0x100000
676+
esp8285.menu.eesz.2M1M.build.spiffs_end=0x1FA000
677+
esp8285.menu.eesz.2M1M.build.spiffs_blocksize=8192
678+
esp8285.menu.eesz.2M=2MB (FS:none OTA:~1019KB)
679+
esp8285.menu.eesz.2M.build.flash_size=2M
680+
esp8285.menu.eesz.2M.build.flash_size_bytes=0x200000
681+
esp8285.menu.eesz.2M.build.flash_ld=eagle.flash.2m.ld
682+
esp8285.menu.eesz.2M.build.spiffs_pagesize=256
683+
esp8285.menu.eesz.2M.upload.maximum_size=1044464
684+
esp8285.menu.eesz.2M.build.rfcal_addr=0x1FC000
628685
esp8285.menu.led.2=2
629686
esp8285.menu.led.2.build.led=-DLED_BUILTIN=2
630687
esp8285.menu.led.0=0

cores/esp8266/Esp.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,6 @@ bool EspClass::rtcUserMemoryWrite(uint32_t offset, uint32_t *data, size_t size)
193193
}
194194
}
195195

196-
197-
198-
extern "C" void __real_system_restart_local();
199196
void EspClass::reset(void)
200197
{
201198
__real_system_restart_local();
@@ -267,11 +264,12 @@ uint8_t EspClass::getBootMode(void)
267264
return system_get_boot_mode();
268265
}
269266

267+
#ifndef F_CPU
270268
uint8_t EspClass::getCpuFreqMHz(void)
271269
{
272270
return system_get_cpu_freq();
273271
}
274-
272+
#endif
275273

276274
uint32_t EspClass::getFlashChipId(void)
277275
{

cores/esp8266/Esp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,14 @@ class EspClass {
157157
uint8_t getBootVersion();
158158
uint8_t getBootMode();
159159

160+
#if defined(F_CPU) || defined(CORE_MOCK)
161+
constexpr uint8_t getCpuFreqMHz() const
162+
{
163+
return clockCyclesPerMicrosecond();
164+
}
165+
#else
160166
uint8_t getCpuFreqMHz();
167+
#endif
161168

162169
uint32_t getFlashChipId();
163170
uint8_t getFlashChipVendorId();
@@ -201,6 +208,7 @@ class EspClass {
201208
};
202209

203210
#ifndef CORE_MOCK
211+
204212
uint32_t EspClass::getCycleCount()
205213
{
206214
return esp_get_cycle_count();

cores/esp8266/MD5Builder.cpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#include <Arduino.h>
22
#include <MD5Builder.h>
3+
#include <memory>
34

4-
uint8_t hex_char_to_byte(uint8_t c){
5-
return (c >= 'a' && c <= 'f') ? (c - ((uint8_t)'a' - 0xa)) :
6-
(c >= 'A' && c <= 'F') ? (c - ((uint8_t)'A' - 0xA)) :
7-
(c >= '0' && c<= '9') ? (c - (uint8_t)'0') : 0;
5+
uint8_t hex_char_to_byte(uint8_t c) {
6+
return (c >= 'a' && c <= 'f') ? (c - ((uint8_t)'a' - 0xa)) :
7+
(c >= 'A' && c <= 'F') ? (c - ((uint8_t)'A' - 0xA)) :
8+
(c >= '0' && c <= '9') ? (c - (uint8_t)'0') : 0;
89
}
910

1011
void MD5Builder::begin(void){
@@ -18,25 +19,27 @@ void MD5Builder::add(const uint8_t * data, const uint16_t len){
1819

1920
void MD5Builder::addHexString(const char * data){
2021
uint16_t i, len = strlen(data);
21-
uint8_t * tmp = (uint8_t*)malloc(len/2);
22-
if(tmp == NULL) {
22+
auto tmp = std::unique_ptr<uint8_t[]>{new(std::nothrow) uint8_t[len / 2]};
23+
24+
if (!tmp) {
2325
return;
2426
}
27+
2528
for(i=0; i<len; i+=2) {
2629
uint8_t high = hex_char_to_byte(data[i]);
2730
uint8_t low = hex_char_to_byte(data[i+1]);
2831
tmp[i/2] = (high & 0x0F) << 4 | (low & 0x0F);
2932
}
30-
add(tmp, len/2);
31-
free(tmp);
33+
add(tmp.get(), len/2);
3234
}
3335

34-
bool MD5Builder::addStream(Stream & stream, const size_t maxLen){
36+
bool MD5Builder::addStream(Stream &stream, const size_t maxLen) {
3537
const int buf_size = 512;
3638
int maxLengthLeft = maxLen;
37-
uint8_t * buf = (uint8_t*) malloc(buf_size);
3839

39-
if(!buf) {
40+
auto buf = std::unique_ptr<uint8_t[]>{new(std::nothrow) uint8_t[buf_size]};
41+
42+
if (!buf) {
4043
return false;
4144
}
4245

@@ -45,47 +48,47 @@ bool MD5Builder::addStream(Stream & stream, const size_t maxLen){
4548

4649
// determine number of bytes to read
4750
int readBytes = bytesAvailable;
48-
if(readBytes > maxLengthLeft) {
49-
readBytes = maxLengthLeft ; // read only until max_len
51+
if (readBytes > maxLengthLeft){
52+
readBytes = maxLengthLeft; // read only until max_len
5053
}
51-
if(readBytes > buf_size) {
54+
if (readBytes > buf_size){
5255
readBytes = buf_size; // not read more the buffer can handle
5356
}
5457

5558
// read data and check if we got something
56-
int numBytesRead = stream.readBytes(buf, readBytes);
57-
if(numBytesRead< 1) {
59+
int numBytesRead = stream.readBytes(buf.get(), readBytes);
60+
if (numBytesRead < 1) {
5861
return false;
5962
}
6063

6164
// Update MD5 with buffer payload
62-
MD5Update(&_ctx, buf, numBytesRead);
65+
MD5Update(&_ctx, buf.get(), numBytesRead);
6366

6467
yield(); // time for network streams
6568

6669
// update available number of bytes
6770
maxLengthLeft -= numBytesRead;
6871
bytesAvailable = stream.available();
6972
}
70-
free(buf);
73+
7174
return true;
7275
}
7376

7477
void MD5Builder::calculate(void){
7578
MD5Final(_buf, &_ctx);
7679
}
7780

78-
void MD5Builder::getBytes(uint8_t * output){
81+
void MD5Builder::getBytes(uint8_t * output) const {
7982
memcpy(output, _buf, 16);
8083
}
8184

82-
void MD5Builder::getChars(char * output){
83-
for(uint8_t i = 0; i < 16; i++) {
85+
void MD5Builder::getChars(char * output) const {
86+
for (uint8_t i=0; i<16; i++){
8487
sprintf(output + (i * 2), "%02x", _buf[i]);
8588
}
8689
}
8790

88-
String MD5Builder::toString(void){
91+
String MD5Builder::toString(void) const {
8992
char out[33];
9093
getChars(out);
9194
return String(out);

cores/esp8266/MD5Builder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ class MD5Builder {
4040
void addHexString(const String& data){ addHexString(data.c_str()); }
4141
bool addStream(Stream & stream, const size_t maxLen);
4242
void calculate(void);
43-
void getBytes(uint8_t * output);
44-
void getChars(char * output);
45-
String toString(void);
43+
void getBytes(uint8_t * output) const;
44+
void getChars(char * output) const;
45+
String toString(void) const;
4646
};
4747

4848

cores/esp8266/PolledTimeout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct TimeSourceCycles
7676

7777
using timeType = decltype(ESP.getCycleCount());
7878
static timeType time() {return ESP.getCycleCount();}
79-
static constexpr timeType ticksPerSecond = F_CPU; // 80'000'000 or 160'000'000 Hz
79+
static constexpr timeType ticksPerSecond = ESP.getCpuFreqMHz() * 1000000UL; // 80'000'000 or 160'000'000 Hz
8080
static constexpr timeType ticksPerSecondMax = 160000000; // 160MHz
8181
};
8282

cores/esp8266/StackThunk.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
#include <stdint.h>
2828
#include <stdlib.h>
29+
#include <stdio.h>
30+
#include "pgmspace.h"
31+
#include "debug.h"
2932
#include "StackThunk.h"
3033
#include <ets_sys.h>
3134

@@ -46,6 +49,11 @@ void stack_thunk_add_ref()
4649
stack_thunk_refcnt++;
4750
if (stack_thunk_refcnt == 1) {
4851
stack_thunk_ptr = (uint32_t *)malloc(_stackSize * sizeof(uint32_t));
52+
if (!stack_thunk_ptr) {
53+
// This is a fatal error, stop the sketch
54+
DEBUGV("Unable to allocate BearSSL stack\n");
55+
abort();
56+
}
4957
stack_thunk_top = stack_thunk_ptr + _stackSize - 1;
5058
stack_thunk_save = NULL;
5159
stack_thunk_repaint();

cores/esp8266/Tone.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323

2424
#include "Arduino.h"
25+
#include "user_interface.h"
2526
#include "core_esp8266_waveform.h"
2627

2728
// Which pins have a tone running on them?
@@ -35,10 +36,10 @@ static void _startTone(uint8_t _pin, uint32_t high, uint32_t low, unsigned long
3536

3637
pinMode(_pin, OUTPUT);
3738

38-
high = std::max(high, (uint32_t)100);
39-
low = std::max(low, (uint32_t)100);
39+
high = std::max(high, (uint32_t)microsecondsToClockCycles(25)); // new 20KHz maximum tone frequency,
40+
low = std::max(low, (uint32_t)microsecondsToClockCycles(25)); // (25us high + 25us low period = 20KHz)
4041

41-
if (startWaveform(_pin, high, low, (uint32_t) duration * 1000)) {
42+
if (startWaveformCycles(_pin, high, low, microsecondsToClockCycles(duration * 1000))) {
4243
_toneMap |= 1 << _pin;
4344
}
4445
}
@@ -48,7 +49,7 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration) {
4849
if (frequency == 0) {
4950
noTone(_pin);
5051
} else {
51-
uint32_t period = 1000000L / frequency;
52+
uint32_t period = (1000000L * system_get_cpu_freq()) / frequency;
5253
uint32_t high = period / 2;
5354
uint32_t low = period - high;
5455
_startTone(_pin, high, low, duration);
@@ -62,7 +63,7 @@ void tone(uint8_t _pin, double frequency, unsigned long duration) {
6263
if (frequency < 1.0) { // FP means no exact comparisons
6364
noTone(_pin);
6465
} else {
65-
double period = 1000000.0 / frequency;
66+
double period = (1000000.0L * system_get_cpu_freq()) / frequency;
6667
uint32_t high = (uint32_t)((period / 2.0) + 0.5);
6768
uint32_t low = (uint32_t)(period + 0.5) - high;
6869
_startTone(_pin, high, low, duration);

cores/esp8266/Updater.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "Updater.h"
22
#include "eboot_command.h"
33
#include <esp8266_peri.h>
4+
#include "StackThunk.h"
45

56
//#define DEBUG_UPDATER Serial
67

@@ -40,6 +41,14 @@ UpdaterClass::UpdaterClass()
4041
{
4142
#if ARDUINO_SIGNING
4243
installSignature(&esp8266::updaterSigningHash, &esp8266::updaterSigningVerifier);
44+
stack_thunk_add_ref();
45+
#endif
46+
}
47+
48+
UpdaterClass::~UpdaterClass()
49+
{
50+
#if ARDUINO_SIGNING
51+
stack_thunk_del_ref();
4352
#endif
4453
}
4554

@@ -199,14 +208,14 @@ bool UpdaterClass::end(bool evenIfRemaining){
199208
#ifdef DEBUG_UPDATER
200209
DEBUG_UPDATER.println(F("no update"));
201210
#endif
211+
_reset();
202212
return false;
203213
}
204214

205215
if(hasError() || (!isFinished() && !evenIfRemaining)){
206216
#ifdef DEBUG_UPDATER
207217
DEBUG_UPDATER.printf_P(PSTR("premature end: res:%u, pos:%zu/%zu\n"), getError(), progress(), _size);
208218
#endif
209-
210219
_reset();
211220
return false;
212221
}
@@ -226,6 +235,7 @@ bool UpdaterClass::end(bool evenIfRemaining){
226235
#endif
227236
if (sigLen != _verify->length()) {
228237
_setError(UPDATE_ERROR_SIGN);
238+
_reset();
229239
return false;
230240
}
231241

@@ -251,6 +261,7 @@ bool UpdaterClass::end(bool evenIfRemaining){
251261
uint8_t *sig = (uint8_t*)malloc(sigLen);
252262
if (!sig) {
253263
_setError(UPDATE_ERROR_SIGN);
264+
_reset();
254265
return false;
255266
}
256267
ESP.flashRead(_startAddress + binSize, (uint32_t *)sig, sigLen);
@@ -262,9 +273,12 @@ bool UpdaterClass::end(bool evenIfRemaining){
262273
DEBUG_UPDATER.printf("\n");
263274
#endif
264275
if (!_verify->verify(_hash, (void *)sig, sigLen)) {
276+
free(sig);
265277
_setError(UPDATE_ERROR_SIGN);
278+
_reset();
266279
return false;
267280
}
281+
free(sig);
268282
#ifdef DEBUG_UPDATER
269283
DEBUG_UPDATER.printf_P(PSTR("[Updater] Signature matches\n"));
270284
#endif

0 commit comments

Comments
 (0)