Skip to content

Update 20.08 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
85ea47e
Fixed PUYA flash write buffer alignment (#7491)
drzony Jul 30, 2020
d92e1ed
Basic authentication with ESP8266httpUpdate (#7190)
drhideg Jul 30, 2020
3be0cbb
Typo (#7502)
pfeerick Aug 3, 2020
fc1aa55
Remove warnings when buinding NoAssert (#7499)
earlephilhower Aug 4, 2020
a8e35a5
Add valgrind mocked test to CI (#7501)
earlephilhower Aug 4, 2020
9afb084
Clean up minor warnings from LGTM.com (#7500)
earlephilhower Aug 4, 2020
3e567e9
Add SerialEvent() callback to loop processing (#7505)
earlephilhower Aug 6, 2020
79fc0b3
CI: on host: force 64 bit mode like `make -j2 CI` implicitly does (#7…
d-a-v Aug 7, 2020
fc2426a
sys/pgmspace.h: Refactor inline asm (#7510)
jjsuwa Aug 9, 2020
7773237
webserver: add define WEBSERVER_HAS_HOOK when ::addHook() is present …
d-a-v Aug 11, 2020
6feda9e
base64 class uses String, adding harmless #include (#7517)
d-a-v Aug 11, 2020
683b8e6
Fix spelling typos in files under doc/esp8266wifi (#7520)
standby24x7 Aug 12, 2020
01edc0e
Fix and add details to Serial doc (#7521)
devyte Aug 13, 2020
e0fedc5
avoid circular #include dependence for PolledTimeout (#7356)
d-a-v Aug 15, 2020
e2b8f6a
Update PIO CI to be less chatty, fix CI fail (#7530)
earlephilhower Aug 16, 2020
f42327d
doc: gcc handles duplicate literal strings (#7531)
d-a-v Aug 17, 2020
5b3d290
Add synthetic IntegerDivideByZero exception (#7496)
earlephilhower Aug 17, 2020
c33a6a2
Updater MD5 cleanup on begin (#7534)
CriPstian Aug 18, 2020
1ff927d
Fix spelling typo under doc/faq (#7538)
standby24x7 Aug 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions cores/esp8266/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,6 @@ void analogWriteFreq(uint32_t freq);
void analogWriteResolution(int res);
void analogWriteRange(uint32_t range);

unsigned long millis(void);
unsigned long micros(void);
uint64_t micros64(void);
void delay(unsigned long);
void delayMicroseconds(unsigned int us);
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);

Expand Down
2 changes: 2 additions & 0 deletions cores/esp8266/Crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void *createBearsslHmac(const br_hash_class *hashType, const void *data, const s

String createBearsslHmac(const br_hash_class *hashType, const uint8_t hashTypeNaturalLength, const String &message, const void *hashKey, const size_t hashKeyLength, const size_t hmacLength)
{
(void) hashTypeNaturalLength;
assert(1 <= hmacLength && hmacLength <= hashTypeNaturalLength);

uint8_t hmac[hmacLength];
Expand Down Expand Up @@ -152,6 +153,7 @@ void *createBearsslHmacCT(const br_hash_class *hashType, const void *data, const

String createBearsslHmacCT(const br_hash_class *hashType, const uint8_t hashTypeNaturalLength, const String &message, const void *hashKey, const size_t hashKeyLength, const size_t hmacLength)
{
(void) hashTypeNaturalLength;
assert(1 <= hmacLength && hmacLength <= hashTypeNaturalLength);

uint8_t hmac[hmacLength];
Expand Down
7 changes: 4 additions & 3 deletions cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,15 +697,16 @@ static SpiFlashOpResult spi_flash_write_puya(uint32_t offset, uint32_t *data, si
} else {
bytesLeft = 0;
}
rc = spi_flash_read(pos, flash_write_puya_buf, bytesNow);
size_t bytesAligned = (bytesNow + 3) & ~3;
rc = spi_flash_read(pos, flash_write_puya_buf, bytesAligned);
if (rc != SPI_FLASH_RESULT_OK) {
return rc;
}
for (size_t i = 0; i < bytesNow / 4; ++i) {
for (size_t i = 0; i < bytesAligned / 4; ++i) {
flash_write_puya_buf[i] &= *ptr;
++ptr;
}
rc = spi_flash_write(pos, flash_write_puya_buf, bytesNow);
rc = spi_flash_write(pos, flash_write_puya_buf, bytesAligned);
pos += bytesNow;
}
return rc;
Expand Down
7 changes: 5 additions & 2 deletions cores/esp8266/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,13 @@ class EspClass {
#if defined(F_CPU) || defined(CORE_MOCK)
constexpr uint8_t getCpuFreqMHz() const
{
return clockCyclesPerMicrosecond();
return esp_get_cpu_freq_mhz();
}
#else
uint8_t getCpuFreqMHz();
uint8_t getCpuFreqMHz() const
{
return esp_get_cpu_freq_mhz();
}
#endif

uint32_t getFlashChipId();
Expand Down
16 changes: 16 additions & 0 deletions cores/esp8266/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
#include "HardwareSerial.h"
#include "Esp.h"


// SerialEvent functions are weak, so when the user doesn't define them,
// the linker just sets their address to 0 (which is checked below).
// The Serialx_available is just a wrapper around Serialx.available(),
// but we can refer to it weakly so we don't pull in the entire
// HardwareSerial instance if the user doesn't also refer to it.
void serialEvent() __attribute__((weak));

HardwareSerial::HardwareSerial(int uart_nr)
: _uart_nr(uart_nr), _rx_size(256)
{}
Expand Down Expand Up @@ -162,6 +170,14 @@ size_t HardwareSerial::readBytes(char* buffer, size_t size)

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
HardwareSerial Serial(UART0);

// Executed at end of loop() processing when > 0 bytes available in the Serial port
void serialEventRun(void)
{
if (serialEvent && Serial.available()) {
serialEvent();
}
}
#endif
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL1)
HardwareSerial Serial1(UART1);
Expand Down
2 changes: 2 additions & 0 deletions cores/esp8266/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,6 @@ class HardwareSerial: public Stream
extern HardwareSerial Serial;
extern HardwareSerial Serial1;

extern void serialEventRun(void) __attribute__((weak));

#endif
54 changes: 37 additions & 17 deletions cores/esp8266/PolledTimeout.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/*
PolledTimeout.h - Encapsulation of a polled Timeout

Copyright (c) 2018 Daniel Salazar. All rights reserved.
This file is part of the esp8266 core for Arduino environment.

Expand All @@ -23,9 +23,10 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <limits>

#include <Arduino.h>
#include <c_types.h> // IRAM_ATTR
#include <limits> // std::numeric_limits
#include <type_traits> // std::is_unsigned
#include <core_esp8266_features.h>

namespace esp8266
{
Expand Down Expand Up @@ -70,13 +71,13 @@ struct TimeSourceMillis

struct TimeSourceCycles
{
// time policy based on ESP.getCycleCount()
// time policy based on esp_get_cycle_count()
// this particular time measurement is intended to be called very often
// (every loop, every yield)

using timeType = decltype(ESP.getCycleCount());
static timeType time() {return ESP.getCycleCount();}
static constexpr timeType ticksPerSecond = ESP.getCpuFreqMHz() * 1000000UL; // 80'000'000 or 160'000'000 Hz
using timeType = decltype(esp_get_cycle_count());
static timeType time() {return esp_get_cycle_count();}
static constexpr timeType ticksPerSecond = esp_get_cpu_freq_mhz() * 1000000UL; // 80'000'000 or 160'000'000 Hz
static constexpr timeType ticksPerSecondMax = 160000000; // 160MHz
};

Expand Down Expand Up @@ -161,13 +162,13 @@ class timeoutTemplate
return expiredRetrigger();
return expiredOneShot();
}

IRAM_ATTR // fast
operator bool()
{
return expired();
return expired();
}

bool canExpire () const
{
return !_neverExpires;
Expand All @@ -178,6 +179,7 @@ class timeoutTemplate
return _timeout != alwaysExpired;
}

// Resets, will trigger after this new timeout.
IRAM_ATTR // called from ISR
void reset(const timeType newUserTimeout)
{
Expand All @@ -186,12 +188,30 @@ class timeoutTemplate
_neverExpires = (newUserTimeout < 0) || (newUserTimeout > timeMax());
}

// Resets, will trigger after the timeout previously set.
IRAM_ATTR // called from ISR
void reset()
{
_start = TimePolicyT::time();
}

// Resets to just expired so that on next poll the check will immediately trigger for the user,
// also change timeout (after next immediate trigger).
IRAM_ATTR // called from ISR
void resetAndSetExpired (const timeType newUserTimeout)
{
reset(newUserTimeout);
_start -= _timeout;
}

// Resets to just expired so that on next poll the check will immediately trigger for the user.
IRAM_ATTR // called from ISR
void resetAndSetExpired ()
{
reset();
_start -= _timeout;
}

void resetToNeverExpires ()
{
_timeout = alwaysExpired + 1; // because canWait() has precedence
Expand All @@ -202,7 +222,7 @@ class timeoutTemplate
{
return TimePolicyT::toUserUnit(_timeout);
}

static constexpr timeType timeMax()
{
return TimePolicyT::timeMax;
Expand Down Expand Up @@ -235,14 +255,14 @@ class timeoutTemplate
}
return false;
}

IRAM_ATTR // fast
bool expiredOneShot() const
{
// returns "always expired" or "has expired"
return !canWait() || checkExpired(TimePolicyT::time());
}

timeType _timeout;
timeType _start;
bool _neverExpires;
Expand All @@ -259,14 +279,14 @@ using periodic = polledTimeout::timeoutTemplate<true> /*__attribute__((deprecate
using oneShotMs = polledTimeout::timeoutTemplate<false>;
using periodicMs = polledTimeout::timeoutTemplate<true>;

// Time policy based on ESP.getCycleCount(), and intended to be called very often:
// Time policy based on esp_get_cycle_count(), and intended to be called very often:
// "Fast" versions sacrifices time range for improved precision and reduced execution time (by 86%)
// (cpu cycles for ::expired(): 372 (millis()) vs 52 (ESP.getCycleCount()))
// (cpu cycles for ::expired(): 372 (millis()) vs 52 (esp_get_cycle_count()))
// timeMax() values:
// Ms: max is 26843 ms (26.8 s)
// Us: max is 26843545 us (26.8 s)
// Ns: max is 1073741823 ns ( 1.07 s)
// (time policy based on ESP.getCycleCount() is intended to be called very often)
// (time policy based on esp_get_cycle_count() is intended to be called very often)

using oneShotFastMs = polledTimeout::timeoutTemplate<false, YieldPolicy::DoNothing, TimePolicy::TimeFastMillis>;
using periodicFastMs = polledTimeout::timeoutTemplate<true, YieldPolicy::DoNothing, TimePolicy::TimeFastMillis>;
Expand Down
2 changes: 2 additions & 0 deletions cores/esp8266/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ bool UpdaterClass::begin(size_t size, int command, int ledPin, uint8_t ledOn) {

_reset();
clearError(); // _error = 0
_target_md5 = emptyString;
_md5 = MD5Builder();

#ifndef HOST_MOCK
wifi_set_sleep_type(NONE_SLEEP_T);
Expand Down
2 changes: 2 additions & 0 deletions cores/esp8266/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef CORE_BASE64_H_
#define CORE_BASE64_H_

#include <WString.h>

class base64
{
public:
Expand Down
23 changes: 23 additions & 0 deletions cores/esp8266/core_esp8266_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,29 @@ extern "C" {
#endif

void precache(void *f, uint32_t bytes);
unsigned long millis(void);
unsigned long micros(void);
uint64_t micros64(void);
void delay(unsigned long);
void delayMicroseconds(unsigned int us);

#if defined(F_CPU) || defined(CORE_MOCK)
#ifdef __cplusplus
constexpr
#else
inline
#endif
int esp_get_cpu_freq_mhz()
{
return F_CPU / 1000000L;
}
#else
inline int esp_get_cpu_freq_mhz()
{
return system_get_cpu_freq();
}
#endif


#ifdef __cplusplus
}
Expand Down
3 changes: 3 additions & 0 deletions cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ static void loop_wrapper() {
}
loop();
loop_end();
if (serialEventRun) {
serialEventRun();
}
esp_schedule();
}

Expand Down
5 changes: 4 additions & 1 deletion cores/esp8266/core_esp8266_postmortem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,11 @@ void __wrap_system_restart_local() {
ets_printf_P(PSTR("\nAbort called\n"));
}
else if (rst_info.reason == REASON_EXCEPTION_RST) {
// The GCC divide routine in ROM jumps to the address below and executes ILL (00 00 00) on div-by-zero
// In that case, print the exception as (6) which is IntegerDivZero
bool div_zero = (rst_info.exccause == 0) && (rst_info.epc1 == 0x4000dce5);
ets_printf_P(PSTR("\nException (%d):\nepc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n"),
rst_info.exccause, rst_info.epc1, rst_info.epc2, rst_info.epc3, rst_info.excvaddr, rst_info.depc);
div_zero ? 6 : rst_info.exccause, rst_info.epc1, rst_info.epc2, rst_info.epc3, rst_info.excvaddr, rst_info.depc);
}
else if (rst_info.reason == REASON_SOFT_WDT_RST) {
ets_printf_P(PSTR("\nSoft WDT reset\n"));
Expand Down
2 changes: 1 addition & 1 deletion doc/boards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,6 @@ DOIT ESP-Mx DevKit (ESP8285)
----------------------------

DOIT ESP-Mx DevKit - This is a development board by DOIT, with a DOIT ESP-Mx module (`datasheet <https://github.com/SmartArduino/SZDOITWiKi/wiki/ESP8285---ESP-M2>`__) using a ESP8285 Chip. With the DOIT ESP-Mx module, GPIO pins 9 and 10 are not available. The DOIT ESP-Mx DevKit board has a red power LED and a blue LED connected to GPIO16 and is active low to turn on. It uses a CH340C, USB to Serial converter chip.
ESP8285 (`datasheet <http://www.espressif.com/sites/default/files/0a-esp8285_datasheet_en_v1.0_20160422.pdf>`__) is a multi-chip package which contains ESP8266 and 1MB flash.

ESP8285 (`datasheet <http://www.espressif.com/sites/default/files/0a-esp8285_datasheet_en_v1.0_20160422.pdf>`__) is a multi-chip package which contains ESP8266 and 1MB flash.

2 changes: 1 addition & 1 deletion doc/esp8266wifi/bearssl-client-secure-class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ setFingerprint(const uint8_t fp[20]) / setFingerprint(const char \*fpStr)

Verify the SHA1 fingerprint of the certificate returned matches this one. If the server certificate changes, it will fail. If an array of 20 bytes are sent in, it is assumed they are the binary SHA1 values. If a `char*` string is passed in, it is parsed as a series of human-readable hex values separated by spaces or colons (e.g. `setFingerprint("00:01:02:03:...:1f");`)

This fingerprint is calcuated on the raw X509 certificate served by the server. In very rare cases, these certificates have certain encodings which should be normalized before taking a fingerprint (but in order to preserve memory BearSSL does not do this normalization since it would need RAM for an entire copy of the cert), and the fingerprint BearSSL calculates will not match the fingerprint OpenSSL calculates. In this case, you can enable SSL debugging and get a dump of BearSSL's calculated fingerprint and use that one in your code, or use full certificate validation. See the `original issue and debug here <https://github.com/esp8266/Arduino/issues/6209>`__.
This fingerprint is calculated on the raw X509 certificate served by the server. In very rare cases, these certificates have certain encodings which should be normalized before taking a fingerprint (but in order to preserve memory BearSSL does not do this normalization since it would need RAM for an entire copy of the cert), and the fingerprint BearSSL calculates will not match the fingerprint OpenSSL calculates. In this case, you can enable SSL debugging and get a dump of BearSSL's calculated fingerprint and use that one in your code, or use full certificate validation. See the `original issue and debug here <https://github.com/esp8266/Arduino/issues/6209>`__.

setTrustAnchors(BearSSL::X509List \*ta)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion doc/esp8266wifi/client-class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ In this mode, every ``write()`` is flushed. It means that after a call to

When set to ``true`` in ``WiFiClient`` implementation,

- It slows down transfers, and implicitely disable the Nagle algorithm.
- It slows down transfers, and implicitly disable the Nagle algorithm.

- It also allows to avoid a temporary copy of data that otherwise consumes
at most ``TCP_SND_BUF`` = (2 * ``MSS``) bytes per connection,
Expand Down
2 changes: 1 addition & 1 deletion doc/esp8266wifi/scan-class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Return information if a network discovered during the scan is hidden or not.

WiFi.isHidden(networkItem)

Returned value if the ``bolean`` type, and ``true`` means that network is hidden. The ``networkItem`` is a zero based index of network discovered during scan.
Returned value if the ``boolean`` type, and ``true`` means that network is hidden. The ``networkItem`` is a zero based index of network discovered during scan.

getNetworkInfo
^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion doc/esp8266wifi/scan-examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Complete sketch is below. The code inside ``setup()`` is the same as described i
lastScanMillis = currentMillis;
}

// print out Wi-Fi network scan result uppon completion
// print out Wi-Fi network scan result upon completion
int n = WiFi.scanComplete();
if(n >= 0)
{
Expand Down
4 changes: 2 additions & 2 deletions doc/esp8266wifi/server-examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ Complete sketch is presented below.

// close the connection:
client.stop();
Serial.println("[Client disonnected]");
Serial.println("[Client disconnected]");
}
}

Expand Down Expand Up @@ -236,7 +236,7 @@ The page would be refreshed every 5 seconds. Each time this happens, you should
Host: 192.168.1.104
DNT: 1
Connection: Keep-Alive
[client disonnected]
[client disconnected]

Conclusion
~~~~~~~~~~
Expand Down
6 changes: 3 additions & 3 deletions doc/faq/a01-espcomm_sync-failed.rst
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,14 @@ example at 921600 baud, but with two reset retries.

Reset Method: nodemcu, reset retries

If you are interested how noodemcu reset method is implemented, then
If you are interested how nodemcu reset method is implemented, then
check circuit below. As indicated it does not pull to ground RTS and DTR
lines once you open Serial Monitor in Arduino IDE.

.. figure:: pictures/a01-nodemcu-reset-implementation.png
:alt: Implementation of noodemcu reset
:alt: Implementation of nodemcu reset

Implementation of noodemcu reset
Implementation of nodemcu reset

It consists of two transistors and resistors that you can locate on
NodeMCU board on right. On left you can see complete circuit and the
Expand Down
Loading