adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.01k stars 1.19k forks source link

SPI.deinit() crash #8278

Closed bill88t closed 3 days ago

bill88t commented 1 year ago

CircuitPython version

Adafruit CircuitPython 8.2.3 on 2023-08-11; Adafruit Feather ESP32-S3 TFT with ESP32S3

Code/REPL

import board
a = board.SPI()
a.deinit()

Behavior

[16:33:14.473] Disconnected
[16:33:15.474] Warning: Could not open tty device (No such file or directory)
[16:33:15.474] Waiting for tty device..
[16:33:17.477] Connected

Auto-reload is off.
Running in safe mode! Not running saved code.

You are in safe mode because:
CircuitPython core code crashed hard. Whoops!
Fault detected by hardware.
Please file an issue with your program at https://github.com/adafruit/circuitpython/issues.
Press reset to exit safe mode.

Description

No response

Additional information

No response

ladyada commented 1 year ago

well you def shouldnt be able to de'init it since its still being used by the TFT :) but should not hardcrash either

bill88t commented 1 year ago

Perhaps it would be best to have a check inside of the SPI type that prohibits it from being deinitialised. Having that exposed only to the C api could allow circuitpy to alloc it for "system usage" and prohibit it's deinit. Shall I go and give it a try?

ladyada commented 1 year ago

gooooood question - im going to let @tannewt or @jepler decide who/where it should be fixed :)

tannewt commented 1 year ago

Seems to me that the best way to fix is to have displayio check for deinit SPI before using it. If it is, then displayio can deinit itself.