Skip to content

Commit 77e6844

Browse files
authored
Merge branch 'master' into NVS_Flash_CI_test
2 parents 71f85c5 + 3e65a57 commit 77e6844

File tree

867 files changed

+11285
-5415
lines changed

Some content is hidden

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

867 files changed

+11285
-5415
lines changed

.github/scripts/sketch_utils.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,30 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
109109
exit 1
110110
fi
111111

112+
# The directory that will hold all the artifcats (the build directory) is
113+
# provided through:
114+
# 1. An env variable called ARDUINO_BUILD_DIR.
115+
# 2. Created at the sketch level as "build" in the case of a single
116+
# configuration test.
117+
# 3. Created at the sketch level as "buildX" where X is the number
118+
# of configuration built in case of a multiconfiguration test.
119+
112120
ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp"
113-
if [ -z "$ARDUINO_BUILD_DIR" ]; then
114-
build_dir="$sketchdir/build"
115-
else
121+
if [ -n "$ARDUINO_BUILD_DIR" ]; then
116122
build_dir="$ARDUINO_BUILD_DIR"
123+
elif [ $len -eq 1 ]; then
124+
build_dir="$sketchdir/build"
117125
fi
118126

119127
mkdir -p "$ARDUINO_CACHE_DIR"
120128
for i in `seq 0 $(($len - 1))`
121129
do
122-
rm -rf "$build_dir$i"
123-
mkdir -p "$build_dir$i"
130+
if [ $len -ne 1 ]; then
131+
build_dir="$sketchdir/build$i"
132+
fi
133+
rm -rf $build_dir
134+
mkdir -p $build_dir
135+
124136
currfqbn=`echo $fqbn | jq -r --argjson i $i '.[$i]'`
125137
sketchname=$(basename $sketchdir)
126138
echo "Building $sketchname with FQBN=$currfqbn"
@@ -134,7 +146,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
134146
-hardware "$user_path/hardware" \
135147
-libraries "$user_path/libraries" \
136148
-build-cache "$ARDUINO_CACHE_DIR" \
137-
-build-path "$build_dir$i" \
149+
-build-path "$build_dir" \
138150
$xtra_opts "${sketchdir}/${sketchname}.ino"
139151
done
140152
}

.github/scripts/tests_run.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,24 @@ function run_test() {
1414
len=1
1515
fi
1616

17+
if [ $len -eq 1 ]; then
18+
build_dir="tests/$sketchname/build"
19+
report_file="tests/$sketchname/$sketchname.xml"
20+
fi
21+
1722
for i in `seq 0 $(($len - 1))`
1823
do
1924
echo "Running test: $sketchname -- Config: $i"
2025
if [ $erase_flash -eq 1 ]; then
2126
esptool.py -c $target erase_flash
2227
fi
2328

24-
pytest tests --build-dir tests/$sketchname/build$i -k test_$sketchname --junit-xml=tests/$sketchname/$sketchname$i.xml
29+
if [ $len -ne 1 ]; then
30+
build_dir="tests/$sketchname/build$i"
31+
report_file="tests/$sketchname/$sketchname$i.xml"
32+
fi
33+
34+
pytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file
2535
result=$?
2636
if [ $result -ne 0 ]; then
2737
return $result

boards.txt

Lines changed: 1916 additions & 285 deletions
Large diffs are not rendered by default.

cores/esp32/HardwareSerial.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ void HardwareSerial::setRxInvert(bool invert)
491491
// negative Pin value will keep it unmodified
492492
void HardwareSerial::setPins(int8_t rxPin, int8_t txPin, int8_t ctsPin, int8_t rtsPin)
493493
{
494+
if(_uart == NULL) {
495+
log_e("setPins() shall be called after begin() - nothing done");
496+
return;
497+
}
494498
uartSetPins(_uart, rxPin, txPin, ctsPin, rtsPin);
495499
}
496500

cores/esp32/esp32-hal-i2c.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ esp_err_t i2cInit(uint8_t i2c_num, int8_t sda, int8_t scl, uint32_t frequency){
7272
} else if(frequency > 1000000UL){
7373
frequency = 1000000UL;
7474
}
75+
log_i("Initialising I2C Master: sda=%d scl=%d freq=%d", sda, scl, frequency);
7576

7677
i2c_config_t conf = { };
7778
conf.mode = I2C_MODE_MASTER;

cores/esp32/esp32-hal-ledc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void ledcWrite(uint8_t chan, uint32_t duty)
8989
//Fixing if all bits in resolution is set = LEDC FULL ON
9090
uint32_t max_duty = (1 << channels_resolution[chan]) - 1;
9191

92-
if(duty == max_duty){
92+
if((duty == max_duty) && (max_duty != 1)){
9393
duty = max_duty + 1;
9494
}
9595

@@ -226,3 +226,7 @@ void analogWrite(uint8_t pin, int value) {
226226
ledcWrite(pin_to_channel[pin] - 1, value);
227227
}
228228
}
229+
230+
int8_t analogGetChannel(uint8_t pin) {
231+
return pin_to_channel[pin] - 1;
232+
}

cores/esp32/esp32-hal-uart.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ uint32_t uartAvailableForWrite(uart_t* uart)
238238
}
239239
UART_MUTEX_LOCK();
240240
uint32_t available = uart_ll_get_txfifo_len(UART_LL_GET_HW(uart->num));
241+
size_t txRingBufferAvailable = 0;
242+
if (ESP_OK == uart_get_tx_buffer_free_size(uart->num, &txRingBufferAvailable)) {
243+
available += txRingBufferAvailable;
244+
}
241245
UART_MUTEX_UNLOCK();
242246
return available;
243247
}

cores/esp32/esp32-hal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ void yield(void);
9292
#include "esp32-hal-cpu.h"
9393

9494
void analogWrite(uint8_t pin, int value);
95+
int8_t analogGetChannel(uint8_t pin);
9596

9697
//returns chip temperature in Celsius
9798
float temperatureRead();

docs/source/faq.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
##########################
22
Frequently Asked Questions
33
##########################
4+
5+
How to modify an sdkconfig option in Arduino?
6+
---------------------------------------------
7+
8+
Arduino-esp32 project is based on ESP-IDF. While ESP-IDF supports configuration of various compile-time options (known as "Kconfig options" or "sdkconfig options") via a "menuconfig" tool, this feature is not available in Arduino IDE.
9+
10+
To use the arduino-esp32 core with a modified sdkconfig option, you need to use ESP-IDF to compile Arduino libraries. Please see :doc:`esp-idf_component` and :doc:`lib_builder` for the two solutions available.
11+
12+
Note that modifying ``sdkconfig`` or ``sdkconfig.h`` files found in the arduino-esp32 project tree **does not** result in changes to these options. This is because ESP-IDF libraries are included into the arduino-esp32 project tree as pre-built libraries.
13+

docs/source/guides/tools_menu.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ Events Run On
196196

197197
This function is also used to select the core that runs the Arduino events. This is only valid if the target SoC has 2 cores.
198198

199+
Erase All Flash Before Sketch Upload
200+
************************************
201+
202+
This option selects the flash memory region to be erased before uploading the new sketch.
203+
204+
* **Disabled** - Upload the sketch without erasing all flash contents. (Default)
205+
* **Enabled** - Erase all flash contents before uploading the sketch.
206+
199207
Port
200208
****
201209

libraries/BLE/src/BLEAdvertisedDevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <esp_gattc_api.h>
1313

1414
#include <map>
15+
#include <vector>
1516

1617
#include "BLEAddress.h"
1718
#include "BLEScan.h"

libraries/ESP32/keywords.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#######################################
2+
# Syntax Coloring Map
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
#######################################
10+
# Methods and Functions (KEYWORD2)
11+
#######################################
12+
13+
#######################################
14+
# Constants (LITERAL1)
15+
#######################################
16+
17+
RGB_BUILTIN LITERAL1

libraries/Update/src/Update.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
#define ENCRYPTED_BLOCK_SIZE 16
3030

31+
#define SPI_SECTORS_PER_BLOCK 16 // usually large erase block is 32k/64k
32+
#define SPI_FLASH_BLOCK_SIZE (SPI_SECTORS_PER_BLOCK*SPI_FLASH_SEC_SIZE)
33+
3134
class UpdateClass {
3235
public:
3336
typedef std::function<void(size_t, size_t)> THandlerFunction_Progress;
@@ -166,6 +169,7 @@ class UpdateClass {
166169
bool _verifyHeader(uint8_t data);
167170
bool _verifyEnd();
168171
bool _enablePartition(const esp_partition_t* partition);
172+
bool _chkDataInBlock(const uint8_t *data, size_t len) const; // check if block contains any data or is empty
169173

170174

171175
uint8_t _error;

libraries/Update/src/Updater.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,23 @@ bool UpdateClass::_writeBuffer(){
203203
if (!_progress && _progress_callback) {
204204
_progress_callback(0, _size);
205205
}
206-
if(!ESP.partitionEraseRange(_partition, _progress, SPI_FLASH_SEC_SIZE)){
207-
_abort(UPDATE_ERROR_ERASE);
208-
return false;
206+
size_t offset = _partition->address + _progress;
207+
bool block_erase = (_size - _progress >= SPI_FLASH_BLOCK_SIZE) && (offset % SPI_FLASH_BLOCK_SIZE == 0); // if it's the block boundary, than erase the whole block from here
208+
bool part_head_sectors = _partition->address % SPI_FLASH_BLOCK_SIZE && offset < (_partition->address / SPI_FLASH_BLOCK_SIZE + 1) * SPI_FLASH_BLOCK_SIZE; // sector belong to unaligned partition heading block
209+
bool part_tail_sectors = offset >= (_partition->address + _size) / SPI_FLASH_BLOCK_SIZE * SPI_FLASH_BLOCK_SIZE; // sector belong to unaligned partition tailing block
210+
if (block_erase || part_head_sectors || part_tail_sectors){
211+
if(!ESP.partitionEraseRange(_partition, _progress, block_erase ? SPI_FLASH_BLOCK_SIZE : SPI_FLASH_SEC_SIZE)){
212+
_abort(UPDATE_ERROR_ERASE);
213+
return false;
214+
}
209215
}
210-
if (!ESP.partitionWrite(_partition, _progress + skip, (uint32_t*)_buffer + skip/sizeof(uint32_t), _bufferLen - skip)) {
216+
217+
// try to skip empty blocks on unecrypted partitions
218+
if ((_partition->encrypted || _chkDataInBlock(_buffer + skip/sizeof(uint32_t), _bufferLen - skip)) && !ESP.partitionWrite(_partition, _progress + skip, (uint32_t*)_buffer + skip/sizeof(uint32_t), _bufferLen - skip)) {
211219
_abort(UPDATE_ERROR_WRITE);
212220
return false;
213221
}
222+
214223
//restore magic or md5 will fail
215224
if(!_progress && _command == U_FLASH){
216225
_buffer[0] = ESP_IMAGE_HEADER_MAGIC;
@@ -389,4 +398,20 @@ const char * UpdateClass::errorString(){
389398
return _err2str(_error);
390399
}
391400

401+
bool UpdateClass::_chkDataInBlock(const uint8_t *data, size_t len) const {
402+
// check 32-bit aligned blocks only
403+
if (!len || len % sizeof(uint32_t))
404+
return true;
405+
406+
size_t dwl = len / sizeof(uint32_t);
407+
408+
do {
409+
if (*(uint32_t*)data ^ 0xffffffff) // for SPI NOR flash empty blocks are all one's, i.e. filled with 0xff byte
410+
return true;
411+
412+
data += sizeof(uint32_t);
413+
} while (--dwl);
414+
return false;
415+
}
416+
392417
UpdateClass Update;

libraries/WebServer/src/WebServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ void WebServer::sendContent_P(PGM_P content, size_t size) {
527527
}
528528

529529

530-
void WebServer::_streamFileCore(const size_t fileSize, const String & fileName, const String & contentType)
530+
void WebServer::_streamFileCore(const size_t fileSize, const String & fileName, const String & contentType, const int code)
531531
{
532532
using namespace mime;
533533
setContentLength(fileSize);
@@ -536,7 +536,7 @@ void WebServer::_streamFileCore(const size_t fileSize, const String & fileName,
536536
contentType != String(FPSTR(mimeTable[none].mimeType))) {
537537
sendHeader(F("Content-Encoding"), F("gzip"));
538538
}
539-
send(200, contentType, "");
539+
send(code, contentType, "");
540540
}
541541

542542
String WebServer::pathArg(unsigned int i) {

libraries/WebServer/src/WebServer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ class WebServer
139139
static String urlDecode(const String& text);
140140

141141
template<typename T>
142-
size_t streamFile(T &file, const String& contentType) {
143-
_streamFileCore(file.size(), file.name(), contentType);
142+
size_t streamFile(T &file, const String& contentType, const int code = 200) {
143+
_streamFileCore(file.size(), file.name(), contentType, code);
144144
return _currentClient.write(file);
145145
}
146146

@@ -160,7 +160,7 @@ class WebServer
160160
void _prepareHeader(String& response, int code, const char* content_type, size_t contentLength);
161161
bool _collectHeader(const char* headerName, const char* headerValue);
162162

163-
void _streamFileCore(const size_t fileSize, const String & fileName, const String & contentType);
163+
void _streamFileCore(const size_t fileSize, const String & fileName, const String & contentType, const int code = 200);
164164

165165
String _getRandomHexString();
166166
// for extracting Auth parameters

libraries/WiFi/src/WiFiAP.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class WiFiAPClass
3838
public:
3939

4040
bool softAP(const char* ssid, const char* passphrase = NULL, int channel = 1, int ssid_hidden = 0, int max_connection = 4, bool ftm_responder = false);
41-
bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcp_lease_start = INADDR_NONE);
41+
bool softAPConfig(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dhcp_lease_start = (uint32_t) 0);
4242
bool softAPdisconnect(bool wifioff = false);
4343

4444
uint8_t softAPgetStationNum();

libraries/WiFi/src/WiFiClient.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,14 @@ int WiFiClient::connect(const char *host, uint16_t port, int32_t timeout)
303303

304304
int WiFiClient::setSocketOption(int option, char* value, size_t len)
305305
{
306-
int res = setsockopt(fd(), SOL_SOCKET, option, value, len);
306+
return setSocketOption(SOL_SOCKET, option, (const void*)value, len);
307+
}
308+
309+
int WiFiClient::setSocketOption(int level, int option, const void* value, size_t len)
310+
{
311+
int res = setsockopt(fd(), level, option, value, len);
307312
if(res < 0) {
308-
log_e("%X : %d", option, errno);
313+
log_e("fail on %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
309314
}
310315
return res;
311316
}
@@ -330,11 +335,7 @@ int WiFiClient::setTimeout(uint32_t seconds)
330335

331336
int WiFiClient::setOption(int option, int *value)
332337
{
333-
int res = setsockopt(fd(), IPPROTO_TCP, option, (char *) value, sizeof(int));
334-
if(res < 0) {
335-
log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
336-
}
337-
return res;
338+
return setSocketOption(IPPROTO_TCP, option, (const void*)value, sizeof(int));
338339
}
339340

340341
int WiFiClient::getOption(int option, int *value)

libraries/WiFi/src/WiFiClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class WiFiClient : public ESPLwIPClient
8787
int fd() const;
8888

8989
int setSocketOption(int option, char* value, size_t len);
90+
int setSocketOption(int level, int option, const void* value, size_t len);
9091
int setOption(int option, int *value);
9192
int getOption(int option, int *value);
9293
int setTimeout(uint32_t seconds);

libraries/WiFi/src/WiFiGeneric.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ static void _arduino_event_cb(void* arg, esp_event_base_t event_base, int32_t ev
495495
log_v("SC Found Channel");
496496
arduino_event.event_id = ARDUINO_EVENT_SC_FOUND_CHANNEL;
497497
} else if (event_base == SC_EVENT && event_id == SC_EVENT_GOT_SSID_PSWD) {
498-
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
498+
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE
499499
smartconfig_event_got_ssid_pswd_t *event = (smartconfig_event_got_ssid_pswd_t *)event_data;
500500
log_v("SC: SSID: %s, Password: %s", (const char *)event->ssid, (const char *)event->password);
501501
#endif
@@ -668,7 +668,7 @@ bool wifiLowLevelInit(bool persistent){
668668
cfg.static_tx_buf_num = 0;
669669
cfg.dynamic_tx_buf_num = 32;
670670
cfg.tx_buf_type = 1;
671-
cfg.cache_tx_buf_num = 1; // can't be zero!
671+
cfg.cache_tx_buf_num = 4; // can't be zero!
672672
cfg.static_rx_buf_num = 4;
673673
cfg.dynamic_rx_buf_num = 32;
674674
}

libraries/WiFiClientSecure/src/WiFiClientSecure.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,14 @@ int WiFiClientSecure::setTimeout(uint32_t seconds)
378378
}
379379
int WiFiClientSecure::setSocketOption(int option, char* value, size_t len)
380380
{
381-
int res = setsockopt(sslclient->socket, SOL_SOCKET, option, value, len);
381+
return setSocketOption(SOL_SOCKET, option, (const void*)value, len);
382+
}
383+
384+
int WiFiClientSecure::setSocketOption(int level, int option, const void* value, size_t len)
385+
{
386+
int res = setsockopt(sslclient->socket, level, option, value, len);
382387
if(res < 0) {
383-
log_e("%X : %d", option, errno);
388+
log_e("fail on %d, errno: %d, \"%s\"", sslclient->socket, errno, strerror(errno));
384389
}
385390
return res;
386391
}

libraries/WiFiClientSecure/src/WiFiClientSecure.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class WiFiClientSecure : public WiFiClient
8181
bool getFingerprintSHA256(uint8_t sha256_result[32]) { return get_peer_fingerprint(sslclient, sha256_result); };
8282
int setTimeout(uint32_t seconds);
8383
int setSocketOption(int option, char* value, size_t len);
84+
int setSocketOption(int level, int option, const void* value, size_t len);
8485

8586
operator bool()
8687
{

libraries/WiFiClientSecure/src/ssl_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "WiFi.h"
2222

2323
#if !defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
24-
# warning "Please configure IDF framework to include mbedTLS -> Enable pre-shared-key ciphersuites and activate at least one cipher"
24+
# warning "Please configure IDF framework to include mbedTLS -> Enable PSK based ciphersuite modes (MBEDTLS_KEY_EXCHANGE_PSK) and activate at least one cipher"
2525
#else
2626

2727
const char *pers = "esp32-tls";

0 commit comments

Comments
 (0)