From ef4c8e6e971da0aa40d555f6875003290d1d4c3f Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Thu, 24 May 2018 20:37:53 +1000 Subject: [PATCH] esp32: Silence ESP-IDF log messages when in raw REPL mode. This prevents clients such as ampy, mpy-utils, etc getting confused by extraneous data. --- ports/esp32/main.c | 9 +++++++++ ports/esp32/modnetwork.c | 12 +++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ports/esp32/main.c b/ports/esp32/main.c index 2fa86fd3c9..e7290c7eb8 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -28,6 +28,7 @@ #include #include +#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -35,6 +36,7 @@ #include "nvs_flash.h" #include "esp_task.h" #include "soc/cpu.h" +#include "esp_log.h" #include "py/stackctrl.h" #include "py/nlr.h" @@ -58,6 +60,11 @@ STATIC StaticTask_t mp_task_tcb; STATIC StackType_t mp_task_stack[MP_TASK_STACK_LEN] __attribute__((aligned (8))); +int vprintf_null(const char *format, va_list ap) { + // do nothing: this is used as a log target during raw repl mode + return 0; +} + void mp_task(void *pvParameter) { volatile uint32_t sp = (uint32_t)get_sp(); #if MICROPY_PY_THREAD @@ -93,9 +100,11 @@ soft_reset: for (;;) { if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) { + vprintf_like_t vprintf_log = esp_log_set_vprintf(vprintf_null); if (pyexec_raw_repl() != 0) { break; } + esp_log_set_vprintf(vprintf_log); } else { if (pyexec_friendly_repl() != 0) { break; diff --git a/ports/esp32/modnetwork.c b/ports/esp32/modnetwork.c index 8a2e266c62..9f7aa77dfa 100644 --- a/ports/esp32/modnetwork.c +++ b/ports/esp32/modnetwork.c @@ -139,24 +139,26 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) { // This is a workaround as ESP32 WiFi libs don't currently // auto-reassociate. system_event_sta_disconnected_t *disconn = &event->event_info.disconnected; - ESP_LOGI("wifi", "STA_DISCONNECTED, reason:%d", disconn->reason); + char *message = ""; switch (disconn->reason) { case WIFI_REASON_BEACON_TIMEOUT: - mp_printf(MP_PYTHON_PRINTER, "beacon timeout\n"); // AP has dropped out; try to reconnect. + message = "\nbeacon timeout"; break; case WIFI_REASON_NO_AP_FOUND: - mp_printf(MP_PYTHON_PRINTER, "no AP found\n"); // AP may not exist, or it may have momentarily dropped out; try to reconnect. + message = "\nno AP found"; break; case WIFI_REASON_AUTH_FAIL: - mp_printf(MP_PYTHON_PRINTER, "authentication failed\n"); + message = "\nauthentication failed"; wifi_sta_connected = false; break; default: // Let other errors through and try to reconnect. break; } + ESP_LOGI("wifi", "STA_DISCONNECTED, reason:%d%s", disconn->reason, message); + if (wifi_sta_connected) { wifi_mode_t mode; if (esp_wifi_get_mode(&mode) == ESP_OK) { @@ -164,7 +166,7 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) { // STA is active so attempt to reconnect. esp_err_t e = esp_wifi_connect(); if (e != ESP_OK) { - mp_printf(MP_PYTHON_PRINTER, "error attempting to reconnect: 0x%04x", e); + ESP_LOGI("wifi", "error attempting to reconnect: 0x%04x", e); } } }