Asynchronous UART TX on STM32 and Pyboard #9187
-
I have been using MicroPython on a few STM32 Nucleo boards (F0, L4, G0) and built a few small tools that handle multiple UART channels at the same time. I love how easy it is to set up UARTs to asynchronously receive data, and throw an interrupt when RX_IDLE. Does the Pyboard support multiple non-blocking calls to uart.write() (on different UART peripherals, of course) ? Research: |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 22 replies
-
Not at the moment unfortunately. Some of the ports (e.g. rp2) have a tx ring buffer and an IRQ that keeps writing out the buffer in the background (which is what lets flush and txdone work). The STM32 does not have this. Ideally, DMA support for the various busses (I2C, SPI, UART, etc) is something that would be great to support. |
Beta Was this translation helpful? Give feedback.
-
The easiest way to handle concurrent use of different UARTs is to use |
Beta Was this translation helpful? Give feedback.
-
Just checked the implementation of
|
Beta Was this translation helpful? Give feedback.
-
OK, I stand corrected. My testing was done with short bytearrays and mainly at high baudrates. Sending a 1000 byte array at 9600 baud, |
Beta Was this translation helpful? Give feedback.
-
Do you have to grab or push the large data blob in one take? Can't you nibble at the data for read, and nibble at the data when writing? The only requirement is a known terminator, right? Would this not address the issue at practical level? Not sure if this helps, but I have been playing with or using an asyncio wrapper (task) around just using UART.any(), and setting the task to self schedule using a custom decorator at a duration 0.1 seconds. For what I am doing this seems to be responsive enough, while still letting other tasks get time via asyncio even loop. I am nibbling away at strings that are between 1 and 512 or so, using ESP as bridge to a Pico H, sending json formatted strings that are actually encapsulated MQTT messages. I can do the same idea sending data base to ESP from sending the topic then the payload as different writes, or fragments of same, I just need to know that the terminator is, say 3 zero bytes for example. So sending 100 bytes, then 100, then 100, etc. until 3 zero bytes? I would think as long as you know the expected terminator, the number of reads or writes can be any number until terminator. |
Beta Was this translation helpful? Give feedback.
-
We've established (by code review and by testing) that A possible issue is that Does anyone know of any existing stream types other than UART and socket which may be passed to |
Beta Was this translation helpful? Give feedback.
-
The plot thickens. Even with |
Beta Was this translation helpful? Give feedback.
-
That's because at STM32 the UART code it waits for timeout_char instead of timeout. And timout_char will be forced to be at least 1 character time. Edit: Actually finally twice the time is used. |
Beta Was this translation helpful? Give feedback.
-
@jimmo As a general point I think TX should always be buffered as per RP2. Having Buffering also offers the prospect of abstracting the UART hardware and ensuring all ports behave similarly. Where an application requires timeouts, a task using |
Beta Was this translation helpful? Give feedback.
-
@peterhinch @jimmo With the MIMXRT port, the timeout setting is ignore for tx.write() at the moment. There is a timeout, but internally calculated based on the message size and the baudrate, ensuring that the call will not block forever. The only thing I could implement easily at the moment is a special treatment of timeout=0, which would return a timeout error if uart.write() cannot put all data immediately into the send buffer, but instead would block until all data is either sent or put into a send buffer. |
Beta Was this translation helpful? Give feedback.
Not at the moment unfortunately.
Some of the ports (e.g. rp2) have a tx ring buffer and an IRQ that keeps writing out the buffer in the background (which is what lets flush and txdone work). The STM32 does not have this.
Ideally, DMA support for the various busses (I2C, SPI, UART, etc) is something that would be great to support.