Skip to content

Commit d0f4f7e

Browse files
authored
Merge pull request #186 from baba-dev/codex/fix-double-free,-stabilize-boot-process
fix: guard Tab5 hosted Wi-Fi and enable heap tracing
2 parents 36ee7ed + c1d3851 commit d0f4f7e

File tree

8 files changed

+80
-26
lines changed

8 files changed

+80
-26
lines changed

custom/integration/wifi_remote/hosted_safe.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
#include "freertos/task.h"
1212
#include "sdkconfig.h"
1313

14-
#if CONFIG_M5TAB5_USE_ESP_HOSTED
14+
#if CONFIG_APP_ENABLE_WIFI_HOSTED
1515
# include "esp_hosted_api.h"
1616
# include "esp_wifi.h"
1717
# include "esp_wifi_remote.h"
1818
#endif
1919

2020
static const char* TAG = "hosted_safe";
21-
static bool s_hosted_ready = false;
21+
static bool s_hosted_ready = false; // Guarded by CONFIG_APP_ENABLE_WIFI_HOSTED
2222

23-
#if CONFIG_M5TAB5_USE_ESP_HOSTED
23+
#if CONFIG_APP_ENABLE_WIFI_HOSTED
2424
static void slave_pulse_reset(void)
2525
{
2626
const gpio_num_t rst = 54;
@@ -40,7 +40,7 @@ static void slave_pulse_reset(void)
4040

4141
bool hosted_try_init_with_retries(void)
4242
{
43-
#if !CONFIG_M5TAB5_USE_ESP_HOSTED
43+
#if !CONFIG_APP_ENABLE_WIFI_HOSTED
4444
ESP_LOGI(TAG, "ESP-Hosted disabled via Kconfig.");
4545
return false;
4646
#else
@@ -95,7 +95,7 @@ bool hosted_try_init_with_retries(void)
9595

9696
void hosted_deinit_safe(void)
9797
{
98-
#if CONFIG_M5TAB5_USE_ESP_HOSTED
98+
#if CONFIG_APP_ENABLE_WIFI_HOSTED
9999
if (!s_hosted_ready)
100100
{
101101
return;

platforms/tab5/Kconfig.projbuild

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
menu "M5Tab5 Connectivity"
22

3-
config M5TAB5_USE_ESP_HOSTED
4-
bool "Enable ESP-Hosted (Wi-Fi over SDIO)"
5-
default n
6-
help
7-
When enabled, the app will initialize the ESP-Hosted SDIO slave (ESP32-Cx).
8-
When disabled, boot never touches SDIO/Hosted and Wi-Fi is unavailable.
3+
if APP_ENABLE_WIFI_HOSTED
94

105
config M5TAB5_HOSTED_BOOT_RETRIES
116
int "Hosted init retries at boot"
@@ -17,4 +12,6 @@ config M5TAB5_HOSTED_BOOT_DELAY_MS
1712
range 0 5000
1813
default 500
1914

15+
endif
16+
2017
endmenu

platforms/tab5/dependencies.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ dependencies:
125125
source:
126126
registry_url: https://components.espressif.com/
127127
type: service
128+
rules:
129+
- if: CONFIG_APP_ENABLE_WIFI_HOSTED
128130
version: 1.4.0
129131
espressif/esp_lcd_ili9881c:
130132
component_hash: eb9ba0484d1d14171b69e5d192716fb1cdd6ef068aa4014dc3202486e124498e
@@ -225,6 +227,8 @@ dependencies:
225227
source:
226228
registry_url: https://components.espressif.com/
227229
type: service
230+
rules:
231+
- if: CONFIG_APP_ENABLE_WIFI_HOSTED
228232
version: 0.8.5
229233
espressif/led_strip:
230234
component_hash: f907c58f722c58ab8545366668cfd8769cefb7d97a631a14e9d16234cc72bdff

platforms/tab5/main/Kconfig.projbuild

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ config APP_LOG_LEVEL
88
Sets the default log verbosity for the application layer.
99
0 = none, 1 = error, 2 = warn, 3 = info, 4 = debug, 5 = verbose.
1010

11+
menu "App Features"
12+
13+
config APP_ENABLE_WIFI_HOSTED
14+
bool "Enable ESP-Hosted (Wi-Fi over SDIO) on Tab5"
15+
default n
16+
help
17+
When enabled, the firmware will power on the ESP-Hosted SDIO coprocessor
18+
and bring up the remote Wi-Fi stack. Disable this to keep SDIO idle while
19+
other system issues are being debugged.
20+
21+
endmenu
22+
1123
config HAL_AUDIO_ENABLE_LONG_DEMO
1224
bool "Enable long Canon in D demo"
1325
default n

platforms/tab5/main/app_main.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,63 @@
33
*
44
* SPDX-License-Identifier: MIT
55
*/
6+
// clang-format off
67
#include <memory>
78

9+
#include <app.h>
10+
#include <esp_err.h>
11+
#include <esp_heap_trace.h>
812
#include <freertos/FreeRTOS.h>
913
#include <freertos/task.h>
10-
14+
#include <hal/hal.h>
1115
#include <sdkconfig.h>
1216

1317
#include "hal/hal_esp32.h"
14-
#include <app.h>
15-
#include <hal/hal.h>
18+
// clang-format on
1619

1720
#if defined(CONFIG_I2C_ENABLE_LEGACY_DRIVERS) && CONFIG_I2C_ENABLE_LEGACY_DRIVERS
18-
#error "Legacy ESP-IDF I2C driver is unsupported; disable CONFIG_I2C_ENABLE_LEGACY_DRIVERS."
21+
# error "Legacy ESP-IDF I2C driver is unsupported; disable CONFIG_I2C_ENABLE_LEGACY_DRIVERS."
1922
#endif
2023

2124
#if !defined(CONFIG_I2C_SKIP_LEGACY_CONFLICT_CHECK) || !CONFIG_I2C_SKIP_LEGACY_CONFLICT_CHECK
22-
#error "Enable CONFIG_I2C_SKIP_LEGACY_CONFLICT_CHECK so the legacy driver stays dormant."
25+
# error "Enable CONFIG_I2C_SKIP_LEGACY_CONFLICT_CHECK so the legacy driver stays dormant."
26+
#endif
27+
28+
#if CONFIG_HEAP_TRACING
29+
namespace
30+
{
31+
constexpr size_t kHeapTraceDepth = 256;
32+
heap_trace_record_t s_heap_trace_records[kHeapTraceDepth];
33+
} // namespace
2334
#endif
2435

2536
extern "C" void app_main(void)
2637
{
2738
// 应用层初始化回调
2839
app::InitCallback_t callback;
2940

30-
callback.onHalInjection = []() {
41+
#if CONFIG_HEAP_TRACING
42+
ESP_ERROR_CHECK(heap_trace_init_standalone(s_heap_trace_records, kHeapTraceDepth));
43+
ESP_ERROR_CHECK(heap_trace_start(HEAP_TRACE_ALL));
44+
#endif
45+
46+
callback.onHalInjection = []()
47+
{
3148
// 注入桌面平台的硬件抽象
3249
hal::Inject(std::make_unique<HalEsp32>());
3350
};
3451

3552
// 应用层启动
3653
app::Init(callback);
37-
while (!app::IsDone()) {
54+
while (!app::IsDone())
55+
{
3856
app::Update();
3957
vTaskDelay(1);
4058
}
4159
app::Destroy();
60+
61+
#if CONFIG_HEAP_TRACING
62+
ESP_ERROR_CHECK(heap_trace_stop());
63+
heap_trace_dump();
64+
#endif
4265
}

platforms/tab5/main/hal/components/hal_wifi.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
#include <cstring>
99
#include <esp_check.h>
1010
#include <esp_event.h>
11-
#include <esp_hosted_api.h>
1211
#include <esp_log.h>
1312
#include <esp_netif.h>
14-
#include <esp_wifi.h>
1513
#include <freertos/FreeRTOS.h>
1614
#include <freertos/task.h>
1715
#include <mooncake_log.h>
@@ -21,6 +19,11 @@
2119
#include "integration/wifi_remote/hosted_safe.h"
2220
#include "sdkconfig.h"
2321

22+
#if CONFIG_APP_ENABLE_WIFI_HOSTED
23+
# include <esp_hosted_api.h>
24+
# include <esp_wifi.h>
25+
#endif
26+
2427
#define TAG "wifi"
2528

2629
#define WIFI_SSID "M5Tab5-UserDemo-WiFi"
@@ -30,7 +33,7 @@
3033
namespace
3134
{
3235

33-
#if CONFIG_M5TAB5_USE_ESP_HOSTED
36+
#if CONFIG_APP_ENABLE_WIFI_HOSTED
3437

3538
struct WifiRuntimeState
3639
{
@@ -210,13 +213,13 @@ namespace
210213
return ESP_OK;
211214
}
212215

213-
#endif // CONFIG_M5TAB5_USE_ESP_HOSTED
216+
#endif // CONFIG_APP_ENABLE_WIFI_HOSTED
214217

215218
} // namespace
216219

217220
bool HalEsp32::wifi_init()
218221
{
219-
#if !CONFIG_M5TAB5_USE_ESP_HOSTED
222+
#if !CONFIG_APP_ENABLE_WIFI_HOSTED
220223
ESP_LOGW(TAG, "ESP-Hosted disabled via Kconfig; skipping Wi-Fi init");
221224
return false;
222225
#else

platforms/tab5/main/idf_component.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
dependencies:
33
## Required IDF version
44
idf: "~5.4"
5-
espressif/esp_hosted: 1.4.0
6-
espressif/esp_wifi_remote: 0.8.5
5+
espressif/esp_hosted:
6+
version: 1.4.0
7+
rules:
8+
- if: "CONFIG_APP_ENABLE_WIFI_HOSTED"
9+
espressif/esp_wifi_remote:
10+
version: 0.8.5
11+
rules:
12+
- if: "CONFIG_APP_ENABLE_WIFI_HOSTED"
713
chmorgan/esp-audio-player: 1.0.7
814
chmorgan/esp-file-iterator: 1.0.0
915
espressif/led_strip: 3.0.0

platforms/tab5/sdkconfig.defaults

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ CONFIG_ESP_EXTCONN_SLAVE_ENABLE_PIN=54
9393
CONFIG_ESP_EXTCONN_SLAVE_ENABLE_LEVEL=1
9494

9595
# Hosted feature default (safe)
96-
CONFIG_M5TAB5_USE_ESP_HOSTED=n
96+
CONFIG_APP_ENABLE_WIFI_HOSTED=n
9797
CONFIG_M5TAB5_HOSTED_BOOT_RETRIES=3
9898
CONFIG_M5TAB5_HOSTED_BOOT_DELAY_MS=500
99+
100+
# Heap diagnostics
101+
CONFIG_HEAP_POISONING_LIGHT=y
102+
CONFIG_HEAP_TASK_TRACKING=y
103+
CONFIG_HEAP_TRACING=y
104+
CONFIG_HEAP_TRACING_STANDALONE=y
105+
CONFIG_HEAP_TRACING_STACK_DEPTH=12
106+
CONFIG_COMPILER_STACK_CHECK_MODE_STRONG=y
107+
CONFIG_ESP_SYSTEM_MEMPROT_FEATURE=y

0 commit comments

Comments
 (0)