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

Hard fault with Feather RP2350 + ST7789 display after resizing terminal followed by running a REPL command #10084

Open
samblenny opened this issue Feb 21, 2025 · 6 comments

Comments

@samblenny
Copy link

CircuitPython version and board name

Adafruit CircuitPython 9.2.4 on 2025-01-28; Adafruit Feather RP2350 with rp2350a

Code/REPL

from board import SPI, D5, D6                                                   
import displayio                                                                
from fourwire import FourWire                                                   
import supervisor                                                               
                                                                                
from adafruit_st7789 import ST7789                                              
                                                                                
                                                                                
# Initialize 320x240 ST7789 IPS display with terminal at 2x scale.              
# The 2x zoom makes it easier to read the display.                              
displayio.release_displays()                                                    
bus = FourWire(SPI(), chip_select=D5, command=D6)                               
display = ST7789(bus, width=320, height=240, rotation=270)                      
supervisor.reset_terminal(160, 120)                                             
zoom_2x = displayio.Group(scale=2)                                              
display.root_group = None                                                       
zoom_2x.append(displayio.CIRCUITPYTHON_TERMINAL)                                
display.root_group = zoom_2x

# To trigger the hard fault, connect to serial REPL and run a command like `1+1` or `print()`

Behavior

  1. When the board boots from a hard reset, the boot messages look normal, and I can open the REPL and get a prompt
  2. Editing a line of text at the REPL prompt works fine. But, as soon as I press Enter to run a command like 1+1, print("hello world"), or import board, the board resets. The only exception I found is if I press Enter on a blank line. In that case, I get another >>> prompt. A single space, a #, or anything else I tried would trigger a reset.
  3. Upon reconnecting to the serial terminal, it shows a hard fault message:
Auto-reload is off.
Running in safe mode! Not running saved code.

You are in safe mode because:
CircuitPython core code crashed hard. Whoops!
Hard fault: memory access or instruction error.
Please file an issue with your program at github.com/adafruit/circuitpython/issues.
Press reset to exit safe mode.

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

Description

Hardware setup:

Libraries:

Notes on Reproducer Code:

  • I tried reducing the reproducer to something smaller, but all of the included lines appear to be necessary to trigger the bug.
  • If I just do a supervisor.reset_terminal(160, 120) without changing anything about the root group, the display shows 4 tiled copies of the 160, 120 terminal. But, the characters look kinda glitched. It seems possible there might be some kind of buffer overflow thing going on.

Additional information

No response

@samblenny samblenny added the bug label Feb 21, 2025
@samblenny
Copy link
Author

I get the same hard fault with these additional firmware versions:

  • adafruit-circuitpython-adafruit_feather_rp2350-en_US-9.2.1.uf2
  • adafruit-circuitpython-adafruit_feather_rp2350-en_US-9.2.2.uf2
  • adafruit-circuitpython-adafruit_feather_rp2350-en_US-9.2.3.uf2

@samblenny
Copy link
Author

Also, it's not necessary to wire up the display just to reproduce the fault:

  1. I can get the same fault on the Feather RP2350 with the display disconnected
  2. I got the same hard fault result by running the reproducer above on a Metro RP2350 with no display connected
    (Adafruit CircuitPython 9.2.4 on 2025-01-28; Adafruit Metro RP2350 with rp2350b)

@samblenny
Copy link
Author

samblenny commented Feb 21, 2025

Another data point (thanks to @ Neradoc on discord for mentioning this):

If you register a release_displays atexit, like this:

import atexit
atexit.register(displayio.release_displays)

it stops the hard fault when you use the REPL. But, if your goal was to continue using the 2x zoom after code.py ends so you can have it for the REPL (perhaps with USB keyboard), then releasing the display doesn't help.

@tannewt
Copy link
Member

tannewt commented Feb 21, 2025

The zoom_2x = displayio.Group(scale=2) object will go away when the VM does. It is VM heap allocated. It should replace this with displayio.CIRCUITPYTHON_TERMINAL but I'm not sure why.

I think you want a settings.toml setting for terminal scale.

@samblenny
Copy link
Author

The zoom_2x = displayio.Group(scale=2) object will go away when the VM does.

Yeah... I figured something might be going out of scope, but the hard fault message said to file an issue, so I did.

I think you want a settings.toml setting for terminal scale.

Is that a thing that's possible? I didn't find any mention of such things in the docs.

@samblenny
Copy link
Author

I didn't find any mention of such things in the docs.

oh... actually... I just realized that the latest vs stable Environment variable docs are different, and I was looking at stable. Will CIRCUITPY_DISPLAY_WIDTH and CIRCUITPY_DISPLAY_HEIGHT work on something that's not a picodvi display? The latest docs page implies perhaps not?

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

No branches or pull requests

2 participants