uart-hello-world
The canonical "printf via UART" walkthrough: open a port with alp_uart_open(), send a greeting plus a monotonically-increasing counter every second, handle the error paths. The producer-only variant most vendor SDKs ship as their first tutorial — uart-echo is the bidirectional companion.
Source: examples/peripheral-io/uart-hello-world/.
Why not just printf?
Zephyr's printf lands on the console UART — a single, Kconfig-pinned device. Real apps often need to drive a different one: a Bluetooth modem on a secondary port, a GPS module, a stepper driver expecting TMC2209 datagrams, a debug pin that isn't the console.
alp_uart_*() opens any UART by portable instance ID (ALP_E1M_UART0, ALP_E1M_UART1) without touching CONFIG_CONSOLE_*. It also takes a byte buffer plus an explicit length — which is what you want for binary protocols. printf is text-only.
What it does
-
alp_init(), thenalp_uart_open()onALP_E1M_UART0. -
Builds its config from
ALP_UART_CONFIG_DEFAULT(ALP_E1M_UART0)— the macro fills identity from the ID and every other field with its canonical default, which is exactly 115200 8N1. Nothing to override for this app; override a field after the macro when a chip demands different framing:alp_uart_config_t cfg = ALP_UART_CONFIG_DEFAULT(ALP_E1M_UART0);cfg.baudrate = 9600; /* then pass &cfg to alp_uart_open */ -
alp_uart_write()ships astatic constgreeting with an explicit\r\n— serial terminals expect CR+LF, unlike stdout. -
Loops five times:
snprintfinto a bounded stack buffer, clamp the length (snprintf returns what would have been written), write it, wait a second. -
alp_uart_close()releases the SDK handle. It does not power down the controller or drop the line — on real hardware the UART keeps idling high. Use Zephyr'spm_device_action_runafter close if you truly need it off.
The example deliberately keeps the raw ALP_E1M_UART0 instance ID in view; uart-echo opens the same port by its board-macro alias. Both styles are first-class.
board.yaml
som:
sku: E1M-AEN801
preset: e1m-evk
pins:
- { e1m: E1M_UART0, macro: EVK_UART_PORT_DEBUG, doc: "Console UART exposed on the debug header" }
cores:
m55_hp:
app: ./src
peripherals:
- uart
diagnostics:
log_level: info
The uart entry becomes CONFIG_SERIAL=y in alp.conf, which also activates the SDK's alp_uart_* wrapper layer.
Expected output
On the SDK log console:
[uart-hello] open ALP_E1M_UART0 @ 115200 8N1
[uart-hello] greeting written
[uart-hello] tick 0 written
[uart-hello] tick 1 written
...
[uart-hello] done
On a terminal attached to ALP_E1M_UART0 itself:
Alp SDK uart-hello-world
tick 0
tick 1
tick 2
tick 3
tick 4
If the port can't open the example prints open failed: alp_last_error=<n> and exits cleanly. Most common causes: no alp-uart0 devicetree alias on this board, or the driver rejected the baudrate/framing combination with -ENOTSUP.
Status
Runs on native_sim/native/64; the harness latches on [uart-hello] done.
See also
<alp/peripheral.h>reference — UARTuart-echo— bidirectional companionuart-rx-ringbuf— interrupt-driven RX into a ring bufferhello-world— the same heartbeat over the console- Examples overview