uart-echo
Open the debug UART at 115200 8N1, do one 50 ms read, write a fixed hello string, and close. There is no echo loop. The minimal demo for <alp/peripheral.h>'s UART class.
Source: examples/peripheral-io/uart-echo/.
board.yaml
som:
sku: E1M-AEN801
preset: e1m-evk
cores:
m55_hp:
app: ./src
peripherals: [uart]
diagnostics:
log_level: info
Source (abbreviated)
#include "alp/peripheral.h"
#include "alp/board.h" /* BOARD_UART_DEBUG */
int main(void)
{
(void)alp_init();
printf("[uart] open BOARD_UART_DEBUG @ 115200 8N1\n");
alp_uart_t *u = alp_uart_open(&(alp_uart_config_t){
.port_id = BOARD_UART_DEBUG, /* E1M EVK: ALP_E1M_UART0; E1M-X EVK: ALP_E1M_X_UART0 */
.baudrate = 115200,
.data_bits = 8,
.stop_bits = 1,
.parity = ALP_UART_PARITY_NONE,
});
if (u == NULL) {
printf("[uart] open failed: alp_last_error=%d\n", (int)alp_last_error());
printf("[uart] done\n");
return 0;
}
/* One read with a 50 ms timeout. */
uint8_t b = 0;
alp_status_t s = alp_uart_read(u, &b, 1, 50);
printf("[uart] read -> status=%d byte=0x%02x\n", (int)s, b);
/* Write a fixed greeting. */
static const uint8_t hello[] = "[uart] hello
";
s = alp_uart_write(u, hello, sizeof hello - 1);
printf("[uart] write -> %d\n", (int)s);
alp_uart_close(u);
printf("[uart] done\n");
return 0;
}
See also
<alp/peripheral.h>reference — UARTuart-rx-ringbuf— interrupt-driven variant- Examples overview
Questions about this page? Email contact@alplab.ai