Skip to content

Hard fault using .send() inside asyncio #10329

Open
@phlidwsn

Description

@phlidwsn

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions