1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-25 20:02:37 +03:00

896 Commits

Author SHA1 Message Date
Dirk Mueller
158039e414 Reduce mem footprint of ESP.getResetInfo() (#7030)
This function has excessively long datastrings that can
better be stored in flash, reducing runtime memory footprint.

Also detailed formatting only makes sense when there is an
exception or a watchdog. In other cases instead of printing
an unhelpful "flag: 0" we can just return the ResetReason, which
is much more readable.

Saves about 120 bytes of (data) memory.
2020-01-22 06:00:11 -08:00
Earle F. Philhower, III
5bc3079217
Fix Updater potential overflow, add host tests (#6954)
* Fix Updater potential overflow, add host tests

Fixes #4674

The Updater class could, when exactly 4K bytes were in the buffer but
not yet written to flash, allow overwriting data written to it beyond
the passed-in size parameter.

Fix per @jason-but's suggestion, and add a host test (plus minor changes
to Updater code to support host testing).

* Add missed mock file

* Remove most testing ifdefs fro updater

Per @mcspr's suggestion, we can pass in fake link symbols allowing
Updater to take the address of `_FS_start`/etc. even when building on
the host for testing.

There is still a single remaining wifi_set_power_mode ifdef'd and a
duplication of the digitalWrite/pinMode for testing vs. host building.

Co-authored-by: Develo <deveyes@gmail.com>
2020-01-08 17:38:28 -08:00
Earle F. Philhower, III
b62d8c7633
Update BearSSL, increase SSL stack (#6980)
Only minor updates to headers and no functionality change on the
portions that we use in the ESP8266.

@Teddyz reported random crashes while running against a local MQTT
server and was able to report stack usages of up to 6136 bytes.
Increase the SSL stack to a little more than that, once again.
2020-01-04 08:18:14 -08:00
StanJ
3197d2ac4e Issue2524 allow clocks below 100KHz (#6934)
* change bus clock (busywait) to be programmable [issue 2524], remove unused slave STOP function

* change bus clock (busywait) to be programmable [issue 2524], remove unused slave STOP function

* change bus clock (busywait) to be programmable [issue 2524], remove unused slave STOP function

* correct for underflow < 233Hz

* change bus clock (busywait) to be programmable [issue 2524], convert tabs to spaces

* updated minimum I2C speed for calculated bus clock
2019-12-28 19:07:38 -03:00
Dirk Mueller
698ffc3498 Various String handling cleanups (#6945)
Use the proper api (::clear(), isEmpty()) instead of doing
comparisons/assignments of empty strings. Also fix mixture
of tabs and spaces in the source code.
2019-12-26 17:03:18 -03:00
Dirk Mueller
6c2ab25087 Code size optimisations for ESP.getFullVersion() (#6936)
This saves about ~ 60 bytes of flash usage (50% reduction of
the total function size)
2019-12-23 17:52:16 -08:00
M Hightower
30bfdad458 Added missing "if (umm_heap == NULL) {..." to umm_free_heap_size_lw (#6929)
also called through xPortGetFreeHeapSize, umm_free_heap_size, ...

Co-authored-by: Earle F. Philhower, III <earlephilhower@yahoo.com>
2019-12-20 15:45:16 -08:00
Earle F. Philhower, III
52d84b1ead
Add a CRC32 over progmem and ESP.checkFlashCRC (#6566)
* Add a CRC32 over progmem and ESP.checkFlashCRC

Automatically embed a CRC32 of the program memory (including bootloader
but excluding any filesystems) in all images in unused space in the
bootloader block.

Add a call, ESP.checkFlashCRC() which returns false if the calculated
CRC doesn't match the one stored in the image (i.e. flash corruption).

Fixes #4165

* Add example that corrupts itself, comments

Show CRC checking catch a 1-bit error in program code by corrupting a
large array, and then return it to clean and verify the CRC matches once
again.

Add comments to the CRC check routine

Clean up pylint complaints on crc32bin.py

* Check linker script for CRC space in bootsector

Add an assertion in the eboot linker file to guarantee that we have at
least 8 bytes of unused space at the end of the boot sector to patch in
the CRC.  If not, the eboot link will fail.

* Add note about what to do if CRC check fails

Per discussion with @d-a-v.

When the CRC check fails, you could *try* to do certain things (but may
not succeed since there is known flash corruption at that point).  List
a few ideas for application authors.

* Only single, flash/ram friendly crc32() function

* Combine the CRC calc and bin generation in 1 step

Per discussion w/@mcspr, combine the CRC calculation with the binary
generation, removing the additional build step.
2019-12-20 14:38:35 -08:00
Earle F. Philhower, III
1d0bc5efdf
Allow GZIP compressed flash updates (#6820)
* Allow GZIP compressed flash updates

Modified the bootloader to be able to take stored updates in compressed
GZIP format (i.e. the output of "gzip -9 xxx.bin") and decompress them
on-the-fly to their final destination.  This can work for apps and for
filesystems (when used with the 2-step update option).

Allow eboot to be built using -Os/2 optimizations by fixing some portions
which failed when any optimizations were used.  Add -Wall and use data
and function sections to reduce size.  Use -Os to minimize size.

Remove obsolete esptool-ck calls to build a .ROM image, we don't use it.

Move all uninitted variables to RAM from IRAM, allowing 8-bit access.

Hook in @d-a-v and @pfalcon's uzlib port to actually do the
decompression.  Do not use any CRC checking which saves space.  Since we
have overwritten all of flash by the time we know id the CRC matches,
there's nothing we could have done anyway.

Adjust the Updater class to support GZIP files and not attempt to patch
them.

Bootloader builds to 0xd90 out of 0xfff bytes.

* Add @d-a-v's patch for httpupdate

https://github.com/esp8266/Arduino/pull/6820#pullrequestreview-326541014

* Update uzlib to point to pfalcon++

For now, because there are some self-test failures with @d-a-v's esp8266
branch (whose cool new features we don't actually use in eboot now)
start with pfalcon's 2.9 release and add the 2 patches (clcidx to code
from IRAM/RODATA, and the Windows test file renaming) needed to build
and run successfully.

* Add (c) notice for uzlib to README
2019-12-18 09:17:38 -08:00
david gauchard
3d128e5c78
release 2.6.3 (#6916) 2019-12-16 14:42:16 +01:00
StanJ
5612738636 change to make inline helpers truly inline [issue 6875] (#6898)
* change to make inline helpers truly inline [issue 6875]

* pulled the inline helpers out of the TWI class [issue 6875]

* removed some inlines causing issues [issue 6875]

* removed 2 more inlines from slave timeout section [issue 6875]

* removed 2 more inline attributes on public functions, moved twi_scl_valley up into the master section [issue 6875]
2019-12-15 14:38:33 -03:00
david gauchard
72a4dde64f
sntp callback: use a recurrent schedule function (#6888) 2019-12-10 11:41:42 +01:00
Earle F. Philhower, III
759ba27b62 Use 128B chunks instead of 1B writes in Print::print(FlashStringHelper) (#6893)
Fixes #6524

Should help with speed of output when printing large flash strings to
things like a file or a TCP connection.

Use a 128 byte chunk in a temp buffer to send data using write(),
reducing the # of write calls by ~128x.
2019-12-09 23:04:49 -03:00
Earle F. Philhower, III
7605dc1643
Only set flashmode byte when uploading an executable (#6891)
Fixes #6880

The updater was patching in the proper flashmode configuration byte for
all uploads, apps and filesystems.  This ended up corrupting one byte on
every FS upload.

Change updated to only patch theflashmode if it is doing an app.
2019-12-08 19:34:04 -07:00
StanJ
2309a1c9cb removed TWI_CLOCK_STRETCH_MULTIPLIER (#6867) 2019-12-03 14:45:58 -03:00
StanJ
cc6d346aa5 added clock stretch yield, [issue 2162] fixed twi::status (#6860) 2019-12-01 01:21:54 -03:00
Dirk O. Kaar
22b2687a25 Conflict with pre-included Arduino.h (the indirect includes thereof) (#6853)
* Conflict with pre-included Arduino.h (the indirect includes thereof) resolved.

* Include both time.h and sys/time.h
2019-11-28 15:31:57 -03:00
david gauchard
bc204a9bfa
release 2.6.2 (#6849) 2019-11-28 01:38:43 +01:00
Dirk O. Kaar
c37903c33b Uninitialized stack object can have unintended bad values (#6846) 2019-11-27 20:27:52 -03:00
david gauchard
05d28bc045 reset artificial timezone when using newlib (#6828) 2019-11-24 00:19:16 -03:00
Earle F. Philhower, III
ebae47c13a
Expand BSSL stack (#6819)
Fixes #6811 which found an issue where connecting to scripts.google.com
would *occasionally* cause a crash.  On inspection, it was found that up
to 5828 bytes of stack were used once in a while, so expand the stack to
5900 bytes to cover this case plus a little extra.
2019-11-20 18:05:38 -07:00
Dirk O. Kaar
007e495e0d Implement invert for HardwareSerial (#6816)
* Simple i/f to turn on inverted logic on UART0.

* Refactor invert from HardwareSerial to uart

* Final refactoring of invert bits into config bitmap.

* Overload instead of default arg for subclassing.

* Prevent unwanted effects if setting invert on other than UART0 - only that has these flags defined and documented.
2019-11-20 09:17:42 -07:00
Dirk O. Kaar
916eb89b07 Mark esp_schedule IRAM_ATTR to make it ISR safe - this complements the suspend CONT via esp_yield pattern in esp_delay for early returning from delay due to external events. In libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp this is done from CBs, that are called from tools/sdk/lwip/include/lwip/dns.h (#6809) 2019-11-20 00:50:40 -03:00
Dirk O. Kaar
cb6b30a47d Weak binding lessens version dependency between ESP8266 and MT library CoopTask. (#6790) 2019-11-19 04:43:28 -03:00
Earle F. Philhower, III
b71872ccca
Add stdint, move headers up in core_features.h (#6793)
Fixes #6791 which I think only happened when the file was included from
a .C file (due to the headers being included only ifdef __cplusplus).
2019-11-17 20:26:03 -07:00
david gauchard
af85bd2efc
release process for 2.6.1 (#6773) 2019-11-14 10:24:22 +01:00
Dirk O. Kaar
6f3c57b7fa Fix issue with functions scheduled from scheduled functions (#6770)
Calling schedule_function() from a scheduled function would result in an infinite loop, because the list traversal would never end.
2019-11-14 00:56:18 -03:00
Earle F. Philhower, III
09896d5287 Add String::concat(char*, len) to allow non null-term strings (#6754)
* Add comcat(char*, len) to Sting

Fixes #5061

Adds a concat(const char *data, int len) method which allows arbitrary
sequences of data (including ones w/embedded \0s) to be appended to a
String.  May be useful for certain MQTT operations.

Adds sanity test for the feature to host suite

* Review comment cleanups
2019-11-14 00:58:07 +01:00
s-hadinger
41d99ad48a WString explicit converters to reduce Flash size (#6759)
* WString explicit converters to reduce Flash size

* Fix add return value for start/endsWith

* Adding const to startsWith() and endsWith()
2019-11-12 18:47:26 +01:00
Peter
2c2468f962 Add ipv4_addr_t for espconn/LwIP1.4 compat (#6740)
`espconnn.h` references ipv4_addr_t, so it seems appropriate it be defined here also.
2019-11-10 00:41:26 +01:00
Develo
643ec203b3
Release 2.6.0 (#6733) 2019-11-08 19:08:14 -03:00
Niek van der Maas
3b1ad418b3 Add missing time.h include, use relative include path on time.h includes (#6730)
* Add missing time.h include

* Change other includes of time.h as well

* Added comment
2019-11-08 13:16:03 -03:00
Develo
453eb2d064
Add wait loop at the end of mode, refactor can_yield (#6721)
* Add wait loop at the end of mode, refactor can_yield

* fix mock build
2019-11-07 18:25:20 -03:00
david gauchard
6f7eb2828a Make SPIFFS and LittleFS stay out of link when not needed (#6699)
* define two weak functions defaulting to no-op
redefine them to do something useful when either spiffs or littlefs are used

* noop

* single entry point for closing FSes

* rename functions, override when instanciated, add link to explanation

* spiffs: call end on destructor
2019-11-06 21:37:52 -03:00
hreintke
2abcd16efb Implementation of a generic CallBackList (#5710)
* Initial version

Move to experimental namespace

Change namespace
2019-11-05 19:48:04 -03:00
Dirk O. Kaar
d14419efa2 Save 16 bytes RAM by placing esp8266_gpioToFn (core_esp8266_wiring_digital.cpp) array in PROGMEM (#6703)
* Save 16 bytes RAM by placing the array in PROGMEM.

* Reduce runtime computation at expense of switching from uint8_t[16] to uint32_t*[16]
2019-11-05 12:37:15 -03:00
Mike Nix
60c8975feb Spi0command (#6674)
* precache() - preload code into the flash cache.

By preloading code into the flash cache we can take control over when
SPI Flash reads will occur when code is executing.
This can be useful where the timing of a section of code is extremely
critical and we don't want random pauses to pull code in from the SPI
flash chip.

It can also be useful for code that accesses/uses SPI0 which is connected
to the flash chip.

Non interrupt handler code that is infrequently called but might otherwise
require being in valuable IRAM - such as bit-banging I/O code or some code
run at bootup can avoid being permanently in IRAM.

Macros are provided to make precaching one or more blocks of code in any
function easy.

* Fix missing include

* Make precache extern "C"

* Attempt 2 at making precache extern "C"

* Fix calculation of number of cache lines to preload

With certain alignments/lengths of code it was possible to not read enough
into the flash cache.

This commit makes the length calculation clearer and adds an extra cache
line to ensure we precache enough code.

* SPI0Command - A utility function for generic SPI commands on SPI0

The rom code does not support some flash functions, or have a generic
way of sending custom commands to the flash chip.
In particular XMC flash chips have a third status register, and the
ROM only supports two.

There are also certain requirements for using SPI0 such as waiting
for the flash to be idle and not allowing your code to trigger a flash
cache miss while using SPI0.

* Clean some trailing spaces

* Upgrade _SPI0Command to _SPICommand

We needed to assess the SPI registers as base+offset to avoid referring to the
registers using constant addresses as these addresses were loaded from flash
and had the potential to trigger a flash cache miss.
For similar reasons functions need to be called via function pointers stored
in RAM. Also avoid constants in FLASH, use a copy stored in RAM.

As a side effect we can now select which controller to access as a parameter.

* Tidy up a comment thats no longer applicable

* Comments, formatting and variable renames

Added a number of comments to better explain the code and improved the
formatting.

Also renamed some variables for consistency.

* put SPI0Command in namespace experimental

* Add a comment noting that the code has only been tested on bus 0

* Replace use of memcpy with for loops in _SPICommand()

memcpy is not guaranteed to be safe (IRAM_ATTR or ROM) like I thought.
As a bonus the for loop is guaranteed to do 32-bit wide transfers, unlike memcpy.

* Typo fix

what happens when you forget to edit after copy/paste

* Move the SpiOpResult enum into experimental namespace
2019-11-04 23:14:35 -03:00
Mike Nix
692e542d58 precache() - preload code into the flash cache. (#6628)
* precache() - preload code into the flash cache.

By preloading code into the flash cache we can take control over when
SPI Flash reads will occur when code is executing.
This can be useful where the timing of a section of code is extremely
critical and we don't want random pauses to pull code in from the SPI
flash chip.

It can also be useful for code that accesses/uses SPI0 which is connected
to the flash chip.

Non interrupt handler code that is infrequently called but might otherwise
require being in valuable IRAM - such as bit-banging I/O code or some code
run at bootup can avoid being permanently in IRAM.

Macros are provided to make precaching one or more blocks of code in any
function easy.

* Fix missing include

* Make precache extern "C"

* Attempt 2 at making precache extern "C"

* Fix calculation of number of cache lines to preload

With certain alignments/lengths of code it was possible to not read enough
into the flash cache.

This commit makes the length calculation clearer and adds an extra cache
line to ensure we precache enough code.

* Add noinline to PRECACHE_ATTR macro

Precached code needs to be noinline to ensure the no-reorder-blocks is applied.
2019-11-03 05:23:36 -03:00
david gauchard
bf4a4351b6
increase include file compatibility with other architectures (#6700) 2019-11-02 02:48:23 +01:00
Dirk Mueller
14262af0d1 Cleanup base64::encode functions (#6607)
* Cleanup base64::encode functions

The implementation choice here using libb64 is generally good as it
is a relatively fast implementation, however the adaptation to
use PROGMEM for the translation function was a bad choice, as reading
randomly PROGMEM with byte-wide access is very very very slow.

Doing a naive if-snake is between 20% and 55% faster and uses less
flash (about 120 bytes less) and also for reasons I don't understand
8 bytes less data RAM (maybe the removal of static?).

In addition the base64::encode function was allocating for larger
input a huge amount of memory (twice the total size). we can reduce
that by doing a chunk-wise conversation to base64.

* Create authorisation base64 encoded string without newlines

Rather than first creating a string with newlines and then
stripping it away in the fast path of constructing the query,
we can call the right method and trust that the result does
not have newlines anymore.
2019-10-31 13:18:36 -07:00
Earle F. Philhower, III
72dd589599 Add time to filesystem API (#6544)
* Add time to filesystem API

Support the ESP32 File::getLastWrite() call and setting the time on
all filesystems automatically (assuming the system clock has
been set properly and time(NULL) returns the proper time!).

Adds Dir::fileTime() to get the time of a file being listed, similar to
Dir::fileName() and Dir::fileSize().

Adds ::setTimeCallback(time_t (*cb)()) to File, Dir, and FS, allowing
users to override the default timestamp on a per-file, directory, or
filesystem basis. By default, a simple callback returning time(nullptr)
is implemented.

LittleFS uses the 't' attribute and should be backwards compatible.

SD/SDFS work and include wrappers for obsolete SdFat timestamp callbacks
using the MSDOS time.

This PR does not update SPIFFS, due to compatability concerns and a
possible massive rewrite which would make it possible to determine if an
old-style ot metadata enabled FS is present at mount time.

Includes an updated SD/listfiles and LittleFS_time example.

Replaces #6315

* Add links to new mklittlefs w/timestamp support

Include the update mklittlefs which generated 't' metadata on imported
files.
	../tools/sdk/lwip2/include/netif/lowpan6_opts.h

* Add explicit note about timestamp being local time

* Address review concerns

Clean up some awkward object instantiations.

Remove the _enableTime flag/setter from SPIFFS.

Clean up the FSConfig constructors using C++ style init lists.
2019-10-31 14:09:52 +01:00
M Hightower
7a43092df0 Update core with upstream umm_malloc (#6438)
* WIP: Initial overlay of upstream version of umm_malloc over
our current version w/o any edits.

Using files from:
  https://github.com/rhempel/umm_malloc/tree/master/src
  https://github.com/rhempel/c-helper-macros/tree/develop

The following file remanents from our old version were removed:
  umm_malloc.cpp, umm_performance.h, umm_performance.cpp, and umm_stats.h

This is intended to be a "compare to" for changes made to
upstream version.

* WIP: upstream version of umm_malloc customized for Arduino ESP8266 Core
See comments at the top of umm_malloc.cpp for a summary of changes so far.

Added support for integrity check and poison check to refactored heap.cpp.

* Resoved Travis CI - issue

* Corrected #ifdef's for UMM_STATS/UMM_STATS_FULL

* Corrected UMM_REALLOC_DEFRAG option to be more like the original umm_realloc.
Updated some comments and changed method of defining _rom_putc1.

* Updated UMM_POISON_CHECK_LITE - Expanded the poison check on the current
allocation to include its nearest allocated neighbors in the heap.
That is to say, if the nearest neighbor is free, then the next one over
is checked. And this is done in both directions.
umm_malloc() will also checks the neighbors of the selected
allocation before use.

Merged umm_malloc.c into umm_malloc.cpp.

Added additional stats for debug build.

On going comment cleanup.

Removed #if 0 block from isr_safe_printf.

Corrected mistyped UMM_POISON_CHECK UMM_CHECK_POISON.
Corrected other conditional build issues.

* Updated printing in heap.cpp to behave the way os_printf did.

Updated printing in heap.cpp to behave the way os_printf would have with regards
to system_set_os_print. ie. setDebugOutput enable/disables printing

Expanded #ifdef fenceing of .c files to prevent Arduino IDE from building them
outside of the .cpp file they are included in.

Corrected more conditional building issues.

Remaining concern - umm_info(0, true) printing - does it need an ISR safe method,
all printing is done from within a critical sectionn with rsil(15)?
Or should be have the print option disabled for non-debug builds.
ie. Debug port: "Disabled"

* Merged latest, 2019-09-07, from upstream umm_malloc

* R.Hempel 2019-09-07 - Separate the malloc() and free() functionality into
*                        wrappers that use critical section protection macros
*                        and static core functions that assume they are
*                        running in a protected con text. Thanks @devyte

* Resolved issue where OOM selected w/ Debug port: "Disabled" caused hang.

With OOM selected w/ Debug port: "Disabled" you can now use
Serial.setDebugOutput(true); to enable OOM message displaying.
This is the behavior previously available with os_printf.

commit rev 1

* Fixed realloc OOM bug introduced due to confusing code, added comment for future.

umm_info(NULL, true) is now treated as a debug option that is enabled by
Arduino IDE->tools `Debug port: "Serial"`, etc. It now prints when
DEBUG_ESP_PORT or UMM_INFO_PRINT are defined.

Cleanup comments and some conditionals.

* Updated to track PRs for various print definitions. Cleaned up comments

* Added missing "#ifdef __cplusplus"

* Reorganize local enhancements
More comment cleanups
Added Status TODOs marks for upstream

* Print notice message for the need of -DUMM_INFO_PRINT

* This updates the heap management library, umm_malloc, to the current upstream
version at https://github.com/rhempel/umm_malloc. Some reorganizing and new code
was needed to use the new version.

This is a list of note worthy changes:

UMM_POISON - now has a lite option as well as the previous intensive check
option. The code for running the full poison test at the call of the various
alloc functions was removed in the upstream version. In this port the missing
code was added to heap.cpp and umm_local.cpp.
* UMM_POISON - appears to have been partially changed to UMM_POISON_CHECK,
  I treat it as depricated and used UMM_POISON_CHECK, when needed.
  However, the Arduino Core's references to UMM_POISON were replaced with
  UMM_POISON_CHECK_LITE.
* UMM_POISON_CHECK_LITE - Less intense, it just checks poison on active
  neighboring allocations.
* UMM_POISON_CHECK - Full heap intensive check of poison

UMM_INFO_PRINT - This new define makes building UMM_INFO with printing
capability, optional. When umm_info(NULL, true) is used to print a debug view of
heap information to the debug port, it has to walk the heap and print out
information, while in a critical section. This requires that the print function
be able to print w/o doing malloc calls and from an IRQ disabled context. It
also requires more IRAM to handle printing. Without this define
`umm_info(NULL, true)` will not print.
* UMM_INFO_PRINT is enabled as part of selecting `Debug port: "Serial" or
* "Serial1"`. To make available all the time use '-D UMM_INFO_PRINT`.

A cautionary note, on the use of UMM_INTEGRITY_CHECK, UMM_POISON_CHECK, and
UMM_INFO_PRINT. All of these run with IRQs disabled, for periods that can go
into 100's of us. With umm_info(NULL, true) that may go into seconds, depending
on the serial interface speed and the number of memory allocations present. Use
UMM_INTEGRITY_CHECK, UMM_POISON_CHECK, and UMM_INFO_PRINT sparingly.
If you want to see numbers for the disabled time, explore using
UMM_CRITICAL_METRICS in umm_malloc_cfg.h.

* This updates the heap management library, umm_malloc, to the current upstream
version at https://github.com/rhempel/umm_malloc. Some reorganizing and new code
was needed to use the new version.

This is a list of note worthy changes:

UMM_POISON - now has a lite option as well as the previous intensive check
option. The code for running the full poison test at the call of the various
alloc functions was removed in the upstream version. In this port the missing
code was added to heap.cpp and umm_local.cpp.
* UMM_POISON - appears to have been partially changed to UMM_POISON_CHECK,
  I treat it as depricated and used UMM_POISON_CHECK, when needed.
  However, the Arduino Core's references to UMM_POISON were replaced with
  UMM_POISON_CHECK_LITE.
* UMM_POISON_CHECK_LITE - Less intense, it just checks poison on active
  neighboring allocations.
* UMM_POISON_CHECK - Full heap intensive check of poison

UMM_INFO_PRINT - This new define makes building UMM_INFO with printing
capability, optional. When umm_info(NULL, true) is used to print a debug view of
heap information to the debug port, it has to walk the heap and print out
information, while in a critical section. This requires that the print function
be able to print w/o doing malloc calls and from an IRQ disabled context. It
also requires more IRAM to handle printing. Without this define
`umm_info(NULL, true)` will not print.
* UMM_INFO_PRINT is enabled as part of selecting `Debug port: "Serial" or
* "Serial1"`. To make available all the time use '-D UMM_INFO_PRINT`.

A cautionary note, on the use of UMM_INTEGRITY_CHECK, UMM_POISON_CHECK, and
UMM_INFO_PRINT. All of these run with IRQs disabled, for periods that can go
into 100's of us. With umm_info(NULL, true) that may go into seconds, depending
on the serial interface speed and the number of memory allocations present. Use
UMM_INTEGRITY_CHECK, UMM_POISON_CHECK, and UMM_INFO_PRINT sparingly.
If you want to see numbers for the disabled time, explore using
UMM_CRITICAL_METRICS in umm_malloc_cfg.h.

* Updated upstream TODO

* Changes on printing to comply with new understanding of SPI bus availability
from an ISR vs forground with INTLEVEL 15.

* Removed no longer needed files.

* OOM build option now saves file and line number for post mortem reporting.

* Missed change.

* Consolated upstream integration comments into Notes.h. This helps
keep these comments separated from the upstream code and to avoid
getting lost. I'll expand this as I think of and remember more.

* Comment updates.

* Notes update.

* Changes to heap.cpp -
Refactored macro PTR_CHECK__LOG_LAST_FAIL.
Replaced macros __umm_... with uppercase versions.
Corrected misplaced POISON_CHECK__PANIC_FL macro in realloc.

Added debug free options for OOM and Poison to umm_malloc_cfg.h

Updated Notes.h.

Lines that start with "//C" are meant to flag reviewer's attention.

* Corrected Full Poison Check's placement and documented the
thinking behind its placement and Integrity Checks placement
with relation to the *alloc function. Just so I don't forget
again :/

* Fixed typos
2019-10-29 03:42:30 -03:00
Dirk O. Kaar
6e51ef0cc8 Wakeup delayed scheduling (#6485)
* Fix for scheduling recurrent functions while inside scheduled function

* Check that fn are valid. Invoking invalid functions throws otherwise.

* Added wakeup token to scheduler. Toggling the token value breaks a scheduled function

out from a delayed execution and makes it run on the next scheduler iteration.

* Timer reset reliability fix.

* Shrink interrupts-locked regions.

Add check for periodic yield to scheduled functions run-loop.

* Ordered, more predictable, scheduling. Before, it had different ordering compared to

FastScheduler as well as sequential calls from loop().

* Optional, for the paranoid: revert changes to (non-recurrent) schedule_function() / run_scheduled_functions().

* Comment

* Adapt one-line ifs to general style in same source file.

* Fix wakeupToken handling - don't respond to toggle, but to different value

vs. that at registering function with scheduler.

* Reword comment.

* Putting aside std::atomic concerns, use a callback for scheduler alarming.

In the future, async future's .then() might take advantage of this direction.

* Drop atomic include, align function type syntax.

* Reduce flash use.

* Prefer const ref over call by value plus std::move().
2019-10-28 08:55:00 -03:00
Clemens Kirchgatterer
e4c6a7a73a Reapply fix for redundant FS size check (#6666)
My fix for a redundant FS size check was merged, (bde1ce0e01 (diff-6690102111beb33824c743666a874d7c)) but later reverted (a389a995fb (diff-6690102111beb33824c743666a874d7c)) I guess by accident.
2019-10-28 01:40:35 +01:00
Gijs Noorlander
36c369bb8f Double I2C read in one transaction skips a clock pulse (#5528) (#6654)
* Double I2C read in one transaction skips a clock pulse (#5528)

See https://github.com/esp8266/Arduino/issues/5528  and the more elaborate [description](https://github.com/maarten-pennings/I2C-tool/blob/master/I2Ctest8266/README.md#how-to-fix)
where @maarten-pennings did all the hard work, but as far as I could see, no PR was made.

I also noticed some code duplication, which I moved to separate functions.

According to [this documentation on I2C clock stretching](https://www.i2c-bus.org/clock-stretching/) it is not allowed to have some slave keep the clock low during transmission of a byte, only after an ack.
So that's why it is not done in the while loop.
But I wondered if there should be an extra delay between the sequence of pulses and the extra added clock "valley". See my comment in the code.

Fixes #5528

* [I2C] Restore clock stretch functionality during transfer

As requested here: 8357a8c644 (r339310509)

* [I2C] Move duplicated clock stretch call to twi_scl_valley function
2019-10-26 20:59:19 -07:00
Dirk Mueller
1e17dddd89 Fix inconsistent CRLF/LF combinations (#6653)
These files had either CRLF, LFCR or LF or a mixture of it.
Consistently format them as git text files (unix style) with
trailing whitespace removed.
2019-10-19 13:10:41 -03:00
Robin Richtsfeld
45d71ae4bd Support FS update in two steps (#6505)
* Support FS update in two steps
2019-10-16 10:11:15 +02:00
Earle F. Philhower, III
2a5d215977
Reduce the IRAM usage of I2C code by 600-1500 bytes (#6326)
* Reduce the IRAM (and heap) usage of I2C code

The I2C code takes a large chunk of IRAM space.  Attempt to reduce the
size of the routines without impacting functionality.

First, remove the `static` classifier on the sda/scl variables in the
event handlers.  The first instructions in the routines overwrite the
last value stored in them, anyway, and their addresses are never taken.

* Make most variables ints, not uint8_ts

Where it doesn't make a functional difference, make global variables
ints and not unit8_t.  Bytewide updates and extracts require multiple
instructions and hence increase IRAM usage as well as runtime.

* Make local flag vars int

Sketch uses 270855 bytes (25%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27940 bytes (34%) of dynamic memory, leaving 53980 bytes for local variables. Maximum is 81920 bytes.
./xtensa-lx106-elf/bin/xtensa-lx106-elf-objdump -t  -j .text1 /tmp/arduino_build_9615/*elf | sort -k1 | head -20
401000cc l     F .text1	00000014 twi_delay
401000ec l     F .text1	00000020 twi_reply$part$1
4010010c g     F .text1	00000035 twi_reply
4010014c g     F .text1	00000052 twi_stop
401001a0 g     F .text1	0000003b twi_releaseBus
40100204 g     F .text1	000001e6 twi_onTwipEvent
40100404 l     F .text1	000001f7 onSdaChange
40100608 l     F .text1	000002fd onSclChange
40100908 l     F .text1	0000003b onTimer

* Factor out !scl in onSdaChange

If SCL is low then all branches of the case are no-ops, so factor that
portion outo to remove some redundant logic in each case.

Sketch uses 270843 bytes (25%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27944 bytes (34%) of dynamic memory, leaving 53976 bytes for local variables. Maximum is 81920 bytes.

401000cc l     F .text1	00000014 twi_delay
401000ec l     F .text1	00000020 twi_reply$part$1
4010010c g     F .text1	00000035 twi_reply
4010014c g     F .text1	00000052 twi_stop
401001a0 g     F .text1	0000003b twi_releaseBus
40100204 g     F .text1	000001e6 twi_onTwipEvent
40100404 l     F .text1	000001e7 onSdaChange
401005f8 l     F .text1	000002fd onSclChange
401008f8 l     F .text1	0000003b onTimer

0x0000000040107468                _text_end = ABSOLUTE (.)

* Make tiny twi_reply inline

twi_reply is a chunk of code that can be inlined and actually save IRAM
space because certain conditions acan be statically evaluated by gcc.

Sketch uses 270823 bytes (25%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27944 bytes (34%) of dynamic memory, leaving 53976 bytes for local variables. Maximum is 81920 bytes.

401000cc l     F .text1	00000014 twi_delay
401000f4 g     F .text1	00000052 twi_stop
40100148 g     F .text1	0000003b twi_releaseBus
401001b0 g     F .text1	00000206 twi_onTwipEvent
401003d0 l     F .text1	000001e7 onSdaChange
401005c4 l     F .text1	000002fd onSclChange
401008c4 l     F .text1	0000003b onTimer
40100918 g     F .text1	00000085 millis
401009a0 g     F .text1	0000000f micros
401009b0 g     F .text1	00000022 micros64
401009d8 g     F .text1	00000013 delayMicroseconds
401009f0 g     F .text1	00000034 __digitalRead
401009f0  w    F .text1	00000034 digitalRead
40100a3c g     F .text1	000000e4 interrupt_handler
40100b20 g     F .text1	0000000f vPortFree

0x0000000040107434                _text_end = ABSOLUTE (.)

* Inline additional twi_** helper functions

Sketch uses 270799 bytes (25%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27944 bytes (34%) of dynamic memory, leaving 53976 bytes for local variables. Maximum is 81920 bytes.

401000cc l     F .text1	00000014 twi_delay
401000f4  w    F .text1	0000003b twi_releaseBus
4010015c g     F .text1	00000246 twi_onTwipEvent
401003bc l     F .text1	000001e7 onSdaChange
401005b0 l     F .text1	000002f9 onSclChange
401008ac l     F .text1	0000003b onTimer

0x000000004010741c                _text_end = ABSOLUTE (.)

* Convert state machine to 1-hot for faster lookup

GCC won't use a lookup table for the TWI state machine, so it ends up
using a series of straight line compare-jump, compare-jumps to figure
out which branch of code to execute for each state.  For branches that
have multiple states that call them, this can expand to a lot of code.

Short-circuit the whole thing by converting the FSM to a 1-hot encoding
while executing it, and then just and-ing the 1-hot state with the
bitmask of states with the same code.

Sketch uses 270719 bytes (25%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27944 bytes (34%) of dynamic memory, leaving 53976 bytes for local variables. Maximum is 81920 bytes.

401000cc l     F .text1	00000014 twi_delay
401000f4  w    F .text1	0000003b twi_releaseBus
4010015c g     F .text1	00000246 twi_onTwipEvent
401003c0 l     F .text1	000001b1 onSdaChange
40100580 l     F .text1	000002da onSclChange
4010085c l     F .text1	0000003b onTimer

0x00000000401073cc                _text_end = ABSOLUTE (.)

Saves 228 bytes of IRAM vs. master, uses 32 additional bytes of heap.

* Factor out twi_status setting

twi_status is set immediately before  an event handler is called,
resulting in lots of duplicated code.  Set the twi_status flag inside
the handler itself.

Saves an add'l ~100 bytes of IRAM from prior changes, for a total of
~340 bytes.

earle@server:~/Arduino/hardware/esp8266com/esp8266/tools$ ./xtensa-lx106-elf/bin/xtensa-lx106-elf-objdump -t  -j .text1 /tmp/arduino_build_849115/*elf | sort -k1 | head -20

401000cc l     F .text1	00000014 twi_delay
401000f4  w    F .text1	0000003b twi_releaseBus
40100160 g     F .text1	0000024e twi_onTwipEvent
401003c8 l     F .text1	00000181 onSdaChange
40100558 l     F .text1	00000297 onSclChange

* Use a struct to hold globals for TWI

Thanks to the suggestion from @mhightower83, move all global objects
into a struct.  This lets a single base pointer register to be used in
place of constantly reloading the address of each individual variable.

This might be better expressed by moving this to a real C++
implementaion based on a class object (the twi.xxxx would go back to the
old xxx-only naming for vars), but there would then need to be API
wrappers since the functionality is exposed through a plain C API.

Saves 168 additional code bytes, for a grand total of 550 bytes IRAM.

earle@server:~/Arduino/hardware/esp8266com/esp8266/tools$ ./xtensa-lx106-elf/bin/xtensa-lx106-elf-objdump -t  -j .text1 /tmp/arduino_build_849115/*elf | sort -k1 | head -20

401000cc l     F .text1	00000014 twi_delay
401000e8  w    F .text1	00000032 twi_releaseBus
40100128 g     F .text1	00000217 twi_onTwipEvent
4010034c l     F .text1	00000149 onSdaChange
4010049c l     F .text1	00000267 onSclChange
40100704 l     F .text1	00000028 onTimer

* Use enums for states, move one more var to twi struct

Make the TWI states enums and not #defines, in the hope that it will
allow GCC to more easily flag problems and general good code
organization.

401000cc l     F .text1	00000014 twi_delay
401000e8  w    F .text1	00000032 twi_releaseBus
40100128 g     F .text1	00000217 twi_onTwipEvent
4010034c l     F .text1	00000149 onSdaChange
4010049c l     F .text1	00000257 onSclChange
401006f4 l     F .text1	00000028 onTimer

Looks like another 16 bytes IRAM saved from the prior push.

Sketch uses 267079 bytes (25%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27696 bytes (33%) of dynamic memory, leaving 54224 bytes for local variables. Maximum is 81920 bytes.

* Save 4 heap bytes by reprdering struct

* Convert to C++ class, clean up code

Convert the entire file into a C++ class (with C wrappers to preserve
the ABI).  This allows for setting individual values of the global
struct(class) in-situ instead of a cryptic list at the end of the struct
definition.  It also removes a lot of redundant `twi.`s from most class
members.

Clean up the code by converting from `#defines` to inline functions, get
rid of ternarys-as-ifs, use real enums, etc.

For slave_receiver.ino, the numbers are:
GIT Master IRAM: 0x723c
This push IRAM: 0x6fc0

For a savings of 636 total IRAM bytes (note, there may be a slight flash
text increase, but we have 1MB of flash to work with and only 32K of IRAM
so the tradeoff makes sense.

* Run astyle core.conf, clean up space/tab/etc.

Since the C++ version has significant text differences anyway, now is a
good time to clean up the mess of spaces, tabs, and differing cuddles.

* Add enum use comment, rename twi::delay, fix SDA/SCL_READ bool usage

Per review comments

* Replace clock stretch repeated code w/inline loop

There were multiple places where the code was waiting for a slave to
finish stretching the clock.  Factor them out to an *inline* function
to reduce code smell.

* Remove slave code when not using slave mode

Add a new twi_setSlaveMode call which actually attached the interrupts
to the slave pin change code onSdaChenge/onSclChange.  Don't attach
interrupts in the main twi_begin.

Because slave mode is only useful should a onoReceive or onRequest
callback, call twi_setSlaveMode and attach interrupts on the Wire
setters.

This allows GCC to not link in slave code unless slave mode is used,
saving over 1,000 bytes of IRAM in the common, master-only case.
2019-10-14 14:32:41 -07:00
dsv19
8c3f1be63f Serial.flush modification (#5293)
* Modify Serial.flush

* Add function to uart tests
2019-10-08 05:36:39 -07:00
david gauchard
fabd169abc Puyafix (#6619)
* PUYA was not correctly enabled

* remove duplicate
2019-10-07 19:31:30 -03:00