From ac19ecf3d512ee0a4338966b70974f2f5fc7a913 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Thu, 6 Oct 2016 18:16:00 +0300 Subject: [PATCH] On app cpu (#1) * move loop task to APP CPU * Rework WiFi boot so it works when loop is on APP CPU --- cores/esp32/main.cpp | 12 ++++++++---- libraries/WiFi/src/WiFiGeneric.cpp | 28 ++++++++++------------------ 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/cores/esp32/main.cpp b/cores/esp32/main.cpp index 48a3ef76..80fd075f 100644 --- a/cores/esp32/main.cpp +++ b/cores/esp32/main.cpp @@ -7,8 +7,11 @@ void initVariant() {} void init() __attribute__((weak)); void init() {} -void bootWiFi() __attribute__((weak)); -void bootWiFi() {} +void startWiFi() __attribute__((weak)); +void startWiFi() {} + +void initWiFi() __attribute__((weak)); +void initWiFi() {} extern void loop(); extern void setup(); @@ -18,7 +21,7 @@ void loopTask(void *pvParameters) bool setup_done = false; for(;;) { if(!setup_done) { - bootWiFi(); + startWiFi(); setup(); setup_done = true; } @@ -30,6 +33,7 @@ extern "C" void app_main() { init(); initVariant(); - xTaskCreatePinnedToCore(loopTask, "loopTask", 4096, NULL, 1, NULL, 0); + initWiFi(); + xTaskCreatePinnedToCore(loopTask, "loopTask", 4096, NULL, 1, NULL, 1); } diff --git a/libraries/WiFi/src/WiFiGeneric.cpp b/libraries/WiFi/src/WiFiGeneric.cpp index 5b5b426f..9cd2fd32 100644 --- a/libraries/WiFi/src/WiFiGeneric.cpp +++ b/libraries/WiFi/src/WiFiGeneric.cpp @@ -286,29 +286,21 @@ void wifi_dns_found_callback(const char *name, const ip_addr_t *ipaddr, void *ca * */ #include "nvs_flash.h" -void bootWiFi() +void initWiFi() { - esp_err_t err; - wifi_init_config_t cfg; - wifi_mode_t mode = WIFI_MODE_NULL; - bool auto_connect = false; - - err = nvs_flash_init(); - if (err != ESP_OK) { - log_e("nvs_flash_init fail %d", err); - return; - } - + wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); + nvs_flash_init(); system_init(); tcpip_adapter_init(); esp_event_loop_init(WiFiGenericClass::_eventCallback, NULL); + esp_wifi_init(&cfg); +} - cfg.event_handler = &esp_event_send; - err = esp_wifi_init(&cfg); - if (err != ESP_OK) { - log_e("esp_wifi_init fail %d\n", err); - return; - } +void startWiFi() +{ + esp_err_t err; + wifi_mode_t mode = WIFI_MODE_NULL; + bool auto_connect = false; err = esp_wifi_start(); if (err != ESP_OK) {