1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-13 13:01:55 +03:00
Commit Graph

3999 Commits

Author SHA1 Message Date
8ffe41b7df Enable 128K virtual memory via external SPI SRAM (#6994)
Provides a transparently accessible additional block of RAM of 128K to
8MB by using an external SPI SRAM.  This memory is managed using the UMM
memory manager and can be used by the core as if it were internal RAM
(albeit much slower to read or write).

The use case would be for things which are quite large but not
particularly frequently used or compute intensive.  For example, the SSL
buffers of 16K++ are a good fit for this, as are the contents of Strings
(both to avoid main heap fragmentation as well as allowing Strings of
>30KB).

A fully associative LRU cache is used to limit the SPI bus bottleneck,
and background writeback is supported.

Uses a define in boards.txt to enable.  If this value is not defined,
then the entire VM routines should not be linked in to user apps
so there should be no space penalty w/o it.

UMM `malloc` and `new` are modified to support internal and external
heap regions.  By default, everything comes from the standard heap, but
a call to `ESP.setExternalHeap()` before the allocation (followed by a
call to `ESP.resetHeap()` will make the allocation come from external
RAM.  See the `virtualmem.ino` example for use.

If there is no external RAM installed, the `setExternalHeap` call is a
no-op.

The String and BearSSL libraries have been modified to use this external
RAM automatically.

Theory of Operation:

The Xtensa core generates a hardware exception (unrelated to C++
exceptions) when an address that's defined as invalid for load or store.
The XTOS ROM routines capture the machine state and call a standard C
exception handler routine (or the default one which resets the system).

We hook into this exception callback and decode the EXCVADDR (the
address being accessed) and use the exception PC to read out the
faulting instruction. We decode that instruction and simulate it's
behavior (i.e. either loading or storing some data to a
register/external memory) and then return to the calling application.

We use the hardware SPI interface to talk to an external SRAM/PSRAM,
and implement a simple cache to minimize the amount of times we need
to go out over the (slow) SPI bus. The SPI is set up in a DIO mode
which uses no more pins than normal SPI, but provides for ~2X faster
transfers.  SIO mode is also supported.

NOTE: This works fine for processor accesses, but cannot be used by
any of the peripherals' DMA. For that, we'd need a real MMU.

Hardware Configuration (only use 3.3V compatible SRAMs!):

  SPI byte-addressible SRAM/PSRAM: 23LC1024 or smaller
    CS   -> GPIO15
    SCK  -> GPIO14
    MOSI -> GPIO13
    MISO -> GPIO12
 (note these are GPIO numbers, not the Arduino Dxx pin names.  Refer
  to your ESP8266 board schematic for the mapping of GPIO to pin.)

Higher density PSRAM (ESP-PSRAM64H/etc.) should work as well, but
I'm still waiting on my chips so haven't done any testing.  Biggest
concern is their command set and functionality in DIO mode.  If DIO
mode isn't supported, then a fallback to SIO is possible.

This PR originated with code from @pvvx's esp8266web server at
https://github.com/pvvx/esp8266web (licensed in the public domain)
but doesn't resemble it much any more.  Thanks, @pvvx!

Keep a list of the last 8 lines in RAM (~.5KB of RAM) and use that to
speed up things like memcpys and other operations where the source and
destination addresses are inside VM RAM.

A custom set of SPI routines is used in the VM system for speed and code
size (and because the core cannot be dependent on a library).

Because UMM manages RAM in 8 byte chunks, attempting to manage the
entire 1M available space on a 1M PSRAM causes the block IDs to
overflow, crashing things at some point.  Limit the UMM allocation to
only 256K in this case.  The remaining space can manually be assigned to
buffers/etc. managed by the application, not malloc()/free().
2021-03-14 18:44:02 -07:00
c720c0d9e8 Stream::send() (#6979) 2021-03-14 17:36:20 -07:00
4cc1472821 [BREAKING] base64::encode() compat with esp32: no newlines by default (#7910) 2021-03-14 17:24:33 -07:00
656a33e6f8 BREAKING - Use IRAM_ATTR in place of ICACHE_RAM_ATTR (#7921)
Update the core to use the define that the ESP32 uses, IRAM_ATTR, for
placing code in DRAM.
2021-03-14 16:56:47 -07:00
6743a65987 Minor EspSoftwareSerial release 6.11.7, for deprecated ICACHE_RAM_ATTR in upcoming ESP8266 Arduino core 3.0.0. (#7922) 2021-03-14 16:15:37 -07:00
49a09279eb Merge pull request #6280 from aerlon/wifi_mesh_update_2.2
WiFi Mesh Update 2.2
2021-03-14 18:11:32 -03:00
7fbf620ab6 Merge branch 'master' into wifi_mesh_update_2.2 2021-03-14 16:41:13 -03:00
444002180b OOM debug: warn about String reallocation (#7908)
* OOM debug: warn about String reallocation

* threshold set to 128 bytes, +defines

* warn only when capacity had already reached the threshold
2021-03-14 07:57:23 +01:00
e07542d701 Fix link to ESP8266 NonOS SDK (#7914) 2021-03-11 07:24:24 -08:00
e99df4fe1a Add I2S class support (#7874)
Fixes #427

Adds a basic I2S class based off of the Arduino-SAMD core.  The raw
i2s_xxx functions are still a better  way to use I2S due to their
flexibility, but this will allow basic Arduino sketches to work.
2021-03-07 08:14:07 -08:00
9fc5afd5fd OOM: avoid warn when calling *alloc(0) (#7909) 2021-03-04 13:27:42 -08:00
d3d49d5db4 Update mklittlefs executable (#7906)
Rebuild entire toolchain instead of manually hacking the tools JSON to
ensure repeatability.

New mklittlefs sets the new FS timestamp added in #7873
2021-03-04 11:29:38 +01:00
c90c329a48 Track creation time of LittleFS FS (#7873) 2021-03-02 17:50:00 -08:00
22442f0873 Added ESP32 compatible methods for setting/getting hostname (#7900) 2021-03-02 17:32:34 -08:00
807ed51d0f AP & dhcp-server: fix uninitialized variables (#7905) 2021-03-03 01:12:01 +01:00
e3fe7a5776 EspSoftwareSerial, bump up Arduino library manager related files 6.11.6 (#7891) 2021-02-21 11:04:37 -08:00
f42ab617e9 Update to EspSoftwareSerial 6.11.5 (#7889) 2021-02-21 09:23:20 -08:00
a5308d6ef4 String: add missing long long operator implementations (#7888) 2021-02-19 08:38:43 -08:00
d41b4037cc board manager: + Agrumino lemon v4 (#7883) 2021-02-19 08:21:16 -08:00
83f5f29cfd Support to reboot into UART download mode (#7854)
without any external wiring.

This patch introduces the new method
Esp.rebootIntoUartDownloadMode()

When the user calls this method the ESP8266 reboots into the UART
download mode. In this mode the user can use esptool.py to flash a new
firmware file. The following command was used to test it:
$ esptool.py --before no_reset --after soft_reset --chip esp8266 \
    --port /dev/ttyUSB0 --baud 460800 write_flash 0x0 firmware.bin

The implementation is based on the original implementation in the
boot ROM. Some parts of the original implementation can be found in
[1]. This patch is a squashed and simplified version of [2]. The non
squashed version might be helpful in case of debugging issues.

[1] https://github.com/twischer/xtensa-subjects/blob/master/reversed/bootrom.c
[2] https://github.com/twischer/Arduino/tree/reboot_uart_download_full

Signed-off-by: Timo Wischer <twischer@freenet.de>
2021-02-17 08:25:52 -08:00
bc3daef76d WIFI_RESUME improve speed and example (#7877)
Improve resume speed by passing in last known BSSID
Provide a simpler example for WIFI_SHUTDOWN/WIFI_RESUME
Add documentation for WIFI_SHUTDOWN and WIFI_RESUME.
2021-02-15 13:51:37 -08:00
e4435fa306 Update board-specific defines (#7875)
Fixes #6805

Update the build.board for several boards which were originally added
with a generic type.
2021-02-14 14:42:50 +01:00
483519f852 String: compatibility with 64 bits scalars (#7863)
time_t is now 64 bits. String(time_t) was ambiguous
tests added
2021-02-13 08:47:47 -08:00
a886515ce9 Fix ESP8266SdFat architecture, Windows CI (#7866)
* Fix ESP8266SdFat architecture

Avoid problems reported in
https://forum.arduino.cc/index.php?topic=726897.msg4889319

* Fix Windows CI, python3 now *maybe* exists

Python3 used to be called "python.exe" on earlier VMs, but it looks like
the image has been updated and a "python3.exe" does now exist.  Update
the CI script to first check it "python3" exists, and if not then do the
copy hack, OTW do nothing.
2021-02-08 12:02:49 -08:00
07b4c09b90 eboot: .RODATA, upstream uzlib, move CRC, save 112 bytes (#7844)
RODATA can be copied automatically by the bootrom, so no reason not to
allow its use for strings and constants in eboot.c

Revert to pfalcon's original uzlib since the single patch to remove
RODATA is not required.

Rationalize eboot.ld linker script, clean up BSS and init it in code.

Saves 112 bytes of space in the bootloader sector by removing the
extra code associated with literal loads.

* Move CRC out of bootload sector

We added protection to only erase the bootload sector when flashing an
image when the new sector != the old sector.  This was intended to
minimize the chance of bricking (i.e. if there was a powerfail during
flashing of the boot sector the chip would be dead).

Unfortunately, by placing the CRC inside the eboot sector *every*
application will have a unique eboot sector (due to the crc/len), so
this protection doesn't work.

Move the CRC into the first 8 bytes of IROM itself.  This frees up extra
space in the boot sector and ensures that eboot won't be reflashed
unless there really is an eboot change.
2021-02-07 16:32:56 -08:00
6c564c269c EspSoftwareSerial bug-fix release 6.11.4 (#7862) 2021-02-06 15:10:24 -08:00
27da34760b At MDNS.end() also release services (#7859) 2021-02-04 14:46:13 +01:00
20413f817b Update toolchain to support std::remainder (#7849)
Update newlib to enable the __ieee754_remainder(f) calls required by
std::remainder and others.

Add device test for std::remainder variants.

Fixes #7845
2021-01-29 12:30:42 -08:00
39d14530ff Add a check for all URLs in the package file (#7848)
Avoid issues like #7847 by downloading and checking SHA for each file in
the package.json bundle.
2021-01-28 08:56:45 -08:00
600c5d7c0b Fix typo in 32-bit Windows package JSON (#7847)
Fatfingered the 32-bit Windows pointer to the Python interpreter.  Our
CI and my own testing missed due to being on 64-bit Windows.

For 2.7.4 release, I'll add a file of the appropriate name to the
release for now, but this will correct things for 3.0.0 and forward.
2021-01-28 08:08:03 -08:00
c2393d05be Fix improper GENERIC board IDs (#7839)
A couple board types reported ESP8266_GENERIC instead of their proper
types in boards.txt (and in defined generated therefrom/etc.).

Give them proper board types based on their names, like other modules.
2021-01-27 00:06:12 -08:00
f2d83ba43d allow to set pin to OUTPUT_OPEN_DRAIN in analogWriteMode (#7841)
* allow to set pin to OUTPUT_OPEN_DRAIN in analogWrite

* remove parameter with default value

* Update core_esp8266_wiring_pwm.cpp

* update documentation accordingly
2021-01-26 23:56:43 -08:00
53e5688453 Update to EspSoftwareSerial 6.11.3: prepares for ESP8266 Arduino core PR 6979. (#7840) 2021-01-26 01:03:56 +01:00
349e67f7f5 Fix I2S reported rate for 24b mode (#7838)
Adjust the number of bittimes when returning the real I2S rate.
2021-01-24 09:59:20 -08:00
f0e8f8eac4 Update eboot to build with C17, not C99 standard (#7837)
No functional change.  Make the main core and eboot build using the
same C standard version (gnu17).
2021-01-23 16:24:15 -08:00
e0cfb5a995 Add 24-bit mode to I2S (#7835)
Add basic 24 bit mode to the I2S API with a i2s_set_bits() call.
By default 16b mode is still used, but if i2s_set_bits(24) is run
before i2s_begin() then the HW will drive 24-bits of data.  This
data must be left-aligned (i.e. bits 31..8) in 4-byte samples.

Fixes #5244 (the HW doesn't support 8 or 32 bits, only 16 or 24).
2021-01-23 14:40:29 -08:00
b3fe0aab19 Hexdump fix&update (#7831)
* hexdump() must be "C"; add ascii data in dump
* remove previous version
2021-01-22 23:04:22 +01:00
11a2fb3872 Dynamically configure exceptions support (#7834) 2021-01-22 17:08:45 +02:00
2402958208 Merge pull request #7629 from Erriez/feature/issue-2246-multi-wifi-hidden
Add support for hidden SSID's Multi WiFi
2021-01-21 01:11:21 -03:00
d90015e326 Merge branch 'master' into feature/issue-2246-multi-wifi-hidden 2021-01-19 16:12:54 +01:00
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
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
a4b6003c2e Replacement for Boot ROM aes_unwrap (#7773)
* Replacement for Boot ROM aes_unwrap

* Removed unnecessary test
2021-01-13 15:43:55 -08:00
dbc5e4164c Supersede #3856, remove undef min/max (#7824)
Remove a straggler `undef min/max` from core header
Supersedes #3856
2021-01-12 17:58:04 -08:00
df5e113b88 HeapSelectDram for pvPortMalloc, ... (#7790)
* Add inline always option to HeapSelect

* Add option to force DRAM for pvPort... APIs

* revert print_loc premature change

* Renamed macro to be more specific, FORCE_ALWAYS_INLINE to FORCE_ALWAYS_INLINE_HEAP_SELECT
2021-01-12 15:08:41 -08:00
e938739115 Prevent nullptr dereference on OOM (#7823) 2021-01-12 14:55:57 -08:00
0203dea024 Added replacement for the Boot ROM _xtos_set_exception_handler (#7820)
Added replacement for the Boot ROM `_xtos_set_exception_handler`
to handle installing our replacement `_xtos_c_wrapper_handler`.

Simplified install in the non 32-bit exception module to make use of the
improved `_xtos_set_exception_handler`

Reorganized and improved comments.
2021-01-12 22:51:26 +01:00
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
34545a160d Invalid read return value fix (#7817)
Fixes #7814.

Return 0, not MAXINT, when a read is called on a File without a backing
instance of a SPIFFS/LittleFS/SD File.
2021-01-08 20:08:36 -08:00
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