Skip to content

Commit 50ea394

Browse files
authored
Merge branch 'master' into poc-cache-config
2 parents c070657 + 3e567e9 commit 50ea394

37 files changed

+461
-241
lines changed

bootloaders/eboot/eboot.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,10 @@ int main()
231231
ets_wdt_enable();
232232

233233
ets_putc('0'+res); ets_putc('\n');
234-
234+
#if 0
235+
//devyte: this verify step below (cmp:) only works when the end of copy operation above does not overwrite the
236+
//beginning of the image in the empty area, see #7458. Disabling for now.
237+
//TODO: replace the below verify with hash type, crc, or similar.
235238
// Verify the copy
236239
ets_putc('c'); ets_putc('m'); ets_putc('p'); ets_putc(':');
237240
if (res == 0) {
@@ -241,6 +244,7 @@ int main()
241244
}
242245

243246
ets_putc('0'+res); ets_putc('\n');
247+
#endif
244248
if (res == 0) {
245249
cmd.action = ACTION_LOAD_APP;
246250
cmd.args[0] = cmd.args[1];

bootloaders/eboot/eboot.elf

-680 Bytes
Binary file not shown.

cores/esp8266/Arduino.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ extern "C" {
4343
#define HIGH 0x1
4444
#define LOW 0x0
4545

46-
#define PWMRANGE 1023
47-
4846
//GPIO FUNCTIONS
4947
#define INPUT 0x00
5048
#define INPUT_PULLUP 0x02
@@ -176,6 +174,7 @@ int analogRead(uint8_t pin);
176174
void analogReference(uint8_t mode);
177175
void analogWrite(uint8_t pin, int val);
178176
void analogWriteFreq(uint32_t freq);
177+
void analogWriteResolution(int res);
179178
void analogWriteRange(uint32_t range);
180179

181180
unsigned long millis(void);

cores/esp8266/Crypto.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void *createBearsslHmac(const br_hash_class *hashType, const void *data, const s
100100

101101
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)
102102
{
103+
(void) hashTypeNaturalLength;
103104
assert(1 <= hmacLength && hmacLength <= hashTypeNaturalLength);
104105

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

153154
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)
154155
{
156+
(void) hashTypeNaturalLength;
155157
assert(1 <= hmacLength && hmacLength <= hashTypeNaturalLength);
156158

157159
uint8_t hmac[hmacLength];

cores/esp8266/Esp.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,15 +699,16 @@ static SpiFlashOpResult spi_flash_write_puya(uint32_t offset, uint32_t *data, si
699699
} else {
700700
bytesLeft = 0;
701701
}
702-
rc = spi_flash_read(pos, flash_write_puya_buf, bytesNow);
702+
size_t bytesAligned = (bytesNow + 3) & ~3;
703+
rc = spi_flash_read(pos, flash_write_puya_buf, bytesAligned);
703704
if (rc != SPI_FLASH_RESULT_OK) {
704705
return rc;
705706
}
706-
for (size_t i = 0; i < bytesNow / 4; ++i) {
707+
for (size_t i = 0; i < bytesAligned / 4; ++i) {
707708
flash_write_puya_buf[i] &= *ptr;
708709
++ptr;
709710
}
710-
rc = spi_flash_write(pos, flash_write_puya_buf, bytesNow);
711+
rc = spi_flash_write(pos, flash_write_puya_buf, bytesAligned);
711712
pos += bytesNow;
712713
}
713714
return rc;

cores/esp8266/HardwareSerial.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
#include "HardwareSerial.h"
3333
#include "Esp.h"
3434

35+
36+
// SerialEvent functions are weak, so when the user doesn't define them,
37+
// the linker just sets their address to 0 (which is checked below).
38+
// The Serialx_available is just a wrapper around Serialx.available(),
39+
// but we can refer to it weakly so we don't pull in the entire
40+
// HardwareSerial instance if the user doesn't also refer to it.
41+
void serialEvent() __attribute__((weak));
42+
3543
HardwareSerial::HardwareSerial(int uart_nr)
3644
: _uart_nr(uart_nr), _rx_size(256)
3745
{}
@@ -162,6 +170,14 @@ size_t HardwareSerial::readBytes(char* buffer, size_t size)
162170

163171
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL)
164172
HardwareSerial Serial(UART0);
173+
174+
// Executed at end of loop() processing when > 0 bytes available in the Serial port
175+
void serialEventRun(void)
176+
{
177+
if (serialEvent && Serial.available()) {
178+
serialEvent();
179+
}
180+
}
165181
#endif
166182
#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL1)
167183
HardwareSerial Serial1(UART1);

cores/esp8266/HardwareSerial.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,6 @@ class HardwareSerial: public Stream
207207
extern HardwareSerial Serial;
208208
extern HardwareSerial Serial1;
209209

210+
extern void serialEventRun(void) __attribute__((weak));
211+
210212
#endif

cores/esp8266/Updater.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ UpdaterClass::UpdaterClass()
3535
, _startAddress(0)
3636
, _currentAddress(0)
3737
, _command(U_FLASH)
38+
, _ledPin(-1)
3839
, _hash(nullptr)
3940
, _verify(nullptr)
4041
, _progress_callback(nullptr)

cores/esp8266/core_esp8266_features.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,19 @@ inline uint32_t esp_get_cycle_count() {
9292
__asm__ __volatile__("rsr %0,ccount":"=a"(ccount));
9393
return ccount;
9494
}
95-
#endif // not CORE_MOCK
95+
96+
inline uint32_t esp_get_program_counter() __attribute__((always_inline));
97+
inline uint32_t esp_get_program_counter() {
98+
uint32_t pc;
99+
__asm__ __volatile__("movi %0, ." : "=r" (pc) : : ); // ©earlephilhower
100+
return pc;
101+
}
102+
103+
#else // CORE_MOCK
104+
105+
inline uint32_t esp_get_program_counter() { return 0; }
106+
107+
#endif // CORE_MOCK
96108

97109

98110
// Tools for preloading code into the flash cache

cores/esp8266/core_esp8266_main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ static void loop_wrapper() {
198198
}
199199
loop();
200200
loop_end();
201+
if (serialEventRun) {
202+
serialEventRun();
203+
}
201204
esp_schedule();
202205
}
203206

cores/esp8266/core_esp8266_wiring_pwm.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,21 @@
2727
extern "C" {
2828

2929
static uint32_t analogMap = 0;
30-
static int32_t analogScale = PWMRANGE;
30+
static int32_t analogScale = 255; // Match upstream default, breaking change from 2.x.x
3131
static uint16_t analogFreq = 1000;
3232

3333
extern void __analogWriteRange(uint32_t range) {
34-
if (range > 0) {
34+
if ((range >= 15) && (range <= 65535)) {
3535
analogScale = range;
3636
}
3737
}
3838

39+
extern void __analogWriteResolution(int res) {
40+
if ((res >= 4) && (res <= 16)) {
41+
analogScale = (1 << res) - 1;
42+
}
43+
}
44+
3945
extern void __analogWriteFreq(uint32_t freq) {
4046
if (freq < 100) {
4147
analogFreq = 100;
@@ -57,6 +63,10 @@ extern void __analogWrite(uint8_t pin, int val) {
5763
val = analogScale;
5864
}
5965

66+
// Per the Arduino docs at https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/
67+
// val: the duty cycle: between 0 (always off) and 255 (always on).
68+
// So if val = 0 we have digitalWrite(LOW), if we have val==range we have digitalWrite(HIGH)
69+
6070
analogMap &= ~(1 << pin);
6171
uint32_t high = (analogPeriod * val) / analogScale;
6272
uint32_t low = analogPeriod - high;
@@ -75,5 +85,6 @@ extern void __analogWrite(uint8_t pin, int val) {
7585
extern void analogWrite(uint8_t pin, int val) __attribute__((weak, alias("__analogWrite")));
7686
extern void analogWriteFreq(uint32_t freq) __attribute__((weak, alias("__analogWriteFreq")));
7787
extern void analogWriteRange(uint32_t range) __attribute__((weak, alias("__analogWriteRange")));
88+
extern void analogWriteResolution(int res) __attribute__((weak, alias("__analogWriteResolution")));
7889

7990
};

doc/boards.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,6 @@ DOIT ESP-Mx DevKit (ESP8285)
476476
----------------------------
477477

478478
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.
479-
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.
480479

480+
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.
481481

doc/ota_updates/readme.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ Updater is in the Core and deals with writing the firmware to the flash, checkin
669669

670670
**Note:** The bootloader command will be stored into the first 128 bytes of user RTC memory, then it will be retrieved by eboot on boot. That means that user data present there will be lost `(per discussion in #5330) <https://github.com/esp8266/Arduino/pull/5330#issuecomment-437803456>`__.
671671

672+
**Note:** For uncompressed firmware images, the Updater will change the flash mode bits if they differ from the flash mode the device is currently running at. This ensures that the flash mode is not changed to an incompatible mode when the device is in a remote or hard to access area. Compressed images are not modified, thus changing the flash mode in this instance could result in damage to the ESP8266 and/or flash memory chip or your device no longer be accessible via OTA, and requiring re-flashing via a serial connection `(per discussion in #7307) <https://github.com/esp8266/Arduino/issues/7307#issuecomment-631523053>`__.
673+
672674
Update process - memory view
673675
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
674676

doc/reference.rst

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,19 @@ Analog output
102102

103103
``analogWrite(pin, value)`` enables software PWM on the given pin. PWM
104104
may be used on pins 0 to 16. Call ``analogWrite(pin, 0)`` to disable PWM
105-
on the pin. ``value`` may be in range from 0 to ``PWMRANGE``, which is
106-
equal to 1023 by default. PWM range may be changed by calling
107-
``analogWriteRange(new_range)``.
105+
on the pin.
106+
107+
``value`` may be in range from 0 to 255 (which is the Arduino default).
108+
PWM range may be changed by calling ``analogWriteRange(new_range)`` or
109+
``analogWriteResolution(bits)``. ``new_range`` may be from 15...65535
110+
or ``bits`` may be from 4...16.
111+
112+
**NOTE:** The default ``analogWrite`` range was 1023 in releases before
113+
3.0, but this lead to incompatibility with external libraries which
114+
depended on the Arduino core default of 256. Existing applications which
115+
rely on the prior 1023 value may add a call to ``analogWriteRange(1023)``
116+
to their ``setup()`` routine to return to their old behavior. Applications
117+
which already were calling ``analogWriteRange`` need no change.
108118

109119
PWM frequency is 1kHz by default. Call
110120
``analogWriteFreq(new_frequency)`` to change the frequency. Valid values
@@ -113,7 +123,7 @@ are from 100Hz up to 40000Hz.
113123
The ESP doesn't have hardware PWM, so the implementation is by software.
114124
With one PWM output at 40KHz, the CPU is already rather loaded. The more
115125
PWM outputs used, and the higher their frequency, the closer you get to
116-
the CPU limits, and the less CPU cycles are available for sketch execution.
126+
the CPU limits, and the fewer CPU cycles are available for sketch execution.
117127

118128
Timing and delays
119129
-----------------

libraries/ESP8266HTTPClient/examples/StreamHttpsClient/StreamHttpsClient.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void loop() {
5050
Serial.print("[HTTPS] begin...\n");
5151

5252
// configure server and url
53-
const uint8_t fingerprint[20] = {0xEB, 0xD9, 0xDF, 0x37, 0xC2, 0xCC, 0x84, 0x89, 0x00, 0xA0, 0x58, 0x52, 0x24, 0x04, 0xE4, 0x37, 0x3E, 0x2B, 0xF1, 0x41};
53+
const uint8_t fingerprint[20] = {0x15, 0x77, 0xdc, 0x04, 0x7c, 0x00, 0xf8, 0x70, 0x09, 0x34, 0x24, 0xf4, 0xd3, 0xa1, 0x7a, 0x6c, 0x1e, 0xa3, 0xe0, 0x2a};
5454

5555
client->setFingerprint(fingerprint);
5656

libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const int led = 13;
1717

1818
void handleRoot() {
1919
digitalWrite(led, 1);
20-
server.send(200, "text/plain", "hello from esp8266!");
20+
server.send(200, "text/plain", "hello from esp8266!\r\n");
2121
digitalWrite(led, 0);
2222
}
2323

@@ -86,6 +86,66 @@ void setup(void) {
8686

8787
server.onNotFound(handleNotFound);
8888

89+
/////////////////////////////////////////////////////////
90+
// Hook examples
91+
92+
server.addHook([](const String & method, const String & url, WiFiClient * client, ESP8266WebServer::ContentTypeFunction contentType) {
93+
(void)method; // GET, PUT, ...
94+
(void)url; // example: /root/myfile.html
95+
(void)client; // the webserver tcp client connection
96+
(void)contentType; // contentType(".html") => "text/html"
97+
Serial.printf("A useless web hook has passed\n");
98+
Serial.printf("(this hook is in 0x%08x area (401x=IRAM 402x=FLASH))\n", esp_get_program_counter());
99+
return ESP8266WebServer::CLIENT_REQUEST_CAN_CONTINUE;
100+
});
101+
102+
server.addHook([](const String&, const String & url, WiFiClient*, ESP8266WebServer::ContentTypeFunction) {
103+
if (url.startsWith("/fail")) {
104+
Serial.printf("An always failing web hook has been triggered\n");
105+
return ESP8266WebServer::CLIENT_MUST_STOP;
106+
}
107+
return ESP8266WebServer::CLIENT_REQUEST_CAN_CONTINUE;
108+
});
109+
110+
server.addHook([](const String&, const String & url, WiFiClient * client, ESP8266WebServer::ContentTypeFunction) {
111+
if (url.startsWith("/dump")) {
112+
Serial.printf("The dumper web hook is on the run\n");
113+
114+
// Here the request is not interpreted, so we cannot for sure
115+
// swallow the exact amount matching the full request+content,
116+
// hence the tcp connection cannot be handled anymore by the
117+
// webserver.
118+
#ifdef STREAMTO_API
119+
// we are lucky
120+
client->toWithTimeout(Serial, 500);
121+
#else
122+
auto last = millis();
123+
while ((millis() - last) < 500) {
124+
char buf[32];
125+
size_t len = client->read((uint8_t*)buf, sizeof(buf));
126+
if (len > 0) {
127+
Serial.printf("(<%d> chars)", (int)len);
128+
Serial.write(buf, len);
129+
last = millis();
130+
}
131+
}
132+
#endif
133+
// Two choices: return MUST STOP and webserver will close it
134+
// (we already have the example with '/fail' hook)
135+
// or IS GIVEN and webserver will forget it
136+
// trying with IS GIVEN and storing it on a dumb WiFiClient.
137+
// check the client connection: it should not immediately be closed
138+
// (make another '/dump' one to close the first)
139+
Serial.printf("\nTelling server to forget this connection\n");
140+
static WiFiClient forgetme = *client; // stop previous one if present and transfer client refcounter
141+
return ESP8266WebServer::CLIENT_IS_GIVEN;
142+
}
143+
return ESP8266WebServer::CLIENT_REQUEST_CAN_CONTINUE;
144+
});
145+
146+
// Hook examples
147+
/////////////////////////////////////////////////////////
148+
89149
server.begin();
90150
Serial.println("HTTP server started");
91151
}

0 commit comments

Comments
 (0)