Skip to content

ESP32C3 display initialization problems #272

@maro48m

Description

@maro48m

Hi,

After some pause i've tried once again to build and run lvgl_micropython on my device.

I'm using esp32c3 mini 1U with 4mb flash.

This time, after running command: python3 make.py --optimize-size --flash-size=4 esp32 BOARD=ESP32_GENERIC_C3 DISPLAY=gc9a01 INDEV=cst816s and uploading bin to device micropython is launching and giving prompt.
Now when i try to launch code:

import lvgl as lv
import gc9a01
import lcd_bus
from machine import SPI, Pin
from micropython import const
import task_handler  # NOQA
import time  # NOQA
import gc


# display settings

WIDTH = const(240)
HEIGHT = const(240)

SPI_HOST = const(1)
SPI_SCK = const(6)
SPI_MOSI = const(7)
SPI_MISO = const(-1)

LCD_FREQ = const(80000000)
LCD_DC = const(2)
LCD_CS = const(10)
LCD_RST = const(-1)
LCD_BACKLIGHT = const(3)

TOUCH_CS = const(-1)
TOUCH_FREQ = const(10000000)

LCD_PIXEL_CLOCK_HZ    = const (20 * 1000 * 1000)
LCD_BK_LIGHT_ON_LEVEL  = const (1)
LCD_BK_LIGHT_OFF_LEVEL = const (0)

BUFFER_SIZE = WIDTH * HEIGHT // 20


print(1)
# Initialize the SPI bus
spi_bus = SPI.Bus(
    host = SPI_HOST,
    mosi = SPI_MOSI,
    miso = SPI_MISO,
    sck = SPI_SCK
)
print(2)
# Initialize the display bus
display_bus = lcd_bus.SPIBus(
    spi_bus = spi_bus,
    dc = LCD_DC,
    cs = LCD_CS,
    freq=LCD_FREQ ,
    spi_mode = 0
)
print(3)
fb1 = display_bus.allocate_framebuffer(BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA)
fb2 = display_bus.allocate_framebuffer(BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA)

gc.collect()
print(4)
display = gc9a01.GC9A01(
    data_bus=display_bus,
    display_width=WIDTH,
    display_height=HEIGHT,
    frame_buffer1=fb1,
    frame_buffer2=fb2,
    backlight_pin=LCD_BACKLIGHT,
    color_space=lv.COLOR_FORMAT.RGB565,
    rgb565_byte_swap=True
)

print(5)
display.set_power(True)

display.init()
display.set_backlight(100)
lv.init()

th = task_handler.TaskHandler(500)

scrn = lv.screen_active()
scrn.set_style_bg_color(lv.color_hex(0x000000), 0)  # 0x000000 , 0x0000FF

label = lv.label(scrn)
label.set_text("HELLO WORLD!!")
label.set_style_text_color(lv.color_hex(0x0000FF), 0)
label.align(lv.ALIGN.CENTER, 0, 0)

sometimes code runs and displays red "HELLO WORLD!"
but sometimes it crashes with Core 0panic:

A fatal error occurred. The crash dump printed below may be used to help
determine what caused it. If you are not already running the most recent
version of MicroPython, consider upgrading. New versions often fix bugs.

To learn more about how to debug and/or report this crash visit the wiki
page at: https://github.com/micropython/micropython/wiki/ESP32-debugging

LVGL MicroPython 
IDF version : c9763f62
Machine     : ESP32C3 module with ESP32C3

Guru Meditation Error: Core  0 panic'ed (Store access fault). Exception was unhandled.

Core  0 register dump:
MEPC    : 0x42098582  RA      : 0x42097f9e  SP      : 0x3fca76e0  GP      : 0x3fc95400  
TP      : 0x3fc396a8  T0      : 0x4005890e  T1      : 0x0000000f  T2      : 0x3fcaa7d0  
S0/FP   : 0x3fca7710  S1      : 0x3fca93b0  A0      : 0x3fcaae74  A1      : 0x00008522  
A2      : 0x3fca94b0  A3      : 0x3fca94c0  A4      : 0x3fca94b0  A5      : 0x00008528  
A6      : 0x00000000  A7      : 0x0000884a  S2      : 0x3c24cbbc  S3      : 0x3fca9444  
S4      : 0x3c2556e0  S5      : 0x3fca9440  S6      : 0x00000000  S7      : 0x3fc98f30  
S8      : 0x3fca93c4  S9      : 0x3c256446  S10     : 0x00001036  S11     : 0x3c25642e  
T3      : 0x00008d0a  T4      : 0x00000001  T5      : 0x00008d02  T6      : 0x00000007  
MSTATUS : 0x00001881  MTVEC   : 0x40380001  MCAUSE  : 0x00000007  MTVAL   : 0x00008528  
MHARTID : 0x00000000  

Stack memory:
3fca76e0: 0x3c2108c0 0x3fca94b0 0x00008522 0x3fcaae74 0x000010c8 0x3fca76e4 0x00008528 0x00008528
3fca7700: 0x00000003 0x0000884a 0x3fca7740 0x3fca7740 0x00000000 0x3fca9440 0x00000000 0x3fcaae74
3fca7720: 0x3fca93c8 0x3c256442 0x00001036 0x3fca94b0 0x00008d0a 0x00000001 0x3fca7770 0x42041130
3fca7740: 0x00001036 0x3fca93b0 0x000000f0 0x000000f0 0x00000000 0x3fca9440 0x3c2556e0 0x000000f0
3fca7760: 0x3c2110c4 0x3fca93c4 0x3fca77a0 0x4202bbdc 0x00000000 0x42041110 0x3fca93cc 0x00000002
3fca7780: 0x00000002 0x00000002 0x000000f0 0x000000f0 0x00000000 0x3fca9440 0x3fca77d0 0x42007b60
3fca77a0: 0x3fca93cc 0x00000000 0x00000002 0x3c20f294 0x00000000 0x3fca93cc 0x00000000 0x3c20f294
3fca77c0: 0x3c24cbbc 0x3fca93b0 0x3c256447 0x4038413c 0x3fca93f0 0x3c245504 0x3fca9344 0x00000000
3fca77e0: 0x00008d0a 0x3fca9438 0x00000012 0x00000007 0x3fca7910 0x3c241d85 0x40383082 0x3fca78a0
3fca7800: 0x3fca93b0 0x3c24cbbc 0x3fca9444 0x00000001 0x3fca9440 0x3fca9344 0x3fc98f30 0x3c245000
3fca7820: 0x3fcaad7e 0x00000fca 0x3fcaad75 0x3fca77d0 0x00000000 0x3fca9688 0x3fca9560 0x3fcaad75
3fca7840: 0x00000fca 0x3fcaad7e 0x000000a0 0x00000020 0x3fca9344 0x0000000c 0x00000001 0x3fca94f0
3fca7860: 0x0000008c 0x3fca93b0 0x3fca78a0 0x420e07be 0x3fca78b4 0x3fca9688 0x3fca9624 0x3fc98f30
3fca7880: 0x3fca78b4 0x3fca9340 0x3fca962c 0x00000068 0x0000000c 0x00000000 0x3fca8fd0 0x420e6498
3fca78a0: 0x3c24cbbc 0x3fca78d8 0x3fca9040 0x00000000 0x00000000 0x3fca9e60 0x3fca8fd0 0x3fca8fd0
3fca78c0: 0x00000011 0x00000000 0x3fca78b4 0x420e7d00 0x00000000 0x3fca9688 0x3fca9560 0x3fca968c
3fca78e0: 0x3c24cbbc 0x3fca9610 0x3fcaad7f 0x4038413c 0x3fca94a0 0x3c245504 0x3fca94a0 0x00000000
3fca7900: 0x3fca94a0 0x3fca9680 0x00000020 0x4210d1c4 0x3fca79f0 0x00000001 0x40383082 0x3fca79c0
3fca7920: 0x3fca9610 0x3c24cbbc 0x3fca968c 0x00000000 0x3fca9688 0x00000000 0x3fc98f30 0x3c245000
3fca7940: 0x00000000 0x00000000 0x00000000 0x3fca78f0 0x3fcaac00 0x00000000 0x00000010 0x00000000
3fca7960: 0x00000000 0x00000000 0x0000007c 0x0000001a 0x00000000 0x00000000 0x00000000 0x3fc98f8c
3fca7980: 0x00000068 0x3fca9610 0x3fca79c0 0x420e07be 0x3fcaac00 0x3fca9470 0x00000080 0x00000004
3fca79a0: 0x00000003 0x00000041 0x000000e9 0x00000001 0x00000001 0x00000000 0x3fca9480 0x4211c9a6
3fca79c0: 0x3fc9e000 0x3fc9e000 0x00000000 0x600c2194 0x3fca7a5c 0x4211c8c4 0x4211caac 0x00000000
3fca79e0: 0x00000005 0x00000041 0x3fcaab2c 0x00000000 0x00000000 0x00000000 0x4211c962 0x3fca7a64
3fca7a00: 0x00000041 0x00000001 0x00000001 0x00000005 0x00000041 0x00000003 0x00000004 0x00000080
3fca7a20: 0x00000000 0x00000000 0x00000000 0x3fca79c0 0x00000001 0x3fca7a58 0x00000005 0x3c239000
3fca7a40: 0x00000001 0x00000002 0x3c225000 0x4211cbb4 0x00000000 0x00000000 0x42010080 0x00800001
3fca7a60: 0x0000007a 0x3fca7a5c 0x4211c8c4 0x4211caac 0x00000020 0x00000002 0x3fca9450 0x3fca7a00
3fca7a80: 0x3fcb89bc 0x3fc98f30 0x00000001 0x420fc000 0x3c235000 0x3c235000 0x3fc9e000 0x420fc33c
3fca7aa0: 0x3fcb89bc 0x3fc98f30 0x3fca89bc 0x420fc4e2 0x00000000 0x00000000 0x00000000 0x00000000
3fca7ac0: 0x00000000 0x00000000 0x00000000 0x3fca7ab0 0x00000000 0x00000000 0x00000000 0x00000000



ELF file SHA256: 64dfa59b3

Rebooting...
ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0xc (RTC_SW_CPU_RST),boot:0xc (SPI_FAST_FLASH_BOOT)
Saved PC:0x40380d88
SPIWP:0xee
mode:DIO, clock div:2
load:0x3fcd5820,len:0xfd8
load:0x403cc710,len:0x948
load:0x403ce710,len:0x2c20
entry 0x403cc710

sometimes it throws error about not enough memory, but it reports missing 1GB of memory...:

  File "<stdin>", line 75, in <module>
  File "display_driver_framework.py", line 187, in __init__
MemoryError: memory allocation failed, allocating 1070239896 bytes```

both problems occur in ```display = gc9a01.GC9A01([...]``` line

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions