Skip to content

Commit 91ddbb1

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 50ad559 + 2bb32bd commit 91ddbb1

File tree

116 files changed

+870
-339
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+870
-339
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ set(LIBRARY_SRCS
4242
libraries/AsyncUDP/src/AsyncUDP.cpp
4343
libraries/BluetoothSerial/src/BluetoothSerial.cpp
4444
libraries/DNSServer/src/DNSServer.cpp
45-
libraries/EEPROM/EEPROM.cpp
45+
libraries/EEPROM/src/EEPROM.cpp
4646
libraries/ESPmDNS/src/ESPmDNS.cpp
4747
libraries/FFat/src/FFat.cpp
4848
libraries/FS/src/FS.cpp
@@ -181,6 +181,7 @@ set(COMPONENT_ADD_INCLUDEDIRS
181181
libraries/BLE/src
182182
libraries/BluetoothSerial/src
183183
libraries/DNSServer/src
184+
libraries/EEPROM/src
184185
libraries/ESP32/src
185186
libraries/ESPmDNS/src
186187
libraries/FFat/src

boards.txt

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ menu.FlashSize=Flash Size
66
menu.PartitionScheme=Partition Scheme
77
menu.DebugLevel=Core Debug Level
88
menu.PSRAM=PSRAM
9+
menu.Revision=Board Revision
910

1011
##############################################################
1112

@@ -1697,6 +1698,15 @@ esp32-evb.menu.FlashFreq.40.build.flash_freq=40m
16971698
esp32-evb.menu.UploadSpeed.115200=115200
16981699
esp32-evb.menu.UploadSpeed.115200.upload.speed=115200
16991700

1701+
esp32-evb.menu.PartitionScheme.default=Default
1702+
esp32-evb.menu.PartitionScheme.default.build.partitions=default
1703+
esp32-evb.menu.PartitionScheme.no_ota=No OTA (Large APP)
1704+
esp32-evb.menu.PartitionScheme.no_ota.build.partitions=no_ota
1705+
esp32-evb.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
1706+
esp32-evb.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA)
1707+
esp32-evb.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
1708+
esp32-evb.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
1709+
17001710
##############################################################
17011711

17021712
esp32-gateway.name=OLIMEX ESP32-GATEWAY
@@ -1712,7 +1722,13 @@ esp32-gateway.serial.disableRTS=true
17121722
esp32-gateway.build.mcu=esp32
17131723
esp32-gateway.build.core=esp32
17141724
esp32-gateway.build.variant=esp32-gateway
1715-
esp32-gateway.build.board=ESP32_GATEWAY
1725+
#esp32-gateway.build.board=ESP32_GATEWAY
1726+
esp32-gateway.menu.Revision.RevC=Revision C or older
1727+
esp32-gateway.menu.Revision.RevC.build.board=ESP32_GATEWAY='C'
1728+
esp32-gateway.menu.Revision.RevE=Revision E
1729+
esp32-gateway.menu.Revision.RevE.build.board=ESP32_GATEWAY='E'
1730+
esp32-gateway.menu.Revision.RevF=Revision F
1731+
esp32-gateway.menu.Revision.RevF.build.board=ESP32_GATEWAY='F'
17161732

17171733
esp32-gateway.build.f_cpu=240000000L
17181734
esp32-gateway.build.flash_mode=dio
@@ -1730,6 +1746,15 @@ esp32-gateway.menu.FlashFreq.40.build.flash_freq=40m
17301746
esp32-gateway.menu.UploadSpeed.115200=115200
17311747
esp32-gateway.menu.UploadSpeed.115200.upload.speed=115200
17321748

1749+
esp32-gateway.menu.PartitionScheme.default=Default
1750+
esp32-gateway.menu.PartitionScheme.default.build.partitions=default
1751+
esp32-gateway.menu.PartitionScheme.no_ota=No OTA (Large APP)
1752+
esp32-gateway.menu.PartitionScheme.no_ota.build.partitions=no_ota
1753+
esp32-gateway.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
1754+
esp32-gateway.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA)
1755+
esp32-gateway.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
1756+
esp32-gateway.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
1757+
17331758
##############################################################
17341759

17351760
esp32-poe.name=OLIMEX ESP32-PoE
@@ -1763,6 +1788,15 @@ esp32-poe.menu.FlashFreq.40.build.flash_freq=40m
17631788
esp32-poe.menu.UploadSpeed.115200=115200
17641789
esp32-poe.menu.UploadSpeed.115200.upload.speed=115200
17651790

1791+
esp32-poe.menu.PartitionScheme.default=Default
1792+
esp32-poe.menu.PartitionScheme.default.build.partitions=default
1793+
esp32-poe.menu.PartitionScheme.no_ota=No OTA (Large APP)
1794+
esp32-poe.menu.PartitionScheme.no_ota.build.partitions=no_ota
1795+
esp32-poe.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
1796+
esp32-poe.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA)
1797+
esp32-poe.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
1798+
esp32-poe.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
1799+
17661800
##############################################################
17671801

17681802
espino32.name=ThaiEasyElec's ESPino32
@@ -2738,7 +2772,7 @@ lopy4.menu.DebugLevel.verbose.build.code_debug=5
27382772
oroca_edubot.name=OROCA EduBot
27392773

27402774
oroca_edubot.upload.tool=esptool_py
2741-
oroca_edubot.upload.maximum_size=1310720
2775+
oroca_edubot.upload.maximum_size=3145728
27422776
oroca_edubot.upload.maximum_data_size=327680
27432777
oroca_edubot.upload.wait_for_upload_port=true
27442778

@@ -2754,9 +2788,16 @@ oroca_edubot.build.f_cpu=240000000L
27542788
oroca_edubot.build.flash_mode=dio
27552789
oroca_edubot.build.flash_size=4MB
27562790
oroca_edubot.build.boot=dio
2757-
oroca_edubot.build.partitions=default
2791+
oroca_edubot.build.partitions=huge_app
27582792
oroca_edubot.build.defines=
27592793

2794+
oroca_edubot.menu.PartitionScheme.huge_app=Huge APP (3MB No OTA)
2795+
oroca_edubot.menu.PartitionScheme.huge_app.build.partitions=huge_app
2796+
oroca_edubot.menu.PartitionScheme.huge_app.upload.maximum_size=3145728
2797+
oroca_edubot.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA)
2798+
oroca_edubot.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
2799+
oroca_edubot.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
2800+
27602801
oroca_edubot.menu.FlashFreq.80=80MHz
27612802
oroca_edubot.menu.FlashFreq.80.build.flash_freq=80m
27622803
oroca_edubot.menu.FlashFreq.40=40MHz

cores/esp32/WMath.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,23 @@ void randomSeed(unsigned long seed)
3737

3838
long random(long howbig)
3939
{
40-
if(howbig == 0) {
41-
return 0;
40+
uint32_t x = esp_random();
41+
uint64_t m = uint64_t(x) * uint64_t(howbig);
42+
uint32_t l = uint32_t(m);
43+
if (l < howbig) {
44+
uint32_t t = -howbig;
45+
if (t >= howbig) {
46+
t -= howbig;
47+
if (t >= howbig)
48+
t %= howbig;
49+
}
50+
while (l < t) {
51+
x = esp_random();
52+
m = uint64_t(x) * uint64_t(howbig);
53+
l = uint32_t(m);
54+
}
4255
}
43-
return esp_random() % howbig;
56+
return m >> 32;
4457
}
4558

4659
long random(long howsmall, long howbig)

cores/esp32/esp32-hal-i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static void IRAM_ATTR i2cTriggerDumps(i2c_t * i2c, uint8_t trigger, const char l
451451
static void i2cApbChangeCallback(void * arg, apb_change_ev_t ev_type, uint32_t old_apb, uint32_t new_apb){
452452
i2c_t* i2c = (i2c_t*) arg; // recover data
453453
if(i2c == NULL) { // point to peripheral control block does not exits
454-
return false;
454+
return;
455455
}
456456
uint32_t oldFreq=0;
457457
switch(ev_type){

cores/esp32/esp32-hal-misc.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#include "esp_partition.h"
2222
#include "esp_log.h"
2323
#include "esp_timer.h"
24+
#ifdef CONFIG_APP_ROLLBACK_ENABLE
25+
#include "esp_ota_ops.h"
26+
#endif //CONFIG_APP_ROLLBACK_ENABLE
2427
#ifdef CONFIG_BT_ENABLED
2528
#include "esp_bt.h"
2629
#endif //CONFIG_BT_ENABLED
@@ -115,7 +118,7 @@ unsigned long IRAM_ATTR micros()
115118

116119
unsigned long IRAM_ATTR millis()
117120
{
118-
return (unsigned long) (esp_timer_get_time() / 1000);
121+
return (unsigned long) (esp_timer_get_time() / 1000ULL);
119122
}
120123

121124
void delay(uint32_t ms)
@@ -145,6 +148,9 @@ void initVariant() {}
145148
void init() __attribute__((weak));
146149
void init() {}
147150

151+
bool verifyOta() __attribute__((weak));
152+
bool verifyOta() { return true; }
153+
148154
#ifdef CONFIG_BT_ENABLED
149155
//overwritten in esp32-hal-bt.c
150156
bool btInUse() __attribute__((weak));
@@ -153,6 +159,20 @@ bool btInUse(){ return false; }
153159

154160
void initArduino()
155161
{
162+
#ifdef CONFIG_APP_ROLLBACK_ENABLE
163+
const esp_partition_t *running = esp_ota_get_running_partition();
164+
esp_ota_img_states_t ota_state;
165+
if (esp_ota_get_state_partition(running, &ota_state) == ESP_OK) {
166+
if (ota_state == ESP_OTA_IMG_PENDING_VERIFY) {
167+
if (verifyOta()) {
168+
esp_ota_mark_app_valid_cancel_rollback();
169+
} else {
170+
log_e("OTA verification failed! Start rollback to the previous version ...");
171+
esp_ota_mark_app_invalid_rollback_and_reboot();
172+
}
173+
}
174+
}
175+
#endif
156176
//init proper ref tick value for PLL (uncomment if REF_TICK is different than 1MHz)
157177
//ESP_REG(APB_CTRL_PLL_TICK_CONF_REG) = APB_CLK_FREQ / REF_CLK_FREQ - 1;
158178
#ifdef F_CPU

cores/esp32/esp32-hal-psram.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ bool psramInit(){
1919
}
2020
uint32_t chip_ver = REG_GET_FIELD(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_VER_PKG);
2121
uint32_t pkg_ver = chip_ver & 0x7;
22-
if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 || pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2 || pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4) {
22+
if (pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 || pkg_ver == EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2) {
2323
spiramFailed = true;
2424
log_w("PSRAM not supported!");
2525
return false;

cores/esp32/wiring_shift.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
2525
uint8_t i;
2626

2727
for(i = 0; i < 8; ++i) {
28-
digitalWrite(clockPin, HIGH);
28+
//digitalWrite(clockPin, HIGH);
2929
if(bitOrder == LSBFIRST)
3030
value |= digitalRead(dataPin) << i;
3131
else
3232
value |= digitalRead(dataPin) << (7 - i);
33+
digitalWrite(clockPin, HIGH);
3334
digitalWrite(clockPin, LOW);
3435
}
3536
return value;

libraries/EEPROM/EEPROM.cpp renamed to libraries/EEPROM/src/EEPROM.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ size_t EEPROMClass::readString (int address, char* value, size_t maxLen)
279279
return 0;
280280

281281
memcpy((uint8_t*) value, _data + address, len);
282+
value[len] = 0;
282283
return len;
283284
}
284285

File renamed without changes.

libraries/WebServer/examples/FSBrowser/FSBrowser.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
#include <ESPmDNS.h>
2929

3030
#define FILESYSTEM SPIFFS
31-
#define FORMAT_FILESYSTEM true
31+
// You only need to format the filesystem once
32+
#define FORMAT_FILESYSTEM false
3233
#define DBG_OUTPUT_PORT Serial
3334

3435
#if FILESYSTEM == FFat

libraries/WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void setup()
1818

1919
Serial.println();
2020
Serial.println();
21-
Serial.print("Wait for WiFi... ");
21+
Serial.print("Waiting for WiFi... ");
2222

2323
while(WiFiMulti.run() != WL_CONNECTED) {
2424
Serial.print(".");
@@ -39,32 +39,30 @@ void loop()
3939
const uint16_t port = 80;
4040
const char * host = "192.168.1.1"; // ip or dns
4141

42-
43-
44-
Serial.print("connecting to ");
42+
Serial.print("Connecting to ");
4543
Serial.println(host);
4644

4745
// Use WiFiClient class to create TCP connections
4846
WiFiClient client;
4947

5048
if (!client.connect(host, port)) {
51-
Serial.println("connection failed");
52-
Serial.println("wait 5 sec...");
49+
Serial.println("Connection failed.");
50+
Serial.println("Waiting 5 seconds before retrying...");
5351
delay(5000);
5452
return;
5553
}
5654

57-
// This will send the request to the server
58-
client.print("Send this data to server");
55+
// This will send a request to the server
56+
client.print("Send this data to the server");
5957

60-
//read back one line from server
58+
//read back one line from the server
6159
String line = client.readStringUntil('\r');
6260
client.println(line);
6361

64-
Serial.println("closing connection");
62+
Serial.println("Closing connection.");
6563
client.stop();
6664

67-
Serial.println("wait 5 sec...");
65+
Serial.println("Waiting 5 seconds before restarting...");
6866
delay(5000);
6967
}
7068

libraries/WiFi/src/WiFiClient.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,38 +202,56 @@ void WiFiClient::stop()
202202
}
203203

204204
int WiFiClient::connect(IPAddress ip, uint16_t port)
205+
{
206+
return connect(ip,port,-1);
207+
}
208+
int WiFiClient::connect(IPAddress ip, uint16_t port, int32_t timeout)
205209
{
206210
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
207211
if (sockfd < 0) {
208212
log_e("socket: %d", errno);
209213
return 0;
210214
}
215+
fcntl( sockfd, F_SETFL, fcntl( sockfd, F_GETFL, 0 ) | O_NONBLOCK );
211216

212217
uint32_t ip_addr = ip;
213218
struct sockaddr_in serveraddr;
214219
bzero((char *) &serveraddr, sizeof(serveraddr));
215220
serveraddr.sin_family = AF_INET;
216221
bcopy((const void *)(&ip_addr), (void *)&serveraddr.sin_addr.s_addr, 4);
217222
serveraddr.sin_port = htons(port);
218-
int res = lwip_connect_r(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr));
219-
if (res < 0) {
220-
log_e("lwip_connect_r: %d", errno);
223+
fd_set fdset;
224+
struct timeval tv;
225+
FD_ZERO(&fdset);
226+
FD_SET(sockfd, &fdset);
227+
tv.tv_sec = 0;
228+
tv.tv_usec = timeout * 1000;
229+
lwip_connect_r(sockfd, (struct sockaddr*)&serveraddr, sizeof(serveraddr));
230+
int res = select(sockfd + 1, nullptr, &fdset, nullptr, timeout<0 ? nullptr : &tv);
231+
if (res != 1)
232+
{
233+
log_e("select: %d",errno);
221234
close(sockfd);
222235
return 0;
223236
}
237+
fcntl( sockfd, F_SETFL, fcntl( sockfd, F_GETFL, 0 ) & (~O_NONBLOCK) );
224238
clientSocketHandle.reset(new WiFiClientSocketHandle(sockfd));
225239
_rxBuffer.reset(new WiFiClientRxBuffer(sockfd));
226240
_connected = true;
227241
return 1;
228242
}
229243

230244
int WiFiClient::connect(const char *host, uint16_t port)
245+
{
246+
return connect(host,port,-1);
247+
}
248+
int WiFiClient::connect(const char *host, uint16_t port, int32_t timeout)
231249
{
232250
IPAddress srv((uint32_t)0);
233251
if(!WiFiGenericClass::hostByName(host, srv)){
234252
return 0;
235253
}
236-
return connect(srv, port);
254+
return connect(srv, port, timeout);
237255
}
238256

239257
int WiFiClient::setSocketOption(int option, char* value, size_t len)

libraries/WiFi/src/WiFiClient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ class WiFiClient : public Client
4141
WiFiClient(int fd);
4242
~WiFiClient();
4343
int connect(IPAddress ip, uint16_t port);
44+
int connect(IPAddress ip, uint16_t port, int32_t timeout);
4445
int connect(const char *host, uint16_t port);
46+
int connect(const char *host, uint16_t port, int32_t timeout);
4547
size_t write(uint8_t data);
4648
size_t write(const uint8_t *buf, size_t size);
4749
size_t write_P(PGM_P buf, size_t size);

0 commit comments

Comments
 (0)