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

ESP32 hard crash on i2c display #4962

Closed
jfurcean opened this issue Jul 2, 2021 · 17 comments · Fixed by #5220
Closed

ESP32 hard crash on i2c display #4962

jfurcean opened this issue Jul 2, 2021 · 17 comments · Fixed by #5220
Assignees
Labels
bug crash displayio espressif applies to multiple Espressif chips
Milestone

Comments

@jfurcean
Copy link

jfurcean commented Jul 2, 2021

CircuitPython version

Adafruit CircuitPython 7.0.0-alpha.3-493-gc37f354d2 on 2021-07-02; FeatherS2 with ESP32S2

Code/REPL

import busio
import board
import displayio
import adafruit_displayio_ssd1306

displayio.release_displays()

i2c = busio.I2C(board.SCL, board.SDA)

display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)

Behavior

This code crashes on the final line using a Feather S2 and the STEMMA QT 0.91" OLED Display 128x32.

Description

Additional information

No response

@jfurcean jfurcean added the bug label Jul 2, 2021
@meltdown03
Copy link

I get also a hard crash when using the the SPI display on the Kaluga V1.2 . It worked a month ago. Happens at the same line of code (except SPI bus)

@meltdown03
Copy link

meltdown03 commented Jul 3, 2021

SPI seems to work now, as of build today (5756ddd). I see some SPI fixes were commited

@jerryneedell
Copy link
Collaborator

I2C works OK on an ESP32s2 SAOLA-WROVER with the current tip of main.

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.

Code done running.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 7.0.0-alpha.3-493-gc37f354d2 on 2021-07-03; Saola 1 w/Wrover with ESP32S2
>>> import busio
>>> import board
>>> import displayio
>>> import adafruit_displayio_ssd1306
>>> 
>>> displayio.release_displays()
>>> i2c = busio.I2C(board.IO2, board.IO1)
>>> display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
>>> display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)
>>> 
>>> 
>>> 

@jerryneedell
Copy link
Collaborator

jerryneedell commented Jul 3, 2021

And it also works now , for me, on a FeatherS2 (using an OLED SSD1306 featherwing)
This appears to be the same commit that failed above...

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 7.0.0-alpha.3-493-gc37f354d2 on 2021-07-03; FeatherS2 with ESP32S2
>>> import busio
>>> import board
>>> import displayio
>>> import adafruit_displayio_ssd1306
>>> 
>>> displayio.release_displays()
>>> 
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> 
>>> display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
>>> display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)
>>> 
>>> 

@jerryneedell
Copy link
Collaborator

Trying to reproduce the failing test setup - I have a STEMMA OLED SSD1306 132x64.
It also works for me on the FeatherS2

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 7.0.0-alpha.3-493-gc37f354d2 on 2021-07-03; FeatherS2 with ESP32S2
>>> import busio
>>> import board
>>> import displayio
>>> import adafruit_displayio_ssd1306
>>> 
>>> displayio.release_displays()
>>> 
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> display_bus = displayio.I2CDisplay(i2c, device_address=0x3D)
>>> display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=64)
>>> 
>>> 
>>> 

@jfurcean
Copy link
Author

jfurcean commented Jul 3, 2021

It works fine when running in REPL the first time, but crashes on import adafruit_displayio_ssd1306 after a soft reboot.

Adafruit CircuitPython 7.0.0-alpha.3-493-gc37f354d2 on 2021-07-02; FeatherS2 with ESP32S2
>>> import busio
>>> import board
>>> import displayio
>>> import adafruit_displayio_ssd1306
>>> displayio.release_displays()
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>> display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
>>> display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)
>>> 
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:

Code done running.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 7.0.0-alpha.3-493-gc37f354d2 on 2021-07-02; FeatherS2 with ESP32S2
>>> import busio
>>> import board
>>> import displayio
>>> import adafruit_displayio_ssd1306

@jerryneedell
Copy link
Collaborator

Ah -- that reminds me of a very old issue I ran across on the feathers2 -- I had that problem if I used the .uf2 bootloader, but not if I flash with the .bin file ....
adafruit/tinyuf2#74

I have not been using the UF2 bootloader on the featherS2 or the Saola

@jerryneedell
Copy link
Collaborator

Ah -- never mind -- I just crashed mine trying to run the code after a soft reboot....

@jerryneedell
Copy link
Collaborator

jerryneedell commented Jul 3, 2021

but it crashes before the last line -- mine crashes on the import adafruit_displayio_ssd1306 line
ah -- I missed that this is exactly what you see... bug confirmed

@jerryneedell
Copy link
Collaborator

jerryneedell commented Jul 3, 2021

@jfurcean if found that it works if I do a

import displayio
displayio.release_displays()

after the soft reboot

then I can run the code repeatedly after soft reboot if I release the display each time.

@jerryneedell
Copy link
Collaborator

I wonder if this is a displayio issue -- or even an expected behavior if the display is not released.

@jerryneedell
Copy link
Collaborator

jerryneedell commented Jul 3, 2021

Well -- that does not make senses since the code does the release, but for some reason, it has to be done before importing the ssd1306 library...


Adafruit CircuitPython 7.0.0-alpha.3-493-gc37f354d2 on 2021-07-03; FeatherS2 with ESP32S2
>>> import displayio
>>> displayio.release_displays()
>>> import busio
>>> import board
>>> import displayio
>>> import adafruit_displayio_ssd1306
>>>
>>> displayio.release_displays()
>>>
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>>
>>> display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
>>> display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)
>>>
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.

Code done running.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 7.0.0-alpha.3-493-gc37f354d2 on 2021-07-03; FeatherS2 with ESP32S2
>>> import displayio
>>> displayio.release_displays()
>>> import busio
>>> import board
>>> import displayio
>>> import adafruit_displayio_ssd1306
>>>
>>> displayio.release_displays()
>>>
>>> i2c = busio.I2C(board.SCL, board.SDA)
>>>
>>> display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
>>> display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)
>>>
>>>
>>> 


@jfurcean
Copy link
Author

jfurcean commented Jul 3, 2021

It also works fine with QT PY Haxpress and the QT PY RP2040 without changing the order.

Adafruit CircuitPython 7.0.0-alpha.3-493-gc37f354d2 on 2021-07-02; Adafruit QT Py RP2040 with rp2040
>>> import busio
>>> import board
>>> import displayio
>>> import adafruit_displayio_ssd1306
>>> displayio.release_displays()
>>> i2c = busio.I2C(board.SCL1, board.SDA1)
>>> display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
>>> display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)
>>> 
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:

Code done running.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 7.0.0-alpha.3-493-gc37f354d2 on 2021-07-02; Adafruit QT Py RP2040 with rp2040
>>> import busio
>>> import board
>>> import displayio
>>> import adafruit_displayio_ssd1306
>>> displayio.release_displays()
>>> i2c = busio.I2C(board.SCL1, board.SDA1)
>>> display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
>>> display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=32)
>>> 
>>> 
>>> 

@jerryneedell
Copy link
Collaborator

it does seem like an issue with the esp32s2 ...
FWIW -- this works repeatedly with soft reboot

import busio
import board
import displayio
displayio.release_displays()
import adafruit_displayio_ssd1306

i2c = busio.I2C(board.SCL, board.SDA)

display_bus = displayio.I2CDisplay(i2c, device_address=0x3D)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=64)

@jerryneedell
Copy link
Collaborator

oops -- accidental close

@jerryneedell jerryneedell reopened this Jul 3, 2021
@deshipu
Copy link

deshipu commented Jul 3, 2021

Well -- that does not make senses since the code does the release, but for some reason, it has to be done before importing the ssd1306 library...

The adafruit_displayio_ssd1306 library doesn't do anything on import, other than setting a few constants: https://github.com/adafruit/Adafruit_CircuitPython_DisplayIO_SSD1306/blob/main/adafruit_displayio_ssd1306.py

This sounds like some kind of a race condition — maybe there is a delay required between releasing the displays and creating a new displayio display. Maybe because it's still updating one frame in the background?

@dhalbert
Copy link
Collaborator

dhalbert commented Jul 3, 2021

A garbage collection is done after each import, so I wonder if it's a storage management problem.

@tannewt tannewt added crash espressif applies to multiple Espressif chips labels Jul 8, 2021
@tannewt tannewt added this to the 7.0.0 milestone Jul 8, 2021
@tannewt tannewt self-assigned this Aug 24, 2021
microdev1 pushed a commit that referenced this issue Aug 25, 2021
This keeps the mutex info in the same spot in memory. "Statically
allocating it" with CircuitPython meant that the buffer moved when
the I2C object is moved to keep it alive for a display.

Fixes #4962
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug crash displayio espressif applies to multiple Espressif chips
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants