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

Panic when installing SSD1306 panel driver with new I2C driver (IDFGH-11469) #12598

Closed
3 tasks done
tupyy opened this issue Nov 16, 2023 · 2 comments
Closed
3 tasks done
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally

Comments

@tupyy
Copy link

tupyy commented Nov 16, 2023

Answers checklist.

  • I have read the documentation ESP-IDF Programming Guide and the issue is not addressed there.
  • I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
  • I have searched the issue tracker for a similar issue and not found a similar issue.

IDF version.

v5.2-dev-3318-g8fc8f3f479

Operating System used.

Linux

How did you build your project?

Command line with idf.py

If you are using Windows, please specify command line type.

None

What is the expected behavior?

I'm using a little OLED display which is controlled via I2C. With ESP-IDF v5.2 a new I2C driver implementation has been added.
I would expect it to boot correctly.

What is the actual behavior?

This exception is raised at boot time IntegerDivideByZero

Steps to reproduce.

This is my code to install the driver:

#define EXAMPLE_LCD_PIXEL_CLOCK_HZ (100 * 1000)
#define EXAMPLE_PIN_NUM_SDA 21
#define EXAMPLE_PIN_NUM_SCL 22
#define EXAMPLE_PIN_NUM_RST -1
#define EXAMPLE_I2C_HW_ADDR 0x3C

// The pixel number in horizontal and vertical
#if CONFIG_EXAMPLE_LCD_CONTROLLER_SSD1306
#define EXAMPLE_LCD_H_RES 128
#define EXAMPLE_LCD_V_RES 64
#elif CONFIG_EXAMPLE_LCD_CONTROLLER_SH1107
#define EXAMPLE_LCD_H_RES 64
#define EXAMPLE_LCD_V_RES 128
#endif
// Bit number used to represent command and parameter
#define EXAMPLE_LCD_CMD_BITS 8
#define EXAMPLE_LCD_PARAM_BITS 8

extern void example_lvgl_demo_ui(lv_disp_t *disp);

/* The LVGL port component calls esp_lcd_panel_draw_bitmap API for send data to
the screen. There must be called lvgl_port_flush_ready(disp) after each
transaction to display. The best way is to use on_color_trans_done callback from
esp_lcd IO config structure. In IDF 5.1 and higher, it is solved inside LVGL
port component. */
static bool notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io,
                                    esp_lcd_panel_io_event_data_t *edata,
                                    void *user_ctx) {
  lv_disp_t *disp = (lv_disp_t *)user_ctx;
  lvgl_port_flush_ready(disp);
  return false;
}

void app_main(void) {
  ESP_LOGI(TAG, "Initialize I2C bus");
  i2c_master_bus_config_t i2c_mst_config = {
      .clk_source = I2C_CLK_SRC_DEFAULT,
      .i2c_port = -1,
      .scl_io_num = 22,
      .sda_io_num = 21,
      .glitch_ignore_cnt = 7,
      .flags.enable_internal_pullup = true,
  };

  i2c_master_bus_handle_t bus_handle;
  ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &bus_handle));

  ESP_LOGI(TAG, "Install panel IO");
  esp_lcd_panel_io_handle_t io_handle = NULL;
  esp_lcd_panel_io_i2c_config_t io_config = {
      .dev_addr = EXAMPLE_I2C_HW_ADDR,
      .control_phase_bytes = 1,               // According to SSD1306 datasheet
      .lcd_cmd_bits = EXAMPLE_LCD_CMD_BITS,   // According to SSD1306 datasheet
      .lcd_param_bits = EXAMPLE_LCD_CMD_BITS, // According to SSD1306 datasheet
      .dc_bit_offset = 6,                     // According to SSD1306 datasheet
  };
  ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(bus_handle, &io_config, &io_handle));

  ESP_LOGI(TAG, "Install SSD1306 panel driver");
  esp_lcd_panel_handle_t panel_handle = NULL;
  esp_lcd_panel_dev_config_t panel_config = {
      .bits_per_pixel = 1,
      .reset_gpio_num = EXAMPLE_PIN_NUM_RST,
  };
  ESP_ERROR_CHECK(
      esp_lcd_new_panel_ssd1306(io_handle, &panel_config, &panel_handle));

  ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
  ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
  ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));

Build or installation Logs.

I (31) boot: ESP-IDF v5.2-dev-3318-g8fc8f3f479-dirty 2nd stage bootloader
I (31) boot: compile time Oct 31 2023 16:56:55
I (33) boot: Multicore bootloader
I (37) boot: chip revision: v1.0
I (41) boot.esp32: SPI Speed      : 40MHz
I (46) boot.esp32: SPI Mode       : DIO
I (50) boot.esp32: SPI Flash Size : 2MB
I (55) boot: Enabling RNG early entropy source...
I (60) boot: Partition Table:
I (64) boot: ## Label            Usage          Type ST Offset   Length
I (71) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (79) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (86) boot:  2 factory          factory app      00 00 00010000 00100000
I (94) boot: End of partition table
I (98) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=0f874h ( 63604) map
I (129) esp_image: segment 1: paddr=0001f89c vaddr=3ffb0000 size=0077ch (  1916) load
I (130) esp_image: segment 2: paddr=00020020 vaddr=400d0020 size=2d780h (186240) map
I (202) esp_image: segment 3: paddr=0004d7a8 vaddr=3ffb077c size=01a00h (  6656) load
I (205) esp_image: segment 4: paddr=0004f1b0 vaddr=40080000 size=0c98ch ( 51596) load
I (236) boot: Loaded app from partition at offset 0x10000
I (236) boot: Disabling RNG early entropy source...
I (248) cpu_start: Multicore app
I (256) cpu_start: Pro cpu start user code
I (256) cpu_start: cpu freq: 160000000 Hz
I (256) cpu_start: Application information:
I (259) cpu_start: Project name:     i2c_oled
I (264) cpu_start: App version:      v5.2-dev-3318-g8fc8f3f479-dirty
I (271) cpu_start: Compile time:     Oct 31 2023 16:56:37
I (278) cpu_start: ELF file SHA256:  fb744a267...
I (283) cpu_start: ESP-IDF:          v5.2-dev-3318-g8fc8f3f479-dirty
I (290) cpu_start: Min chip rev:     v0.0
I (295) cpu_start: Max chip rev:     v3.99
I (300) cpu_start: Chip rev:         v1.0
I (304) heap_init: Initializing. RAM available for dynamic allocation:
I (312) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (318) heap_init: At 3FFBADF8 len 00025208 (148 KiB): DRAM
I (324) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (330) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (337) heap_init: At 4008C98C len 00013674 (77 KiB): IRAM
I (344) spi_flash: detected chip: generic
I (347) spi_flash: flash io: dio
W (351) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (365) main_task: Started on CPU0
I (375) main_task: Calling app_main()
I (375) example: Initialize I2C bus
I (375) gpio: GPIO[21]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (385) gpio: GPIO[22]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0
I (395) example: Install panel IO
I (395) example: Install SSD1306 panel driver
Guru Meditation Error: Core  0 panic'ed (IntegerDivideByZero). Exception was unhandled.

Core  0 register dump:
PC      : 0x400ef3f7  PS      : 0x00060c33  A0      : 0x800ec986  A1      : 0x3ffbce20
0x400ef3f7: i2c_ll_master_cal_bus_clk at /home/cosmin/esp/esp-idf/components/hal/esp32/include/hal/i2c_ll.h:79
 (inlined by) i2c_hal_set_bus_timing at /home/cosmin/esp/esp-idf/components/hal/i2c_hal.c:29

A2      : 0x3ffbe204  A3      : 0x00000000  A4      : 0x00000004  A5      : 0x04c4b400
A6      : 0xb33fffff  A7      : 0xb33fffff  A8      : 0x00000000  A9      : 0x3ffbce10
A10     : 0x00000001  A11     : 0x00000000  A12     : 0x00000000  A13     : 0x00000000
A14     : 0x3ffdfff8  A15     : 0x3ffbe3c0  SAR     : 0x00000020  EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0x00000000
0x4000c2e0: memcpy in ROM

0x4000c2f6: memcpy in ROM



Backtrace: 0x400ef3f4:0x3ffbce20 0x400ec983:0x3ffbce60 0x400ecab3:0x3ffbce90 0x400ed3e8:0x3ffbcec0 0x400d66c7:0x3ffbcf20 0x400d6739:0x3ffbcf70 0x400d6556:0x3ffbcf90 0x400d6a32:0x3ffbcfc0 0x400d6e5d:0x3ffbd000 0x400d5d49:0x3ffbd030 0x400fcecb:0x3ffbd0f0 0x400868a1:0x3ffbd120
0x400ef3f4: i2c_hal_set_bus_timing at /home/cosmin/esp/esp-idf/components/hal/i2c_hal.c:28

0x400ec983: s_i2c_transaction_start at /home/cosmin/esp/esp-idf/components/driver/i2c/i2c_master.c:490 (discriminator 2)

0x400ecab3: s_i2c_synchronous_transaction at /home/cosmin/esp/esp-idf/components/driver/i2c/i2c_master.c:772

0x400ed3e8: i2c_master_transmit at /home/cosmin/esp/esp-idf/components/driver/i2c/i2c_master.c:982

0x400d66c7: panel_io_i2c_tx_buffer at /home/cosmin/esp/esp-idf/components/esp_lcd/src/esp_lcd_panel_io_i2c_v2.c:176

0x400d6739: panel_io_i2c_tx_param at /home/cosmin/esp/esp-idf/components/esp_lcd/src/esp_lcd_panel_io_i2c_v2.c:200

0x400d6556: esp_lcd_panel_io_tx_param at /home/cosmin/esp/esp-idf/components/esp_lcd/src/esp_lcd_panel_io.c:23 (discriminator 2)

0x400d6a32: panel_ssd1306_init at /home/cosmin/esp/esp-idf/components/esp_lcd/src/esp_lcd_panel_ssd1306.c:141

0x400d6e5d: esp_lcd_panel_init at /home/cosmin/esp/esp-idf/components/esp_lcd/src/esp_lcd_panel_ops.c:22 (discriminator 2)

0x400d5d49: app_main at /home/cosmin/esp/esp-idf/examples/peripherals/lcd/i2c_oled/main/i2c_oled_example_main.c:101 (discriminator 2)

0x400fcecb: main_task at /home/cosmin/esp/esp-idf/components/freertos/app_startup.c:208 (discriminator 13)

0x400868a1: vPortTaskWrapper at /home/cosmin/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:162

More Information.

No response

@tupyy tupyy added the Type: Bug bugs in IDF label Nov 16, 2023
@espressif-bot espressif-bot added the Status: Opened Issue is new label Nov 16, 2023
@github-actions github-actions bot changed the title Panic when installing SSD1306 panel driver with new I2C driver Panic when installing SSD1306 panel driver with new I2C driver (IDFGH-11469) Nov 16, 2023
@suda-morris suda-morris removed the Type: Bug bugs in IDF label Nov 17, 2023
@suda-morris
Copy link
Collaborator

That's because you forgot set the SCL clock frequency:

https://github.com/espressif/esp-idf/blob/master/components/esp_lcd/test_apps/i2c_lcd/main/test_i2c_lcd_panel.c#L42

@tupyy
Copy link
Author

tupyy commented Nov 17, 2023

Thank you. This was the problem.

@tupyy tupyy closed this as completed Nov 17, 2023
@espressif-bot espressif-bot added Status: Done Issue is done internally Resolution: NA Issue resolution is unavailable and removed Status: Opened Issue is new labels Nov 17, 2023
movsb pushed a commit to movsb/esp-idf that referenced this issue Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

3 participants