From d75708993a8ae851815e273a699040ab2e8d63b6 Mon Sep 17 00:00:00 2001 From: raw-designs Date: Tue, 1 Sep 2026 08:07:10 +0200 Subject: [PATCH] =?UTF-8?q?fix(P4):=20Panel-Bringup=20meldet=20Fehler=20im?= =?UTF-8?q?=20Klartext=20statt=20abzust=C3=BCrzen=20(1.6.2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ein fehlgeschlagener Panel-Aufbau endete bisher in einem ESP_ERROR_CHECK tief im LVGL-Port und damit in einem Speicherauszug ohne erkennbare Ursache. - Die Schritte des Waveshare-Bringups melden ihren Fehler über esp_rom_printf, also auch bei Core-Debug-Level "none". Zusätzlich werden PSRAM-Größe, freier PSRAM, größter freier Block und der Framebuffer-Bedarf ausgegeben. - jc_board_bringup() liefert jetzt einen Status. Kommt das Panel nicht hoch, bleibt die Firmware ohne Anzeige lauffähig (UART + OTA), statt beim ersten LVGL-Zugriff erneut abzustürzen. - ui.cpp: alle öffentlichen Funktionen prüfen, ob ui_init gelaufen ist. - Fehlerbehebung: esp_lcd_touch_new_i2c_gt911 setzt im Fehlerfall einen bereits freigegebenen Zeiger. Das Handle wird vorbelegt und der Rückgabewert geprüft. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_018QoLDQeUh1dCQz7yYZVb4Y --- P4_Display_Firmware/Changelog.txt | 13 +++++++ P4_Display_Firmware/board_bringup.c | 56 +++++++++++++++++++++++++---- P4_Display_Firmware/config.h | 2 +- P4_Display_Firmware/display_hal.cpp | 14 +++++--- P4_Display_Firmware/ui.cpp | 27 +++++++++++++- 5 files changed, 99 insertions(+), 13 deletions(-) diff --git a/P4_Display_Firmware/Changelog.txt b/P4_Display_Firmware/Changelog.txt index 66c6e3d..b8d72c4 100644 --- a/P4_Display_Firmware/Changelog.txt +++ b/P4_Display_Firmware/Changelog.txt @@ -1,3 +1,16 @@ +Version 1.6.2: +- Kommt das Panel nicht hoch, stürzt der P4 nicht mehr wortlos ab. Die Bringup-Schritte + melden ihren Fehler jetzt im Klartext auf der seriellen Konsole (auch bei abgeschaltetem + Core-Debug-Level), zusammen mit PSRAM-Größe, freiem PSRAM und dem tatsächlich benötigten + Framebuffer-Bedarf. Vorher endete ein fehlgeschlagener Panel-Aufbau in einem + Speicherauszug, aus dem die Ursache nicht hervorging. +- Schlägt der Panel-Aufbau fehl, läuft die Firmware ohne Anzeige weiter, statt ein zweites + Mal abzustürzen: UART-Verbindung und OTA bleiben offen, die S3 kann also neu flashen. + Alle Oberflächenfunktionen prüfen dafür, ob das Dashboard überhaupt aufgebaut wurde. +- Fehlerbehebung: Findet der Touch-Controller nicht statt, lieferte der Hersteller-Treiber + einen bereits freigegebenen Zeiger zurück, der ungeprüft weiterverwendet wurde. Das + Display läuft in diesem Fall jetzt einfach ohne Bedienung weiter. + Version 1.6.1: - Waveshare 7" (H): Bild und Touch lassen sich um 180 Grad drehen, wenn das Panel auf dem Kopf eingebaut ist. Schalter WS7_ROTATE_180 in pins_config.h, Vorgabe ist gedreht. diff --git a/P4_Display_Firmware/board_bringup.c b/P4_Display_Firmware/board_bringup.c index 3332d85..33571a5 100644 --- a/P4_Display_Firmware/board_bringup.c +++ b/P4_Display_Firmware/board_bringup.c @@ -19,6 +19,7 @@ #if JC_USE_REAL_PANEL #include +#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "driver/gpio.h" @@ -26,6 +27,8 @@ #include "driver/i2c_master.h" #include "esp_log.h" #include "esp_cache.h" +#include "esp_heap_caps.h" +#include "esp_rom_sys.h" #include "esp_ldo_regulator.h" #include "esp_lcd_panel_io.h" #include "esp_lcd_panel_ops.h" @@ -66,6 +69,27 @@ static i2c_master_bus_handle_t s_i2c_handle = NULL; +// Klartext-Meldung auf der seriellen Konsole. Bewusst esp_rom_printf: das laeuft auch bei +// abgeschaltetem Core-Debug-Level und ohne Heap, also genau dann, wenn es darauf ankommt. +#define BSP_STEP(call, what) \ + do { \ + esp_err_t _err = (call); \ + if (_err != ESP_OK) { \ + esp_rom_printf("[Panel] FEHLER: %s -> %s\n", what, esp_err_to_name(_err)); \ + } \ + } while (0) + +// Ohne PSRAM passt kein Framebuffer. Bei 1280x720 in RGB888 werden 3 x 2,7 MB gebraucht - +// bleibt der Panel-Treiber daran haengen, sieht man hier sofort, woran es liegt. +static void bsp_report_psram(size_t needed_bytes) +{ + esp_rom_printf("[Panel] PSRAM gesamt %u KB, frei %u KB, groesster Block %u KB, benoetigt %u KB\n", + (unsigned)(heap_caps_get_total_size(MALLOC_CAP_SPIRAM) / 1024), + (unsigned)(heap_caps_get_free_size(MALLOC_CAP_SPIRAM) / 1024), + (unsigned)(heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM) / 1024), + (unsigned)(needed_bytes / 1024)); +} + // ===================================================================================== #if JC_PANEL_TYPE == WS_PANEL_7H // ===================================================================================== @@ -215,7 +239,9 @@ static void jc_touch_scale(esp_lcd_touch_handle_t tp, uint16_t *x, uint16_t *y, #endif // Bringt Panel + Touch + LVGL-Port hoch (LVGL laeuft danach in eigenem Task). -void jc_board_bringup(void) +// Rueckgabe false: Panel kam nicht hoch - der Aufrufer darf dann KEINE LVGL-Funktion +// benutzen, sonst folgt ein zweiter Absturz, der die eigentliche Ursache ueberdeckt. +bool jc_board_bringup(void) { jc_backlight_init(); @@ -248,20 +274,23 @@ void jc_board_bringup(void) // Kein Hersteller-Panel-Treiber: DSI-Bus, DBI-Kommandokanal und DPI-Panel werden // direkt angelegt. Entscheidend ist die Referenztaktquelle PLL_F20M - mit der // Standardquelle bleibt das Bild auf ESP32-P4 Rev. 1.3 / ECO2 schwarz. + bsp_report_psram((size_t)BSP_LCD_H_RES * BSP_LCD_V_RES * BSP_LCD_FB_BYTES_PER_PX + * LVGL_PORT_LCD_BUFFER_NUMS); + esp_lcd_dsi_bus_config_t bus_config = { .bus_id = 0, .num_data_lanes = WS7_DSI_LANES, .phy_clk_src = MIPI_DSI_PHY_PLLREF_CLK_SRC_PLL_F20M, .lane_bit_rate_mbps = WS7_DSI_LANE_MBPS, }; - esp_lcd_new_dsi_bus(&bus_config, &mipi_dsi_bus); + BSP_STEP(esp_lcd_new_dsi_bus(&bus_config, &mipi_dsi_bus), "MIPI-DSI-Bus"); esp_lcd_dbi_io_config_t dbi_config = { .virtual_channel = 0, .lcd_cmd_bits = 8, .lcd_param_bits = 8, }; - esp_lcd_new_panel_io_dbi(mipi_dsi_bus, &dbi_config, &io); + BSP_STEP(esp_lcd_new_panel_io_dbi(mipi_dsi_bus, &dbi_config, &io), "DBI-Kommandokanal"); esp_lcd_dpi_panel_config_t dpi_config = { .virtual_channel = 0, @@ -283,7 +312,14 @@ void jc_board_bringup(void) .use_dma2d = true, }, }; - esp_lcd_new_panel_dpi(mipi_dsi_bus, &dpi_config, &disp_panel); + BSP_STEP(esp_lcd_new_panel_dpi(mipi_dsi_bus, &dpi_config, &disp_panel), + "DPI-Panel (Framebuffer im PSRAM)"); + if (disp_panel == NULL) { + esp_rom_printf("[Panel] Abbruch: Panel wurde nicht angelegt. Haeufigste Ursache ist zu " + "wenig PSRAM - PSRAM in den Board-Einstellungen aktivieren oder in " + "pins_config.h weniger Framebuffer waehlen.\n"); + return false; + } // Panel wecken (MADCTL / Sleep Out / Display On). Ein Reset gibt es hier nicht: // ein reines DPI-Panel kennt keine reset-Funktion, esp_lcd_panel_reset() wuerde @@ -297,7 +333,7 @@ void jc_board_bringup(void) esp_lcd_panel_io_tx_param(io, 0x29, &zero, 1); // Display On vTaskDelay(pdMS_TO_TICKS(20)); } - esp_lcd_panel_init(disp_panel); // DPI-Videoausgabe starten + BSP_STEP(esp_lcd_panel_init(disp_panel), "DPI-Videoausgabe starten"); #elif JC_PANEL_TYPE == JC_PANEL_70 // ---------------- 7,0" JD9165 (1024x600) ---------------- esp_lcd_dsi_bus_config_t bus_config = JD9165_PANEL_BUS_DSI_2CH_CONFIG(); @@ -388,7 +424,9 @@ void jc_board_bringup(void) esp_lcd_dpi_panel_register_event_callbacks(disp_panel, &cbs, NULL); esp_lcd_panel_io_handle_t tp_io_handle = NULL; - esp_lcd_touch_handle_t tp_handle; + // MUSS vorbelegt sein: schlaegt die Touch-Initialisierung fehl, gibt der Treiber einen + // unbrauchbaren Zeiger zurueck. Ohne Vorbelegung landet Muell im LVGL-Port. + esp_lcd_touch_handle_t tp_handle = NULL; esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG(); tp_io_config.scl_speed_hz = 100000; #if JC_PANEL_TYPE == WS_PANEL_7H @@ -417,12 +455,16 @@ void jc_board_bringup(void) .process_coordinates = jc_touch_scale, #endif }; - esp_lcd_touch_new_i2c_gt911(tp_io_handle, &tp_cfg, &tp_handle); + if (esp_lcd_touch_new_i2c_gt911(tp_io_handle, &tp_cfg, &tp_handle) != ESP_OK) { + esp_rom_printf("[Panel] Touch-Controller nicht gefunden - Anzeige laeuft ohne Bedienung.\n"); + tp_handle = NULL; + } lvgl_port_interface_t interface = (dpi_config.flags.use_dma2d) ? LVGL_PORT_INTERFACE_MIPI_DSI_DMA : LVGL_PORT_INTERFACE_MIPI_DSI_NO_DMA; lvgl_port_init(disp_panel, tp_handle, interface); + return true; } #endif // JC_USE_REAL_PANEL diff --git a/P4_Display_Firmware/config.h b/P4_Display_Firmware/config.h index cdb7af6..fb7396d 100644 --- a/P4_Display_Firmware/config.h +++ b/P4_Display_Firmware/config.h @@ -126,7 +126,7 @@ // ------------------------------------------------------------------------------------- // Firmware // ------------------------------------------------------------------------------------- -#define DISPLAY_FW_VERSION "1.6.1" // Firmware-Stand der P4-Display-Steuerung (Info-Seite) +#define DISPLAY_FW_VERSION "1.6.2" // Firmware-Stand der P4-Display-Steuerung (Info-Seite) // ------------------------------------------------------------------------------------- // Protokoll diff --git a/P4_Display_Firmware/display_hal.cpp b/P4_Display_Firmware/display_hal.cpp index 637c1a9..d37a068 100644 --- a/P4_Display_Firmware/display_hal.cpp +++ b/P4_Display_Firmware/display_hal.cpp @@ -28,16 +28,22 @@ static ProtocolClient* g_client = nullptr; // ECHTE HARDWARE - Bringup in board_bringup.c, LVGL-Mutex im Hersteller-Port. // ===================================================================================== extern "C" { - void jc_board_bringup(void); // board_bringup.c + bool jc_board_bringup(void); // board_bringup.c void jc_backlight_set(int percent); // board_bringup.c bool lvgl_port_lock(int timeout_ms); // lvgl_port_v9.c (Vendor-BSP) void lvgl_port_unlock(void); // lvgl_port_v9.c (Vendor-BSP) } +// Kam das Panel nicht hoch, laeuft die Firmware ohne Anzeige weiter: UART-Client und +// OTA bleiben erreichbar, damit die S3 neu flashen kann. Jeder LVGL-Zugriff wuerde sonst +// einen Folgeabsturz ausloesen, der die eigentliche Ursache im Log ueberdeckt. +static bool s_panel_ready = false; + void hal_init(ProtocolClient* client) { g_client = client; - jc_board_bringup(); // Panel + Touch + LVGL-Port (eigener Task) + s_panel_ready = jc_board_bringup(); // Panel + Touch + LVGL-Port (eigener Task) jc_backlight_set(100); + if (!s_panel_ready) return; if (lvgl_port_lock(-1)) { // UI im LVGL-Kontext aufbauen ui_init(g_client); lvgl_port_unlock(); @@ -45,8 +51,8 @@ void hal_init(ProtocolClient* client) { } void hal_loop() { /* LVGL laeuft im Port-Task - hier nichts zu tun. */ } -void hal_lock() { lvgl_port_lock(-1); } -void hal_unlock(){ lvgl_port_unlock(); } +void hal_lock() { if (s_panel_ready) lvgl_port_lock(-1); } +void hal_unlock(){ if (s_panel_ready) lvgl_port_unlock(); } void hal_backlight(int percent) { jc_backlight_set(percent); } // ===================================================================================== diff --git a/P4_Display_Firmware/ui.cpp b/P4_Display_Firmware/ui.cpp index 29afeb6..adafdde 100644 --- a/P4_Display_Firmware/ui.cpp +++ b/P4_Display_Firmware/ui.cpp @@ -3127,6 +3127,11 @@ static void dash_timers_cb(lv_timer_t*) { // ===================================================================================== // Aufbau (Header + Schublade + Seiten) // ===================================================================================== +// Erst true, wenn das Dashboard steht. Kam das Panel nicht hoch (siehe display_hal.cpp), +// wird ui_init nie aufgerufen - dann duerfen die uebrigen Funktionen nichts anfassen, +// sonst greifen sie auf nicht angelegte LVGL-Objekte zu. +static bool g_uiReady = false; + void ui_init(ProtocolClient* client) { g_client = client; @@ -3486,6 +3491,8 @@ void ui_init(ProtocolClient* client) { show_page(PG_DASH); if (g_client) g_client->sendListProfiles(); + + g_uiReady = true; } // Haengt den Ergebnis-/Abbruchtext eines beendeten Tuning-Laufs an 'out' an. @@ -3531,6 +3538,8 @@ static void appendTuneLive(String& out, const char* kreis, uint32_t elapsedMs, // Live-Aktualisierung // ===================================================================================== void ui_update(const MachineState& st) { + if (!g_uiReady) return; + g_state = st; // Boot-Splash: erster State = Verbindung zur Maschine steht -> Start-Animation ausblenden @@ -4171,9 +4180,11 @@ void ui_update(const MachineState& st) { } } -void ui_toast(const char* txt, bool error) { showToast(txt, error); } +void ui_toast(const char* txt, bool error) { if (g_uiReady) showToast(txt, error); } void ui_set_profiles(const String profiles[], int count) { + if (!g_uiReady) return; + // Schnellwahl-Overlay (falls offen) mit derselben Antwort befuellen prof_picker_fill(profiles, count); if (!profList) return; @@ -4189,6 +4200,8 @@ void ui_set_profiles(const String profiles[], int count) { } void ui_set_profile_details(const String& json) { + if (!g_uiReady) return; + if (!profDetailLbl) return; JsonDocument doc; if (deserializeJson(doc, json)) { @@ -4233,6 +4246,8 @@ void ui_set_profile_details(const String& json) { } void ui_set_usage_stats(const String& json) { + if (!g_uiReady) return; + if (!g_statSummary) return; JsonDocument doc; if (deserializeJson(doc, json)) { @@ -4290,6 +4305,8 @@ void ui_set_usage_stats(const String& json) { } void ui_set_wifi_networks(const String& json) { + if (!g_uiReady) return; + wifi_scan_done(); // Scan abgeschlossen: Button wieder freigeben if (!wifiList) return; @@ -4331,6 +4348,8 @@ void ui_set_debug(const char* txt) { (void)txt; } // --- OTA-Overlay (Aufrufe unter hal_lock()) --- void ui_ota_begin() { + if (!g_uiReady) return; + if (!g_otaScreen) return; lv_label_set_text(g_otaStatus, "Update läuft - bitte nicht ausschalten!"); lv_obj_set_style_text_color(g_otaStatus, COL_TEXT, 0); @@ -4339,15 +4358,21 @@ void ui_ota_begin() { lv_obj_move_foreground(g_otaScreen); } void ui_ota_progress(uint32_t bytes) { + if (!g_uiReady) return; + if (!g_otaBytes) return; lv_label_set_text_fmt(g_otaBytes, "%lu KB übertragen", (unsigned long)(bytes / 1024)); } void ui_ota_done() { + if (!g_uiReady) return; + if (!g_otaStatus) return; lv_label_set_text(g_otaStatus, "Fertig - Neustart..."); lv_obj_set_style_text_color(g_otaStatus, COL_OK, 0); } void ui_ota_fail(const char* msg) { + if (!g_uiReady) return; + if (!g_otaStatus) return; lv_label_set_text_fmt(g_otaStatus, "Fehlgeschlagen: %s", msg); lv_obj_set_style_text_color(g_otaStatus, COL_DANGER, 0);