← index #1642PR #11915
Related · high · value 0.364
QUERY · ISSUE

stm32: Implement Asynchronous UART TX

openby ryannathansopened 2015-11-24updated 2018-02-17
enhancementport-stm32

I am attempting to write large blocks (eg: 2048 bytes) of data to the UART at low baudrates whilst attempting to execute other code. I've discovered that the UART TX is actually blocking until the write is completed. This is a bit of a pain...

This issue is for creating an asynchronous write option for UART. Related to #1533

Probably either interrupt or DMA driven. Should ideally behave like the UART RX does, with a definable buffer in python code, or block as it currently does.

Reading related issues it seems like #1422 has had some success using DMA. Personally, I don't require the callback as I'm not streaming from a file, just an existing bytearray in memory.

I haven't had a chance to read the huge threads on some of the issues I've found so I'm not 100% up to date yet...

CANDIDATE · PULL REQUEST

stm32/uart: Fix UART timeout issue with low baudrate.

mergedby yn386opened 2023-07-01updated 2023-09-01
port-stm32

MicroPython Version

v1.20.0-261-g813d559bc

Environment

NUCLEO-G474RE

How to reproduce

Execute this code:

from pyb import UART
uart = UART(1, 4800, bits=8, parity=None, stop=1)
print(uart)

print(uart.any())
print(uart.write("123"))
print(uart.write(b"abcd"))
print(uart.writechar(1))

Got result:

UART(1, baudrate=4800, bits=8, parity=None, stop=1, flow=0, timeout=0, timeout_char=4, rxbuf=64)
0
3
Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
OSError: [Errno 110] ETIMEDOUT

Detail of changes

timeout_char is calculated at
https://github.com/micropython/micropython/blob/813d559bc098eeaa1c6e0fa1deff92e666c0b458/ports/stm32/machine_uart.c#L253
However, if 13000 / baudrate is not divisible by baudrate (such as 4800, 9600, ...), calculated timeout will be less than actual timeout required.
To solve this issue, this PR rounds up timeout_char if 13000 / baudrate is not divisible by baudrate.

Since this PR affects test results using tests/pyb/uart.py, I also modified expected test result.

Effect of changes

Be able to write values with low baudlate.

UART(1, baudrate=4800, bits=8, parity=None, stop=1, flow=0, timeout=0, timeout_char=5, rxbuf=64)
0
3
4
None

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied