OSError: [Errno 110] ETIMEDOUT, STM32, asyncio #13315
Replies: 2 comments 4 replies
-
How is the UART configured? I recommend |
Beta Was this translation helpful? Give feedback.
-
Re synchronisation the need for this depends on the code that calls your synchronous await self.rx_stream.readinto(self.buffer) It can therefore be preempted by another task. The general solution is to use a await self.request_data()
await asyncio.sleep_ms(100)
data = await self.read_response() If all the data has been sent after the 100ms delay, preemption won't occur. But in that case you need to ensure that the UART read buffer is big enough to hold the worst-case message. I don't think this is ideal. I would use the following approach. The class would have a class UART_INST:
def __init__(self, uart_number,baudrate):
self.uart = UART(uart_number)
self.uart.init(baudrate, bits=8, parity=None, stop=1)
self.read_complete = asyncio.Event()
self.buffer = array.array('f',bytearray(80))
self.rx_stream = asyncio.StreamReader(self.uart)
self.tx_stream = asyncio.StreamWriter(self.uart, {})
self.read_task = asyncio.create_task(self._stream_read())
async def _stream_read(self):
while True:
await self.rx_stream.readinto(self.buffer)
self.read_complete.set()
await asyncio.sleep_ms(50) # Do you actually need this?
async def _read(self, n=None): # Now it does need to be async
self.read_complete.clear()
await self.read_complete.wait()
data = self.buffer[0:n].decode("utf-8")
return data
async def _write(self, data):
self.tx_stream.write(data)
await self.tx_stream.drain() Then your calling code would do: await self.request_data()
data = await self.read_response() # Won't return until a complete message has been received You immediately await data after requesting it, reducing the demands on the UART buffer. Restarting Within a running Incidentally your use of |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm getting Errno 110 on an STM32 (Nucleo H723ZG) using asyncio and could use some thoughts on what might be causing this.
I have two slightly different code bases running on two different systems. The one runs fine. Never has any issues. The other is running into this error every 12 to 24 hours. I don't know what I should be looking for to troubleshoot this. There is nothing that I am actually waiting on in my code.
My code is setup with a couple of tasks that run forever. I am reading some data from devices connected to UARTs. I poll them every 100 to 500 ms depending on what is connected. Interestingly enough, the one setup that is running fine is polling data every 10 ms.
The tasks just look like the below. This is just pseudocode but its nothing complicated.
I have been running low on ram when importing modules, but once everything is running I have around 16k consistently free.
Edit: I should note that this error is occurring in different tasks but always on the call to write data to a UART. Specifically it is occurring in the uasyncio/stream line 1 in write.
Beta Was this translation helpful? Give feedback.
All reactions