From 3b36a70c9a8250d10cd77d0d9408b2567c2c1e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sat, 18 May 2024 13:50:10 +0200 Subject: [PATCH 1/6] [core] Fix ESP_LOG#() macro syntax --- cores/common/base/lt_logger.h | 50 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/cores/common/base/lt_logger.h b/cores/common/base/lt_logger.h index 0af8f5f94..df8754c68 100644 --- a/cores/common/base/lt_logger.h +++ b/cores/common/base/lt_logger.h @@ -100,31 +100,31 @@ void lt_log_disable(); #endif // ESP32 compat -#define log_printf(...) LT_I(__VA_ARGS__) -#define log_v(...) LT_V(__VA_ARGS__) -#define log_d(...) LT_D(__VA_ARGS__) -#define log_i(...) LT_I(__VA_ARGS__) -#define log_w(...) LT_W(__VA_ARGS__) -#define log_e(...) LT_E(__VA_ARGS__) -#define log_n(...) LT_E(__VA_ARGS__) -#define isr_log_v(...) LT_V(__VA_ARGS__) -#define isr_log_d(...) LT_D(__VA_ARGS__) -#define isr_log_i(...) LT_I(__VA_ARGS__) -#define isr_log_w(...) LT_W(__VA_ARGS__) -#define isr_log_e(...) LT_E(__VA_ARGS__) -#define isr_log_n(...) LT_E(__VA_ARGS__) -#define ESP_LOGV(...) LT_V(__VA_ARGS__) -#define ESP_LOGD(...) LT_D(__VA_ARGS__) -#define ESP_LOGI(...) LT_I(__VA_ARGS__) -#define ESP_LOGW(...) LT_W(__VA_ARGS__) -#define ESP_LOGE(...) LT_E(__VA_ARGS__) -#define ESP_EARLY_LOGV(...) LT_V(__VA_ARGS__) -#define ESP_EARLY_LOGD(...) LT_D(__VA_ARGS__) -#define ESP_EARLY_LOGI(...) LT_I(__VA_ARGS__) -#define ESP_EARLY_LOGW(...) LT_W(__VA_ARGS__) -#define ESP_EARLY_LOGE(...) LT_E(__VA_ARGS__) -#define ets_printf(...) LT_I(__VA_ARGS__) -#define ETS_PRINTF(...) LT_I(__VA_ARGS__) +#define log_printf(...) LT_I(__VA_ARGS__) +#define log_v(...) LT_V(__VA_ARGS__) +#define log_d(...) LT_D(__VA_ARGS__) +#define log_i(...) LT_I(__VA_ARGS__) +#define log_w(...) LT_W(__VA_ARGS__) +#define log_e(...) LT_E(__VA_ARGS__) +#define log_n(...) LT_E(__VA_ARGS__) +#define isr_log_v(...) LT_V(__VA_ARGS__) +#define isr_log_d(...) LT_D(__VA_ARGS__) +#define isr_log_i(...) LT_I(__VA_ARGS__) +#define isr_log_w(...) LT_W(__VA_ARGS__) +#define isr_log_e(...) LT_E(__VA_ARGS__) +#define isr_log_n(...) LT_E(__VA_ARGS__) +#define ESP_LOGV(tag, ...) LT_V(__VA_ARGS__) +#define ESP_LOGD(tag, ...) LT_D(__VA_ARGS__) +#define ESP_LOGI(tag, ...) LT_I(__VA_ARGS__) +#define ESP_LOGW(tag, ...) LT_W(__VA_ARGS__) +#define ESP_LOGE(tag, ...) LT_E(__VA_ARGS__) +#define ESP_EARLY_LOGV(tag, ...) LT_V(__VA_ARGS__) +#define ESP_EARLY_LOGD(tag, ...) LT_D(__VA_ARGS__) +#define ESP_EARLY_LOGI(tag, ...) LT_I(__VA_ARGS__) +#define ESP_EARLY_LOGW(tag, ...) LT_W(__VA_ARGS__) +#define ESP_EARLY_LOGE(tag, ...) LT_E(__VA_ARGS__) +#define ets_printf(...) LT_I(__VA_ARGS__) +#define ETS_PRINTF(...) LT_I(__VA_ARGS__) #define LT_RET(ret) \ LT_E("ret=%d", ret); \ From dfabfbb9212a88302db3ee209d069c861a504f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sat, 18 May 2024 13:50:25 +0200 Subject: [PATCH 2/6] [beken-72xx] Increase MBEDTLS_ENTROPY_MAX_SOURCES --- cores/beken-72xx/base/config/tls_config.h | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 cores/beken-72xx/base/config/tls_config.h diff --git a/cores/beken-72xx/base/config/tls_config.h b/cores/beken-72xx/base/config/tls_config.h new file mode 100644 index 000000000..3806110d1 --- /dev/null +++ b/cores/beken-72xx/base/config/tls_config.h @@ -0,0 +1,9 @@ +/* Copyright (c) Kuba Szczodrzyński 2024-05-18. */ + +#pragma once + +#include_next "tls_config.h" + +// allow more entropy sources +#undef MBEDTLS_ENTROPY_MAX_SOURCES +#define MBEDTLS_ENTROPY_MAX_SOURCES 10 From b255402659004472e6ac7f3698ab645a63f15b5c Mon Sep 17 00:00:00 2001 From: devgs Date: Fri, 31 May 2024 15:54:41 +0300 Subject: [PATCH 3/6] [beken-72xx] Fix race condition when checking Wi-Fi SSID (#274) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix for a race condition in WiFi connection loop There seems to be the race between the event RW_EVT_STA_CONNECTED and an actual valid SSID value returned by BDK. If even a small delay is injected immediately after the event reception the valid value becomes available. Without this fix, due to a polling nature of ESPHome WiFiComponent::check_connecting_finished function may observe the WiFiSTAConnectStatus::CONNECTED status but with an empty SSID value, leading to `Incomplete connection.` warning and immediate attempt to start another connection, while the current one was actually established. * Fixed clang format conformance * Apply suggestions from code review * Update cores/beken-72xx/arduino/libraries/WiFi/WiFiEvents.cpp Co-authored-by: Cossid <83468485+Cossid@users.noreply.github.com> --------- Co-authored-by: Kuba Szczodrzyński Co-authored-by: Cossid <83468485+Cossid@users.noreply.github.com> --- .../arduino/libraries/WiFi/WiFiEvents.cpp | 49 ++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/cores/beken-72xx/arduino/libraries/WiFi/WiFiEvents.cpp b/cores/beken-72xx/arduino/libraries/WiFi/WiFiEvents.cpp index 6aa3cef34..f95ad19cd 100644 --- a/cores/beken-72xx/arduino/libraries/WiFi/WiFiEvents.cpp +++ b/cores/beken-72xx/arduino/libraries/WiFi/WiFiEvents.cpp @@ -27,6 +27,40 @@ static void wifiEventTask(void *arg) { } } +// There is a race condition, when we have an event about a successful +// connection but no SSID yet returned by BDK. Even a single millisecond +// delay should prevent this from happening. It's better to waste a bit +// of time here than to lose a valid connection down the line. +static String waitForValidSSID(WiFiClass *pWiFi) { + String result; + + // Read the initial value that might just be available already. + result = pWiFi->SSID(); + + if (!result.length()) { + std::size_t i = 0; + for (; i < 10; i++) { + // Delay and query again. + delay(1); + result = pWiFi->SSID(); + + if (result.length()) { + LT_DM(WIFI, "Got valid SSID after %u delays", i + 1); + break; + } + + // It's a good idea to yield. + yield(); + } + + if (!result.length()) { + LT_WM(WIFI, "Could not obtain a valid SSID after %u delays", i); + } + } + + return result; +} + void wifiEventSendArduino(EventId event) { event = (EventId)(RW_EVT_ARDUINO | event); wifiStatusCallback((rw_evt_type *)&event); @@ -52,11 +86,6 @@ void wifiEventHandler(rw_evt_type event) { LT_DM(WIFI, "BK event %u", event); - if (event <= RW_EVT_STA_GOT_IP) - pDATA->lastStaEvent = event; - else - pDATA->lastApEvent = event; - EventId eventId; EventInfo eventInfo; String ssid; @@ -103,7 +132,7 @@ void wifiEventHandler(rw_evt_type event) { case RW_EVT_STA_CONNECTED: eventId = ARDUINO_EVENT_WIFI_STA_CONNECTED; - ssid = pWiFi->SSID(); + ssid = waitForValidSSID(pWiFi); eventInfo.wifi_sta_connected.ssid_len = ssid.length(); eventInfo.wifi_sta_connected.channel = pWiFi->channel(); eventInfo.wifi_sta_connected.authmode = pWiFi->getEncryption(); @@ -145,5 +174,13 @@ void wifiEventHandler(rw_evt_type event) { break; } + // Publish state update only after the event data is retrieved. + // This relates to the race condition with RW_EVT_STA_CONNECTED. + if (event <= RW_EVT_STA_GOT_IP) { + pDATA->lastStaEvent = event; + } else { + pDATA->lastApEvent = event; + } + pWiFi->postEvent(eventId, eventInfo); } From 21a194f43db20cd0b598f19ef84dffd0bd834e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sat, 18 May 2024 21:59:30 +0200 Subject: [PATCH 4/6] [core] Fix lwIP debugging support --- builder/frameworks/base.py | 2 -- builder/utils/libs-queue.py | 3 +++ cores/common/base/config/lwipopts.h | 7 +++++++ docs/dev/config.md | 7 +++++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/builder/frameworks/base.py b/builder/frameworks/base.py index c9317c23a..3a4209e21 100644 --- a/builder/frameworks/base.py +++ b/builder/frameworks/base.py @@ -20,8 +20,6 @@ env.ParseCustomFlashLayout(platform, board) # Add flash layout C defines env.AddFlashLayout(board) -# Write custom header options -env.ApplyCustomOptions(platform) # Export board manifest for ltchiptool env.ExportBoardData(board) # Print information about versions and custom options diff --git a/builder/utils/libs-queue.py b/builder/utils/libs-queue.py index ddca5a27e..dc7064a07 100644 --- a/builder/utils/libs-queue.py +++ b/builder/utils/libs-queue.py @@ -184,6 +184,9 @@ def BuildLibraries(self): else: self.env.Append(CPPPATH=self.includes) + # prepend headers with custom options + self.env.ApplyCustomOptions(self.env.PioPlatform()) + # clone the environment for the whole library queue queue_env = self.env.Clone() # add private options to the cloned environment diff --git a/cores/common/base/config/lwipopts.h b/cores/common/base/config/lwipopts.h index 2557d02c8..5ce265028 100644 --- a/cores/common/base/config/lwipopts.h +++ b/cores/common/base/config/lwipopts.h @@ -15,8 +15,15 @@ // set lwIP debugging options according to LT config #if LT_DEBUG_LWIP +// enable main debugging switch #undef LWIP_DEBUG #define LWIP_DEBUG 1 +// enable all messages +#undef LWIP_DBG_MIN_LEVEL +#define LWIP_DBG_MIN_LEVEL 0 +// enable all debugging types +#undef LWIP_DBG_TYPES_ON +#define LWIP_DBG_TYPES_ON 0xF8 // make lwIP use printf() library #include #undef LWIP_PLATFORM_DIAG diff --git a/docs/dev/config.md b/docs/dev/config.md index bc668db2b..827ecd575 100644 --- a/docs/dev/config.md +++ b/docs/dev/config.md @@ -13,7 +13,10 @@ custom_fw_version = 1.2.0 # custom build options (#defines, NOT compiler flags) custom_options.lwip = - LWIP_IPV4 = 1 + # make sure to enable LT_DEBUG_LWIP as well + NETIF_DEBUG = 0x80 + IP_DEBUG = 0x80 + TCP_DEBUG = 0x80 custom_options.freertos = configUSE_TICK_HOOK = 1 @@ -82,7 +85,7 @@ To see debug messages from i.e. OTA, loglevel must also be changed. - `LT_DEBUG_OTA` (1) - OTA updates (`Update` library) - `LT_DEBUG_FDB` (0) - FlashDB debugging (macros within the library) - `LT_DEBUG_MDNS` (0) - mDNS client library -- `LT_DEBUG_LWIP` (0) - enables `LWIP_DEBUG`, provides `LWIP_PLATFORM_DIAG`; per-module options (i.e. `TCP_DEBUG`) are off by default and need to be enabled separately +- `LT_DEBUG_LWIP` (0) - enables `LWIP_DEBUG`, provides `LWIP_PLATFORM_DIAG`; per-module options (i.e. `TCP_DEBUG`) are off by default and need to be enabled separately - see example in `Project options` above - `LT_DEBUG_LWIP_ASSERT` (0) - enables assertions within lwIP (doesn't need `LT_DEBUG_LWIP`) !!! tip From fa2064b9578e60ec48e0ec524052cb2341608a66 Mon Sep 17 00:00:00 2001 From: Jaco Malan <47391204+Jaco1990@users.noreply.github.com> Date: Fri, 31 May 2024 14:59:46 +0200 Subject: [PATCH 5/6] [realtek-ambz] Temporarily workaround CHANGE interrupts not supported (#282) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix change interruptsnot supported on rtl8710b * Update cores/realtek-amb/arduino/src/wiring_irq.c --------- Co-authored-by: Kuba Szczodrzyński --- cores/realtek-amb/arduino/src/wiring_irq.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cores/realtek-amb/arduino/src/wiring_irq.c b/cores/realtek-amb/arduino/src/wiring_irq.c index f387fccca..34cfc2dcc 100644 --- a/cores/realtek-amb/arduino/src/wiring_irq.c +++ b/cores/realtek-amb/arduino/src/wiring_irq.c @@ -61,6 +61,9 @@ void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, case CHANGE: #if LT_RTL8720C event = IRQ_FALL_RISE; +// Prevents Change interrupt errors on RTL8710B chips. +#elif LT_RTL8710B + event = IRQ_RISE; #else LT_W("CHANGE interrupts not supported"); #endif From fbaae21011bd7939107bb06b5acba6736585e2f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Fri, 31 May 2024 15:01:17 +0200 Subject: [PATCH 6/6] [release] v1.6.0 --- platform.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform.json b/platform.json index c09423c32..f8b81ba2c 100644 --- a/platform.json +++ b/platform.json @@ -6,7 +6,7 @@ "type": "git", "url": "https://github.com/libretiny-eu/libretiny.git" }, - "version": "1.5.1", + "version": "1.6.0", "frameworks": { "base": { "title": "Base Framework (SDK only)",