Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion bootloaders/eboot/eboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ int main()
ets_wdt_enable();

ets_putc('0'+res); ets_putc('\n');

#if 0
//devyte: this verify step below (cmp:) only works when the end of copy operation above does not overwrite the
//beginning of the image in the empty area, see #7458. Disabling for now.
//TODO: replace the below verify with hash type, crc, or similar.
// Verify the copy
ets_putc('c'); ets_putc('m'); ets_putc('p'); ets_putc(':');
if (res == 0) {
Expand All @@ -239,6 +242,7 @@ int main()
}

ets_putc('0'+res); ets_putc('\n');
#endif
if (res == 0) {
cmd.action = ACTION_LOAD_APP;
cmd.args[0] = cmd.args[1];
Expand Down
Binary file modified bootloaders/eboot/eboot.elf
Binary file not shown.
3 changes: 1 addition & 2 deletions cores/esp8266/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ extern "C" {
#define HIGH 0x1
#define LOW 0x0

#define PWMRANGE 1023

//GPIO FUNCTIONS
#define INPUT 0x00
#define INPUT_PULLUP 0x02
Expand Down Expand Up @@ -176,6 +174,7 @@ int analogRead(uint8_t pin);
void analogReference(uint8_t mode);
void analogWrite(uint8_t pin, int val);
void analogWriteFreq(uint32_t freq);
void analogWriteResolution(int res);
void analogWriteRange(uint32_t range);

unsigned long millis(void);
Expand Down
1 change: 1 addition & 0 deletions cores/esp8266/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ UpdaterClass::UpdaterClass()
, _startAddress(0)
, _currentAddress(0)
, _command(U_FLASH)
, _ledPin(-1)
, _hash(nullptr)
, _verify(nullptr)
, _progress_callback(nullptr)
Expand Down
14 changes: 13 additions & 1 deletion cores/esp8266/core_esp8266_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,19 @@ inline uint32_t esp_get_cycle_count() {
__asm__ __volatile__("rsr %0,ccount":"=a"(ccount));
return ccount;
}
#endif // not CORE_MOCK

inline uint32_t esp_get_program_counter() __attribute__((always_inline));
inline uint32_t esp_get_program_counter() {
uint32_t pc;
__asm__ __volatile__("movi %0, ." : "=r" (pc) : : ); // ©earlephilhower
return pc;
}

#else // CORE_MOCK

inline uint32_t esp_get_program_counter() { return 0; }

#endif // CORE_MOCK


// Tools for preloading code into the flash cache
Expand Down
15 changes: 13 additions & 2 deletions cores/esp8266/core_esp8266_wiring_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@
extern "C" {

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

extern void __analogWriteRange(uint32_t range) {
if (range > 0) {
if ((range >= 15) && (range <= 65535)) {
analogScale = range;
}
}

extern void __analogWriteResolution(int res) {
if ((res >= 4) && (res <= 16)) {
analogScale = (1 << res) - 1;
}
}

extern void __analogWriteFreq(uint32_t freq) {
if (freq < 100) {
analogFreq = 100;
Expand All @@ -57,6 +63,10 @@ extern void __analogWrite(uint8_t pin, int val) {
val = analogScale;
}

// Per the Arduino docs at https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/
// val: the duty cycle: between 0 (always off) and 255 (always on).
// So if val = 0 we have digitalWrite(LOW), if we have val==range we have digitalWrite(HIGH)

analogMap &= ~(1 << pin);
uint32_t high = (analogPeriod * val) / analogScale;
uint32_t low = analogPeriod - high;
Expand All @@ -75,5 +85,6 @@ extern void __analogWrite(uint8_t pin, int val) {
extern void analogWrite(uint8_t pin, int val) __attribute__((weak, alias("__analogWrite")));
extern void analogWriteFreq(uint32_t freq) __attribute__((weak, alias("__analogWriteFreq")));
extern void analogWriteRange(uint32_t range) __attribute__((weak, alias("__analogWriteRange")));
extern void analogWriteResolution(int res) __attribute__((weak, alias("__analogWriteResolution")));

};
2 changes: 1 addition & 1 deletion cores/esp8266/heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void ICACHE_RAM_ATTR print_loc(size_t size, const char* file, int line)
if (inISR && (uint32_t)file >= 0x40200000) {
DEBUG_HEAP_PRINTF("File: %p", file);
} else if (!inISR && (uint32_t)file >= 0x40200000) {
char buf[ets_strlen(file)] __attribute__ ((aligned(4)));
char buf[ets_strlen(file) + 1] __attribute__((aligned(4)));
ets_strcpy(buf, file);
DEBUG_HEAP_PRINTF(buf);
} else {
Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/umm_malloc/umm_local.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ int ICACHE_FLASH_ATTR umm_info_safe_printf_P(const char *fmt, ...) {
the PROGMEM address must be word (4 bytes) aligned. The destination
address for ets_memcpy must also be word-aligned.
*/
char ram_buf[ets_strlen(fmt)] __attribute__ ((aligned(4)));
char ram_buf[ets_strlen(fmt) + 1] __attribute__((aligned(4)));
ets_strcpy(ram_buf, fmt);
va_list argPtr;
va_start(argPtr, fmt);
Expand Down
2 changes: 2 additions & 0 deletions doc/ota_updates/readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ Updater is in the Core and deals with writing the firmware to the flash, checkin

**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>`__.

**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>`__.

Update process - memory view
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
18 changes: 14 additions & 4 deletions doc/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,19 @@ Analog output

``analogWrite(pin, value)`` enables software PWM on the given pin. PWM
may be used on pins 0 to 16. Call ``analogWrite(pin, 0)`` to disable PWM
on the pin. ``value`` may be in range from 0 to ``PWMRANGE``, which is
equal to 1023 by default. PWM range may be changed by calling
``analogWriteRange(new_range)``.
on the pin.

``value`` may be in range from 0 to 255 (which is the Arduino default).
PWM range may be changed by calling ``analogWriteRange(new_range)`` or
``analogWriteResolution(bits)``. ``new_range`` may be from 15...65535
or ``bits`` may be from 4...16.

**NOTE:** The default ``analogWrite`` range was 1023 in releases before
3.0, but this lead to incompatibility with external libraries which
depended on the Arduino core default of 256. Existing applications which
rely on the prior 1023 value may add a call to ``analogWriteRange(1023)``
to their ``setup()`` routine to retrurn to their old behavior. Applications
which already were calling ``analogWriteRange`` need no change.

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

Timing and delays
-----------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void loop() {
Serial.print("[HTTPS] begin...\n");

// configure server and url
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};
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};

client->setFingerprint(fingerprint);

Expand Down
62 changes: 61 additions & 1 deletion libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const int led = 13;

void handleRoot() {
digitalWrite(led, 1);
server.send(200, "text/plain", "hello from esp8266!");
server.send(200, "text/plain", "hello from esp8266!\r\n");
digitalWrite(led, 0);
}

Expand Down Expand Up @@ -86,6 +86,66 @@ void setup(void) {

server.onNotFound(handleNotFound);

/////////////////////////////////////////////////////////
// Hook examples

server.addHook([](const String & method, const String & url, WiFiClient * client, ESP8266WebServer::ContentTypeFunction contentType) {
(void)method; // GET, PUT, ...
(void)url; // example: /root/myfile.html
(void)client; // the webserver tcp client connection
(void)contentType; // contentType(".html") => "text/html"
Serial.printf("A useless web hook has passed\n");
Serial.printf("(this hook is in 0x%08x area (401x=IRAM 402x=FLASH))\n", esp_get_program_counter());
return ESP8266WebServer::CLIENT_REQUEST_CAN_CONTINUE;
});

server.addHook([](const String&, const String & url, WiFiClient*, ESP8266WebServer::ContentTypeFunction) {
if (url.startsWith("/fail")) {
Serial.printf("An always failing web hook has been triggered\n");
return ESP8266WebServer::CLIENT_MUST_STOP;
}
return ESP8266WebServer::CLIENT_REQUEST_CAN_CONTINUE;
});

server.addHook([](const String&, const String & url, WiFiClient * client, ESP8266WebServer::ContentTypeFunction) {
if (url.startsWith("/dump")) {
Serial.printf("The dumper web hook is on the run\n");

// Here the request is not interpreted, so we cannot for sure
// swallow the exact amount matching the full request+content,
// hence the tcp connection cannot be handled anymore by the
// webserver.
#ifdef STREAMTO_API
// we are lucky
client->toWithTimeout(Serial, 500);
#else
auto last = millis();
while ((millis() - last) < 500) {
char buf[32];
size_t len = client->read((uint8_t*)buf, sizeof(buf));
if (len > 0) {
Serial.printf("(<%d> chars)", (int)len);
Serial.write(buf, len);
last = millis();
}
}
#endif
// Two choices: return MUST STOP and webserver will close it
// (we already have the example with '/fail' hook)
// or IS GIVEN and webserver will forget it
// trying with IS GIVEN and storing it on a dumb WiFiClient.
// check the client connection: it should not immediately be closed
// (make another '/dump' one to close the first)
Serial.printf("\nTelling server to forget this connection\n");
static WiFiClient forgetme = *client; // stop previous one if present and transfer client refcounter
return ESP8266WebServer::CLIENT_IS_GIVEN;
}
return ESP8266WebServer::CLIENT_REQUEST_CAN_CONTINUE;
});

// Hook examples
/////////////////////////////////////////////////////////

server.begin();
Serial.println("HTTP server started");
}
Expand Down
Loading