Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SquareLine自定义ESP开发板 (BSP-591) #449

Open
zeandon opened this issue Dec 3, 2024 · 1 comment
Open

SquareLine自定义ESP开发板 (BSP-591) #449

zeandon opened this issue Dec 3, 2024 · 1 comment

Comments

@zeandon
Copy link

zeandon commented Dec 3, 2024

我在网上看到了这个链接:https://www.bilibili.com/opus/721643227044642853 。里面提到了可以通过修改esp-bsp 仓库中的示例:custom_waveshare_7inch,设计自己的开发板模板。
在查看了这个文件之后,我发现这块7英寸屏幕的接口是I2C和并行数据线,所以想问一下能否对这个文件进行修改,实现驱动一块驱动芯片为ILI9341的240x320分辨率的TFT触摸屏幕(触摸和数据都使用SPI进行传输),具体引脚定义如下:
1733213861672
如果可以实现,需要修改 示例custom_waveshare_7inch 中的哪些部分?
同时,这份2022年的文章(https://www.bilibili.com/opus/721643227044642853 )中提到的代码好像与现在的文件中的代码有所差异,官方有更新关于SquareLine自定义ESP32开发板的相关内容吗?
打扰了,希望能收到回复,非常感谢!

@github-actions github-actions bot changed the title SquareLine自定义ESP开发板 SquareLine自定义ESP开发板 (BSP-591) Dec 3, 2024
@zeandon
Copy link
Author

zeandon commented Dec 6, 2024

我按照上面提到的文章对ws_7inch.c、ws_7inch.h、idf_component.yml、mainfest,json进行了修改:
在ws_7inch.c中,将include的头文件改为:

`#include "esp_timer.h"
#include "driver/gpio.h"
#include "driver/ledc.h"
#include "esp_err.h"
#include "esp_log.h"
#include "esp_check.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_vendor.h"
#include "esp_lcd_panel_ops.h"

#include "bsp/ws_7inch.h"
#include "esp_lcd_ili9341.h"
#include "esp_lcd_touch_stmpe610.h"
#include "esp_lvgl_port.h"
#include "bsp_err_check.h"
#include "bsp/display.h"
#include "bsp/touch.h"`

将bsp_i2c_init函数修改为bsp_spi_init函数:

esp_err_t bsp_spi_init(void)
{
    ESP_LOGI(TAG, "Initialize SPI bus");
    spi_bus_config_t buscfg = {
        .sclk_io_num = BSP_T_CLK,
        .mosi_io_num = BSP_T_MOSI,
        .miso_io_num = BSP_T_MISO,
        .quadwp_io_num = -1, // Quad SPI LCD driver is not yet supported
        .quadhd_io_num = -1, // Quad SPI LCD driver is not yet supported
        .max_transfer_sz = BSP_LCD_H_RES * 80 * sizeof(uint16_t), // transfer 80 lines of pixels (assume pixel is RGB565) at most in one SPI transaction
    };
    ESP_ERROR_CHECK(spi_bus_initialize(T_HOST, &buscfg, SPI_DMA_CH_AUTO)); // Enable the DMA feature

    return ESP_OK;
}

将bsp_display_new函数中关于初始化i2c和8080的代码修改为:

  esp_err_t bsp_display_new(const bsp_display_config_t *config, esp_lcd_panel_handle_t *ret_panel, esp_lcd_panel_io_handle_t *ret_io)
  {
      esp_err_t ret = ESP_OK;
  
      ESP_LOGI(TAG, "Initialize SPI bus");
      spi_bus_config_t buscfg = {
          .sclk_io_num = BSP_LCD_SCK,
          .mosi_io_num = BSP_LCD_MOSI,
          .miso_io_num = BSP_LCD_MISO,
          .quadwp_io_num = -1, // Quad SPI LCD driver is not yet supported
          .quadhd_io_num = -1, // Quad SPI LCD driver is not yet supported
          .max_transfer_sz = BSP_LCD_H_RES * 80 * sizeof(uint16_t), // transfer 80 lines of pixels (assume pixel is RGB565) at most in one SPI transaction
      };
      ESP_ERROR_CHECK(spi_bus_initialize(LCD_HOST, &buscfg, SPI_DMA_CH_AUTO)); // Enable the DMA feature
  
      ESP_LOGI(TAG, "Install panel IO");
      esp_lcd_panel_io_handle_t io_handle = NULL;
      esp_lcd_panel_io_spi_config_t io_config = {
          .dc_gpio_num = BSP_LCD_DC,
          .cs_gpio_num = BSP_LCD_CS,
          .pclk_hz = BSP_LCD_PIXEL_CLOCK_HZ,
          .lcd_cmd_bits = LCD_CMD_BITS,
          .lcd_param_bits = LCD_PARAM_BITS,
          .spi_mode = 0,
          .trans_queue_depth = 10,
      };
      // Attach the LCD to the SPI bus
      ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)LCD_HOST, &io_config, &io_handle));
  
      esp_lcd_panel_handle_t panel_handle = NULL;
      esp_lcd_panel_dev_config_t panel_config = {
          .reset_gpio_num = EXAMPLE_PIN_NUM_RST,
          .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_BGR,
          .bits_per_pixel = 16,
      };
      // Create LCD panel handle for ILI9341, with the SPI IO device handle
      ESP_ERROR_CHECK(esp_lcd_new_panel_ili9341(io_handle, &panel_config, &panel_handle));
  
      ESP_GOTO_ON_ERROR(esp_lcd_panel_reset(*ret_panel), err, TAG, "");
      ESP_GOTO_ON_ERROR(esp_lcd_panel_init(*ret_panel), err, TAG, "");
      ESP_GOTO_ON_ERROR(esp_lcd_panel_disp_on_off(*ret_panel, true), err, TAG, "");
      return ret;
  
  err:
      if (*ret_panel) {
          esp_lcd_panel_del(*ret_panel);
      }
      if (*ret_io) {
          esp_lcd_panel_io_del(*ret_io);
      }
      if (buscfg) {
          esp_lcd_del_spi_bus(buscfg);
      }
      return ret;
  }

将bsp_touch_new函数中关于i2c的部分修改为spi:

esp_err_t bsp_touch_new(const bsp_touch_config_t *config, esp_lcd_touch_handle_t *ret_touch)
{
    /* Initilize SPI */
    BSP_ERROR_CHECK_RETURN_ERR(bsp_spi_init());

    /* Initialize touch */
    const esp_lcd_touch_config_t tp_cfg = {
        .x_max = BSP_LCD_H_RES,
        .y_max = BSP_LCD_V_RES,
        .rst_gpio_num = GPIO_NUM_NC, // Shared with LCD reset
        .int_gpio_num = BSP_T_IRQ,
        .levels = {
            .reset = 0,
            .interrupt = 0,
        },
        .flags = {
            .swap_xy = 0,
            .mirror_x = 0,
            .mirror_y = 0,
        },
    };
    esp_lcd_panel_io_handle_t tp_io_handle = NULL;
    const esp_lcd_panel_io_spi_config_t tp_io_config = ESP_LCD_TOUCH_IO_SPI_STMPE610_CONFIG(BSP_T_CS);
    ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)LCD_HOST, &tp_io_config, &tp_io_handle), TAG, "");

    ESP_LOGI(TAG, "Initialize touch controller STMPE610");
    ESP_ERROR_CHECK(esp_lcd_touch_new_spi_stmpe610(tp_io_handle, &tp_cfg, &tp));

}

在ws_7inch.h中,对原来的关于i2c和8080引脚定义修改为两个spi引脚定义:

// /* I2C */
// #define BSP_I2C_SCL           (GPIO_NUM_41)
// #define BSP_I2C_SDA           (GPIO_NUM_42)

#define T_HOST    SPI1_HOST
#define LCD_HOST  SPI2_HOST

/* SPI */
#define BSP_T_IRQ        (GPIO_NUM_9)
#define BSP_T_MOSI       (GPIO_NUM_46)
#define BSP_T_MISO       (GPIO_NUM_3)
#define BSP_T_CS         (GPIO_NUM_8)
#define BSP_T_CLK        (GPIO_NUM_18)
#define BSP_LCD_MISO     (GPIO_NUM_17)
#define BSP_LCD_LED      (GPIO_NUM_16)
#define BSP_LCD_SCK      (GPIO_NUM_15)
#define BSP_LCD_MOSI     (GPIO_NUM_7)
#define BSP_LCD_DC       (GPIO_NUM_6)
#define BSP_LCD_RESET    (GPIO_NUM_5)
#define BSP_LCD_CS       (GPIO_NUM_4)

// /* Display */
// #define BSP_LCD_WIDTH   (16)
// #define BSP_LCD_DB0     (GPIO_NUM_13)
// #define BSP_LCD_DB1     (GPIO_NUM_12)
// #define BSP_LCD_DB2     (GPIO_NUM_11)
// #define BSP_LCD_DB3     (GPIO_NUM_10)
// #define BSP_LCD_DB4     (GPIO_NUM_9)
// #define BSP_LCD_DB5     (GPIO_NUM_46)
// #define BSP_LCD_DB6     (GPIO_NUM_3)
// #define BSP_LCD_DB7     (GPIO_NUM_8)
// #define BSP_LCD_DB8     (GPIO_NUM_18)
// #define BSP_LCD_DB9     (GPIO_NUM_17)
// #define BSP_LCD_DB10    (GPIO_NUM_16)
// #define BSP_LCD_DB11    (GPIO_NUM_15)
// #define BSP_LCD_DB12    (GPIO_NUM_7)
// #define BSP_LCD_DB13    (GPIO_NUM_6)
// #define BSP_LCD_DB14    (GPIO_NUM_5)
// #define BSP_LCD_DB15    (GPIO_NUM_4)
// #define BSP_LCD_CS      (GPIO_NUM_NC)
// #define BSP_LCD_DC      (GPIO_NUM_37)
// #define BSP_LCD_WR      (GPIO_NUM_38)
// #define BSP_LCD_RD      (GPIO_NUM_NC)
// #define BSP_LCD_RST     (GPIO_NUM_39)
// #define BSP_LCD_WAIT    (GPIO_NUM_1)
// #define BSP_LCD_BL      (GPIO_NUM_NC)
// #define BSP_LCD_TP_INT     ###(GPIO_NUM_2)`
idf_component.yml文件如下:
`description: ESP-BSP SquareLine LVGL Example
dependencies:
  idf: ">=4.4"
  ws_7inch:
    version: "1.0"
    override_path: "../components/ws_7inch"

mainfest.json文件如下:

{
    "name":"MyESPBoard",
    "version":"1.0.0",
    "mcu":"ESP32S3",

    "screen_width":"320",
    "screen_height":"240",
    "screen_color_swap":true,

    "supported_lvgl_version":"8.2.0, 8.3.*",

    "short_description":"short_description",
    "long_description":"long_description",

    "placeholders":
    {
        "__ESP_BOARD_INCLUDE__": "bsp/ws_7inch.h",
        "__ESP_BOARD_I2C_INIT__": ""
    }
}

经过这些修改之后,我按照步骤,生成了SquareLine所需的文件,并且用SquareLine生成了UI文件。但是将生成的UI文件添加到ESP32工程,烧录到板子上之后,似乎发生了崩溃,错误显示如下:

ELF file SHA256: 

Rebooting...
���ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x28 (SPI_FAST_FLASH_BOOT)
Saved PC:0x40379c4c
--- 0x40379c4c: esp_restart_noos at /home/zando/esp/esp-idf/components/esp_system/port/soc/esp32s3/system_internal.c:158

SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce2820,len:0x1918
load:0x403c8700,len:0x4
load:0x403c8704,len:0xe5c
load:0x403cb700,len:0x303c
entry 0x403c893c
I (31) boot: ESP-IDF v5.3.1 2nd stage bootloader
I (31) boot: compile time Dec  6 2024 16:28:24
I (31) boot: Multicore bootloader
I (34) boot: chip revision: v0.2
I (38) qio_mode: Enabling default flash chip QIO
I (43) boot.esp32s3: Boot SPI Speed : 80MHz
I (48) boot.esp32s3: SPI Mode       : QIO
I (53) boot.esp32s3: SPI Flash Size : 8MB
I (58) boot: Enabling RNG early entropy source...
I (63) boot: Partition Table:
I (67) boot: ## Label            Usage          Type ST Offset   Length
I (74) boot:  0 nvs              WiFi data        01 02 00010000 00006000
I (81) boot:  1 fctry            WiFi data        01 02 00016000 00006000
I (89) boot:  2 factory          factory app      00 00 00020000 00200000
I (96) boot:  3 storage          Unknown data     01 82 00220000 00200000
I (104) boot:  4 model            Unknown data     01 82 00420000 00200000
I (111) boot: End of partition table
I (116) esp_image: segment 0: paddr=00020020 vaddr=3c060020 size=168d8h ( 92376) map
I (138) esp_image: segment 1: paddr=00036900 vaddr=3fc9a100 size=0340ch ( 13324) load
I (141) esp_image: segment 2: paddr=00039d14 vaddr=40378000 size=06304h ( 25348) load
I (149) esp_image: segment 3: paddr=00040020 vaddr=42000020 size=5ad64h (372068) map
I (209) esp_image: segment 4: paddr=0009ad8c vaddr=4037e304 size=0bd50h ( 48464) load
I (226) boot: Loaded app from partition at offset 0x20000
I (226) boot: Disabling RNG early entropy source...
E (238) octal_psram: PSRAM ID read error: 0x00000000, PSRAM chip not found or not supported, or wrong PSRAM line mode
E cpu_start: Failed to init external RAM, needed for external .bss segment

abort() was called at PC 0x403796a1 on core 0
--- 0x403796a1: call_start_cpu0 at /home/zando/esp/esp-idf/components/esp_system/port/cpu_start.c:578



Backtrace: 0x40379d12:0x3fceb220 0x40382341:0x3fceb240 0x40387c9d:0x3fceb260 0x403796a1:0x3fceb2d0 0x403cca4c:0x3fceb340 0x403cce6d:0x3fceb380 0x403c89a5:0x3fceb4b0 0x40045c01:0x3fceb570 0x40043ab6:0x3fceb6f0 0x40034c45:0x3fceb710
--- 0x40379d12: panic_abort at /home/zando/esp/esp-idf/components/esp_system/panic.c:463
0x40382341: esp_system_abort at /home/zando/esp/esp-idf/components/esp_system/port/esp_system_chip.c:92
0x40387c9d: abort at /home/zando/esp/esp-idf/components/newlib/abort.c:38
0x403796a1: call_start_cpu0 at /home/zando/esp/esp-idf/components/esp_system/port/cpu_start.c:578
0x40045c01: ets_run_flash_bootloader in ROM
0x40043ab6: main in ROM
0x40034c45: .stack_ok in ROM

请问这是因为对bsp文件修改出错而导致的问题吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant