adafruit / circuitpython

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

TinyS3 board digitalio shared module does not work #8416

Closed qutefox closed 1 year ago

qutefox commented 1 year ago

CircuitPython version

Adafruit CircuitPython 8.2.6 on 2023-09-12; TinyS3 with ESP32S3

Code/REPL

import digitalio
import time
import board

time.sleep(5) # give us some time to update code via USB when we are stuck in a crash loop.
tmp = digitalio.DigitalInOut(board.D34)
tmp.direction = digitalio.Direction.OUTPUT # crashes the board

Behavior

Board crashes and hard resets

Description

When I try to set D34 pin as output using the digitalio module the board hard resets. This always happens. The board doesn't give any error message so finding the root cause was really hard.

Additional information

One workaround I've found is:

import digitalio
import time
import board

time.sleep(5) # give us some time to update code via USB when we are stuck in a crash loop.
tmp = digitalio.DigitalInOut(board.D34)
tmp.switch_to_output(True)

Then the board does not crash during setup. But when I try to set the value it will still crash so the workaround doesn't really help me for long:

tmp.value = False # crashes the board
tmp.switch_to_output(False) # this crashes the board as well, workaround doesn't work anymore
tannewt commented 1 year ago

Do other pins work ok? Does GPIO34 fail on other S3 boards?

anecdata commented 1 year ago

I can't reproduce:

Adafruit CircuitPython 8.2.6 on 2023-09-12; TinyS3 with ESP32S3
>>> import digitalio
>>> import board
>>> 
>>> tmp = digitalio.DigitalInOut(board.D34)
>>> tmp.direction = digitalio.Direction.OUTPUT
>>> tmp.value = True
>>> tmp.value = False
>>> 
>>> tmp.switch_to_input()
>>> tmp.value
False
>>> 
>>> tmp.switch_to_output(False)
>>> tmp.value = True
>>> tmp.value = False
>>> 

Output using first code snippet above as code.py:

[tio 13:26:31] Connected

Code stopped by auto-reload. Reloading soon.
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 8.2.6 on 2023-09-12; TinyS3 with ESP32S3
>>> 

Output from workaround code snippets above as code.py:

[tio 13:29:26] Connected

Code stopped by auto-reload. Reloading soon.
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 8.2.6 on 2023-09-12; TinyS3 with ESP32S3
>>> 
qutefox commented 1 year ago

Is there a way for me to somehow capture the reason of the crash on my board? Like a debugger just plugged in connected to some of the pins? Unexpected maker also said that I should downgrade the firmware and try 8.2.3 or 8.2.4 because he uses that and that is what I should use as well.

tannewt commented 1 year ago

DEBUG=1 builds of CP will usually output the ESP-IDF logging onto the UART. That's how I debug crashes. The adafruit discord is a good place to get help doing that if you need it. https://adafru.it/discord in #circuitpython-dev

qutefox commented 1 year ago

Okay. I can still reproduce the issue on my board. Going to make a build on my Ubuntu machine and come back here with my findings.

qutefox commented 1 year ago

I have the debug build.

(It was exciting to make it because the build dependencies had a mismatch:

It seems that the example code is not enough. First I had a lot more code running and since I got crashes and hard resets I started to komment out code segements and the very last bit was that digitalio code. Interestingly when I put back the digitalio my board crashes, if I remove my board does not crash.

Now on to the debug output:

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd0108,len:0x16a4
load:0x403b6000,len:0xeac
load:0x403ba000,len:0x2f7c
entry 0x403b6328
I (25) boot: ESP-IDF v4.4-dev-3608-gbbe2a1bf34 2nd stage bootloader
I (25) boot: compile time 11:13:59
I (25) boot: chip revision: 0
I (28) qio_mode: Enabling default flash chip QIO
I (33) boot.esp32s3: Boot SPI Speed : 80MHz
I (38) boot.esp32s3: SPI Mode       : QIO
I (43) boot.esp32s3: SPI Flash Size : 8MB
I (47) boot: Enabling RNG early entropy source...
W (53) bootloader_random: RNG for ESP32-S3 not currently supported
I (60) boot: Partition Table:
I (63) boot: ## Label            Usage          Type ST Offset   Length
I (71) boot:  0 nvs              WiFi data        01 02 00009000 00005000
I (78) boot:  1 otadata          OTA data         01 00 0000e000 00002000
I (86) boot:  2 ota_0            OTA app          00 10 00010000 00200000
I (93) boot:  3 ota_1            OTA app          00 11 00210000 00200000
I (100) boot:  4 uf2              factory app      00 00 00410000 00040000
I (108) boot:  5 ffat             Unknown data     01 81 00450000 003b0000
I (116) boot: End of partition table
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd0108,len:0x16a4
load:0x403b6000,len:0xeac
load:0x403ba000,len:0x2f7c
entry 0x403b6328
I (25) boot: ESP-IDF v4.4-dev-3608-gbbe2a1bf34 2nd stage bootloader
I (25) boot: compile time 11:13:59
I (25) boot: chip revision: 0
I (28) qio_mode: Enabling default flash chip QIO
I (33) boot.esp32s3: Boot SPI Speed : 80MHz
I (38) boot.esp32s3: SPI Mode       : QIO
I (43) boot.esp32s3: SPI Flash Size : 8MB
I (48) boot: Enabling RNG early entropy source...
W (53) bootloader_random: RNG for ESP32-S3 not currently supported
I (60) boot: Partition Table:
I (63) boot: ## Label            Usage          Type ST Offset   Length
I (71) boot:  0 nvs              WiFi data        01 02 00009000 00005000
I (78) boot:  1 otadata          OTA data         01 00 0000e000 00002000
I (86) boot:  2 ota_0            OTA app          00 10 00010000 00200000
I (93) boot:  3 ota_1            OTA app          00 11 00210000 00200000
I (101) boot:  4 uf2              factory app      00 00 00410000 00040000
I (108) boot:  5 ffat             Unknown data     01 81 00450000 003b0000
I (116) boot: End of partition table
I (620) esp_image: segment 0: paddr=00010020 vaddr=3c130020 size=4d710h (317200) map
I (673) esp_image: segment 1: paddr=0005d738 vaddr=3fc9cf70 size=028e0h ( 10464) load
I (676) esp_image: segment 2: paddr=00060020 vaddr=42000020 size=1282e4h (1213156) map
I (863) esp_image: segment 3: paddr=0018830c vaddr=3fc9f850 size=03540h ( 13632) load
I (866) esp_image: segment 4: paddr=0018b854 vaddr=40374000 size=18f70h (102256) load
I (888) esp_image: segment 5: paddr=001a47cc vaddr=600fe000 size=0102ch (  4140) load
I (900) boot: Loaded app from partition at offset 0x10000
I (900) boot: Disabling RNG early entropy source...
W (900) bootloader_random: RNG for ESP32-S3 not currently supported
I (918) spiram: Found 64MBit SPI RAM device
I (919) spiram: SPI RAM mode: sram 80m
I (919) spiram: PSRAM initialized, cache is in normal (1-core) mode.
I (924) cpu_start: Pro cpu up.
I (927) cpu_start: Starting app cpu, entry point is 0x40378728
I (0) cpu_start: App cpu up.
I (1852) spiram: SPI SRAM memory test OK
I (1860) cpu_start: Pro cpu start user code
I (1860) cpu_start: cpu freq: 240000000
I (1861) cpu_start: Application information:
I (1863) cpu_start: Project name:     circuitpython
I (1869) cpu_start: App version:      8.2.6
I (1874) cpu_start: Compile time:     Sep 24 2023 11:16:10
I (1880) cpu_start: ELF file SHA256:  f148ed9287beaa72...
I (1886) cpu_start: ESP-IDF:          630c2724f
I (1891) heap_init: Initializing. RAM available for dynamic allocation:
I (1899) heap_init: At 3FCAF008 len 0003A708 (233 KiB): D/IRAM
I (1905) heap_init: At 3FCE9710 len 00005724 (21 KiB): STACK/DRAM
I (1912) heap_init: At 3FCF0000 len 00008000 (32 KiB): DRAM
I (1918) heap_init: At 600FF040 len 00000FC0 (3 KiB): RTCRAM
I (1925) spi_flash: detected chip: gd
I (1929) spi_flash: flash io: dio
I (1934) sleep: Configure to isolate all GPIO pins in sleep state
I (1940) sleep: Enable automatic switching of GPIO sleep configuration
I (1947) coexist: coexist rom version e7ae62f
I (1952) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (10) gpio: GPIO[17]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (10) gpio: GPIO[18]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (20) gpio: GPIO[0]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (1030) gpio: GPIO[18]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1030) gpio: GPIO[17]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1040) gpio: GPIO[0]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1050) gpio: GPIO[1]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1060) gpio: GPIO[2]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1070) gpio: GPIO[3]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1080) gpio: GPIO[4]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1090) gpio: GPIO[5]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1100) gpio: GPIO[6]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1110) gpio: GPIO[7]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1110) gpio: GPIO[8]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1120) gpio: GPIO[9]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1130) gpio: GPIO[10]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1140) gpio: GPIO[11]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1150) gpio: GPIO[12]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1160) gpio: GPIO[13]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1170) gpio: GPIO[14]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1180) gpio: GPIO[15]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1190) gpio: GPIO[16]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1200) gpio: GPIO[17]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1210) gpio: GPIO[18]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1220) gpio: GPIO[21]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1230) gpio: GPIO[33]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1240) gpio: GPIO[34]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1250) gpio: GPIO[35]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1250) gpio: GPIO[36]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1260) gpio: GPIO[37]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1270) gpio: GPIO[38]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1280) gpio: GPIO[45]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1290) gpio: GPIO[46]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1300) gpio: GPIO[47]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1310) gpio: GPIO[48]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
E (1320) I2S: i2s_driver_uninstall(2047): I2S port 0 has not installed
E (1330) I2S: i2s_driver_uninstall(2047): I2S port 1 has not installed
E (1330) timer_group: timer_deinit(312): HW TIMER NEVER INIT ERROR
E (1340) timer_group: timer_deinit(312): HW TIMER NEVER INIT ERROR
E (1350) timer_group: timer_deinit(312): HW TIMER NEVER INIT ERROR
E (1360) timer_group: timer_deinit(312): HW TIMER NEVER INIT ERROR
I (1420) gpio: GPIO[0]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1420) gpio: GPIO[1]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1420) gpio: GPIO[2]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1430) gpio: GPIO[3]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1440) gpio: GPIO[4]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1450) gpio: GPIO[5]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1460) gpio: GPIO[6]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1470) gpio: GPIO[7]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1480) gpio: GPIO[8]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1490) gpio: GPIO[9]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1500) gpio: GPIO[10]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1510) gpio: GPIO[11]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1520) gpio: GPIO[12]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1530) gpio: GPIO[13]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1540) gpio: GPIO[14]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1550) gpio: GPIO[15]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1550) gpio: GPIO[16]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1560) gpio: GPIO[17]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1570) gpio: GPIO[18]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1580) gpio: GPIO[21]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1590) gpio: GPIO[33]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1600) gpio: GPIO[34]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1610) gpio: GPIO[35]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1620) gpio: GPIO[36]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1630) gpio: GPIO[37]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1640) gpio: GPIO[38]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1650) gpio: GPIO[45]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1660) gpio: GPIO[46]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1670) gpio: GPIO[47]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (1680) gpio: GPIO[48]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
E (1690) I2S: i2s_driver_uninstall(2047): I2S port 0 has not installed
E (1690) I2S: i2s_driver_uninstall(2047): I2S port 1 has not installed
I (1790) espidf: Reserving 0 bytes of psram
E (13450) i2c: i2c_driver_delete(411): i2c driver install error
I (13460) gpio: GPIO[34]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (13460) gpio: GPIO[36]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (13460) gpio: GPIO[37]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd0108,len:0x16a4
load:0x403b6000,len:0xeac
load:0x403ba000,len:0x2f7c
entry 0x403b6328

It complains about E (13450) i2c: i2c_driver_delete(411): i2c driver install error Trying to understand why. Maybe I should post my whole code. I use an IO expander over I2C.

from adafruit_mcp230xx.mcp23017 import MCP23017
mcp23017 = MCP23017(board.I2C())

And it initializes correctly. When the chip is not soldered I get an I2C error complaining about address 0x20 not being found. But now the code works (I2C init done for library without errors) until it crashes.

My number one suspicion is that the adafruit_mcp230xx library wraps the digitalio mode and offers similar things:

pin_power_12v_enable = mcp23017.get_pin(2)
 pin_power_12v_enable.switch_to_output(False)

Maybe the library messes up something and that is why digitalio calls causes some I2C crash. Will look into the source code of that library.

qutefox commented 1 year ago

Here is my full code if you are interested: tinys3_crashes.zip

dhalbert commented 1 year ago

Try using the 8.2.x branch if your main aim is to get a working build. The latest main was just updated to ESP-IDF v5.1, and probably has some regression.

@tannewt Note the jinja2 version skew issue above.

qutefox commented 1 year ago

Case can be closed. When I pull my gpio low it causes a short on the power rail and that causes the hard reset. Tannewt from the discord channel noticed that the reason of the startup in the debug output is "POWERON" so it isn't a code problem but a hardware problem on my part.