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

Board enters safe mode after disconnect from 1 of 2 BLE connections. #9573

Open
FlyingThings opened this issue Aug 29, 2024 · 4 comments
Open

Comments

@FlyingThings
Copy link

CircuitPython version

Adafruit CircuitPython 9.1.1 on 2024-07-23; FeatherS3 with ESP32S3
Board ID:unexpectedmaker_feathers3
UID:0740D1DA1CCA

Code/REPL

import board
from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService
import neopixel
import time

def monitor():
    ble = BLERadio()
    #uart = UARTService()
    #advertisement = ProvideServicesAdvertisement(uart)
    pix = neopixel.NeoPixel(board.NEOPIXEL,10)
    tog = True
    last_time_tog = time.monotonic()
    
    while True:
        try:
            #connect to two uart devices.
            while ble.connected and any(UARTService in connection for connection in ble.connections) and len(ble.connections) == 2:
                                        

                try:
                    if right_paw_uart.in_waiting:
                        print(right_paw_uart.read(4))
                    if left_paw_uart.in_waiting:
                        print(left_paw_uart.read(4))
                    if time.monotonic()-last_time_tog>=1:
                        last_time_tog = time.monotonic()
                        print('here')
                        if tog:
                            pix.fill(0xff0000)
                            tog = not tog
                        else:
                            pix.fill(0)
                            tog = not tog
                except ConnectionError:
                    print('NOT CONNECTED')
                    break

            print("disconnected, scanning", len(ble.connections))
            try:
                for advertisement in ble.start_scan(ProvideServicesAdvertisement, timeout=1):
                    if UARTService not in advertisement.services:
                        continue
                    #ble.connect(advertisement)
                    if advertisement.complete_name == "RIGHTPAW":
                        right_paw = ble.connect(advertisement)
                        right_paw_uart = right_paw[UARTService]
                    if advertisement.complete_name == "LEFTPAW":
                        left_paw = ble.connect(advertisement)
                        left_paw_uart = left_paw[UARTService]
                    print(f"connected {advertisement.complete_name}")
                    break
            except ConnectionError:
                print('connection error:not connected')
            ble.stop_scan()
        except ConnectionError as er:
            print('IDK its a connection error:',er)
            time.sleep(1)
monitor()

Behavior

Board will connect to 2 devices "LEFTPAW" and "RIGHTPAW" normally, and receive messages as expected. Restarting one of the connected devices once is usually OK, code will reconnect normally. After a number of restarts of a connected device (sometimes up to 3 restarts) this board will hang, and then finally crash to safe mode.
Here is the caught error immediately before safe mode:

Connection has been disconnected and can no longer be used. Create a new connection.

And the safe mode message:

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.

Description

No response

Additional information

I have similar code running without issue on a Feather NRF52840. The connected devices are Circuit Playground Bluefruit boards running CircuitPython.

@tannewt
Copy link
Member

tannewt commented Sep 12, 2024

Please retest with the absolute newest build.

@FlyingThings
Copy link
Author

Same issue as described above. Here is the error after it restarts into safe mode:

Adafruit CircuitPython 9.1.3-2-gfad755d5e7 on 2024-09-12; FeatherS3 with ESP32S3
>>>
soft reboot

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.

I appreciate the help!

@tannewt
Copy link
Member

tannewt commented Sep 13, 2024

Thanks for the retest! It looks like you got the latest of the 9.1.x branch. Please try https://adafruit-circuit-python.s3.amazonaws.com/bin/unexpectedmaker_feathers3/en_US/adafruit-circuitpython-unexpectedmaker_feathers3-en_US-20240913-main-PR9619-64cb762.uf2 which is on the main branch and includes IDF updates.

@dhalbert
Copy link
Collaborator

Could you try 9.2.0-beta.0?

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

3 participants