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

702 Commits

Author SHA1 Message Date
Develo
0e0e34c614
implement EspClass::getFreeContStack method (#5133)
* implement EspClass::getFreeContStack method

* Remove unneeded extern

* Really remove unneeded extern
2018-09-13 16:02:53 -03:00
david gauchard
ce28a76a24 metric for heap fragmentation (#5090)
* +Esp.getHeapUnfragness()

* only in debug mode

* default value

* always enable, 64->32, light 32 integer square root, comments

* fix when debugging is disabled

* give credits

* cosmetics

* fragmentation metric updates (doc, better api, added getMaxFreeBlockSize())

* api reworked, +example

* fixe types, fix names

* coding style fix

* use astyle for example
2018-09-10 01:50:01 -03:00
Ivan Grokhotkov
0713a01db8 Fix iostream related issues (#5047)
* add stubs for more exception throw calls

Fixes https://github.com/esp8266/Arduino/issues/3358

* libc: make putc_r implementation weak

newlib provides its own implementation of _putc_r, which will call
_write_r (possibly after buffering). Make our implementation weak to
allow using the one from newlib.

Fixes https://github.com/esp8266/Arduino/issues/4630

* libc: fix incorrect return value of _write_r call

Should return number of bytes written, actually returned zero. This
resulted in std::cout going into failed state after the first write.

* tests: add test for output to std::cout
2018-08-26 13:47:01 -04:00
david gauchard
85e68093e9
Automatic stack location selection (SYS or HEAP), enable per library AR-chive in arduino build system (#5018)
Automatic stack location selection (SYS or HEAP), enable per library AR-chive in arduino build system 

* enable dot_a_linkage on internal libraries
* add device tests
* boards generator: deprecate --noextra4k/--allowWPS and fix documentation
2018-08-20 14:35:52 +02:00
Anthony Elder
5c7dbf4e4b Add instantly option to deepSleep (#5052)
* Add instantly option to deepSleep

* Move system_deep_sleep_instant to a new deepSleepInstant function
2018-08-19 05:46:33 -03:00
Anthony Elder
61cc11da22 revert e02932f (#619 works now without it) (#5056) 2018-08-19 04:38:18 -03:00
Earle F. Philhower, III
d96c8f393e
Move some exception strings to PROGMEM (#5050)
The memory allocation failure message was accidentally stored in RAM
and not in PROGMEM.

panic() did not place the __FILE__ string in PROGMEM, either.

Move both to PROGMEM, save ~64 bytes of heap (depends on size of path
of the Arduino core library).
2018-08-16 08:15:02 -07:00
Earle F. Philhower, III
831e75d79e Enclose PROGMEM segment names in quotes (#5049)
__FILE__ is used to name the segments used for each PROGMEM constant,
but __FILE__ may have a space in it.  This would cause compilation
errors.

Add quotes around the entire segment name to work around this.
2018-08-15 16:04:56 -03:00
Earle F. Philhower, III
56b98fd4df Move all PROGMEM to their own section (#5048)
According to the GCC man page, __section__ attributes should only be used
for global variables.  However, the PROGMEM and ICACHE_RODATA macros use
this variable decorator even for local variables.  Most of the time it works,
but when a static or inlined function tries to use a PROGMEM/PSTR/etc.
variable the compiler can throw an error like:
  error: XXX causes a section type conflict with YYY

Change the PROGMEM macro to emit a section name that is unique (a combo
of the file, line, and counter variables to ensure uniqueness).  The
standard linker script will place them properly in .IROM without
any changes.

Fixes #5036 and others.
2018-08-15 11:46:13 -03:00
Jeroen88
e4d9c279ef Function added to detect baudrate (#4978)
* Function added to detect baudrate

* Added uart_start_detect_baudrate, detectBaudrate() wrappers for HardwareSerial and an example usage SerialDetectBaudrate.ino

* Some layout changes to pass Travis tests

* Some more nitty-gritty layout changes to pass Travis tests

* Some even more nitty-gritty layout changes to pass Travis tests

* renamed one function to testBaudrate() and updated doc/reference.rst

* Minor updates to doc/reference.rst

* New lines added
2018-08-01 15:33:25 -04:00
WEMOS Electronics
799193888a Fix digitalPinToBitMask(), portOutputRegister(), portInputRegister() … (#4964)
* fix digitalPinToBitMask(), portOutputRegister(), portInputRegister() and portModeRegister() error when the pin is GPIO16.
2018-07-28 10:07:01 -07:00
Earle F. Philhower, III
9c846bd52e
Fix concat not 0-terminating when String shrunk (#4962)
As @devyte noticed, PR #4955 has an issue when you catenate a string to
itself and the string used to hold a longer value because it does not
explicitly 0-terminate the resulting string.  If the string was extended,
however, reserve() would 0-terminate by default.

Always terminate the result of `s += s;` now.
2018-07-26 09:07:28 -07:00
Earle F. Philhower, III
ff74813d54 Fix String creation and concat issues (#4955)
When a string is concatted to itself, the pointer to its c_str can change
due to realloc().  This would invalidate the passed-in pointer being
concatted, and cause a use-after-free error.  Special case this to avoid
the issue.  Now "a += a;" works properly.

Also use sprintf(%{l}d) instead of non-POSIX ltoa/itoa calls to construct a
string from a signed number (in base 10 only).  The non-posix versions don't
handle INT_MIN properly on either host_tests or on the ESP8266.
2018-07-24 16:20:57 -04:00
Earle F. Philhower, III
bde83e8ea2
Fix waveform missing edges on cycle rollover (#4945)
When the ESP cycle counter rolls over, the "now" can be smaller than the
next-edge time of a waveform generator.  This would cause the edge to be
missed on that specific pin, and make it look like PWM was hung.

Use proper comparison between current time and edge time.

Fixes #4944

Also remove the "sigma-delta.c.unused" file which was replaced by a
working one some time ago.
2018-07-21 18:46:51 -07:00
LaborEtArs
3f6be5ecc8 Adjusted buffer size algorithm (#4934)
Use cencode.h defined macros to calculate the needed buffer size.
2018-07-19 18:16:51 -04:00
Earle F. Philhower, III
63ab79e549
Fix overlapping memcpy call in String::trim (#4938)
memcpy() is undefined when source and destination overlap.  String::trim
uses it when shifting the string left to remove left padding.

Replace with memmove() which is always safe, even when overlapped.
2018-07-18 18:36:31 -07:00
Earle F. Philhower, III
96a340eb51 Fix intermittent host tests failure (#4932)
MD5Builder tests have been randomly, non-repeatably failing due to a problem
with the returned value of MD5Builder.

Valgrind detected a strncpy with an overlapping memory range, which is
an undefined operation.  Fix it with a memmove instead, and get rid
of a couple #define redefinitions which were causing compile warnings
on the host side as well.
2018-07-16 23:22:55 -04:00
Earle F. Philhower, III
fcf2ac5d3d
Optimize waveform stop routines (#4920)
Thanks to ideas from @shimarin for offering ideas to speed up the stopWaveform
calls which may help things like SoftwareSerial run better.

Optimize the stopWaveform routine to abort fast and early whenever possible.

Remove the stopWaveform call from digitalRead().  If you're running a waveform
on a pin and try to read it, that is a logic error and you'll end up reading the
waveform and not the outside world's view of the pin.
2018-07-12 12:45:48 -07:00
teejaydub
60b21ef568 Copy the existing flash mode over the one set in an OTA update image. (#4877) 2018-07-11 12:30:56 -04:00
Tomoatsu Shimada
e6af980b85 Avoid unnecessary waveform de-initialization which corrupts softwareserial (#4913) 2018-07-10 12:40:14 -07:00
Earle F. Philhower, III
d948a1ff2a
Don't stop a waveform simply by calling pinMode (#4906)
Setting a pin direction would cause a waveform generator attached to it to stop.
This could cause PWM to stop if pinMode() is called while running (as it was
called in __analogWrite()).

Remove the stopWaveform call from pinMode, the Tone, analogWrite, or Servo
that initiated the waveform has responsibility for stopping it (and it does)
when complete, irrespective of the pinMode.

Fixes #4905
2018-07-08 20:27:13 -07:00
david gauchard
e486887f18
optionally allow WPS (#4889) 2018-07-06 16:45:25 +02:00
liebman
12d52220ae pin 16 is allowed for analogWrite (#4895) 2018-07-05 18:19:52 -07:00
hreintke
87991aba9f ScheduledInterrupts should still use current schedule_function(..) (#4890) 2018-07-04 12:55:07 -04:00
david gauchard
d580f40e44
fix scheduled interrupt #4609 by @shimarin (#4879) 2018-07-02 23:33:55 +02:00
Earle F. Philhower, III
be7a732b9d Compatibility and IRQ fixed for waveform/tone/pwm (#4872)
* Compatibility and IRQ fixed for waveform/tone/pwm

Fix a compiler ambiguity introduced with a floating point frequency option
for tone().  Thanks to @Rob58329 for discovering this and proposing the
fix.

Match original analogWrite behavior by going from 0...1023 (PWMRANGE) and
not 0...1024, and also explicitly set the analogWrite pin to an OUTPUT.
Thanks to @jandrassy for finding this.

Fixes #4380 discovered by @cranphin where interrupts were disabled on a
stopWaveform().  Remove that completely and bracket the update of non-atomic
fields in the structure with disable/enable IRQs for safety.

* Fix tone(int,int,int) infinite loop

Explicitly cast the frequency, when passed in as an int, to an
unsigned int.  Verified with snippet:
  tone(D1, (int)1000, 500);
  tone(D1, (unsigned int)1000, 500);
  tone(D1, 1000.0, 500);
  tone(D1, (int)1000);
  tone(D1, (unsigned int)1000);
  tone(D1, 1000.0);
2018-07-02 13:02:49 -04:00
hreintke
641c5cdc61 Scheduled Interrupt (#4609)
* Scheduled Interrupt

* use capital letter for Schedule.h

* Prevent memory leak when attach is called multiple times without detach

* Add improved schedule_function

* WIP : Integrate FunctionalInterrupt & ScheduledInterrupt

* Fix travis error
2018-06-19 17:26:57 -04:00
Earle F. Philhower, III
ebda795f34
Support multiple tone(), analogWrite(), and Servo (#4640)
Remove and rewrite all the parts of the core/libraries using TIMER1
and consolidate into a single, shared waveform generation interrupt
structure.  Tone, analogWrite(), Servo all now just call into this
shared resource to perform their tasks so are all compatible
and can be used simultaneously.

This setup enables multiple tones, analogWrites, servos, and stepper
motors to be controlled with reasonable accuracy.  It uses both TIMER1
and the internal ESP cycle counter to handle timing of waveform edges.
TIMER1 is used in non-reload mode and only edges cause interrupts.  The
interrupt is started and stopped as required, minimizing overhead when
these features are not being used.

A generic "startWaveform(pin, high-US, low-US, runtime-US)" and
"stopWaveform(pin)" allow for further types of interfaces.  Minimum
high or low period is ~1 us.

Add a tone(float) method, useful when working with lower frequencies.

Fixes #4321.  Fixes 4349.
2018-06-07 18:38:58 -07:00
david gauchard
73d36bbc80
fix base64_encode_expected_len (#4786) 2018-06-07 15:40:17 +02:00
Earle F. Philhower, III
5a033835e1
Add a build directory for libbearssl.a (#4736)
Simple git submodule and makefile for building the bearssl library
from source in the Arduino tree.
2018-05-23 19:50:26 -07:00
fabianoms
758b0bd124 Minimizing code redundancy (#4695)
String's destructor does the same as the 'invalidate' method.
2018-04-28 17:02:08 -03:00
Ivan Grokhotkov
5d5ea92a4d
Move continuation stack from .bss onto sys stack (#4622) 2018-04-18 11:19:49 +08:00
Peter Hoddie
16a4f22194 save 192 RAM bytes when attachInterrupt unused (#4601) 2018-04-17 17:16:06 -03:00
david gauchard
2315ac20bc
import use of __PROG_TYPES_COMPAT__ define for compatibility with old arduino code (#4619)
restrict usage of deprecated typedefs "prog_*", and cast "pgm_read_*"'s address parameters to "const void*"  only when __PROG_TYPES_COMPAT__ is defined.
also add <avr/pgmspace.h> compatibility
2018-04-10 12:23:33 +02:00
Bryce Schober
3a110aa698 Allow other ESP debug port class types (#4611)
... by casting to void pointers before comparison to avoid compile error
2018-04-06 11:23:46 +02:00
Earle F. Philhower, III
8ae553d99e
I2s input API and examples (#4539)
Enables I2S stereo input via DMA using new API calls:

. i2s_rxtx_begin(bool rx, rool tx);
. i2s_read_sample(uint32_t *l, uint32_t *r);

Original API calls will only enable TX, so this is backwards compatible.

Add simple I2S input example code using Arduino serial plotter.

Add UDP transmit of I2S microphone data to a PC (remote microphone).

Clean up and reorganize code to share RX and TX logic as much as
possible.  Fix a potential WDT error while in blocking sample read
and write.
2018-04-02 07:37:21 -07:00
Kyle Fleming
212a829942 Move cont_init from ram to flash (#4384) 2018-03-31 19:32:34 -03:00
Iman Ahmadvand
241531aa4c Adding softAP SSID & PSK query API (#4138)
* softAP SSID & PSK query API added.
Signatures:
String ESP8266WiFiAP::softAPSSID() const;
String ESP8266WiFiAP::softAPPSK() const;

* Fix for proper C-style string copy

* add API to validate input ip as string
Signatures:
static bool IPAddress::isValid(const String& arg);
static bool IPAddress::isValid(const char* arg, size_t len);

* fix indentation

* fix ip string validation to use built-in implementation.
signatures:
static bool isValid(const String& arg);
static bool isValid(const char* arg);
2018-03-28 09:27:20 -03:00
Develo
29580e8166
Fix for #4565 (rx fifo length), protect access to rx_buffer (#4568)
* Fix for #4565 (rx fifo length), protect access to rx_buffer

* Fix typo

* reworked to separate safe from unsafe functions, factorized some code, constness

* additional rework for uart_rx_fifo_available()

* swapped unsafe function definition order

* Remove static for overrun string

* Some shorthand for perf and readability
2018-03-27 22:28:39 -03:00
Earle F. Philhower, III
decfbdda5f I2S driver fixes for IRQs, protocol, factoring (#4574)
* I2S driver fixes for IRQs, protocol, factoring

All redundant ICACHE_FLASH_ATTR decorators were removed, we already do
this by default for all routines, anyway,

The actual ISR and its called function moved to to IRAM.  Used to be in flash
due to the decorator, which could lead to crashes.  Use ets_memset to mute
buffers in ISR.

Fix the I2S on-the-wire protocol by enabling the transmit delay I2STMS because
I2S is supposed to send the MSB one clock after LRCLK toggles.  This was
causing I2S to be twice as loud as intended in the best of cases, and causing
garbage/noise output when the MSB was set since data was effectively shifted.

Refactor the clock divider setting to be done in one function only, as there
is no reason to do the same complicated bit setting in two spots.

* Comment some add'l registers, use optimstic_yield

Comment the known and unknown I2S register settings for posterity, using
the ESP32 guide as a basis.

Use optimistic_yield() instead of esp_wdt_disable/enable when busy
waiting in blocking writes to ensure we don't hog the CPU completely.

Move the constant IO pins to #defines for easier understanding.
2018-03-27 20:40:34 -03:00
david gauchard
ee1ef4a795 restore HardwareSerial::write(str) (#4564)
* restore HardwareSerial::write(str)

* restore HardwareSerial::write(str) (this time checked)
2018-03-26 12:15:29 -03:00
Christoph Gommel
2105b8b06f Update core_esp8266_si2c.c (#3389)
With this patch the set up clock rate survives a re-init that is done by many libraries several times.

This makes e.g. an accelerated OLED display possible with the adafruit libraries
2018-03-24 17:23:25 -03:00
derSeddy
6464ae0c79 Added 50kHz operation mode for I2C/Wire library (#3401) 2018-03-24 15:46:29 -03:00
mrwgx3
438d3f1d11 Update core_esp8266_si2c.c (#4070)
* Update core_esp8266_si2c.c

Add 'clockCount' decrement, while-loop, twi_status()

* Update core_esp8266_si2c.c

Indents in changed function, removed superflous else
2018-03-24 14:49:27 -03:00
Zhenyu Wu
2d39bcba7d Resolve updater size check bug (#4550) 2018-03-23 15:01:17 -03:00
david gauchard
479f1b3fed HardwareSerial: one more duplicate test missing the call (#4547) 2018-03-21 22:26:34 -03:00
david gauchard
f8f205d54a
Inefficient Print::write(data,len) shows message if used (only in debug mode) (#4537)
* inefficient Print::write(data,len) shows message if used (only in debug mode)
* make HardwareSerial's write(data,len) efficient
* HardwareSerial: remove duplicate tests, move trivial code from .cpp to .h
2018-03-22 01:23:58 +01:00
david gauchard
6580bf3477
uart: fix wdt input overrun (#4536)
* uart: fix wdt on uart input overrun, expose in HardwareSerial::hasOverrun()
2018-03-21 13:28:34 +01:00
Kristijan Gjoshev
f9110f51c2 Add I2S callback on DMA read (#4205)
Add optional callback after every DMA buffer interrupt for lower delay, better timing control of I2S output.
2018-03-19 09:25:34 -07:00
Earle F. Philhower, III
855b03ce4d Fix exception handler, add assert, reduce RAM (#4187)
Move all exception strings to IRAM and out of both PMEM (illegal) and add
output of any assert() failinf conditions.

The exception handler may be called while the SPI interface is in a bad
state.  This means no PROGMEM reads are allowed, and all data and functions
used must be in system RAM or IRAM.

Add a new helper macro, ets_printf_P(), which places a constant string in
IRAM and copies it to the stack before calling the real ets_printf().
This makes the code simpler to read as no unwieldy combinations of
ets_putc/ets_printf/... are required to output anything.

The old handler also mistakenly used PSTR() strings in some places, so
fix those with this patch as well.

Gives back ~180 bytes of heap to every sketch built as the exception handler
is always included an application.
2018-03-18 08:53:08 +08:00