Skip to content
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

Safe Mode: Hard fault: Memory access or instruction error / Internal watchdog timer expired. #10004

Open
mario872 opened this issue Jan 27, 2025 · 0 comments

Comments

@mario872
Copy link

mario872 commented Jan 27, 2025

CircuitPython version

Adafruit CircuitPython 9.2.3-14-g52b5b2da1a on 2025-01-26; Adafruit Feather ESP32-S3 TFT with ESP32S3

Code/REPL

import board
import time
import array
import pulseio

f = open("/codes.txt", "r") # https://github.com/mario872/Sonic-Screwdriver/blob/main/Software/src/codes.txt
# Just moved some lines around from https://raw.githubusercontent.com/adafruit/Adafruit_Learning_System_Guides/master/CircuitPython_TVBGone/codes.txt
input() # To make sure I can tell it when to start
count = 0
for line in f:
    code = eval(line)
    print(code)
    # If this is a repeating code, extract details
    try:
        repeat = code["repeat"]
        delay = code["repeat_delay"]
    except KeyError:  # by default, repeat once only!
        repeat = 1
        delay = 0
    # The table holds the on/off pairs
    table = code["table"]
    pulses = []  # store the pulses here
    # Read through each indexed element
    for i in code["index"]:
        pulses += table[i]  # and add to the list of pulses
    pulses.pop()  # remove one final 'low' pulse

    with pulseio.PulseOut(
        board.D13, frequency=code["freq"], duty_cycle=2**15
    ) as pulse:
        for i in range(repeat):
            pulse.send(array.array("H", pulses))
            time.sleep(delay)

    time.sleep(code["delay"])
    count += 1

Behavior

When running the above code it gets around 3-6 repeats in then I get:

Auto-reload is off.
Running in safe mode! Not running saved code.

You are in safe mode because:
CircuitPython core code crashed hard. Whoops!
Hard fault: memory access or instruction error.
Please file an issue with your program at github.com/adafruit/circuitpython/issues.
Press reset to exit safe mode.

Interestingly, when I run a more complicated program, with this script basically as a function instead, I get:

Auto-reload is off.
Running in safe mode! Not running saved code.

You are in safe mode because:
Internal watchdog timer expired.
Press reset to exit safe mode.

Description

N/A

Additional information

Running a very similar script on the RPi Pico 2 W didn't produce any error less than two weeks ago (with that build of CP from two weeks ago

Edit: Here's the longer program code: https://github.com/mario872/Sonic-Screwdriver/tree/main/Software/src/v5.3
Edit 2: Changing the pulseio.PulseOut line to:

pulse.deinit()
time.sleep(0.01)
pulse = pulseio.PulseOut(board.D13, frequency=code["freq"], duty_cycle=2**15)

Makes it work until line 128 of codes.txt, until it gives this error:

{'index': [0], 'freq': 6961, 'delay': 0.33, 'repeat': 2, 'repeat_delay': 0.127, 'table': [[143]]}
Traceback (most recent call last):
  File "test.py", line 34, in <module>
espidf.IDFError: Invalid argument

Then is goes into safe mode. Edit 4: (Hard Fault: memory access or instruction error)
Edit 3: It appears that then removing any line with an index of [0] fixes that issue, then changing the time.sleep(0.01) to time.sleep(1) stops CP from crashing at all.
Edit 5: There are no lines with and index of [0] until line 128, and with no delay it fails way before then.

@mario872 mario872 added the bug label Jan 27, 2025
@tannewt tannewt added this to the 9.2.x milestone Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants