Skip to content

Commit a0f8b37

Browse files
committed
Merge remote-tracking branch 'origin/master' into docs-embed
2 parents 69dacb4 + 2ede5ac commit a0f8b37

File tree

85 files changed

+7920
-607
lines changed

Some content is hidden

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

85 files changed

+7920
-607
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
/libraries/ArduinoOTA/ @me-no-dev
5555
/libraries/AsyncUDP/ @me-no-dev
5656
/libraries/BLE/ @lucasssvaz @SuGlider
57+
/libraries/ESP_HostedOTA/ @me-no-dev
5758
/libraries/ESP_I2S/ @me-no-dev
5859
/libraries/ESP_NOW/ @P-R-O-C-H-Y @lucasssvaz
5960
/libraries/ESP_SR/ @me-no-dev

.github/ISSUE_TEMPLATE/Issue-report.yml

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ body:
4040
label: Version
4141
description: What version of Arduino ESP32 are you running? If possible, consider updating to the latest version.
4242
options:
43-
- latest stable Release (if not listed below)
44-
- latest development Release Candidate (RC-X)
43+
- Please select a version from the list below
4544
- latest master (checkout manually)
4645
- v3.3.4
4746
- v3.3.3
@@ -62,26 +61,7 @@ body:
6261
- v3.0.2
6362
- v3.0.1
6463
- v3.0.0
65-
- v2.0.17
66-
- v2.0.16
67-
- v2.0.15
68-
- v2.0.14
69-
- v2.0.13
70-
- v2.0.12
71-
- v2.0.11
72-
- v2.0.10
73-
- v2.0.9
74-
- v2.0.8
75-
- v2.0.7
76-
- v2.0.6
77-
- v2.0.5
78-
- v2.0.4
79-
- v2.0.3
80-
- v2.0.2
81-
- v2.0.1
82-
- v2.0.0
83-
- v1.0.6
84-
- other
64+
- Older versions
8565
validations:
8666
required: true
8767
- type: dropdown

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ set(ARDUINO_ALL_LIBRARIES
9090
ESP_I2S
9191
ESP_NOW
9292
ESP_SR
93+
ESP_HostedOTA
9394
ESPmDNS
9495
Ethernet
9596
FFat
@@ -146,6 +147,9 @@ set(ARDUINO_LIBRARY_ESP_SR_SRCS
146147
libraries/ESP_SR/src/ESP_SR.cpp
147148
libraries/ESP_SR/src/esp32-hal-sr.c)
148149

150+
set(ARDUINO_LIBRARY_ESP_HostedOTA_SRCS
151+
libraries/ESP_HostedOTA/src/ESP_HostedOTA.cpp)
152+
149153
set(ARDUINO_LIBRARY_ESPmDNS_SRCS libraries/ESPmDNS/src/ESPmDNS.cpp)
150154

151155
set(ARDUINO_LIBRARY_Ethernet_SRCS libraries/Ethernet/src/ETH.cpp)
@@ -187,11 +191,16 @@ set(ARDUINO_LIBRARY_Matter_SRCS
187191
libraries/Matter/src/MatterEndpoints/MatterEnhancedColorLight.cpp
188192
libraries/Matter/src/MatterEndpoints/MatterFan.cpp
189193
libraries/Matter/src/MatterEndpoints/MatterTemperatureSensor.cpp
194+
libraries/Matter/src/MatterEndpoints/MatterTemperatureControlledCabinet.cpp
190195
libraries/Matter/src/MatterEndpoints/MatterHumiditySensor.cpp
191196
libraries/Matter/src/MatterEndpoints/MatterContactSensor.cpp
197+
libraries/Matter/src/MatterEndpoints/MatterWaterLeakDetector.cpp
198+
libraries/Matter/src/MatterEndpoints/MatterWaterFreezeDetector.cpp
199+
libraries/Matter/src/MatterEndpoints/MatterRainSensor.cpp
192200
libraries/Matter/src/MatterEndpoints/MatterPressureSensor.cpp
193201
libraries/Matter/src/MatterEndpoints/MatterOccupancySensor.cpp
194202
libraries/Matter/src/MatterEndpoints/MatterOnOffPlugin.cpp
203+
libraries/Matter/src/MatterEndpoints/MatterDimmablePlugin.cpp
195204
libraries/Matter/src/MatterEndpoints/MatterThermostat.cpp
196205
libraries/Matter/src/Matter.cpp
197206
libraries/Matter/src/MatterEndPoint.cpp)

boards.txt

Lines changed: 330 additions & 0 deletions
Large diffs are not rendered by default.

cores/esp32/HardwareSerial.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,31 @@ HardwareSerial Serial5(5);
6161
extern void HWCDCSerialEvent(void) __attribute__((weak));
6262
#endif
6363

64+
// C-callable helper used by HAL when pins are detached and the high-level
65+
// HardwareSerial instance must be finalized.
66+
extern "C" void hal_uart_notify_pins_detached(int uart_num) {
67+
log_d("hal_uart_notify_pins_detached: Notifying HardwareSerial for UART%d", uart_num);
68+
switch (uart_num) {
69+
case 0: Serial0.end(); break;
70+
#if SOC_UART_NUM > 1
71+
case 1: Serial1.end(); break;
72+
#endif
73+
#if SOC_UART_NUM > 2
74+
case 2: Serial2.end(); break;
75+
#endif
76+
#if SOC_UART_NUM > 3
77+
case 3: Serial3.end(); break;
78+
#endif
79+
#if SOC_UART_NUM > 4
80+
case 4: Serial4.end(); break;
81+
#endif
82+
#if SOC_UART_NUM > 5
83+
case 5: Serial5.end(); break;
84+
#endif
85+
default: log_e("hal_uart_notify_pins_detached: UART%d not handled!", uart_num); break;
86+
}
87+
}
88+
6489
#if USB_SERIAL_IS_DEFINED == 1 // Native USB CDC Event
6590
// Used by Hardware Serial for USB CDC events
6691
extern void USBSerialEvent(void) __attribute__((weak));
@@ -483,9 +508,6 @@ void HardwareSerial::end() {
483508
// including any tasks or debug message channel (log_x()) - but not for IDF log messages!
484509
_onReceiveCB = NULL;
485510
_onReceiveErrorCB = NULL;
486-
if (uartGetDebug() == _uart_nr) {
487-
uartSetDebug(0);
488-
}
489511
_rxFIFOFull = 0;
490512
uartEnd(_uart_nr); // fully detach all pins and delete the UART driver
491513
_destroyEventTask(); // when IDF uart driver is deleted, _eventTask must finish too

cores/esp32/chip-debug-report.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static void printPerimanInfo(void) {
291291

292292
void printBeforeSetupInfo(void) {
293293
#if ARDUINO_USB_CDC_ON_BOOT
294-
Serial.begin(0);
294+
Serial.begin();
295295
Serial.setDebugOutput(true);
296296
uint8_t t = 0;
297297
while (!Serial && (t++ < 200)) {

cores/esp32/esp32-hal-hosted.c

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "esp32-hal-hosted.h"
1919
#include "esp32-hal-log.h"
20+
#include "esp32-hal.h"
2021
#include "pins_arduino.h"
2122

2223
#include "esp_hosted.h"
@@ -53,6 +54,9 @@ static esp_hosted_coprocessor_fwver_t host_version_struct = {
5354
.major1 = ESP_HOSTED_VERSION_MAJOR_1, .minor1 = ESP_HOSTED_VERSION_MINOR_1, .patch1 = ESP_HOSTED_VERSION_PATCH_1
5455
};
5556

57+
static bool hostedInit();
58+
static bool hostedDeinit();
59+
5660
void hostedGetHostVersion(uint32_t *major, uint32_t *minor, uint32_t *patch) {
5761
*major = host_version_struct.major1;
5862
*minor = host_version_struct.minor1;
@@ -66,6 +70,11 @@ void hostedGetSlaveVersion(uint32_t *major, uint32_t *minor, uint32_t *patch) {
6670
}
6771

6872
bool hostedHasUpdate() {
73+
if (!hosted_initialized) {
74+
log_e("ESP-Hosted is not initialized");
75+
return false;
76+
}
77+
6978
uint32_t host_version = ESP_HOSTED_VERSION_VAL(host_version_struct.major1, host_version_struct.minor1, host_version_struct.patch1);
7079
uint32_t slave_version = 0;
7180

@@ -106,6 +115,11 @@ char *hostedGetUpdateURL() {
106115
}
107116

108117
bool hostedBeginUpdate() {
118+
if (!hosted_initialized) {
119+
log_e("ESP-Hosted is not initialized");
120+
return false;
121+
}
122+
109123
esp_err_t err = esp_hosted_slave_ota_begin();
110124
if (err != ESP_OK) {
111125
log_e("Failed to begin Update: %s", esp_err_to_name(err));
@@ -114,6 +128,11 @@ bool hostedBeginUpdate() {
114128
}
115129

116130
bool hostedWriteUpdate(uint8_t *buf, uint32_t len) {
131+
if (!hosted_initialized) {
132+
log_e("ESP-Hosted is not initialized");
133+
return false;
134+
}
135+
117136
esp_err_t err = esp_hosted_slave_ota_write(buf, len);
118137
if (err != ESP_OK) {
119138
log_e("Failed to write Update: %s", esp_err_to_name(err));
@@ -122,6 +141,11 @@ bool hostedWriteUpdate(uint8_t *buf, uint32_t len) {
122141
}
123142

124143
bool hostedEndUpdate() {
144+
if (!hosted_initialized) {
145+
log_e("ESP-Hosted is not initialized");
146+
return false;
147+
}
148+
125149
esp_err_t err = esp_hosted_slave_ota_end();
126150
if (err != ESP_OK) {
127151
log_e("Failed to end Update: %s", esp_err_to_name(err));
@@ -130,16 +154,31 @@ bool hostedEndUpdate() {
130154
}
131155

132156
bool hostedActivateUpdate() {
157+
if (!hosted_initialized) {
158+
log_e("ESP-Hosted is not initialized");
159+
return false;
160+
}
161+
162+
// Activate can fail on older firmwares and that is not critical
163+
uint32_t slave_version = ESP_HOSTED_VERSION_VAL(slave_version_struct.major1, slave_version_struct.minor1, slave_version_struct.patch1);
164+
uint32_t min_version = ESP_HOSTED_VERSION_VAL(2, 6, 0);
165+
166+
if (slave_version < min_version) {
167+
// Silence messages caused by earlier versions
168+
esp_log_level_set("rpc_core", ESP_LOG_NONE);
169+
}
170+
133171
esp_err_t err = esp_hosted_slave_ota_activate();
134-
if (err != ESP_OK) {
172+
173+
// Any further communication will result in logged errors
174+
esp_log_level_set("sdmmc_io", ESP_LOG_NONE);
175+
esp_log_level_set("H_SDIO_DRV", ESP_LOG_NONE);
176+
177+
if (err != ESP_OK && slave_version >= min_version) {
135178
log_e("Failed to activate Update: %s", esp_err_to_name(err));
179+
return false;
136180
}
137-
// else {
138-
// hostedDeinit();
139-
// delay(1000);
140-
// hostedInit();
141-
// }
142-
return err == ESP_OK;
181+
return true;
143182
}
144183

145184
static bool hostedInit() {
@@ -158,15 +197,22 @@ static bool hostedInit() {
158197
conf.pin_d2.pin = sdio_pin_config.pin_d2;
159198
conf.pin_d3.pin = sdio_pin_config.pin_d3;
160199
conf.pin_reset.pin = sdio_pin_config.pin_reset;
161-
// esp_hosted_sdio_set_config() will fail on second attempt but here temporarily to not cause exception on reinit
162-
if (esp_hosted_sdio_set_config(&conf) != ESP_OK || esp_hosted_init() != ESP_OK) {
163-
log_e("esp_hosted_init failed!");
200+
esp_err_t err = esp_hosted_sdio_set_config(&conf);
201+
if (err != ESP_OK) { //&& err != ESP_ERR_NOT_ALLOWED) { // uncomment when second init is fixed
202+
log_e("esp_hosted_sdio_set_config failed: %s", esp_err_to_name(err));
203+
return false;
204+
}
205+
err = esp_hosted_init();
206+
if (err != ESP_OK) {
207+
log_e("esp_hosted_init failed: %s", esp_err_to_name(err));
164208
hosted_initialized = false;
165209
return false;
166210
}
167211
log_i("ESP-Hosted initialized!");
168-
if (esp_hosted_connect_to_slave() != ESP_OK) {
169-
log_e("Failed to connect to slave");
212+
err = esp_hosted_connect_to_slave();
213+
if (err != ESP_OK) {
214+
log_e("esp_hosted_connect_to_slave failed: %s", esp_err_to_name(err));
215+
hosted_initialized = false;
170216
return false;
171217
}
172218
hostedHasUpdate();

cores/esp32/esp32-hal-uart.c

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
static int s_uart_debug_nr = 0; // UART number for debug output
4343
#define REF_TICK_BAUDRATE_LIMIT 250000 // this is maximum UART badrate using REF_TICK as clock
4444

45+
/* C prototype for the notifier implemented in HardwareSerial.cpp */
46+
extern void hal_uart_notify_pins_detached(int uart_num);
47+
4548
struct uart_struct_t {
4649

4750
#if !CONFIG_DISABLE_HAL_LOCKS
@@ -282,29 +285,67 @@ static bool _uartDetachPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t
282285
// Peripheral Manager detach callback for each specific UART PIN
283286
static bool _uartDetachBus_RX(void *busptr) {
284287
// sanity check - it should never happen
285-
assert(busptr && "_uartDetachBus_RX bus NULL pointer.");
288+
if (busptr == NULL) {
289+
log_e("_uartDetachBus_RX: busptr is NULL");
290+
return false;
291+
}
286292
uart_t *bus = (uart_t *)busptr;
293+
if (bus->_rxPin < 0) {
294+
log_d("_uartDetachBus_RX: RX pin already detached for UART%d", bus->num);
295+
return true;
296+
}
297+
if (bus->_txPin < 0) { // both rx and tx pins are detached, terminate the uart driver
298+
log_d("_uartDetachBus_RX: both RX and TX pins detached for UART%d, terminating driver", bus->num);
299+
hal_uart_notify_pins_detached(bus->num);
300+
return true;
301+
}
287302
return _uartDetachPins(bus->num, bus->_rxPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
288303
}
289304

290305
static bool _uartDetachBus_TX(void *busptr) {
291306
// sanity check - it should never happen
292-
assert(busptr && "_uartDetachBus_TX bus NULL pointer.");
307+
if (busptr == NULL) {
308+
log_e("_uartDetachBus_TX: busptr is NULL");
309+
return false;
310+
}
293311
uart_t *bus = (uart_t *)busptr;
312+
if (bus->_txPin < 0) {
313+
log_d("_uartDetachBus_TX: TX pin already detached for UART%d", bus->num);
314+
return true;
315+
}
316+
if (bus->_rxPin < 0) { // both rx and tx pins are detached, terminate the uart driver
317+
log_d("_uartDetachBus_TX: both RX and TX pins detached for UART%d, terminating driver", bus->num);
318+
hal_uart_notify_pins_detached(bus->num);
319+
return true;
320+
}
294321
return _uartDetachPins(bus->num, UART_PIN_NO_CHANGE, bus->_txPin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
295322
}
296323

297324
static bool _uartDetachBus_CTS(void *busptr) {
298325
// sanity check - it should never happen
299-
assert(busptr && "_uartDetachBus_CTS bus NULL pointer.");
326+
if (busptr == NULL) {
327+
log_e("_uartDetachBus_CTS: busptr is NULL");
328+
return false;
329+
}
300330
uart_t *bus = (uart_t *)busptr;
331+
if (bus->_ctsPin < 0) {
332+
log_d("_uartDetachBus_CTS: CTS pin already detached for UART%d", bus->num);
333+
return true;
334+
}
301335
return _uartDetachPins(bus->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, bus->_ctsPin, UART_PIN_NO_CHANGE);
302336
}
303337

304338
static bool _uartDetachBus_RTS(void *busptr) {
305339
// sanity check - it should never happen
306-
assert(busptr && "_uartDetachBus_RTS bus NULL pointer.");
340+
if (busptr == NULL) {
341+
log_e("_uartDetachBus_RTS: busptr is NULL");
342+
return false;
343+
}
307344
uart_t *bus = (uart_t *)busptr;
345+
if (bus->_rtsPin < 0) {
346+
log_d("_uartDetachBus_RTS: RTS pin already detached for UART%d", bus->num);
347+
return true;
348+
}
308349
return _uartDetachPins(bus->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, bus->_rtsPin);
309350
}
310351

@@ -629,6 +670,16 @@ bool uartSetPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, in
629670
//log_v("setting UART%d pins: prev->new RX(%d->%d) TX(%d->%d) CTS(%d->%d) RTS(%d->%d)", uart_num,
630671
// uart->_rxPin, rxPin, uart->_txPin, txPin, uart->_ctsPin, ctsPin, uart->_rtsPin, rtsPin); vTaskDelay(10);
631672

673+
// mute bus detaching callbacks to avoid terminating the UART driver when both RX and TX pins are detached
674+
peripheral_bus_deinit_cb_t rxDeinit = perimanGetBusDeinit(ESP32_BUS_TYPE_UART_RX);
675+
peripheral_bus_deinit_cb_t txDeinit = perimanGetBusDeinit(ESP32_BUS_TYPE_UART_TX);
676+
peripheral_bus_deinit_cb_t ctsDeinit = perimanGetBusDeinit(ESP32_BUS_TYPE_UART_CTS);
677+
peripheral_bus_deinit_cb_t rtsDeinit = perimanGetBusDeinit(ESP32_BUS_TYPE_UART_RTS);
678+
perimanClearBusDeinit(ESP32_BUS_TYPE_UART_RX);
679+
perimanClearBusDeinit(ESP32_BUS_TYPE_UART_TX);
680+
perimanClearBusDeinit(ESP32_BUS_TYPE_UART_CTS);
681+
perimanClearBusDeinit(ESP32_BUS_TYPE_UART_RTS);
682+
632683
// First step: detaches all previous UART pins
633684
bool rxPinChanged = rxPin >= 0 && rxPin != uart->_rxPin;
634685
if (rxPinChanged) {
@@ -660,6 +711,21 @@ bool uartSetPins(uint8_t uart_num, int8_t rxPin, int8_t txPin, int8_t ctsPin, in
660711
if (rtsPinChanged) {
661712
retCode &= _uartAttachPins(uart->num, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, rtsPin);
662713
}
714+
715+
// restore bus detaching callbacks
716+
if (rxDeinit != NULL) {
717+
perimanSetBusDeinit(ESP32_BUS_TYPE_UART_RX, rxDeinit);
718+
}
719+
if (txDeinit != NULL) {
720+
perimanSetBusDeinit(ESP32_BUS_TYPE_UART_TX, txDeinit);
721+
}
722+
if (ctsDeinit != NULL) {
723+
perimanSetBusDeinit(ESP32_BUS_TYPE_UART_CTS, ctsDeinit);
724+
}
725+
if (rtsDeinit != NULL) {
726+
perimanSetBusDeinit(ESP32_BUS_TYPE_UART_RTS, rtsDeinit);
727+
}
728+
663729
UART_MUTEX_UNLOCK();
664730

665731
if (!retCode) {
@@ -986,6 +1052,9 @@ void uartEnd(uint8_t uart_num) {
9861052
if (uart_is_driver_installed(uart_num)) {
9871053
uart_driver_delete(uart_num);
9881054
}
1055+
if (uartGetDebug() == uart_num) {
1056+
uartSetDebug(0);
1057+
}
9891058
UART_MUTEX_UNLOCK();
9901059
}
9911060

0 commit comments

Comments
 (0)