ESP-IDF v6.0 refuses to initialize MIPI on Waveshare ESP32-P4 Dev Kit Module

andromeda92
Posts: 34
Joined: Tue Nov 18, 2025 5:24 pm

ESP-IDF v6.0 refuses to initialize MIPI on Waveshare ESP32-P4 Dev Kit Module

Postby andromeda92 » Sat May 02, 2026 11:09 pm

Hi,
I have waveshare ESP32-P4 Dev Kit module with waveshare LCD 10.1" 1280x800,
I can't see anything on the screen, the screen is initialized with the correct values, there are no errors in the monitor, the backlight is working, but nothing appears on the screen.

Code: Select all

#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "driver/i2c_master.h"
#include "driver/gpio.h"
#include "driver/ledc.h"      
#include "esp_ldo_regulator.h"
#include "esp_lcd_mipi_dsi.h"
#include "esp_lcd_panel_ops.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_jd9365_10_1.h"
#include "esp_heap_caps.h"

static const char *TAG = "WAVESHARE_P4_COMPLETE";

// --- CONFIGURATION MATÉRIELLE ---
#define I2C_SDA_IO          7
#define I2C_SCL_IO          8
#define LCD_RST_IO          23  
#define LCD_BK_LIGHT_IO     38  

#define LCD_H_RES           1280
#define LCD_V_RES           800
#define I2C_FREQ_HZ         100000

// --- TIMINGS MIPI DPI (ALIGNÉS SUR TES VALEURS ARDUINO) ---
#define VAL_PIXEL_CLK_MHZ   60      // ESP_PANEL_BOARD_LCD_MIPI_DPI_CLK_MHZ
#define VAL_BITRATE_MBPS    1500    

#define VAL_H_PULSE         20      // HPW
#define VAL_H_BACK          20      // HBP
#define VAL_H_FRONT         40      // HFP
#define VAL_V_PULSE         4       // VPW
#define VAL_V_BACK          10      // VBP
#define VAL_V_FRONT         30      // VFP

#define MIPI_LDO_ID         3       // ESP_PANEL_BOARD_LCD_MIPI_PHY_LDO_ID

// --- SÉQUENCE D'INITIALISATION JD9365 ---
static const jd9365_lcd_init_cmd_t vendor_specific_init[] = {
    {0xE0, (uint8_t[]){0x00}, 1, 0}, {0xE1, (uint8_t[]){0x93}, 1, 0}, {0xE2, (uint8_t[]){0x65}, 1, 0}, {0xE3, (uint8_t[]){0xF8}, 1, 0}, {0x80, (uint8_t[]){0x01}, 1, 0},
    {0xE0, (uint8_t[]){0x01}, 1, 0}, {0x00, (uint8_t[]){0x00}, 1, 0}, {0x01, (uint8_t[]){0x38}, 1, 0}, {0x03, (uint8_t[]){0x10}, 1, 0}, {0x04, (uint8_t[]){0x38}, 1, 0},
    {0x0C, (uint8_t[]){0x74}, 1, 0}, {0x17, (uint8_t[]){0x00}, 1, 0}, {0x18, (uint8_t[]){0xAF}, 1, 0}, {0x19, (uint8_t[]){0x00}, 1, 0}, {0x1A, (uint8_t[]){0x00}, 1, 0},
    {0x1B, (uint8_t[]){0xAF}, 1, 0}, {0x1C, (uint8_t[]){0x00}, 1, 0}, {0x35, (uint8_t[]){0x26}, 1, 0}, {0x37, (uint8_t[]){0x09}, 1, 0}, {0x38, (uint8_t[]){0x04}, 1, 0},
    {0x39, (uint8_t[]){0x00}, 1, 0}, {0x3A, (uint8_t[]){0x01}, 1, 0}, {0x3C, (uint8_t[]){0x78}, 1, 0}, {0x3D, (uint8_t[]){0xFF}, 1, 0}, {0x3E, (uint8_t[]){0xFF}, 1, 0},
    {0x3F, (uint8_t[]){0x7F}, 1, 0}, {0x40, (uint8_t[]){0x06}, 1, 0}, {0x41, (uint8_t[]){0xA0}, 1, 0}, {0x42, (uint8_t[]){0x81}, 1, 0}, {0x43, (uint8_t[]){0x1E}, 1, 0},
    {0x44, (uint8_t[]){0x0D}, 1, 0}, {0x45, (uint8_t[]){0x28}, 1, 0}, {0x55, (uint8_t[]){0x02}, 1, 0}, {0x57, (uint8_t[]){0x69}, 1, 0}, {0x59, (uint8_t[]){0x0A}, 1, 0},
    {0x5A, (uint8_t[]){0x2A}, 1, 0}, {0x5B, (uint8_t[]){0x17}, 1, 0}, {0x5D, (uint8_t[]){0x7F}, 1, 0}, {0x5E, (uint8_t[]){0x6A}, 1, 0}, {0x5F, (uint8_t[]){0x5B}, 1, 0},
    {0x60, (uint8_t[]){0x4F}, 1, 0}, {0x61, (uint8_t[]){0x4A}, 1, 0}, {0x62, (uint8_t[]){0x3D}, 1, 0}, {0x63, (uint8_t[]){0x41}, 1, 0}, {0x64, (uint8_t[]){0x2A}, 1, 0},
    {0x65, (uint8_t[]){0x44}, 1, 0}, {0x66, (uint8_t[]){0x43}, 1, 0}, {0x67, (uint8_t[]){0x44}, 1, 0}, {0x68, (uint8_t[]){0x62}, 1, 0}, {0x69, (uint8_t[]){0x52}, 1, 0},
    {0x6A, (uint8_t[]){0x59}, 1, 0}, {0x6B, (uint8_t[]){0x4C}, 1, 0}, {0x6C, (uint8_t[]){0x48}, 1, 0}, {0x6D, (uint8_t[]){0x3A}, 1, 0}, {0x6E, (uint8_t[]){0x26}, 1, 0},
    {0x6F, (uint8_t[]){0x00}, 1, 0}, {0x70, (uint8_t[]){0x7F}, 1, 0}, {0x71, (uint8_t[]){0x6A}, 1, 0}, {0x72, (uint8_t[]){0x5B}, 1, 0}, {0x73, (uint8_t[]){0x4F}, 1, 0},
    {0x74, (uint8_t[]){0x4A}, 1, 0}, {0x75, (uint8_t[]){0x3D}, 1, 0}, {0x76, (uint8_t[]){0x41}, 1, 0}, {0x77, (uint8_t[]){0x2A}, 1, 0}, {0x78, (uint8_t[]){0x44}, 1, 0},
    {0x79, (uint8_t[]){0x43}, 1, 0}, {0x7A, (uint8_t[]){0x44}, 1, 0}, {0x7B, (uint8_t[]){0x62}, 1, 0}, {0x7C, (uint8_t[]){0x52}, 1, 0}, {0x7D, (uint8_t[]){0x59}, 1, 0},
    {0x7E, (uint8_t[]){0x4C}, 1, 0}, {0x7F, (uint8_t[]){0x48}, 1, 0}, {0x80, (uint8_t[]){0x3A}, 1, 0}, {0x81, (uint8_t[]){0x26}, 1, 0}, {0x82, (uint8_t[]){0x00}, 1, 0},
    {0xE0, (uint8_t[]){0x02}, 1, 0}, {0x11, (uint8_t[]){0x00}, 1, 120}, {0x29, (uint8_t[]){0x00}, 1, 20},
};

void app_main(void)
{
    // --- 1. RÉTROÉCLAIRAGE EN PREMIER ---
    ledc_timer_config_t ledc_timer = {
        .speed_mode = LEDC_LOW_SPEED_MODE, .timer_num = LEDC_TIMER_0,
        .duty_resolution = LEDC_TIMER_13_BIT, .freq_hz = 5000, .clk_cfg = LEDC_AUTO_CLK
    };
    ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
    ledc_channel_config_t ledc_channel = {
        .speed_mode = LEDC_LOW_SPEED_MODE, .channel = LEDC_CHANNEL_0,
        .timer_sel = LEDC_TIMER_0, .gpio_num = LCD_BK_LIGHT_IO, .duty = 8191 // 100%
    };
    ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));

    // --- 2. ALIMENTATION LDO ---
    esp_ldo_channel_handle_t ldo_mipi = NULL;
    esp_ldo_channel_config_t ldo_cfg = { .chan_id = MIPI_LDO_ID, .voltage_mv = 2500 }; 
    ESP_ERROR_CHECK(esp_ldo_acquire_channel(&ldo_cfg, &ldo_mipi));

    // --- 3. RESET ÉCRAN ---
    gpio_config_t rst_io_conf = { .mode = GPIO_MODE_OUTPUT, .pin_bit_mask = (1ULL << LCD_RST_IO) };
    gpio_config(&rst_io_conf);
    gpio_set_level(LCD_RST_IO, 0); vTaskDelay(pdMS_TO_TICKS(100));
    gpio_set_level(LCD_RST_IO, 1); vTaskDelay(pdMS_TO_TICKS(200));

    // --- 4. I2C BUS ---
    i2c_master_bus_handle_t i2c_bus = NULL;
    i2c_master_bus_config_t i2c_mst_config = {
        .clk_source = I2C_CLK_SRC_XTAL, .i2c_port = I2C_NUM_1,
        .scl_io_num = I2C_SCL_IO, .sda_io_num = I2C_SDA_IO,
        .glitch_ignore_cnt = 7, .flags.enable_internal_pullup = true,
    };
    ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &i2c_bus));

    i2c_device_config_t dev_cfg = { .device_address = 0x45, .scl_speed_hz = I2C_FREQ_HZ };
    i2c_master_dev_handle_t i2c_dev = NULL;
    ESP_ERROR_CHECK(i2c_master_bus_add_device(i2c_bus, &dev_cfg, &i2c_dev));

    // --- 5. BRIDGE TC358775 ---
    ESP_ERROR_CHECK(i2c_master_transmit(i2c_dev, (uint8_t[]){0x95, 0x11}, 2, 200));
    ESP_ERROR_CHECK(i2c_master_transmit(i2c_dev, (uint8_t[]){0x95, 0x17}, 2, 200));
    ESP_ERROR_CHECK(i2c_master_transmit(i2c_dev, (uint8_t[]){0x96, 0x00}, 2, 200));
    vTaskDelay(pdMS_TO_TICKS(100)); 
    ESP_ERROR_CHECK(i2c_master_transmit(i2c_dev, (uint8_t[]){0x96, 0xFF}, 2, 200));

    // --- 6. DSI BUS ---
    esp_lcd_dsi_bus_handle_t mipi_dsi_bus = NULL;
    esp_lcd_dsi_bus_config_t dsi_bus_config = {
        .bus_id = 0, .num_data_lanes = 2,
        .phy_clk_src = MIPI_DSI_PHY_CLK_SRC_DEFAULT,
        .lane_bit_rate_mbps = VAL_BITRATE_MBPS, 
    };
    ESP_ERROR_CHECK(esp_lcd_new_dsi_bus(&dsi_bus_config, &mipi_dsi_bus));

    // --- 7. DPI CONFIG (60MHz + TIMINGS ARDUINO) ---
    const esp_lcd_dpi_panel_config_t dpi_config = {
        .dpi_clk_src = MIPI_DSI_DPI_CLK_SRC_DEFAULT,
        .dpi_clock_freq_mhz = VAL_PIXEL_CLK_MHZ,
        .video_timing = {
            .h_size = LCD_H_RES, .v_size = LCD_V_RES,
            .hsync_pulse_width = VAL_H_PULSE, .hsync_back_porch = VAL_H_BACK, .hsync_front_porch = VAL_H_FRONT, 
            .vsync_pulse_width = VAL_V_PULSE, .vsync_back_porch = VAL_V_BACK, .vsync_front_porch = VAL_V_FRONT,
        },
        .in_color_format = LCD_COLOR_FMT_RGB888,
    };

    // --- 8. PANEL IO & JD9365 ---
    esp_lcd_panel_io_handle_t mipi_dbi_io = NULL;
    esp_lcd_dbi_io_config_t dbi_config = { .virtual_channel = 0, .lcd_cmd_bits = 8, .lcd_param_bits = 8 };
    ESP_ERROR_CHECK(esp_lcd_new_panel_io_dbi(mipi_dsi_bus, &dbi_config, &mipi_dbi_io));

    jd9365_vendor_config_t vendor_cfg = {
        .mipi_config = { .dsi_bus = mipi_dsi_bus, .lane_num = 2, .dpi_config = &dpi_config },
        .init_cmds = vendor_specific_init,
        .init_cmds_size = sizeof(vendor_specific_init) / sizeof(jd9365_lcd_init_cmd_t),
    };

    esp_lcd_panel_dev_config_t panel_dev_config = {
        .reset_gpio_num = -1, .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
        .bits_per_pixel = 24, .vendor_config = &vendor_cfg,
    };

    esp_lcd_panel_handle_t panel_handle = NULL;
    ESP_ERROR_CHECK(esp_lcd_new_panel_jd9365(mipi_dbi_io, &panel_dev_config, &panel_handle));

    // --- 9. INIT ET DESSIN ---
    ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
    ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));

    // Utilisation de heap_caps_malloc avec DMA pour l'affichage sur P4
    uint8_t *fb = (uint8_t *)heap_caps_malloc(LCD_H_RES * 100 * 3, MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
    if (fb) {
        memset(fb, 0xFF, LCD_H_RES * 100 * 3); // Test Blanc
        esp_lcd_panel_draw_bitmap(panel_handle, 0, 0, LCD_H_RES, 100, fb);
    }

    while (1) vTaskDelay(pdMS_TO_TICKS(1000));
}
on the monitor:
I (27) boot: ESP-IDF v6.0-dirty 2nd stage bootloader
I (28) boot: compile time Apr 27 2026 08:33:41
I (28) boot: Multicore bootloader
I (30) boot: chip revision: v1.0
I (31) boot: efuse block revision: v0.3
I (35) boot.esp32p4: SPI Speed : 40MHz
I (38) boot.esp32p4: SPI Mode : DIO
I (42) boot.esp32p4: SPI Flash Size : 16MB
I (46) boot: Enabling RNG early entropy source...
I (51) boot: Partition Table:
I (53) boot: ## Label Usage Type ST Offset Length
I (59) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (66) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (72) boot: 2 factory factory app 00 00 00010000 00100000
I (80) boot: End of partition table
I (83) esp_image: segment 0: paddr=00010020 vaddr=40030020 size=0e0e0h ( 57568) map
I (103) esp_image: segment 1: paddr=0001e108 vaddr=30100000 size=00068h ( 104) load
I (105) esp_image: segment 2: paddr=0001e178 vaddr=4ff00000 size=01ea0h ( 7840) load
I (111) esp_image: segment 3: paddr=00020020 vaddr=40000020 size=20880h (133248) map
I (145) esp_image: segment 4: paddr=000408a8 vaddr=4ff01ea0 size=0d918h ( 55576) load
I (160) esp_image: segment 5: paddr=0004e1c8 vaddr=4ff0f800 size=034ech ( 13548) load
I (165) esp_image: segment 6: paddr=000516bc vaddr=50108080 size=00024h ( 36) load
I (170) boot: Loaded app from partition at offset 0x10000
I (171) boot: Disabling RNG early entropy source...
I (187) hex_psram: vendor id : 0x0d (AP)
I (187) hex_psram: Latency : 0x01 (Fixed)
I (187) hex_psram: DriveStr. : 0x00 (25 Ohm)
I (188) hex_psram: dev id : 0x03 (generation 4)
I (193) hex_psram: density : 0x07 (256 Mbit)
I (197) hex_psram: good-die : 0x06 (Pass)
I (201) hex_psram: SRF : 0x02 (Slow Refresh)
I (206) hex_psram: BurstType : 0x00 ( Wrap)
I (210) hex_psram: BurstLen : 0x03 (2048 Byte)
I (215) hex_psram: BitMode : 0x01 (X16 Mode)
I (219) hex_psram: Readlatency : 0x04 (14 cycles@Fixed)
I (224) hex_psram: DriveStrength: 0x00 (1/1)
I (228) MSPI Timing: Enter psram timing tuning
I (405) esp_psram: Found 32MB PSRAM device
I (405) esp_psram: Speed: 200MHz
I (406) hex_psram: psram CS IO is dedicated
I (407) cpu_start: Multicore app
I (1392) esp_psram: SPI SRAM memory test OK
I (1401) cpu_start: GPIO 38 and 37 are used as console UART I/O pins
I (1402) cpu_start: Pro cpu start user code
I (1402) cpu_start: cpu freq: 360000000 Hz
I (1404) app_init: Application information:
I (1408) app_init: Project name: esp_lcd_test
I (1412) app_init: App version: 1
I (1415) app_init: Compile time: May 2 2026 23:56:31
I (1421) app_init: ELF file SHA256: 207cf99bd...
I (1425) app_init: ESP-IDF: v6.0-dirty
I (1429) efuse_init: Min chip rev: v0.0
I (1433) efuse_init: Max chip rev: v1.99
I (1437) efuse_init: Chip rev: v1.0
I (1441) heap_init: Initializing. RAM available for dynamic allocation:
I (1448) heap_init: At 4FF14770 len 00026850 (154 KiB): RETENT_RAM
I (1453) heap_init: At 4FF3AFC0 len 00004BF0 (18 KiB): RAM
I (1459) heap_init: At 4FF40000 len 00060000 (384 KiB): RAM
I (1464) heap_init: At 501080A4 len 00007F5C (31 KiB): RTCRAM
I (1469) heap_init: At 30100068 len 00001F98 (7 KiB): TCM
I (1475) esp_psram: Adding pool of 32768K of PSRAM memory to heap allocator
I (1483) spi_flash: detected chip: gd
I (1485) spi_flash: flash io: dio
I (1488) sleep_gpio: Configure to isolate all GPIO pins in sleep state
I (1494) sleep_gpio: Enable automatic switching of GPIO sleep configuration
I (1501) main_task: Started on CPU0
I (1531) main_task: Calling app_main()
I (1931) jd9365: version: 1.0.4
I (1931) i2c_bus: I2C Bus V2 uses the externally initialized bus handle
I (3061) jd9365: LCD ID: 93 65 04
Any idea ?

thanks you for your help.

andromeda92
Posts: 34
Joined: Tue Nov 18, 2025 5:24 pm

Re: ESP-IDF v6.0 refuses to initialize MIPI on Waveshare ESP32-P4 Dev Kit Module

Postby andromeda92 » Sun May 03, 2026 9:12 pm

I solved the problem by following an example, and the touch function also works, so problem solved.

Who is online

Users browsing this forum: Amazon [Bot], Bytespider, ChatGPT-User and 8 guests