1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

1515 Commits

Author SHA1 Message Date
Erriez
d90015e326
Merge branch 'master' into feature/issue-2246-multi-wifi-hidden 2021-01-19 16:12:54 +01:00
Paulo Cabral Sanz
85e2ffffe1
Allow users to inherit and override CertStore (#7827)
Make installCertStore virtual so we can inherit from CertStore and override it
Create CertStoreBase to inherit from
2021-01-18 11:59:20 -08:00
Earle F. Philhower, III
f5fd5912fe
Allow specifying waveform generator in source code (#7800)
* Allow specifying waveform generator in source code

Allows code to explicitly specify which waveform generator it wants,
without needing to use one of the 100 IDE menus or adding a `-D`
compile-time define.

Uses weakrefs to allow for apps to call `enablePhaseLockedWaveform();`
within their `setup()` (or anywhere, really) and have the phase locked
versions override the default waveform generators automatically.

For example:

````
void setup() {
  // Uncomment following line to use phase-locked waveform generator
  // enablePhaseLockedWaveform();
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
  analogWriteRange(1000);
}
void loop() {
  analogWrite(LED_BUILTIN, 100);
  delay(1000);                      // Wait for a second
  analogWrite(LED_BUILTIN, 900);
  delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)
}
````

Also adds an example showing it's use.

Address @dok-net's comments and also remove the _weak/_bound version of
startWaveform() since it's invariant of the actual waveform generator.
2021-01-17 15:57:26 -08:00
Paulo Cabral Sanz
e938739115
Prevent nullptr dereference on OOM (#7823) 2021-01-12 14:55:57 -08:00
Paulo Cabral Sanz
07241dd407
Avoid UB and abort on nullptr buffer (#7822)
* Avoid UB and abort on nullptr buffer
* Report OOM on return value
2021-01-12 22:39:55 +01:00
Paulo Cabral Sanz
98a19ab245
Protect against server hijacking error handling (#7811)
If a server returns "HTTP/1.x -8 OK", for example, it can misguide an application developer into freeing less-important memory so the request can be retried and succeed, when the problem is in the server.

_returnCode is never used anywhere else, but it could still contain a negative value returned by a broken server and therefore could cause troubles in the future (if _returnCode is in fact used)
2021-01-07 21:22:36 -08:00
M Hightower
2f5979f1f0
Verify IRAM sum results using DRAM as reference. (#7812)
Make verify fail more visible.

Updated example irammem.info to show performance and test int16 handling
when IRAM is used.

Removed 4K performance test. It didn't show any new information over the 1K test.
2021-01-07 20:45:15 -08:00
Dirk O. Kaar
f959cb321b
EspSoftwareSerial 6.11.2: Delegate<> assign operators added. (#7815)
Addresses compilation errors with pending PRs due to commit 95fb104562
2021-01-07 20:36:58 -08:00
Earle F. Philhower, III
da138456a6
Fix header FSM in webserver, fix Windows uploads (#7805)
When a file upload ends in \r\n (i.e. a Windows formatted text file) the
sequence of bytes on the wire is `\r\n\r\n----...boundary-marker...`.

When the FSM in Webserver was evaluating the stream, that 2nd `\r` would
be written as valid data and the FSM parser would be reset and see `\n`
as the 1st character, which wouldn't match.  This would a) add an extra
`\r` to uploaded files, and b) cause uploads to hang.

Fix by checking on a header FSM mismatch if the next character input
could possibly match our marker, and if so handle it properly.

Fixes #7803
2021-01-01 13:07:59 -08:00
Dirk O. Kaar
a25895a764
Minor EspSoftwareSerial release 6.11.1 (#7804)
* Minor EspSoftwareSerial release 6.11.0: more GPIOs for ESP32

* EspSoftwareSerial: Fix unused parameter warning.

* Revert "Minor EspSoftwareSerial release 6.11.0 (#7802)"

This reverts commit 229903a24d508288b237afd20de7baf3ff29b74d.
2020-12-31 12:56:44 -08:00
Dirk O. Kaar
229903a24d
Minor EspSoftwareSerial release 6.11.0 (#7802)
* Minor EspSoftwareSerial release 6.11.0: more GPIOs for ESP32

* EspSoftwareSerial: Fix unused parameter warning.
2020-12-31 10:54:12 -08:00
David Luna
a3a7a23a92
Typo error in ESP8266WiFiGeneric.h (#7797)
Error in copyright text about Arduino Wifi library
2020-12-27 22:15:26 +01:00
Earle F. Philhower, III
c487ca5233
Update to SdFat 2.0.2, speed SD access (#7779)
* Update to upstream SdFat 2.0.2

Increases the read/write performance for SD card accesses
by a significant amount, up to 5x (3+MB/s) in testing.

Fixes #7772 

* Add SDFS::availableForWrite handler

Peek into the sector cache to determine the maximum number of
bytes that can be written w/o needing a (slow) SD operation.

Fixes #7650
2020-12-23 11:39:12 -08:00
Earle F. Philhower, III
9de8373f1b
BREAKING - Upgrade to upstream newlib 4.0.0 release (#7708)
* Upgrade to upstream newlib 4.0.0 release

Includes 64 bit time_t and 5 years of updates.

Binary incompatible with libraries which use time_t (due to the size
difference).  Recompiling with the new newlib should be sufficient for
most libraries, assuming source is available.

* Remove tools/sdk/libc directory, it isn't used anywhere

Somewhere along the line the copy of libc in tools/sdl/libc was taken
out of the build process.  Files in there are not used, take add'l time
to build and install on a toolchain release, and just cause confusion.
Remove them.

* Fix 64-bit time for LittleFS

The core was setting 64-bit times automatically on new file creation or
updates, but would fail when attempting to read them back due to 64/32b
confusion.

Now attempt to read 64b time, and if that fails fallback to reading 32b
time to allow both old and new FS to preserve timestamps.

* Update to jjsuwa-sys3175 additions to GCC and newlib

@jjsuwa-sys3175 contributed multiple patches to GCC, included in
the toolchain, as well as a slightly faster pgm_read_byte() macro.

* Rebuild w/addl GCC patches, new BearSSL flags

* Remove copied libgcc.a file, is contained in toolchain
2020-12-23 11:21:38 -08:00
david gauchard
51c2a1437b
more lwIP physical interfaces (#6680)
This commit adds W5500 W5100 and ENC28j60 drivers from @njh with credits
They are available in libraries/
An example is added in W5500 examples directory

plus:
* Extract dhcp server from lwip2 and add it to the core as a class.
  It must always be present, it is linked and can be called by fw on boot.
  So it cannot be stored in a library.
* ethernet: static or dhcp works
* PPPServer: example
* bring WiFi.config() to the lwIP generic interface (argument reorder common function)
* move hostname() from WiFI-STA to generic interface
* remove non readable characters from dhcp-server comments
* dhcp-server: magic_cookie is part of bootp rfc
* fixes from https://github.com/d-a-v/W5500lwIP/issues/17
* enable lwip_hook_dhcp_parse_option()
* +ethernet tcp client example in w5500 library examples
2020-12-22 22:36:21 +01:00
Earle F. Philhower, III
35d22edeec
Rationalize File timestamp callback (#7785)
Fixes #7775

Clean up the passing/setting of custom File time callbacks and add a
host test verifying they work.  Existing core was not passing custom
timeCallbacks set at the FS level down to open()ed files, resulting in
them calling the default time(nullptr) and reporting wrong file modify
times.
2020-12-22 10:41:11 +01:00
Earle F. Philhower, III
f1dc6e90ee
Update to LittleFS v2.3 (#7787)
Minor performance improvement and LFS_READONLY added, enabling smaller
code for things like eboot should we want to us it in a bootloader/etc.
2020-12-21 21:21:42 -08:00
Zakary Kamal Ismail
032db6fc81
WiFiServerSecure: Cache SSL sessions (#7774)
* WiFiServerSecure: Cache the SSL sessions

* Add SSL session caching to HTTPS server examples

* Document server SSL session caching

* Fix an incomplete sentence in the documentation

* Document BearSSL::Session

* Use the number of sessions instead of the buffer size in ServerSessions' constructors
2020-12-21 21:13:43 -08:00
david gauchard
7dbef42ada
LEAmDNS fixes (#7786)
* LEAmDNS2 removed
* LEAmDNSv1: fix macro name
2020-12-22 01:29:00 +01:00
Dirk O. Kaar
dbe7eb89b9
EspSoftwareSerial bug fix release 6.10.1: preciseDelay() could delay() for extremely long time, if period duration was exceeded on entry. (#7771) 2020-12-15 12:22:57 -08:00
Costin Stroie
9a36cfdee9
Add the missing 'rename' method wrapper in SD library. (#7766) 2020-12-14 07:14:50 -08:00
Takayuki 'January June' Suwa
0f58a9009c
WiFiServer.cpp: Fix warning (#7755)
* fix warning as below:

...\libraries\ESP8266WiFi\src\WiFiServer.cpp: In member function 'WiFiClient WiFiServer::available(byte*)':
...\libraries\ESP8266WiFi\src\WiFiServer.cpp:120:55: warning: suggest braces around empty body in an 'if' statement [-Wempty-body]
  120 |             tcp_backlog_accepted(_unclaimed->getPCB());
      |                                                       ^
2020-12-11 10:54:23 +01:00
M Hightower
8b662ed3b3
PoC cache configuration control (#7060)
* PoC cache configuration control

Expaned boards.txt.py to allow new MMU options and create revised .ld's
Updated eboot to pass 48K IRAM segments.
Added Cache_Read_Enable intercept to modify call for 16K ICACHE
Update platform.txt to pass new mmu options through to compiler and linker preprocessor.
Added quick example: esp8266/MMU48K

* Style corrections
Added MMU_ qualifier to new defines.
Moved changes into their own file.
Don't know how to fix platformio issue.

* Added detailed description for Cache_Read_Enable.
Updated tools/sizes.py to report correct IRAM size and indicate ICACHE size.
Merged in earlephilhower's work on unaligned exception. Refactored and added
support for store operations and changed the name to be more closely aligned
with its function. Improved crash reporting path.

* Style and MMU_SEC_HEAP corrections.

* Improved asm register usage.
Added some inline functions to aid in byte and short access to iRAM.
 * only byte read has been tested
Updated .ld file to work better with platform.io; however, I am still
missing some steps, so platformio will still fail.

* Interesting glitch in boards.txt after github merge. A new board in
master was missing new additions added by boards.txt.py in the PR.
Which the CI flags when it rebuilds boards.txt.

* Support for 2nd Heap, excess IRAM, through umm_malloc.

Adapted changes to umm_malloc, Esp.cpp, StackThunk.cpp,
WiFiClientSecureBearSSL.cpp, and virtualmem.ino to irammem.ino from
@earlephilhower PR #6994.

Reworked umm_malloc to use context pointers instead of copy context.
umm_malloc now supports allocations from IRAM. Added class
HeapSelectIram, ... to aid in selecting alternate heaps,
modeled after class InterruptLock.
Restrict alloc request from ISRs to DRAM.

Never ending improvements to debug printing.

Sec Heap option now pulls in free IRAM left over in the 1st 32K block.
Managed through umm_malloc with HeapSelectIram.

Updated examples.

* Post push CI cleanup.

* Cleanup part II

* Cleanup part III

* Updates to support platformio, maybe.

* Added exception C wrapper replacement.

* CI Cleanup

* CI Cleanup II

Don't know what to do with platformio it doesn't like my .S file.
ifdef out USE_ISR_SAFE_EXC_WRAPPER to block the new assemlby module
from building on platformio only.

* Changes to exc-c-wrapper-handler.S to assemble under platformio.

* For platformio, Correction to toolchain-xtensa include path.
@mcspr, Thankyou!

* Temporarily added --print-memory-usage to ld parameters for cross-checking IRAM size.

* undo change to platform.txt

* correct merge conflict. take 1

* Fixed #if... for building umm_get_oom_count. It was not building when UMM_STATS_FULL was used.

* Commented out XMC support. Compatibility issues with PoC when using 16K ICACHE.

* Corrected size.py, DRAM bracketing changed to not include ICACHE with DRAM total.

* Added additional _context for support of use of UMM_INLINE_METRICS.
Corrected some UMM_POSION missed edits.

* Changes to clear errors and warnings from toolchain 10.1

Several fixes and improvements to example MMU48K.

With the improved optimization in toolchain 10.1 The example divide by 0
exception was failing with a HWDT event instead of its exception handler.
The compiler saw the obscured divide by 0 and replaced it with a break point.

* Isolated incompatable definitions related to _xtos_set_exception_handler.
GDBSTUB definitions are different from the BootROM's.

* Update tools/platformio-build.py

Co-authored-by: Max Prokhorov <prokhorov.max@outlook.com>

* Requested changes

Changed mmu related usages of ETS_... defines to DBG_MMU_...

Cleanup in example MMU48K.ino. Removed stale memory reference macro
and mmu_status print statement. Cleanup printf '\n' to be '\r\n'.

Improved issolation of development debug prints from the rest of the debug prints.

* Corrected comment. And added missing include.

* Improve comment.

* style and comment correction

* Added draft mmu.rst file and updated index.
Updated example HeapMetric.ino to also illustrate use of IRAM
Improved comments in exc-c-wrapper-handler.S. Added insurance IRQ disable.

* Updated mmu.rst

Improved function name uniqueness for is_iram, is_dram, and is_icache by
adding prefix mmu_. Also, made them available outside of a debug build.
Made pointer precision width more specific.

Made some of the static inline functions in mmu_irm.h safe for ISRs by
setting then for always inline.

* Add a default MMU_IRAM_SIZE value for a new CI test to pass.

Extended use 'umm_heap_context_t *_context' argument in ..._core functions
and expanded its usage to reduce unnecessary repeated calls to
umm_info(NULL, false), also removed recursion from umm_info(NULL, true).

Fixed stack buffer length in umm_info_safe_printf_P and heap.cpp.

Added example for creating an IRAM reserve section.

Updated mmu.rst. Grammar and spelling corrections.

* CI appeasement

* CI appeasement with comment correction.

* Ensure SYS always runs with DRAM Heap selected.

* Add/move heap stack overflow/underflow check to Esp.cpp where the event was discarded.

* Improved comment clarity of purpose for IramReserve.ino. Clean up MMU48K.ino

* Added missing #include

* Corrected usage of warning

* CI appeasement and use #message not #pragma message

* Updated git version of eboot.elf to match build version.
Good test catch.

* Remove conditional build option USE_ISR_SAFE_EXC_WRAPPER, always install.

Use the replacement wrapper on non32xfer_exception_handler install.

Added comments to code describing some exception handling issues.

* Updated mmu.rst

* Expanded and clarified comments.

Limited access to some detailed typdefs/prototypes to .cpp
modules, to avoid future build conflicts.

Completed TODO for verifing that the "C" structure struct __exception_frame
matches the ASM version.

Fixed some typo's, code rot, and added some more cases in examaple irammem.ino.
Refactored a little and reordered printing to ease comparison between methods.

Corrected `#ifdef __cplusplus` coverage area. Cleaned up `extern "C" ...` usage.
Fixes issues with including mmu_iram.h or esp8266_undocumented.h in .c files.

* Style fixes and more cleanup

* Style fix

* Remove unnessasary IRAM_ATTR from install_non32xfer_exception_handler

Some comment tuning.

In the context of _xtos_set_exception_handler and the functions it registers,
changed to type int for exception cause type. This is also the type used by gdbstub
and some other Xtensa files I found.
2020-12-06 14:15:42 +01:00
david gauchard
594831d605
WiFiClientSecure: use context (#7680)
* move WiFiClientSecure to WiFiClientSecureCtx and add WiFiClientSecure wrapper to handle the context
* explicitely disable context copy constructor (similar to operator=)
* move (static) probeMaxFragmentLength back from ctx to WiFiClientSecure
* route sslclient::status() to context's ::status()
2020-12-03 10:35:24 +01:00
Luca Passarella
7a368747e0
ETag support for WebServer (#7709)
* implemented with native md5
* testing locals variables
* less memory used, partil refactoring
* reworked serveStatic logic, different handler for File and Directory
2020-12-01 09:52:58 +01:00
Earle F. Philhower, III
92175d7090
Rewrite multipart boundary detection (#7728)
Use a simpler, cleaner implementation of multipart form detection as
defined in https://tools.ietf.org/html/rfc7578 .

Implements a simple state machine that detects the `\r\n--<boundary>`
stream in input a character at a time, instead of buffering and
comparing in chunks which can miss things due to alignment issues and
which also had a problem with replacing characters in a binary stream.

Adjust the private _uploadReadByte function to return -1 on error (like
a read()), and the main file upload handler to use that return value
instead of duplicating logic.

Fixes #7723
2020-11-28 17:22:34 -08:00
drderiv
47a57e1ec6
Update to ESP8266HTTPClient.cpp for no Content-Length (#7691)
Response bodies are ignored when _transferEncoding == HTTPC_TE_IDENTITY and there is no Content-Length header.  The added code here fixes that issue.

Add logic to writeToStreamDataBlock to only read what's available so as to avoid timeout, and adjust formatting.
2020-11-20 15:23:43 -08:00
Earle F. Philhower, III
4c7a20868a
Undo accidental loss of 6.10.0 SoftwareSerial (#7714) 2020-11-19 21:53:02 -08:00
Earle F. Philhower, III
ccdde5f396
Re-implement PWM generator logic (#7231)
* Re-implement PWM generator logic

Add special-purpose PWM logic to preserve alignment of PWM signals for
things like RGB LEDs.

Keep a sorted list of GPIO changes in memory.  At time 0 of the PWM
cycle, set all pins to high.  As time progresses bring down the
additional pins as their duty cycle runs out.  This way all PWM signals
are time aligned by construction.

This also reduces the number of PWM interrupts by up to 50%.  Before,
both the rising and falling edge of a PWM pin required an interrupt (and
could shift arround accordingly).  Now, a single IRQ sets all PWM rising
edges (so 1 no matter how many PWM pins) and individual interrupts
generate the falling edges.

The code favors duty cycle accuracy over PWM period accuracy (since PWM
is simulating an analog voltage it's the %age of time high that's the
critical factor in most apps, not the refresh rate).  Measurements give
it about 35% less total error over full range at 20khz than master.

@me-no-dev used something very similar in the original PWM generator.

* Adjust running PWM when analogWriteFreq changed

Use fixed point math to adjust running PWM channels to the new
frequency.

* Also preserve phase of running tone/waveforms

Copy over full high/low periods only on the falling edge of a cycle,
ensuring phase alignment for Tone and Servo.

* Clean up signed/unsigned mismatch, 160MHz operat'n

* Turn off PWM on a Tone or digitalWrite

Ensure both the general purpose waveform generator and the PWM generator
are disabled on a pin used for Tone/digitalWrite.

* Remove hump due to fixed IRQ delta

A hump in the dueling PWMs was very prominent in prior pulls.

The hump was caused by having a PWM falling edge just before the cycle
restart, while having the other channel requesting a 1->0 transition
just outside the busy-loop window of 10us. So it gets an IRQ for channel
B 0->1, then waits 2..8us for the next PWM full cycle 0->1, and ends up
returning from interrupt and not scheduling another IRQ for 10us...hence
the horizontal leg of the bump...

Reduce the minimum IRQ latency a little bit to minimize this effect.
There will still be a (significantly smaller) hump when things cross, but
it won't be anywhere near as bad or detectable.

* Speed PWM generator by reordering data struct

Breaking out bitfields required a load and an AND, slowing things down
in the PWM loop. Convert the bitfield into two separate natural-sized
arrays to reduce code size and increase accuracy.

* Remove if() that could never evaluate TRUE

* Add error feedback to waveform generation

Apply an error term to generated waveform phase times to adjust for any
other ongoing processes/waveforms.  Take the actual edge generation
times, subtract them from the desired, and add 1/4 of that (to dampen
any potential oscillations) to the next similar phase of that waveform.

Allows the waveform to seek its proper period and duty cycle without
hardcoding any specific calibrations (which would change depending on
the codepaths, compiler options, etc.) in the source.

* Move _stopPWM and _removePWMEntry to IRAM

Thanks to @dok-net for noticing these need to be in IRAM as they may be
called by digitalWrites in an IRQ.

* Avoid long wait times when PWM freq is low

* Fix bug where tone/pwm could happen on same pin

* Adjust for random 160MHZ operation

The WiFi stack sometimes changes frequency behind our backs, so ESP's
cycle counter does not count constant ticks.

We can't know how long it's been at a different than expected frequency,
so do the next best thing and make sure we adjust any ESP cycles we're
waiting for by the current CPU speed.

This can lead to a blip in the waveform for 1 period when the frequency
toggles from normal, and when it toggles back, but it should remain
for the intervening periods.

Should avoid a lot of LED shimmering and servo errors during WiFi
connection (and maybe transmission).

* Clean up leftover debugs in ISR

* Subtract constant-time overhead for PWM, add 60khz

PWM has a constant minimum time between loops with a single pin, so pull
that time out of the desired PWM period and shift the center of the PWM
frequency closer to the desired without any dynamic feedback needed.

Enable 60khz PWM, even though it's not terribly useful as it causes an
IRQ every ~8us (and each IRQ is 2-3us).  The core can still run w/o WDT,
but it's performance is about 5x slower than unloaded.

* Fix GPIO16 not toggling properly.

* Remove constant offset to PWM period

analogWrite doesn't know about the change in total PWM cycles, so it is
possible for it to send in a value that's beyond the maximum adjusted
PWM cycle count, royally messing up things.  Remove the offset.

Also, fix bug with timer callback functions potentially disabling the
timer if PWM was still active.

* Remove volatiles, replace with explicit membarrier

Volatiles are expensive in flash/IRAM as well as in runtime because they
introduce `memw` instructions everywhere their values are used.

Remove the volatiles and manually mark handshake signals for
re-read/flush to reduce code and runtime in the waveform generator/PWM.

* Consolidate data into single structure

Save IRAM and flash by using a class to hold waveform generator state.
Allows for bast+offset addressing to be used in many cases, removing
`l32r` and literals from the assembly code.

* Factor out common timer shutdown code

* Remove unneeded extra copy on PWM start

* Factor out common edge work in waveform loop

* Factor out waveform phase feedback loop math

* Reduce PWM size by using 32b count, indexes

Byte-wide operations require extra instructions, so make index and count
a full 32-bits wide.

* GP16O is a 1-bit register, just write to it

Testing indicates that GP16O is just a simple 1-bit wide register in the
RTC module.  Instead of |= and &- (i.e. RmW), use direct assignment in
PWM generator.

* Increase PWM linearity in low/high regions

By adjusting the PWM cycle slightly to account for the fixed time
through the compute loop, increase the linear response near the min and
max areas.

* Remove redundant GetCycleCount (non-IRQ)

* Factor out common timer setup operations

* Fix clean-waveform transition, lock to tone faster

New startWaveform waveforms were being copied over on the falling edge
of the cycle, not the rising edge.  Everything else is based on rising
edge, so adjust accordingly.

Also, feedback a larger % of the error term in standard waveform
generation.  Balances the speed at which it locks to tones under
changing circumstances with it not going completely bonkers when a
transient error occurs due to some other bit.

* Reduce IRAM by pushing more work to _setPWM

Simply mark pins as inactive, don't adjust the ordered list until the
next _startPWM call (in IROM).

* Fix typo in PWM pin 1->0 transition

Actually check the pin mask is active before setting the PWM pin low.
D'oh.

* Combine cleanup and pin remove, save 50 bytes IROM

The cleanup (where marked-off pins are removed from the PWM time map)
and remove (where a chosen pin is taken out of the PWM map) do
essentially the same processing.  Combine them and save ~50 bytes of
code and speed things up a tiny bit.

* Remove unused analogMap, toneMap

Save ~100 bytes of IROM by removing the tone/analog pin tracking from
the interface functions.  They were completely unused.

* Save IRAM/heap by adjusting WVF update struct

The waveform update structure included 2 32-bit quantities (so, used
8 * 17 = 136 bytes of RAM) for the next cycle of a waveform.

Replace that with a single update register, in a posted fashion.  The
logic now sets the new state of a single waveform and returns
immediately (so, no need to wait 1ms if you've got an existing waveform
of 1khz).  The waveform NMI will pick up the changed value on its next
cycle.

Reduces IRAM by 40 bytes, and heap by 144 bytes.

* Don't duplicate PWM period calculation

Let the waveform generator be the single source of truth for the PWM
period in clock cycles.

Reduces IRAM by 32 bytes and makes things generally saner.

* Factor out common PWM update code

Replace repeated PWM update logic with a subroutine, and move the
PWMUpdate pointer into the state itself.  Reduces IROM and IRAM,
removes code duplication.

Also remove single-use macros and ifdef configurable options as the
IRAM and IROM impact of them are now not very large.

* Fix regression when analogWrite done cold

Lost an `initTimer()` call in a refactoring, resulting in the core
hanging forever while waiting for the NMI which will never happen.

Re-add as appropriate.

* Save 16b of IRAM by not re-setting edge intr bit

Per @dok-net, drop the rewrite of the edge trigger flag in the timer
interrupt register.  It's set on startup and never cleared, so this is
redundant.  Drops ~16 bytes of IRAM.

* Allow on-the-fly PWM frequency changes

When PWM is running and analogWriteFreq is called, re-calculate the
entire set of PWM pins to the new frequency.  Preserve the raw
numerator/denominator in an unused bit of the waveform structure to
avoid wasting memory.

* Adjust for fixed overhead on PWM period

Pulls the actual PWM period closer to the requested one with a simple,
0-overhead static adjustment.

* Fix value reversal when analogWrite out of range

Silly mistake, swapped high and low values when checking analogWrite for
over/under values.  Fixed

* Don't optimize the satopWaveform call

Save a few bytes of IRAM by not using -O2 on the stopWaveform call.  It
is not a speed-critical function.

* Avoid side effects in addPWMtoList

* Adjust PWM period as fcn of # of PWM pins

Results in much closer PWM frequency range over any number of PWM pins,
while taking 0 add'l overhead in IRAM or in the IRQ.

* Fix occasional Tone artifacts

When _setPWMFreq was called the initial PWM mask was not set to 0
leading to occasional issues where non-PWM pins would be set to 1
on the nextPWM cycle.  Manifested itself as an overtone at the PWM
frequency +/-.

* Reduce CPU usage and enhance low range PWM output

Borrow a trick from #7022 to exit the busy loop when the next event is
too far out.  Also reduce the IRQ delta subtraction because it was
initially not NMI so there was much more variation than now.

Keep the PWM state machine active at a higher prio than the standard
tone generation when the next edge is very close (i.e. when we're at
the max or min of the range and have 2 or more near edges).  Adds a
lot of resolution to the response at low and high ranges.

Go from relative to absolute cycle counts in the main IRQ loop so that
we don't mingle delta-cycles when the delta start was significantly
different.

* Update min IRQ time to remove humps in PWM linearity

Keep PWM error <2.0% on entire range, from 0-100%, and remove the
hump seen in testC by fixing the min IRQ delay setting.

* Remove minor bump at high PWM frequencies

The IRQ lead time was a tiny bit undersized, causing IRQs to come back
too late for about .25us worth of PWM range.  Adjust the constant
accordingly
2020-11-19 20:47:05 -08:00
david gauchard
eec4dc490b
install a new waveform-flavouring Arduino IDE menu and a new PIO #define (#7712) 2020-11-19 22:33:31 +01:00
Dirk O. Kaar
0e735e386d
Waveform: fix significant jitter, that stresses servos and is clearly audible in Tone output (#7022)
* Allow 100% high or low periods.

Let output remain at current level on stopping instead of always turning to low.

* Fix serious jitter issues in previous versions.

* Use ESP.getCycleCount() just like everyone else.

* Highest timer rate at which this runs stable appears to be 2µs (500kHz).

* Guard for zero period length undefined waveforms.

Fix for zero duty or off cycles and expiring from them.

* Cycle precision for expiry instead of special treatment for 0 value.

* Give expiry proper precedence over updating a waveform

* Important comment

* Refactored, identical behavior.

* Use plural for bit arrays.

* Fix for completely duty or all off cycle period case.

* Expiration is explicitly relative to service time.

* Comment updated, here it's about cycles not usecs.

* Revert misconception of how waveformToEnable/Disable communicates with the NMI handler.

* Rewrite to keep phase in sync if period remains same during duty cycle change.

Refactor identifies to distinguish CPU clock cycle from waveform cycle.

* Rather iterate even if full-duty or no-duty cycle in period, than too many calculations in NMI handler.

* Must fire timer early to reach waveform deadlines, otherwise under some load aggressive jitter occurs.

* Schedule expiry explicitly, too.

Needed to keep track of next timer ccy in each iteration, not just when changing level.

* Quick change lets analogWrite keep phase for any duty cycle (including 0% and 100%).

* Set duration to multiple of period,  so tone stops on LOW pin output.

* Improve phase timing

* Eror causing next Timer IRQ to fail busy-to-off cycle transitions.

* Regression fix, don't reset timer if pending shortly.

* Rather reschedule ISR instead of busy looping during permitted maximum time.

* Lead time improved for ISR

* Reduce number of cycle calculations.

* Reactive the gcc optimize pragmas.

* Simplify calculation.

* handles overshoot where an updated period is shorter than the previous duty cycle

* Misleading code, there must ever be only one bit set at a time, start and stop block until the ISR has handled and reset the token.

* Prevent missing a duty cycle unless it is overshot already.

* Continuously remove distant pending waveform edges from the loop, continuously update now.

* Replace volatile for one-way exchange into ISR with memory fence.

* Remove redundant stack object.

* Revert pending waveform removal from loop - corrupts continuous next event computation.

* Reduce if/do ... while to while

* Convert relative timings to absolute.

* Relax waveform start to possibly cluster phases into same IRQ interval.

* max 12us in ISR seems to work best for servo/fan/led/tone combo test.

* Restructured code in ISR for expiration, this saves 36 byte IRAM, and improves PWM resolution.

* Simplified overshot detection and 0% / 100% duty cycle.

* Leave ISR early if rescheduling is more promising than busy-waiting until next edge.

* Stabilized timings.

* Prevent WDT under load.

* Use clock cycle resolution instead of us for analogWrite.

* Reduce idle calculations in ISR.

* Optimize in-ISR time.

* Support starting new waveform in phase with another running waveform.

* Align phase for analogWrite PWMs.

* Tune preshoot, add lost period fast forward.

* Adapt phase sync code from analogWrite to Servo

* Fix for going off 100% duty cycle period.

* Eschew obfuscation.

* Fixed logic for zero duty cycle.

* Determine generator quantum during same IRQ - this is better than timer resolution, but non-zero.

* Tune timings, fix write barriers and overshoot logic.

* Migrate Tone to waveform with CPU cycle precision

* Can do 60kHz PWM.

* Recalibrated timings after performance optimizations.

Initialize GPIO if needed.

* Fix regression for waveform runtime.

* Test cycle duration values for signed arithmetic safety.

* Performance tuning.

* Performance tweak, in-ISR quantum is now 1.12µs.

* Round up duration instead of down - possibly to zero, which means forever.

* Extend phase alignment with optional phase offset.

* Slightly better in-ISR quantum approximation for steadier increments.

* Waveform stopped by runtime limit in iSR doesn't deinit the timer, but stopWaveform refuses

to do anything if the waveform was stopped by runtime, either.

* Improved quantum correction code.

* Fix broken multi-wave generation.

* Aggregate GPIO output across inner loop. True phase sync, and now better performance.

* IRQ latency can be reduced from 2 to 1 us now, no WDT etc.

* Improved handling of complete idle cycle miss, progress directly into duty cycle.

* Recalibrated after latest changes and reverts.

* Overshoot compensation for duty cycle results in PWM milestone.

* Adjustments to duty/idle cycle to mitigate effects of floating duty cycle logic.

* Remove implicit condition from loop guard and fix timer restart duration

* Host all static globals in an anonymous static struct.

* Busy wait directly for next pending event and go to that pin.

* Record nextEventCcy in waveform struct to save a few cycles.

* Adapt duty cycle modification to only fix full duty and all idle cases.

* Remember next pin to operate between IRQs.

* Don't set pinMode each time on already running PWM or Tone.

* Remove quantum, correct irq latency from testing,reuse isr timeout from master et al

* Move updating "now" out of inner loop, prevents float between pins that are in phase lock.

* Merge init loop with action loop again.

* Adaptive PWM frequency and floating duty cycle.

* Predictive static frequency scaling.

* Dynamic frequency down-scaling

* Frequency scaling is only for PWM-like applications, anything needing real time duty cycles or frequency must be able to fail on overload.

* Conserve IRAM cache, resort to best effort.

* Directly scale frequency for all duty/all idle waves to reasonable maximum, reduces thrashing.

* Getting the math right beats permanently reducing PWM frequency.

* Rename identifier to help think about the problem.

* AutoPwm correction moved to correct location - after overshoot recalc - and allow limited duty floating

* Finish overshoot math fixes.

* First set pin mode, then digital write.

* Simplify calculations, fix non-autoPwm for servo use, where exact duty is needed, idle is elastic.

* Move wave initialization and modification outside the inner loop.

* Some optimizing.

* Updating "now" in the inner loop should lessen interference

* Finally get rid of volatile and use atomic thread fence memory barriers, great for ISR performance.

* Improved idle cycle overshoot mitigation.

* Improved duty cycle overshoot mitigation.

Case for investigation: 3% (shl 5) vs. 1.5% (shl 6), either less fuzz, but a few marked stray spots, or more fuzz, but no bumps in counter-PWM travel test.

* Move startPin etc. into common static struct

* Persist next event cycle across ISR invocations, like initPin was before.

* Recalibrated DELTAIRQ and IRQLATENCY. Tested @ 3x 40kHz PWM + 440Hz Tone

* CPU clock to Timer1 ccy correction must be dynamic even when BSP is compiled for fixed CPU clock.

* Corrected use of Timer1 registers and add rationale to Timer1 use in comment.

Recalibrate for improved frequence downscaling @ 80MHz and 160MHz.

* Let duty cycle overshoot correction depend on relative impact compareed to both period and duty.

* 80MHz/160MHz specific code can be compile-time selected in general, only NMI is affected by

apparent CPU frequency scaling in SDK code.

* Seems that removing the redudant resetting of edge interrupt mode shaves 0.5us off rearm latency.

* Recalibrated delta irq ccys.

* Off-by-one in 100% duty overshoot correction.

* Simple register writes.

* Memory fences checked and joining events into same loop iteration that are close to one another.

* Shorten progression when going off 100% duty.

* Code simplifications.

* Dynamically map pins out from in-ISR handling based on next event timing.

Major performance boost.

* Reverting maximum IRQ period to 10ms. This sets the wave reprogramming rate to 100Hz max.

* Revert recent change that is the most likely cause of reported PWM frequency drop regression.

* Much simplified overshoot mitigation code.

* Fixing overshoot mitigation, 3x 880Hz, 256 states now.

* Increase resolution by keeping reference time moving forward earlier.

* Mitigation logic for ESP8266 SDK boosting to 160MHz during some WiFi ops.

* Event timestamps are all recorded for compile-time CPU frequency, the timer ticks conversion

must be set at compile-time also. The SDK WiFi 160MHz boost mitigation temporarily handles
the CPU clock running twice as fast.

* Expired pins must not be checked for next event.

* Recalibrate after latest changes.

* Save a few bytes code.

* Guards are in place, so xor rather than and bitwise not.

* Reduce memory use.

* SDK boost to 160MHz may last across multiple ISR invocations, therefore adjust target ccy instead of ccount.

* Overshoot mitigation w/o PWM frequency change.

* New PWM overshoot mitigation code keeps frequency. Averages duty between consecutive periods.

* Small refactoring, remove code path that is never taken even at 3x25kHz/1023 PWM.

* Don't ever skip off duty, no matter if late or infinitely short.

* Shed speed-up code that didn't speed up things.

* Must always recompute new waveform.nextEventCcy if there is any busy pin.

* Break out of ISR if timespan to next event allows, instead of busy waiting and stealing CPU cycles from userland.

* Minor code simplification.

* Improve code efficiency.

* Improved performance of loop.

* Recalibrated.

* No positive effect of lead time inclusion was found during testing, remove this code.

Maximum period duration limit is implicit to timer, consider it documented constraint, don't runtime
check in ISR.

* Fix WDT when at 160MHz CPU clock the Timer1 is set below 1µs.

* Consolidate 160MHz constexpr check, finish 1µs minimum for Timer1 fix.

* Test for non-zero before subtract should improve performance.

* Reviewers/tested noted they were seeing WDT, and this change appeared to fix that.

* More expressive use of parentheses and alias CPU2X for reduced code size.

* Bug fix: at 160MHz compiled, don't force minimum Timer1 latency to 2µs.

* Alternate CPU frequency scaling mitigation.

* Handle time-of-flight in the right spot.

* Remove _toneMap from Tone.cpp

Co-authored-by: david gauchard <gauchard@laas.fr>
2020-11-19 22:12:06 +01:00
Dirk O. Kaar
5ae3efb823
EspSoftwareSerial 6.10.0: override keyword for recent Print::availableForWrite() addition (#7710)
* Strict C++ use of "override" update for Print::availableForWrite addition, and ESP32 GPIO fix.

* EspSoftwareSerial: minor version update to 6.10.0
2020-11-15 10:13:34 -08:00
Dirk O. Kaar
9b437d7c5e
Change servo defaults to safer defaults (#7023)
* The default timings were chosen vastly outside specification. On COTS servos, this causes much confusion for the user, because a wide range of angle starting from 0 degress, and a just a large range of angle leading up to 180 degrees, is dead - in fact, the servo doesn't move at all, from any position.

Not investigated further for obvious reasons, as this may have also destroyed servos that ran hot trying to abide by the PWM signal but could not mechanically!

* Change timing limits to safe values. With previous default timings and safety limits, popular servos

could force against internal physical endstops, which could overload and destroy them.

* Review action: revert changes to hard boundary for min/max duty cycle timings. Internal review, fix/drop legacy comments.

* A Servo on each available ESP8266 GPIO (D0-D8), no observed interference.

* Remove possible jerk due to force-cancelling duty cycle.

* Overload attach: can specify initial angle for servo, too.

* Stricter checks for configured, and default, bounded timings.

* Missed the min/max in a comment.

* Default microsecond lower bound of 1000 causes confusing behavior - 200 is minimum enforced elsewhere, so use it here too as nearest multiple of 100 from 180.

* Comment rationale for changed defaults of min/max pulse widths.

Comment rationale for changed defaults of min/max pulse widths.
2020-11-13 23:59:14 -08:00
Matthew Foran
5d2563eee9
Fixed bug in parsing POST file uploads (#7543)
The boundary parsing in the webserver could end up missing boundaries if the
uploaded file had `--` at the start of the line because it read in the entire boundary
length worth of bytes.  Fix by only reading up to either the boundary length or
a newline, avoiding the issue.

Fixes #7542
2020-11-01 18:31:59 -08:00
Earle F. Philhower, III
1bb0815fed
Hook up custom timestamp proc for SD/SDFS (#7686)
The SDFS implementation didn't include plumbing to support user-supplied
timestamp generators (for file create/write times) because the SDFat
library doesn't support a callback parameter.

Work around it by using a single, global (inside sdfs namespace) that
the static timestamp callback member can see and use.

Add a test of the feature in CI.

Fixes #7682
2020-10-31 08:05:34 -07:00
isadora-6th
996211f132
Compile failure fix with FS_NO_GLOBALS flag (#7685) 2020-10-29 17:11:57 -07:00
Earle F. Philhower, III
77bd71ec29
Add Stream loaders for BearSSL (#7675)
Fixes #7671

Allows for code to do things like read certs from LittleFS or even HTTP
connections with code like:

  File cert = LittleFS.open("/client-crt.pem", "r");
  clientCert = new X509List(cert, cert.size());
  cert.close();
2020-10-28 07:22:41 -07:00
Earle F. Philhower, III
cfdcff1028
Catch and display SSL errors for fatal alerts (#7681)
Partial fix to #7678
2020-10-27 22:18:26 -07:00
Earle F. Philhower, III
7f38e141c7
BREAKING: Add Print::availableForWrite method (#7658)
* Add Print::availableForWrite method

Adds an availableForWrite() method to the Print class, matching current
ArduinoCore-API commit 398e70f188e2b861c10d9ffe5e2bfcb6a4a4f489 .

Hook availableForWrite into the SDFS filesystem (other FSes don't have
this capability built-in).

Fixes #7650

* WiFiClient::availableForWrite proto matching Print

* Fix Netdump signedness warning

* Clean up Serial availableForWrite

This is evidently a breaking change due to the type difference.
Arduino's `availableForWrite` returns an `int`, while the
(multiply-implemented, non-virtual) core `availableForWrite` returned
`size_t`.
2020-10-27 11:55:42 +01:00
Erriez
95de525af9
Refactor WiFi scan example (#7655) 2020-10-27 11:20:07 +01:00
Earle F. Philhower, III
c65626622a
Fix long password validation in WebServer (#7676)
Use a base64 encode that doesn't add CRs to the output when comparing
username:password values for authentication.

Fixes #7664
2020-10-25 04:03:02 -07:00
david gauchard
95fb104562
settimeofday_cb: distinguish from user or sntp (#7637)
* settimeofday_cb: distinguish from user or sntp
2020-10-23 10:43:45 +02:00
Erriez
8efaa645c0
Merge branch 'master' into feature/issue-2246-multi-wifi-hidden 2020-10-18 19:11:31 +02:00
Earle F. Philhower, III
e920564b8d
Fix Netdump library architecture (#7659)
When building with the Netdump library, the IDE generates the following warning:
> WARNING: library Netdump claims to run on (esp8266 lwip) architecture(s) and may be incompatible with your current board which runs on (esp8266) architecture(s).

Fix the library.properties to call the architecture just "esp8266"
2020-10-17 11:21:40 -07:00
Erriez
e79eb1174d
BREAKING: Change return EEPROM.end() to bool (#7630) 2020-10-15 15:03:28 -07:00
Develo
81a10a48af
BREAKING: Change return type of channel() (#7656) 2020-10-15 14:48:00 -07:00
Develo
0452f4728f
BREAKING: Change return type of RSSI() (#7657) 2020-10-15 14:00:30 -07:00
Erriez
c82c6840e4 Add WiFi persistent to WiFi Multi example 2020-10-15 20:03:56 +02:00
Erriez
00673e05fb
Merge branch 'master' into feature/issue-2246-multi-wifi-hidden 2020-10-15 19:57:47 +02:00
Erriez
0d94b5f560 Add support for hidden AP's 2020-10-15 19:56:27 +02:00