Skip to content

supervisor.ticks_ms() causes crash #9434

@thirdagemoz

Description

@thirdagemoz

CircuitPython version

adafruit-circuitpython-adafruit_kb2040-en_US-8.2.10.uf2
adafruit-circuitpython-adafruit_kb2040-en_US-9.1.0.uf2

libs:
adafruit-circuitpython-bundle-8.x-mpy-20240716/
adafruit-circuitpython-bundle-9.x-mpy-20240709/

Code/REPL

import board
import usb_hid
import neopixel

import supervisor
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS

US_SAMPLE_TIME = 500
kbd = Keyboard(usb_hid.devices)
kbd_stream = KeyboardLayoutUS(kbd)

pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
pixel.brightness = 0.3


# Main loop, check if toe-stud pressed, also constantly measure
# ultrasound distance to foot
cycle = 0
tick_msecs = 0
while True:
    curr_msecs = supervisor.ticks_ms()
    if curr_msecs - tick_msecs > US_SAMPLE_TIME:
        if cycle == 0:
            cycle = 1
            pixel.fill(255)
        else:
            cycle = 0
            pixel.fill(0)

            sense_str = "AAA"
            kbd_stream.write(sense_str)
        tick_msecs = curr_msecs

Behavior

Dies after 1 minute, 5 seconds. No LED flashing or USB keyboard output. Replacing the supervisor.ticks_ms() function with a time.sleep() function runs without fail. I ran on several KB2040, and connected to the USB ports of two different linux machines and a Mac Studio, all fail in exactly the same way. Doing a gc.collect on each loop iteration has no affect. Log file shows only the USB connection occurrence. Adding debug statements points to the while loop failing to restart an iteration, but adding statements after the while loop do not run--it completely locks up. Reset successfully reruns but then fails again after 1 minute and 5 seconds. Erasing the filesystem and restoring the uf2 and libraries and code.py does not fix the problem. Fail exists in both version 8 and 9.

Description

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    supportissues that involve helping a user accomplish a task

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions