Fixes#7043
Two slightly different custom routines were implemented by hand in
dtostrf (an AVR-lib non-ISO function) and Print. This resulted in
inconsistent output of float/double vars when rounding was needed.
Replace them all with a call to sprintf(), removing the duplicated, not
quite correct code.
Print(String(float)) and Print(float) now generate the same output.
* Code size optimisation of ESP.getResetReason()
doing if/else snakes for something that is a switch/case
is wasteful, as it repeatedly evaluates the same if() condition.
Also repeating strcpy_P is adding code bloat.
This simplification reduces size from 111 to 41 bytes.
* add break statement also to default case
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.
* 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>
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.
* 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
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.
* 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.
* 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
* 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]
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.
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.
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.
* 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.
* 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
* 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
* 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
* 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.