Skip to content

Crash to safe mode when passing spi_device inappropriate parameter #6576

@RetiredWizard

Description

@RetiredWizard

CircuitPython version

Adafruit CircuitPython 8.0.0-alpha.1-39-g4c20b3cb6-dirty on 2022-07-10; FeatherS2 with ESP32S2

Code/REPL

import board,busio
spi = busio.SPI(board.IO36, board.IO35, board.IO37)
from adafruit_bus_device import spi_device
t = spi_device.SPIDevice(spi,board.IO33,baudrate=250000, extra_clocks=8)

Behavior

Board crashes into safe mode.

Description

No response

Additional information

It looks to me like this it tied to the library being frozen into the CP build. If I create a test folder in the lib directory and move the .mpy files from adafruit_bus_devices. I can then replace the import with "from test import spi_device" and when the SPIDevice class is initialized I receive an error indicating that board.IO33 doesn't have the switch_to_output method rather than hard crashing.

 >>> import board,busio
 >>> spi = busio.SPI(board.IO36, board.IO35, board.IO37)
 >>> from test import spi_device
 >>> t = spi_device.SPIDevice(spi,board.IO33,baudrate=250000, extra_clocks=8)
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "adafruit_bus_device/spi_device.py", line 88, in __init__
 AttributeError: 'Pin' object has no attribute 'switch_to_output'

The DEBUG output of the crash is:

Guru Meditation Error: Core 0 panic'ed (LoadStoreError). Exception was unhandled.

Core 0 register dump:
PC : 0x400b23ca PS : 0x00060330 A0 : 0x800b2434 A1 : 0x3ffe0ea0
A2 : 0x3f013960 A3 : 0x00000001 A4 : 0x00000002 A5 : 0x00000007
A6 : 0x3f019408 A7 : 0x3ffe0f08 A8 : 0x8008f907 A9 : 0x3ffe0e60
A10 : 0x00000008 A11 : 0x00000001 A12 : 0x3ffe1090 A13 : 0x00000027
A14 : 0x00003516 A15 : 0x3ffd9975 SAR : 0x0000001a EXCCAUSE: 0x00000003
EXCVADDR: 0x3f013968 LBEG : 0x3ffe1090 LEND : 0x00000027 LCOUNT : 0x4002cb55

Backtrace:0x400b23c7:0x3ffe0ea00x400b2431:0x3ffe0ec0 0x400b7a44:0x3ffe0ee0 0x40098a11:0x3ffe0f30 0x4008e3ce:0x3ffe0f50 0x4008e4d9:0x3ffe0f70 0x4009ca21:0x3ffe0f90 0x40093266:0x3ffe1060 0x4008e3ce:0x3ffe10d0 0x4008e3f2:0x3ffe10f0 0x400d43d7:0x3ffe1110 0x400d4733:0x3ffe11b0 0x400a0955:0x3ffe1240 0x400a0cf6:0x3ffe1270 0x400a1067:0x3ffe12a0 0x401795b0:0x3ffe12c0

ELF file SHA256: a440778e64864986

CPU halted.

And the decoded backtrace:

/home/pi/circuitpython/ports/espressif/common-hal/digitalio/DigitalInOut.c:94
/home/pi/circuitpython/ports/espressif/../../shared-bindings/adafruit_bus_device/spi_device/SPIDevice.c:96
/home/pi/circuitpython/ports/espressif/../../py/objtype.c:1054
/home/pi/circuitpython/ports/espressif/../../py/runtime.c:665
/home/pi/circuitpython/ports/espressif/../../py/runtime.c:680
/home/pi/circuitpython/ports/espressif/../../py/vm.c:1021
/home/pi/circuitpython/ports/espressif/../../py/objfun.c:297
/home/pi/circuitpython/ports/espressif/../../py/runtime.c:665
/home/pi/circuitpython/ports/espressif/../../py/runtime.c:638
/home/pi/circuitpython/ports/espressif/../../shared/runtime/pyexec.c:146
/home/pi/circuitpython/ports/espressif/../../shared/runtime/pyexec.c:734
/home/pi/circuitpython/ports/espressif/../../main.c:823
/home/pi/circuitpython/ports/espressif/../../main.c:922
/home/pi/circuitpython/ports/espressif/supervisor/port.c:394
/home/pi/circuitpython/ports/espressif/build-unexpectedmaker_feathers2/esp-idf/../../esp-idf/components/freertos/port/port_common.c:141

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions