启动时等待usb连接

This commit is contained in:
zqm
2026-04-09 08:55:43 +08:00
parent 708a7c8bf0
commit cd7d033e3e
45 changed files with 7843 additions and 11716 deletions

View File

@@ -2,6 +2,7 @@
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_task_wdt.h"
static const char* TAG = "RustApp";
@@ -9,14 +10,39 @@ extern void rust_app_main();
void rust_app_task(void* pvParameters) {
ESP_LOGI(TAG, "Rust application task started");
// 订阅看门狗,防止任务被复位
ESP_ERROR_CHECK(esp_task_wdt_add(NULL));
rust_app_main();
// 如果 rust_app_main 返回,记录错误并进入无限循环
ESP_LOGE(TAG, "Rust application task unexpectedly returned!");
while (1) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
static TaskHandle_t rust_app_task_handle = NULL;
void rust_app_wrapper_init() {
// 使用静态变量确保函数只被调用一次
static bool initialized = false;
if (initialized) {
ESP_LOGI(TAG, "Rust application already initialized");
return;
}
initialized = true;
ESP_LOGI(TAG, "Initializing Rust application...");
// 创建一个新的任务来运行 Rust 应用
xTaskCreate(rust_app_task, "rust_app_task", 4096, NULL, 5, NULL);
// 增加栈大小到 16384 (16KB) 以防止栈溢出
BaseType_t result = xTaskCreate(rust_app_task, "rust_app_task", 16384, NULL, 5, &rust_app_task_handle);
ESP_LOGI(TAG, "Rust application task created");
if (result != pdPASS) {
ESP_LOGE(TAG, "Failed to create Rust application task!");
} else {
ESP_LOGI(TAG, "Rust application task created successfully");
}
}