adafruit / circuitpython

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

OnDiskBitmap appears to be corrupting memory #5008

Closed dhalbert closed 3 years ago

dhalbert commented 3 years ago

[simplified a bit from original issue]

CircuitPython version

7.0.0-alpha.4 on Tiny2040

Code/REPL

import board
import busio
import displayio
import digitalio
from adafruit_st7789 import ST7789
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
import usb_midi
from adafruit_midi.note_on          import NoteOn
from adafruit_midi.note_off         import NoteOff

keyboard = Keyboard(usb_hid.devices)
ctrl = Keycode.CONTROL
key0 = Keycode.S
key1 = Keycode.X
key2 = Keycode.C
key3 = Keycode.V
shortcuts = [key0, key1, key2, key3]

# Release any resources currently in use for the displays
displayio.release_displays()

#  spi display setup
spi = board.SPI()
tft_cs = board.D7
tft_dc = board.D5

display_bus = displayio.FourWire(
    spi, command=tft_dc, chip_select=tft_cs, reset=board.D6
)

#  display setup
display = ST7789(display_bus, width=240, height=240, rowstart=80)

#  bitmap setup
print(1, displayio)
bitmap = displayio.OnDiskBitmap(open("/parrot-240-sheet.bmp", "rb"))
print(2, displayio)

Behavior

Adafruit CircuitPython 7.0.0-alpha.4 on 2021-07-08; Adafruit QT Py RP2040 with rp2040
>>> import code1
1 <module 'displayio'>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "code1.py", line 39, in <module>
NameError: name 'displayio' is not defined
>>> 

Description

code is adapted from https://learn.adafruit.com/kitty-toe-bean-paw-keypad-color-tct/overview, adapted for TinyRP2040 pinout.

@cmora111 was trying the original Learn Guide program, and saw incorrect usb_hid errors. I tried the original program on a QT Py RP2040, and saw something like the above. I trimmed the program to what is above. Trimming it further (even removing comments!) causes the breakage above not to happen, so it appears to be some kind of memory corruption.

Additional information

No response

cmora111 commented 3 years ago

I have tested the same code on CP 6.x and it works fine.

dhalbert commented 3 years ago

Re-tested on a QT Py RP2040, and pruned the program a bit. I've revised the original post above.

The errors vary, so this appears to be memory corruption, and I think it's due to the OnDiskBitmap.

jepler commented 3 years ago

It seems likely to be related to the palette changes I introduced in 7. Assign it to me if you like.

dhalbert commented 3 years ago

It seems likely to be related to the palette changes I introduced in 7. Assign it to me if you like.

You are more the expert on this, sure, thanks. I am still doing the DMA debugging.

cmora111 commented 3 years ago

What release will the fix be in?

tannewt commented 3 years ago

What release will the fix be in?

It'll be in the next 7.0.0 alpha. Before that you can follow the Absolute Latest link from circuitpython.org/downloads and snag the latest build. (It takes an hour or two after merge but is then available.)

cmora111 commented 3 years ago

Thank you very much!!