Skip to content

Raspberry Pi Pico - Soft reset doesn't clear out pin usage state #4838

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

Closed
dannystaple opened this issue Jun 1, 2021 · 4 comments
Closed
Labels
bug support issues that involve helping a user accomplish a task
Milestone

Comments

@dannystaple
Copy link

Firmware

Adafruit CircuitPython 6.2.0 on 2021-04-05; Raspberry Pi Pico with rp2040

Adafruit CircuitPython 6.2.0-beta.2 on 2021-03-01; Raspberry Pi Pico with rp2040

Code/REPL

import board
import displayio
import busio
from adafruit_st7789 import ST7789

spi = busio.SPI(board.GP18, MOSI=board.GP19)
while not spi.try_lock():
    pass
spi.configure(baudrate=24000000) # Configure SPI for 24MHz
spi.unlock()
tft_cs = board.GP17
tft_dc = board.GP16

displayio.release_displays()
display_bus = displayio.FourWire(spi, chip_select=tft_cs, command=tft_dc)

display = ST7789(display_bus, width=240, height=240, rowstart=80, rotation=180)

print("Hello on the display!")

Behavior

It runs the first time, but if I make changes and save (causing soft reset) or Ctrl-D for a soft reset, I get the following:

code.py output:
Traceback (most recent call last):
  File "code.py", line 5, in <module>
ValueError: GP18 in use

Description

Only seen so far with this SPI setup - but this is my first CircuitPython/Pico SPI device usage.

@dannystaple dannystaple added the bug label Jun 1, 2021
@tannewt tannewt added this to the Support milestone Jun 1, 2021
@tannewt tannewt added the support issues that involve helping a user accomplish a task label Jun 1, 2021
@tannewt
Copy link
Member

tannewt commented Jun 1, 2021

Displays hold onto their pins so that they live through the reset. You'll want a displayio.release_displays() before you reconstruct it.

@tannewt tannewt closed this as completed Jun 1, 2021
@tannewt
Copy link
Member

tannewt commented Jun 1, 2021

More specifically, you'll want it before you reconstruct the SPI.

@dannystaple
Copy link
Author

Thanks. It's a shame I can't use atexit for this. I'm thinking mini-game code that potentially has a big while loop, and I'm assuming the soft exit doesn't come through as an exception that I could handle with a finally clause. Are there any good patterns for that?

@tannewt
Copy link
Member

tannewt commented Jun 3, 2021

Thanks. It's a shame I can't use atexit for this. I'm thinking mini-game code that potentially has a big while loop, and I'm assuming the soft exit doesn't come through as an exception that I could handle with a finally clause. Are there any good patterns for that?

The MicroPython merge brought in atexit functionality but they lumped it into sys so I disabled it. It shouldn't be too hard to move and enable.

You may be interested in #3454 which was done with game code in mind too. It has mechanics for what to do after an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug support issues that involve helping a user accomplish a task
Projects
None yet
Development

No branches or pull requests

2 participants