Skip to content

Commit 6bf48a8

Browse files
Merge branch 'master' into new_timer1_irq
2 parents d48b3ba + 7820fb7 commit 6bf48a8

37 files changed

+476
-103
lines changed

boards.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3811,7 +3811,7 @@ gen4iod.menu.VTable.heap.build.vtable_flags=-DVTABLES_IN_DRAM
38113811
gen4iod.menu.VTable.iram=IRAM
38123812
gen4iod.menu.VTable.iram.build.vtable_flags=-DVTABLES_IN_IRAM
38133813
gen4iod.upload.resetmethod=nodemcu
3814-
gen4iod.build.flash_mode=qio
3814+
gen4iod.build.flash_mode=dio
38153815
gen4iod.build.flash_freq=80
38163816
gen4iod.menu.FlashSize.512K0=512K (no SPIFFS)
38173817
gen4iod.menu.FlashSize.512K0.build.flash_size=512K

cores/esp8266/avr/pgmspace.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "../pgmspace.h"

cores/esp8266/pgmspace.h

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ extern "C" {
2929

3030
#define _SFR_BYTE(n) (n)
3131

32+
#ifdef __PROG_TYPES_COMPAT__
33+
3234
typedef void prog_void;
3335
typedef char prog_char;
3436
typedef unsigned char prog_uchar;
@@ -39,6 +41,8 @@ typedef uint16_t prog_uint16_t;
3941
typedef int32_t prog_int32_t;
4042
typedef uint32_t prog_uint32_t;
4143

44+
#endif // defined(__PROG_TYPES_COMPAT__)
45+
4246
#define SIZE_IRRELEVANT 0x7fffffff
4347

4448
// memchr_P and memrchr_P are not implemented due to danger in its use, and
@@ -112,8 +116,13 @@ static inline uint16_t pgm_read_word_inlined(const void* addr) {
112116
}
113117

114118
// Make sure, that libraries checking existence of this macro are not failing
119+
#ifdef __PROG_TYPES_COMPAT__
120+
#define pgm_read_byte(addr) pgm_read_byte_inlined((const void*)(addr))
121+
#define pgm_read_word(addr) pgm_read_word_inlined((const void*)(addr))
122+
#else
115123
#define pgm_read_byte(addr) pgm_read_byte_inlined(addr)
116124
#define pgm_read_word(addr) pgm_read_word_inlined(addr)
125+
#endif
117126

118127
#else //__ets__
119128
#define pgm_read_byte(addr) (*reinterpret_cast<const uint8_t*>(addr))

doc/esp8266wifi/udp-examples.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Once we have libraries in place we need to create a ``WiFiUDP`` object. Then we
3636
WiFiUDP Udp;
3737
unsigned int localUdpPort = 4210;
3838
char incomingPacket[255];
39-
char replyPacekt[] = "Hi there! Got the message :-)";
39+
char replyPacket[] = "Hi there! Got the message :-)";
4040
4141
Wi-Fi Connection
4242
~~~~~~~~~~~~~~~~
@@ -85,7 +85,7 @@ For each received packet we are sending back an acknowledge packet:
8585
.. code:: cpp
8686
8787
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
88-
Udp.write(replyPacekt);
88+
Udp.write(replyPacket);
8989
Udp.endPacket();
9090
9191
Please note we are sending reply to the IP and port of the sender by using ``Udp.remoteIP()`` and ``Udp.remotePort()``.

doc/libraries.rst

+9-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ ESP-specific APIs
7171

7272
Some ESP-specific APIs related to deep sleep, RTC and flash memories are available in the ``ESP`` object.
7373

74-
``ESP.deepSleep(microseconds, mode)`` will put the chip into deep sleep. ``mode`` is one of ``WAKE_RF_DEFAULT``, ``WAKE_RFCAL``, ``WAKE_NO_RFCAL``, ``WAKE_RF_DISABLED``. (GPIO16 needs to be tied to RST to wake from deepSleep.)
74+
``ESP.deepSleep(microseconds, mode)`` will put the chip into deep sleep. ``mode`` is one of ``WAKE_RF_DEFAULT``, ``WAKE_RFCAL``, ``WAKE_NO_RFCAL``, ``WAKE_RF_DISABLED``. (GPIO16 needs to be tied to RST to wake from deepSleep.) The chip can sleep for at most ``ESP.deepSleepMax()`` microseconds.
7575

7676
``ESP.rtcUserMemoryWrite(offset, &data, sizeof(data))`` and ``ESP.rtcUserMemoryRead(offset, &data, sizeof(data))`` allow data to be stored in and retrieved from the RTC user memory of the chip respectively. Total size of RTC user memory is 512 bytes, so ``offset + sizeof(data)`` shouldn't exceed 512. Data should be 4-byte aligned. The stored data can be retained between deep sleep cycles. However, the data might be lost after power cycling the chip.
7777

@@ -135,6 +135,14 @@ Servo
135135

136136
This library exposes the ability to control RC (hobby) servo motors. It will support up to 24 servos on any available output pin. By default the first 12 servos will use Timer0 and currently this will not interfere with any other support. Servo counts above 12 will use Timer1 and features that use it will be affected. While many RC servo motors will accept the 3.3V IO data pin from a ESP8266, most will not be able to run off 3.3v and will require another power source that matches their specifications. Make sure to connect the grounds between the ESP8266 and the servo motor power supply.
137137

138+
Improved EEPROM library for ESP (ESP_EEPROM)
139+
--------------------------------------------
140+
141+
An improved EEPROM library for ESPxxxx. Uses flash memory as per the standard ESP EEPROM library but reduces reflash - so reducing wear and improving commit() performance.
142+
143+
As actions on the flash need to stop the interrupts, an EEPROM reflash could noticably affect anything using PWM, etc.
144+
145+
138146
Other libraries (not included with the IDE)
139147
-------------------------------------------
140148

libraries/ESP8266WiFi/src/ESP8266WiFiScan.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ std::function<void(int)> ESP8266WiFiScanClass::_onComplete;
6464
* Start scan WiFi networks available
6565
* @param async run in async mode
6666
* @param show_hidden show hidden networks
67+
* @param channel scan only this channel (0 for all channels)
68+
* @param ssid* scan for only this ssid (NULL for all ssid's)
6769
* @return Number of discovered networks
6870
*/
69-
int8_t ESP8266WiFiScanClass::scanNetworks(bool async, bool show_hidden) {
71+
int8_t ESP8266WiFiScanClass::scanNetworks(bool async, bool show_hidden, uint8 channel, uint8* ssid) {
7072
if(ESP8266WiFiScanClass::_scanStarted) {
7173
return WIFI_SCAN_RUNNING;
7274
}
@@ -84,6 +86,8 @@ int8_t ESP8266WiFiScanClass::scanNetworks(bool async, bool show_hidden) {
8486

8587
struct scan_config config;
8688
memset(&config, 0, sizeof(config));
89+
config.ssid = ssid;
90+
config.channel = channel;
8791
config.show_hidden = show_hidden;
8892
if(wifi_station_scan(&config, reinterpret_cast<scan_done_cb_t>(&ESP8266WiFiScanClass::_scanDone))) {
8993
ESP8266WiFiScanClass::_scanComplete = false;

libraries/ESP8266WiFi/src/ESP8266WiFiScan.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ESP8266WiFiScanClass {
3434

3535
public:
3636

37-
int8_t scanNetworks(bool async = false, bool show_hidden = false);
37+
int8_t scanNetworks(bool async = false, bool show_hidden = false, uint8 channel = 0, uint8* ssid = NULL);
3838
void scanNetworksAsync(std::function<void(int)> onComplete, bool show_hidden = false);
3939

4040
int8_t scanComplete();

libraries/ESP8266WiFi/src/WiFiClient.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ void WiFiClient::stop()
280280

281281
uint8_t WiFiClient::connected()
282282
{
283-
if (!_client)
283+
if (!_client || _client->state() == CLOSED)
284284
return 0;
285285

286286
return _client->state() == ESTABLISHED || available();

libraries/ESP8266WiFi/src/include/ClientContext.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ClientContext
4040
tcp_setprio(pcb, TCP_PRIO_MIN);
4141
tcp_arg(pcb, this);
4242
tcp_recv(pcb, &_s_recv);
43-
tcp_sent(pcb, &_s_sent);
43+
tcp_sent(pcb, &_s_acked);
4444
tcp_err(pcb, &_s_error);
4545
tcp_poll(pcb, &_s_poll, 1);
4646

@@ -58,7 +58,7 @@ class ClientContext
5858
tcp_err(_pcb, NULL);
5959
tcp_poll(_pcb, NULL, 0);
6060
tcp_abort(_pcb);
61-
_pcb = 0;
61+
_pcb = nullptr;
6262
}
6363
return ERR_ABRT;
6464
}
@@ -79,7 +79,7 @@ class ClientContext
7979
tcp_abort(_pcb);
8080
err = ERR_ABRT;
8181
}
82-
_pcb = 0;
82+
_pcb = nullptr;
8383
}
8484
return err;
8585
}
@@ -471,11 +471,11 @@ class ClientContext
471471
}
472472
}
473473

474-
err_t _sent(tcp_pcb* pcb, uint16_t len)
474+
err_t _acked(tcp_pcb* pcb, uint16_t len)
475475
{
476476
(void) pcb;
477477
(void) len;
478-
DEBUGV(":sent %d\r\n", len);
478+
DEBUGV(":ack %d\r\n", len);
479479
_write_some_from_cb();
480480
return ERR_OK;
481481
}
@@ -536,7 +536,7 @@ class ClientContext
536536
tcp_sent(_pcb, NULL);
537537
tcp_recv(_pcb, NULL);
538538
tcp_err(_pcb, NULL);
539-
_pcb = NULL;
539+
_pcb = nullptr;
540540
_notify_error();
541541
}
542542

@@ -571,9 +571,9 @@ class ClientContext
571571
return reinterpret_cast<ClientContext*>(arg)->_poll(tpcb);
572572
}
573573

574-
static err_t _s_sent(void *arg, struct tcp_pcb *tpcb, uint16_t len)
574+
static err_t _s_acked(void *arg, struct tcp_pcb *tpcb, uint16_t len)
575575
{
576-
return reinterpret_cast<ClientContext*>(arg)->_sent(tpcb, len);
576+
return reinterpret_cast<ClientContext*>(arg)->_acked(tpcb, len);
577577
}
578578

579579
static err_t _s_connected(void* arg, struct tcp_pcb *pcb, err_t err)

package/build_boards_manager_package.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ rm exclude.txt
6161
# Get additional libraries (TODO: add them as git submodule or subtree?)
6262

6363
# SoftwareSerial library
64-
curl -L -o SoftwareSerial.zip https://github.com/plerup/espsoftwareserial/archive/3.3.1.zip
64+
curl -L -o SoftwareSerial.zip https://github.com/plerup/espsoftwareserial/archive/3.4.1.zip
6565
unzip -q SoftwareSerial.zip
6666
rm -rf SoftwareSerial.zip
6767
mv espsoftwareserial-* SoftwareSerial

tests/README.md

+35-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,14 @@ BSTest library also contains a Python script which can "talk" to the ESP8266 boa
106106
107107
### Test configuration
108108
109-
Some tests need to connect to WiFi AP or to the PC running the tests. This configuration should be set in tests/device/libraries/test_config/test_config.h. This file is not tracked in Git. Create it by copying from tests/device/libraries/test_config/test_config.h.template, and modifying settings in that file.
109+
Some tests need to connect to WiFi AP or to the PC running the tests. In the test code, this configuration is read from environment variables (the ones set using C `getenv`/`setenv` functions). There are two ways environment variables can be set.
110+
111+
- Environment variables which apply to all or most of the tests can be defined in `tests/device/test_env.cfg` file. This file is not present in Git by default. Make a copy of `tests/device/test_env.cfg.template` and change the values to suit your environment.
112+
113+
- Environment variables which apply to a specific test can be set dynamically by the `setup` host side helper (see section below). This is done using `setenv` function defined in `mock_decorators`.
114+
115+
Environment variables can also be used to pass some information from the test code to the host side helper. To do that, test code can set an environment variable using `setenv` C function. Then the `teardown` host side helper can obtain the value of that variable using `request_env` function defined in `mock_decorators`.
116+
110117
111118
### Building and running the tests
112119
@@ -135,15 +142,41 @@ Here are some of the supported targets:
135142
Some tests running on the device need a matching part running on the host. For example, HTTP client test might need a web server running on the host to connect to. TCP server test might need to be connected to by TCP client running on the host. To support such use cases, for each test file, an optional Python test file can be provided. This Python file defines setup and teardown functions which have to be run before and after the test is run on the device. `setup` and `teardown` decorators bind setup/teardown functions to the test with specified name:
136143
137144
```python
138-
from mock_decorators import setup, teardown
145+
from mock_decorators import setup, teardown, setenv, request_env
139146
140147
@setup('WiFiClient test')
141148
def setup_wificlient_test(e):
142149
# create a TCP server
150+
# pass environment variable to the test
151+
setenv(e, 'SERVER_PORT', '10000')
152+
setenv(e, 'SERVER_IP', repr(server_ip))
143153
144154
@teardown('WiFiClient test')
145155
def teardown_wificlient_test(e):
146156
# delete TCP server
157+
# request environment variable from the test, compare to the expected value
158+
read_bytes = request_env(e, 'READ_BYTES')
159+
assert(read_bytes == '4096')
160+
```
161+
162+
Corresponding test code might look like this:
163+
164+
```c++
165+
166+
TEST_CASE("WiFiClient test", "[wificlient]")
167+
{
168+
const char* server_ip = getenv("SERVER_IP");
169+
int server_port = (int) strtol(getenv("SERVER_PORT"), NULL, 0);
170+
171+
WiFiClient client;
172+
REQUIRE(client.connect(server_ip, server_port));
173+
174+
// read data from server
175+
// ...
176+
177+
// Save the result back so that host side helper can read it
178+
setenv("READ_BYTES", String(read_bytes).c_str(), 1);
179+
}
147180
```
148181
149182

tests/device/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.hardware
33
test_report.xml
44
test_report.html
5+
test_env.cfg

tests/device/Makefile

+13-16
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,10 @@ BS_DIR ?= libraries/BSTest
1212
DEBUG_LEVEL ?= DebugLevel=None____
1313
FQBN ?= esp8266com:esp8266:generic:CpuFrequency=80,FlashFreq=40,FlashMode=dio,UploadSpeed=115200,FlashSize=4M1M,LwIPVariant=v2mss536,ResetMethod=none,Debug=Serial,$(DEBUG_LEVEL)
1414
BUILD_TOOL := $(ARDUINO_IDE_PATH)/arduino-builder
15-
TEST_CONFIG := libraries/test_config/test_config.h
15+
TEST_CONFIG := test_env.cfg
1616
TEST_REPORT_XML := test_report.xml
1717
TEST_REPORT_HTML := test_report.html
1818

19-
ifeq ("$(UPLOAD_PORT)","")
20-
$(error "Failed to detect upload port, please export UPLOAD_PORT manually")
21-
endif
22-
23-
ifeq ("$(ARDUINO_IDE_PATH)","")
24-
$(error "Please export ARDUINO_IDE_PATH")
25-
endif
2619

2720
ifneq ("$(V)","1")
2821
SILENT = @
@@ -35,16 +28,17 @@ endif
3528

3629
all: count tests test_report
3730

38-
count:
39-
@echo Running $(words $(TEST_LIST)) tests
31+
$(TEST_LIST): | virtualenv $(TEST_CONFIG) $(BUILD_DIR) $(HARDWARE_DIR)
4032

41-
tests: $(BUILD_DIR) $(HARDWARE_DIR) virtualenv $(TEST_CONFIG) $(TEST_LIST)
33+
tests: $(TEST_LIST)
4234

4335
$(TEST_LIST): LOCAL_BUILD_DIR=$(BUILD_DIR)/$(notdir $@)
4436

4537
$(TEST_LIST):
38+
@echo Running $(words $(TEST_LIST)) tests
4639
$(SILENT)mkdir -p $(LOCAL_BUILD_DIR)
4740
ifneq ("$(NO_BUILD)","1")
41+
@test -n "$(ARDUINO_IDE_PATH)" || (echo "Please export ARDUINO_IDE_PATH" && exit 1)
4842
@echo Compiling $(notdir $@)
4943
$(SILENT)$(BUILD_TOOL) -compile -logger=human \
5044
-libraries "$(PWD)/libraries" \
@@ -59,6 +53,7 @@ ifneq ("$(NO_BUILD)","1")
5953
$@
6054
endif
6155
ifneq ("$(NO_UPLOAD)","1")
56+
@test -n "$(UPLOAD_PORT)" || (echo "Failed to detect upload port, please export UPLOAD_PORT manually" && exit 1)
6257
@echo Uploading binary
6358
$(SILENT)$(ESPTOOL) $(UPLOAD_VERBOSE_FLAG) \
6459
-cp $(UPLOAD_PORT) \
@@ -67,6 +62,7 @@ ifneq ("$(NO_UPLOAD)","1")
6762
-cf $(LOCAL_BUILD_DIR)/$(notdir $@).bin
6863
endif
6964
ifneq ("$(NO_RUN)","1")
65+
@test -n "$(UPLOAD_PORT)" || (echo "Failed to detect upload port, please export UPLOAD_PORT manually" && exit 1)
7066
@echo Running tests
7167
$(SILENT)$(ESPTOOL) $(UPLOAD_VERBOSE_FLAG) -cp $(UPLOAD_PORT) -cd $(UPLOAD_BOARD) -cr
7268
@source $(BS_DIR)/virtualenv/bin/activate && \
@@ -75,6 +71,7 @@ ifneq ("$(NO_RUN)","1")
7571
-p $(UPLOAD_PORT) \
7672
-n $(basename $(notdir $@)) \
7773
-o $(LOCAL_BUILD_DIR)/test_result.xml \
74+
--env-file $(TEST_CONFIG) \
7875
`test -f $(addsuffix .py, $(basename $@)) && echo "-m $(addsuffix .py, $(basename $@))" || echo ""`
7976
endif
8077

@@ -95,7 +92,7 @@ $(HARDWARE_DIR):
9592
cd $(HARDWARE_DIR)/esp8266com && ln -s $(realpath $(ESP8266_CORE_PATH)) esp8266
9693

9794
virtualenv:
98-
make -C $(BS_DIR) virtualenv
95+
@make -C $(BS_DIR) virtualenv
9996

10097
clean:
10198
rm -rf $(BUILD_DIR)
@@ -104,9 +101,9 @@ clean:
104101

105102
$(TEST_CONFIG):
106103
@echo "****** "
107-
@echo "****** libraries/test_config/test_config.h does not exist"
108-
@echo "****** Create one from libraries/test_config/test_config.h.template"
104+
@echo "****** $(TEST_CONFIG) does not exist"
105+
@echo "****** Create one from $(TEST_CONFIG).template"
109106
@echo "****** "
110-
false
107+
@false
111108

112-
.PHONY: tests all count virtualenv test_report $(BUILD_DIR) $(TEST_LIST)
109+
.PHONY: tests all count virtualenv test_report $(TEST_LIST)

tests/device/libraries/BSTest/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $(PYTHON_ENV_DIR):
1414
. $(PYTHON_ENV_DIR)/bin/activate && pip install -r requirements.txt
1515

1616
test: $(TEST_EXECUTABLE) $(PYTHON_ENV_DIR)
17-
. $(PYTHON_ENV_DIR)/bin/activate && python runner.py -e $(TEST_EXECUTABLE)
17+
. $(PYTHON_ENV_DIR)/bin/activate && python runner.py -e $(TEST_EXECUTABLE) -m test/test.py
1818

1919
$(TEST_EXECUTABLE): test/test.cpp
2020
g++ -std=c++11 -Isrc -o $@ test/test.cpp

tests/device/libraries/BSTest/mock_decorators.py

+16
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,19 @@ def func_wrapper():
2626
func_env['teardown'] = func_wrapper
2727
return func_wrapper
2828
return decorator
29+
30+
def setenv(test_env, key, value):
31+
if 'env' not in test_env:
32+
test_env['env'] = []
33+
test_env['env'] += [(key, value)]
34+
35+
def request_env(test_env, key):
36+
return test_env['request_env'](key)
37+
38+
def get_all_envs(test_name):
39+
global env
40+
if test_name not in env:
41+
return None
42+
if 'env' not in env[test_name]:
43+
return None
44+
return env[test_name]['env']

0 commit comments

Comments
 (0)