uart-echo
UART RX → TX echo loop. The minimal demo for <alp/peripheral.h>'s UART class.
Source: examples/uart-echo/.
board.yaml
som:
sku: E1M-AEN701
preset: e1m-evk
cores:
m55_hp:
app: ./src
peripherals: [uart]
diagnostics:
log_level: info
Source (abbreviated)
#include <alp/peripheral.h>
#include <alp/e1m_pinout.h>
int main(void) {
alp_uart_t *uart = alp_uart_open(&(alp_uart_config_t){
.port_id = ALP_E1M_UART0,
.baudrate = 115200u,
.data_bits = 8,
.stop_bits = 1,
.parity = ALP_UART_PARITY_NONE,
});
if (uart == NULL) return -1;
uint8_t byte;
while (1) {
/* Block until a byte arrives (UINT32_MAX = wait forever), echo it. */
if (alp_uart_read(uart, &byte, 1, UINT32_MAX) == ALP_OK) {
alp_uart_write(uart, &byte, 1);
}
}
}
See also
<alp/peripheral.h>reference — UARTuart-rx-ringbuf— interrupt-driven variant- Examples overview
Questions about this page? Discuss in Community Forum