UARTs
UARTs provide asynchronous serial I/O over TX/RX. Final’s type is UartPeriph. Instances: uart0, uart2, uart3, uart4 (common default). Optional RS-232 hardware flow control uses CTS/RTS when .flowHW is true. See the Pin Map.
Set transmission properties before enabling. Changing them while active is not allowed.
Properties (set before enable)
| Property | Values / default | Description |
|---|---|---|
| baud | > 0, def 115200 | bit rate |
| dataBits | 5..8, def 8 | data bits |
| stopBits | 1 or 2, def 1 | stop bits |
| parity | UartPeriph.parityNone (def), parityOdd, parityEven | parity |
| flowHW | bool, def false | if true, claims CTS/RTS pins |
| enabled | bool | open the port and start RX background read |
| path | readonly | device path (e.g. /dev/ttyAMA0) |
115200 uart4.baud!
8 uart4.dataBits!
1 uart4.stopBits!
UartPeriph.parityNone uart4.parity!
false uart4.flowHW!
true uart4.enabled!
Write
.write accepts an Int (one byte) or a ByteList:
0x41 uart4.write^ // 'A'
myBytes uart4.write^ // ByteList
Read with UartReader
Reading needs a byte budget, idle timeout, and optional delimiter. Use UartReader from .newReader^, set its properties, then foreach. The loop ends on timeout, max bytes, delimiter, or error. Check the readonly status fields afterward.
| Property | R/W | Description |
|---|---|---|
| maxN | R/W | max bytes this session; 0 = unlimited |
| timeout | R/W | idle ms between bytes (def 100) |
| untilByte | R/W | stop after this byte (0..255), or -1 for none |
| n | R | bytes delivered |
| timedOut | R | true if idle timeout ended the loop |
| hitDelim | R | true if untilByte was received |
| ok | R | false on hard error |
| err | R | error string when not ok |
Example
Loopback-style read until newline (same pattern as the hardware UART tests):
115200 uart0.baud!
true uart0.enabled!
115200 uart2.baud!
true uart2.enabled!
// TX on uart0
ByteList.new^ >xs
"hello\n" foreach i x:.append^ /foreach
xs> uart0.write^
// RX on uart2 until '\n'
uart2.newReader^ >ts
1000 t:.timeout!
0x0A t:.untilByte! // '\n'
ByteList.new^ >xs
t:peek foreach
i x:.append^
/foreach
// xs> holds the line including '\n' if hitDelim
t:.hitDelim@
t:.timedOut@
tdrop
x:drop
There is no UART demo under examples/pi/ yet; enable the matching overlays (e.g. uart0-pi5 / uart2-pi5) before testing on hardware.