8000 Hard fault using .send() inside asyncio · Issue #10329 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Hard fault using .send() inside asyncio #10329

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

Open
phlidwsn opened this issue May 9, 2025 · 2 comments
Open

Hard fault using .send() inside asyncio #10329

phlidwsn opened this issue May 9, 2025 · 2 comments
Labels
async asyncio related bug crash rp2040 Raspberry Pi RP2040
Milestone

Comments

@phlidwsn
Copy link
phlidwsn commented May 9, 2025

Not sure if this is an actual issue that could be guarded against or just a neat way for the user(me) to be an idiot, but the following code causes a hard fault in CircuitPython.

Occurs when using .send() instead of .asyncio_send(). .asyncio_send() in the same code works just fine.

Hardware: Adafruit RP2040 RFM95 915Mhz

Code:

import board
import digitalio
from adafruit_rfm import rfm9x
import asyncio

class TestCode:
    def __init__(self):
        # Define radio frequency in MHz. Must match your
        # module. Can be a value like 915.0, 433.0, etc.
        RADIO_FREQ_MHZ = 915.0

        # Define Chip Select and Reset pins for the radio module.
        CS = digitalio.DigitalInOut(board.RFM_CS)
        RESET = digitalio.DigitalInOut(board.RFM_RST)

        # Initialise RFM95 radio
        self.radio = rfm9x.RFM9x(board.SPI(), CS, RESET, RADIO_FREQ_MHZ)
        self.radio.enable_crc = True
        self.radio.spreading_factor = 8
    
    async def xmit_job(self):
        while True:
            print("sending")
            self.radio.send(bytes("dsaklfjlkdsjflkasjdflkasjkljfklasjdflkjasdlkfjaskldjlkjfiasdjfalksdjfkalsdjf", "utf-8"))
            await asyncio.sleep(10)
            
    
    async def recv_job(self):
        pass
    
    async def main(self):
        await asyncio.gather(
            self.xmit_job(),
            self.recv_job()
                             )




test = TestCode()
asyncio.run(test.main())

"""
result:
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.
"""

@jerryneedell
Copy link
Collaborator
jerryneedell commented May 9, 2025

Hmmm. Nice catch!
Hopefully, an acceptable temporary work around is "don't do that" 😉

It would be nice to track down the root cause. Is it something in asyncio or is there a way to trap it without the hard fault.
Is there any reason why it should actually work?

@tannewt
Copy link
Member
tannewt commented May 9, 2025

Can you get the hard fault without the RFM library? I'll move this issue to the core since it is a crash.

6D0C
@tannewt tannewt transferred this issue from adafruit/Adafruit_CircuitPython_RFM May 9, 2025
@tannewt tannewt added bug crash rp2040 Raspberry Pi RP2040 async asyncio related labels May 9, 2025
@tannewt tannewt added this to the 10.0.x milestone May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async asyncio related bug crash rp2040 Raspberry Pi RP2040
Projects
None yet
Development

No branches or pull requests

3 participants
0