Skip to content

Commit 36ee7ed

Browse files
authored
Merge pull request #185 from baba-dev/codex/implement-hosted-safe-boot-for-sdio
test(hil): log boot guard monitoring
2 parents ee82737 + a02b26a commit 36ee7ed

File tree

8 files changed

+221
-277
lines changed

8 files changed

+221
-277
lines changed

custom/integration/wifi/hosted_safe.cpp

Lines changed: 0 additions & 71 deletions
This file was deleted.

custom/integration/wifi/hosted_safe.h

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
#include "integration/wifi_remote/hosted_safe.h"
7+
8+
#include "driver/gpio.h"
9+
#include "esp_log.h"
10+
#include "freertos/FreeRTOS.h"
11+
#include "freertos/task.h"
12+
#include "sdkconfig.h"
13+
14+
#if CONFIG_M5TAB5_USE_ESP_HOSTED
15+
# include "esp_hosted_api.h"
16+
# include "esp_wifi.h"
17+
# include "esp_wifi_remote.h"
18+
#endif
19+
20+
static const char* TAG = "hosted_safe";
21+
static bool s_hosted_ready = false;
22+
23+
#if CONFIG_M5TAB5_USE_ESP_HOSTED
24+
static void slave_pulse_reset(void)
25+
{
26+
const gpio_num_t rst = 54;
27+
const gpio_config_t io = {
28+
.pin_bit_mask = 1ULL << rst,
29+
.mode = GPIO_MODE_OUTPUT,
30+
.pull_up_en = 0,
31+
.pull_down_en = 0,
32+
.intr_type = GPIO_INTR_DISABLE,
33+
};
34+
gpio_config(&io);
35+
gpio_set_level(rst, 0);
36+
vTaskDelay(pdMS_TO_TICKS(5));
37+
gpio_set_level(rst, 1);
38+
}
39+
#endif
40+
41+
bool hosted_try_init_with_retries(void)
42+
{
43+
#if !CONFIG_M5TAB5_USE_ESP_HOSTED
44+
ESP_LOGI(TAG, "ESP-Hosted disabled via Kconfig.");
45+
return false;
46+
#else
47+
if (s_hosted_ready)
48+
{
49+
return true;
50+
}
51+
52+
int retries = CONFIG_M5TAB5_HOSTED_BOOT_RETRIES;
53+
while (retries-- >= 0)
54+
{
55+
ESP_LOGI(
56+
TAG, "Resetting SDIO slave and waiting %d ms ...", CONFIG_M5TAB5_HOSTED_BOOT_DELAY_MS);
57+
slave_pulse_reset();
58+
vTaskDelay(pdMS_TO_TICKS(CONFIG_M5TAB5_HOSTED_BOOT_DELAY_MS));
59+
60+
esp_err_t err = esp_hosted_init();
61+
if (err != ESP_OK)
62+
{
63+
ESP_LOGW(TAG, "esp_hosted_init failed (%s)", esp_err_to_name(err));
64+
}
65+
else
66+
{
67+
ESP_LOGI(TAG, "ESP-Hosted initialized.");
68+
s_hosted_ready = true;
69+
70+
wifi_init_config_t wifi_cfg = WIFI_INIT_CONFIG_DEFAULT();
71+
err = esp_wifi_remote_init(&wifi_cfg);
72+
if (err != ESP_OK)
73+
{
74+
ESP_LOGW(TAG,
75+
"esp_wifi_remote_init failed (%s), continuing without Wi-Fi.",
76+
esp_err_to_name(err));
77+
hosted_deinit_safe();
78+
s_hosted_ready = false;
79+
}
80+
}
81+
82+
if (s_hosted_ready)
83+
{
84+
return true;
85+
}
86+
87+
ESP_LOGW(TAG, "ESP-Hosted init failed; %d retry(ies) left.", retries);
88+
vTaskDelay(pdMS_TO_TICKS(250));
89+
}
90+
91+
ESP_LOGW(TAG, "ESP-Hosted not available; booting without Wi-Fi.");
92+
return false;
93+
#endif
94+
}
95+
96+
void hosted_deinit_safe(void)
97+
{
98+
#if CONFIG_M5TAB5_USE_ESP_HOSTED
99+
if (!s_hosted_ready)
100+
{
101+
return;
102+
}
103+
104+
esp_wifi_remote_deinit();
105+
esp_hosted_deinit();
106+
s_hosted_ready = false;
107+
#endif
108+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
#pragma once
7+
8+
#include <stdbool.h>
9+
10+
#include "esp_err.h"
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
bool hosted_try_init_with_retries(void);
17+
void hosted_deinit_safe(void);
18+
19+
#ifdef __cplusplus
20+
}
21+
#endif

platforms/tab5/Kconfig.projbuild

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
menu "M5Tab5 Connectivity"
2+
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.
9+
10+
config M5TAB5_HOSTED_BOOT_RETRIES
11+
int "Hosted init retries at boot"
12+
range 0 10
13+
default 3
14+
15+
config M5TAB5_HOSTED_BOOT_DELAY_MS
16+
int "Delay after slave reset before SDIO init (ms)"
17+
range 0 5000
18+
default 500
19+
20+
endmenu

0 commit comments

Comments
 (0)